Skip to content

Commit

Permalink
resolves #1368 use specified column widths to avoid bugs in column wi…
Browse files Browse the repository at this point in the history
…dth calculation when using colspans (PR #2200)
  • Loading branch information
mojavelinux committed May 22, 2022
1 parent 4c03f53 commit 3853f10
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
This document provides a high-level view of the changes to the {project-name} by release.
For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.

== Unreleased

Bug Fixes::

* use specified column widths to avoid bugs in column width calculation when using colspans (#1368)

== 2.0.1 (2022-05-21) - @mojavelinux

Bug Fixes::
Expand Down
1 change: 1 addition & 0 deletions lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,7 @@ def convert_table node

left_padding = right_padding = nil
table table_data, table_settings do
@column_widths = column_widths unless column_widths.empty?
# NOTE: call width to capture resolved table width
table_width = width
@pdf.ink_table_caption node, alignment, table_width, caption_max_width if node.title? && caption_end == :top
Expand Down
61 changes: 61 additions & 0 deletions spec/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2834,6 +2834,67 @@
(expect pdf.find_text 'cell').to have_size 2
end

it 'should not allow colspan to cause table to exceed width of bounds' do
pdf_theme = { page_margin: 36 }
input = <<~'EOS'
[cols="1,1,1,2",grid=none,frame=sides]
|===
|a 3+|b
2+|c |d >|z
|===
EOS

pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true
lines = (to_pdf input, pdf_theme: pdf_theme, analyze: :line).lines
page_width = pdf.pages[0][:size][0]
right_margin_x = page_width - 36
right_border_x = lines.max_by {|l| l[:from][:x] }[:from][:x]
z_text = pdf.find_unique_text 'z'
(expect right_border_x).to eql right_margin_x
(expect z_text[:x]).to be < right_margin_x
end

it 'should not allow colspan to cause stretch table with autowidth columns to exceed width of bounds' do
pdf_theme = { page_margin: 36 }
input = <<~'EOS'
[.stretch%autowidth,grid=none,frame=sides]
|===
|a 3+|b
2+|c |dddddddddddddddddddddddddddddddddddddddddddddddddd >|z
|===
EOS

pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true
lines = (to_pdf input, pdf_theme: pdf_theme, analyze: :line).lines
page_width = pdf.pages[0][:size][0]
right_margin_x = page_width - 36
right_border_x = lines.max_by {|l| l[:from][:x] }[:from][:x]
z_text = pdf.find_unique_text 'z'
(expect right_border_x).to eql right_margin_x
(expect z_text[:x]).to be < right_margin_x
end

it 'should not allow colspan to cause table to exceed width of bounds when also using rowspan' do
pdf_theme = { page_margin: 36 }
input = <<~'EOS'
[cols="1,1,1,1,1,4",grid=none,frame=sides]
|===
.3+|a 5.+|bcd
.2+|e |f |g |h >|z
|one |more |time |fin
|===
EOS

pdf = to_pdf input, pdf_theme: pdf_theme, analyze: true
lines = (to_pdf input, pdf_theme: pdf_theme, analyze: :line).lines
page_width = pdf.pages[0][:size][0]
right_margin_x = page_width - 36
right_border_x = lines.max_by {|l| l[:from][:x] }[:from][:x]
z_text = pdf.find_unique_text 'z'
(expect right_border_x).to eql right_margin_x
(expect z_text[:x]).to be < right_margin_x
end

it 'should honor rowspan on cell in body row' do
pdf = to_pdf <<~'EOS', analyze: true
[cols=2*^.^]
Expand Down

0 comments on commit 3853f10

Please sign in to comment.