summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2022-07-30 23:58:38 -0600
committerDan Allen <dan.j.allen@gmail.com>2022-07-31 02:47:08 -0600
commitee66cf4aa175005182a070dcb519391b326dd062 (patch)
tree13a8ef8a264a737fb328d52402c4f7b8a40be16a
parentec04894f5114d6bc321bb8d1dd95fbc51443cf24 (diff)
apply text transform and formatting when computing height of background for caption
-rw-r--r--CHANGELOG.adoc3
-rw-r--r--lib/asciidoctor/pdf/converter.rb2
-rw-r--r--spec/listing_spec.rb50
3 files changed, 53 insertions, 2 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index ef397343..37c818b0 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -9,7 +9,8 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co
Bug Fixes::
-* apply text transformation and formatting when checking height of heading for orphan prevention
+* apply text transform and formatting when checking height of heading for orphan prevention
+* apply text transform and formatting when computing height of background for caption
== 2.2.0 (2022-07-22) - @mojavelinux
diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb
index 57e6638c..3df0e3e8 100644
--- a/lib/asciidoctor/pdf/converter.rb
+++ b/lib/asciidoctor/pdf/converter.rb
@@ -3103,7 +3103,7 @@ module Asciidoctor
opts = opts.merge inherited
end
unless scratch? || !(bg_color = @theme[%(#{category_caption}_background_color)] || @theme.caption_background_color)
- caption_height = height_of_typeset_text string
+ caption_height = height_of_typeset_text string, inline_format: true, text_transform: @text_transform
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 } }
diff --git a/spec/listing_spec.rb b/spec/listing_spec.rb
index ad042396..0c1ba612 100644
--- a/spec/listing_spec.rb
+++ b/spec/listing_spec.rb
@@ -541,6 +541,56 @@ describe 'Asciidoctor::PDF::Converter - Listing' do
(expect title_text[:font_size].round).to eql 10
end
+ it 'should apply text transform when computing height of background on caption' do
+ pdf_theme = {
+ code_caption_font_color: 'ffffff',
+ code_caption_font_style: 'normal',
+ code_caption_background_color: '3399FF',
+ code_caption_text_transform: 'uppercase',
+ code_caption_margin_outside: 10,
+ }
+
+ pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: true
+ .Caption with background color that spans multiple lines because of the text transform
+ ----
+ content
+ ----
+ EOS
+
+ title_text = pdf.find_unique_text %r/^CAPTION WITH BACKGROUND COLOR/
+ (expect title_text[:font_color]).to eql 'FFFFFF'
+ (expect title_text[:font_name]).to eql 'NotoSerif'
+ (expect pdf.pages[0][:raw_content]).to include %(/DeviceRGB cs\n0.2 0.6 1.0 scn\n48.24 775.908 498.8 29.982 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 apply text formatting when computing height of background on caption' do
+ pdf_theme = {
+ code_caption_font_color: 'ffffff',
+ code_caption_font_style: 'normal',
+ code_caption_background_color: '3399FF',
+ code_caption_margin_outside: 10,
+ }
+
+ pdf = to_pdf <<~'EOS', pdf_theme: pdf_theme, analyze: true
+ .Caption with background color that contains _inline formatting_ but does not wrap
+ ----
+ content
+ ----
+ EOS
+
+ title_text = pdf.find_unique_text %r/^Caption with background color/
+ (expect title_text[:font_color]).to eql 'FFFFFF'
+ (expect title_text[:font_name]).to eql 'NotoSerif'
+ (expect (pdf.find_unique_text 'inline formatting')[:font_name]).to eql 'NotoSerif-Italic'
+ (expect pdf.pages[0][:raw_content]).to include %(\n0.2 0.6 1.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 place caption below block' do
pdf_theme = { code_caption_end: 'bottom' }