diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-10-25 21:56:28 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-25 21:56:28 -0600 |
| commit | 4d05ecb13cabfcc85dc7d1abab0b8ce871152d8f (patch) | |
| tree | ed4bede239f4da271d39d3eeb9b50022f5a3c3b0 | |
| parent | 10c9c87dbc70ff1e7beff7bedce991b9510c8992 (diff) | |
resolves #2358 support horizontal alignment on AsciiDoc table cell that only contains paragraphs (PR #2359)
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb | 5 | ||||
| -rw-r--r-- | spec/table_spec.rb | 49 |
3 files changed, 55 insertions, 0 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 8b118aa1..6b403054 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -26,6 +26,7 @@ Enhancements:: * upgrade to prawn-icon 3.1.x to add support for the Material Design Icons (`mdi`) as an available font-based icon set (PR #2334) * honor `GS_OPTIONS` environment variable for supplying additional parameters to command called by RGhost optimizer (#2337) * add support for passing a color mode to the default optimizer (#2347) +* support horizontal alignment on AsciiDoc table cell that only contains paragraphs (#2358) Improvements:: diff --git a/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb b/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb index 106bc29e..0a47b6c3 100644 --- a/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb +++ b/lib/asciidoctor/pdf/ext/prawn-table/cell/asciidoc.rb @@ -115,11 +115,16 @@ module Prawn font_size = font_info[:size] end font_style ||= font_info[:style] + if (@align == :center || @align == :right) && content.blocks.map(&:context).uniq == [:paragraph] + prev_text_align = pdf.instance_variable_get :@base_text_align + pdf.instance_variable_set :@base_text_align, @align + end pdf.font font_family, size: font_size, style: font_style do yield ensure pdf.font_color = prev_font_color if prev_font_color pdf.font_scale = prev_font_scale if prev_font_scale + pdf.instance_variable_set :@base_text_align, prev_text_align if prev_text_align end end end diff --git a/spec/table_spec.rb b/spec/table_spec.rb index fb7dba36..09bd0e4a 100644 --- a/spec/table_spec.rb +++ b/spec/table_spec.rb @@ -1877,6 +1877,55 @@ describe 'Asciidoctor::PDF::Converter - Table' do (expect pdf.lines).to eql ['10. ten', '11. eleven', '12. twelve', 'buckle', 'my', 'shoe'] end + it 'should honor horizontal alignment on AsciiDoc table cell' do + pdf = to_pdf <<~'EOS', analyze: true + [cols=1a] + |=== + |left + |=== + + [cols=^1a] + |=== + |center + |=== + + [cols=>1a] + |=== + |right + |=== + EOS + + page_width = pdf.pages[0][:size][0] + midpoint = page_width * 0.5 + left_text = pdf.find_unique_text 'left' + center_text = pdf.find_unique_text 'center' + right_text = pdf.find_unique_text 'right' + (expect left_text[:x]).to be < midpoint + (expect center_text[:x]).to be < midpoint + (expect center_text[:x] + center_text[:width]).to be > midpoint + (expect right_text[:x]).to be > midpoint + end + + it 'should not honor horizontal alignment on AsciiDoc table cell that contains non-paragraph blocks' do + pdf = to_pdf <<~'EOS', analyze: true + [cols=>1a] + |=== + | + left + + ''' + + left + |=== + EOS + + page_width = pdf.pages[0][:size][0] + midpoint = page_width * 0.5 + left_texts = pdf.find_text 'left' + (expect left_texts[0][:x]).to be < midpoint + (expect left_texts[1][:x]).to be < midpoint + end + it 'should convert nested table' do pdf = to_pdf <<~'EOS', analyze: true [cols="1,2a"] |
