diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-07-09 23:45:14 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-09 23:45:14 -0600 |
| commit | 7a7c7ee4c12e3d62b3419607354b0a2977bed6fc (patch) | |
| tree | d91ff5c52c71f17531056fb20b4b99214b5cea10 | |
| parent | e296c4619af0a8e162832c988a4c839a1a283ab5 (diff) | |
resolves #2276 don't allow font scale to compound when entering nested table (PR #2277)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 3 | ||||
| -rw-r--r-- | spec/table_spec.rb | 50 |
3 files changed, 52 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 7d4d1069..09732f3e 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 a4a333a9..2712393a 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -1994,6 +1994,7 @@ module Asciidoctor 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 @@ module Asciidoctor 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 8d5c69f3..14714d41 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -1850,6 +1850,41 @@ describe 'Asciidoctor::PDF::Converter - Table' do (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 @@ describe 'Asciidoctor::PDF::Converter - Table' do 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 @@ describe 'Asciidoctor::PDF::Converter - Table' do .... 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 |
