summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-05-22 13:01:20 -0600
committerGitHub <noreply@github.com>2022-05-22 13:01:20 -0600
commit3853f10d3c8c73b5233d19a7ac83f31d58d9fb51 (patch)
treea888d9dde34a5f5ceb4bce41fca71f3bae861c6c
parent4c03f53b8ab3b3a691cd3a190362ae873db49dc0 (diff)
resolves #1368 use specified column widths to avoid bugs in column width calculation when using colspans (PR #2200)
-rw-r--r--CHANGELOG.adoc6
-rw-r--r--lib/asciidoctor/pdf/converter.rb1
-rw-r--r--spec/table_spec.rb61
3 files changed, 68 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index 2bae7375..4487cc6e 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -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::
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index a8f96433..0766d559 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -2167,6 +2167,7 @@ module Asciidoctor
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
diff --git a/spec/table_spec.rb b/spec/table_spec.rb
index b3e00aa2..70d45614 100644
--- a/spec/table_spec.rb
+++ b/spec/table_spec.rb
@@ -2834,6 +2834,67 @@ describe 'Asciidoctor::PDF::Converter - Table' do
(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*^.^]