From cb6782a1ae09a4276122f579401e38f7143200af Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Sat, 9 Jul 2022 13:06:11 -0600 Subject: [PATCH] resolves #2276 don't allow font scale to compound when entering nested table --- CHANGELOG.adoc | 1 + lib/asciidoctor/pdf/converter.rb | 3 ++ spec/table_spec.rb | 50 ++++++++++++++++++++++++++++++-- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 7d4d1069a..09732f3e0 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -10,6 +10,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co Bug Fixes:: * fix position of background color on caption with outside margin (#2271) +* don't allow font scale to compound when entering nested table (#2276) == 2.1.4 (2022-06-26) - @mojavelinux diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index a4a333a9b..2712393aa 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -1994,6 +1994,7 @@ def convert_table node num_cols = node.columns.size table_header_size = false theme = @theme + prev_font_scale, @font_scale = @font_scale, 1 if node.document.nested? tbl_bg_color = resolve_theme_color :table_background_color # QUESTION: should we fallback to page background color? (which is never transparent) @@ -2337,6 +2338,8 @@ def convert_table node theme_margin :block, :bottom, (next_enclosed_block node) rescue ::Prawn::Errors::CannotFit log :error, (message_with_context 'cannot fit contents of table cell into specified column width', source_location: node.source_location) + ensure + @font_scale = prev_font_scale if prev_font_scale end def convert_thematic_break node diff --git a/spec/table_spec.rb b/spec/table_spec.rb index 8d5c69f32..14714d410 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -1850,6 +1850,41 @@ (expect nested_cell1[:x]).to be < nested_cell2[:x] end + it 'should not compound font scale in nested document' do + pdf = to_pdf <<~'EOS', pdf_theme: { table_font_size: 21 }, analyze: true + |=== + |foo + a| + bar + !=== + !yin !yang + !=== + baz + |=== + EOS + + (expect pdf.text.map {|it| it[:font_size] }.uniq).to eql [21] + end + + it 'should apply uniform font scale to table and nested table' do + pdf = to_pdf <<~'EOS', pdf_theme: { sidebar_font_size: 8.4 }, analyze: true + **** + before + |=== + |foo + a| + bar + !=== + !yin !yang + !=== + baz + |=== + **** + EOS + + (expect pdf.text.map {|it| it[:font_size] }.uniq).to eql [8.4] + end + it 'should restore counter after computing height of table cell in scratch document' do pdf = to_pdf <<~'EOS', analyze: true [cols=2*] @@ -2107,6 +2142,7 @@ it 'should scale font size of nested blocks proportionally' do pdf_theme = { + code_font_size: 14, table_font_size: 8.5, table_font_family: 'Helvetica', } @@ -2121,15 +2157,25 @@ .... literal block inside table .... + + !=== + a! + .... + literal block inside nested table + .... + !=== |=== EOS outside_text = (pdf.find_text 'literal block outside table')[0] (expect outside_text[:font_name]).to eql 'mplus1mn-regular' - (expect outside_text[:font_size]).to eql 11 + (expect outside_text[:font_size]).to eql 14 inside_text = (pdf.find_text 'literal block inside table')[0] (expect inside_text[:font_name]).to eql 'mplus1mn-regular' - (expect inside_text[:font_size]).to be < 9 + (expect inside_text[:font_size]).to (be_within 0.001).of 11.333 + nested_text = (pdf.find_text 'literal block inside nested table')[0] + (expect nested_text[:font_name]).to eql 'mplus1mn-regular' + (expect nested_text[:font_size]).to (be_within 0.001).of 11.333 end it 'should scale font size of nested blocks consistently, even if table is nested inside a block' do