Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #2276 don't allow font scale to compound when entering nested table #2277

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
50 changes: 48 additions & 2 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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*]
Expand Down Expand Up @@ -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',
}
Expand All @@ -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
Expand Down