diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2022-07-03 01:21:38 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-07-03 01:21:38 -0600 |
| commit | 37c22535e259ceebf4a7756f8fe1262abfcd2524 (patch) | |
| tree | 101002c249751d4e43739159c30e651a45f702cb | |
| parent | 5c26c4b68a280b239e1284be2c95c18256c98873 (diff) | |
resolves #2271 fix position of background color on caption with outside margin (PR #2272)
| -rw-r--r-- | CHANGELOG.adoc | 4 | ||||
| -rw-r--r-- | lib/asciidoctor/pdf/converter.rb | 3 | ||||
| -rw-r--r-- | spec/listing_spec.rb | 32 |
3 files changed, 38 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 42fdf986..2fce2276 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -16,6 +16,10 @@ Enhancements:: * add `--theme` option to CLI as shorthand for `-a pdf-theme` (#2250) * add `--sourcemap` option to CLI to enable `:sourcemap` option on processor (#2265) +Bug Fixes:: + +* fix position of background color on caption with outside margin (#2271) + == 2.1.4 (2022-06-26) - @mojavelinux Improvements:: diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index d4339661..2c1f9952 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -3082,7 +3082,8 @@ module Asciidoctor end unless scratch? || !(bg_color = @theme[%(#{category_caption}_background_color)] || @theme.caption_background_color) caption_height = height_of_typeset_text string - fill_at = [bounds.left, cursor + (margin[:top] || 0)] + fill_at = [bounds.left, cursor] + fill_at[1] -= (margin[:top] || 0) unless at_page_top? float { bounding_box(fill_at, width: container_width, height: caption_height) { fill_bounds bg_color } } end indent(*indent_by) do diff --git a/spec/listing_spec.rb b/spec/listing_spec.rb index 7b2180f7..a778f031 100644 --- a/spec/listing_spec.rb +++ b/spec/listing_spec.rb @@ -492,6 +492,7 @@ describe 'Asciidoctor::PDF::Converter - Listing' do code_caption_font_color: 'ffffff', code_caption_font_style: 'bold', code_caption_background_color: 'AA0000', + code_caption_margin_outside: 10, code_background_color: 'transparent', code_border_radius: 0, } @@ -507,6 +508,37 @@ describe 'Asciidoctor::PDF::Converter - Listing' do (expect title_text[:font_color]).to eql 'FFFFFF' (expect title_text[:font_name]).to eql 'NotoSerif-Bold' (expect pdf.pages[0][:raw_content]).to include %(/DeviceRGB cs\n0.66667 0.0 0.0 scn\n48.24 790.899 498.8 14.991 re) + (expect title_text[:y]).to be > 790.899 + (expect title_text[:y]).to (be_within 5).of 790.899 + (expect title_text[:font_size].round).to eql 10 + end + + it 'should allow theme to set background color on caption with outside margin that follows other text' do + pdf_theme = { + code_caption_font_color: 'ffffff', + code_caption_font_style: 'bold', + code_caption_background_color: 'AA0000', + code_caption_margin_outside: 10, + code_background_color: 'transparent', + code_border_radius: 0, + } + + pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: true + before + + .Caption with background color + ---- + content + ---- + EOS + + title_text = pdf.find_unique_text 'Caption with background color' + (expect title_text[:font_color]).to eql 'FFFFFF' + (expect title_text[:font_name]).to eql 'NotoSerif-Bold' + (expect pdf.pages[0][:raw_content]).to include %(\n0.66667 0.0 0.0 scn\n48.24 753.119 498.8 14.991 re) + (expect title_text[:y]).to be > 753.119 + (expect title_text[:y]).to (be_within 5).of 753.119 + (expect title_text[:font_size].round).to eql 10 end it 'should allow theme to place caption below block' do |
