Skip to content

Commit

Permalink
backport fix for #2492 don't warn about missing character in fallback…
Browse files Browse the repository at this point in the history
… font when inline image is advanced to next page

skip fragment for inline image when analyzing fragment for font support
  • Loading branch information
mojavelinux committed Feb 16, 2024
1 parent 7bf5eeb commit 82fa03e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ For a detailed view of what has changed, refer to the {url-repo}/commits/main[co

Bug Fixes::

* don't warn about missing character in fallback font when inline image is advanced to next page (#2492)
* support toc start at value for page numbering and running content when toc is added using macro (#2489)
* fix page number of index entries in prepress book when page numbering starts at toc or after toc and toc is inserted using macro (#2487)

Expand Down
2 changes: 2 additions & 0 deletions lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def draw_fragment_overlay_styles fragment
end

# help Prawn correctly resolve which font to analyze, including the font style
# also instruct Prawn to ignore fragment for inline image since the text is just a placeholder
def analyze_glyphs_for_fallback_font_support fragment_hash
return [fragment_hash] if fragment_hash[:image_obj]
fragment_font = fragment_hash[:font] || (original_font = @document.font.family)
effective_font_styles = @document.font_styles
fragment_font_opts = {}
Expand Down
31 changes: 27 additions & 4 deletions spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2150,6 +2150,24 @@ def traverse node
(expect to_file).to visually_match 'image-wrap-inline.pdf'
end

it 'should not warn about missing image placeholder char in fallback font when image is advanced to next page' do
(expect do
filler = %w(filler) * 26 * %(\n\n)
pdf = to_pdf <<~EOS, pdf_theme: { extends: 'default-with-font-fallbacks' }
#{filler}
#{'x' * 200} Look for the image:square.png[].
EOS
(expect pdf.pages).to have_size 2
(expect get_images pdf).to have_size 1
(expect (get_images pdf, 1)).to be_empty
(expect (get_images pdf, 2)).to have_size 1
pdf.pages.each do |page|
(expect page.text).not_to include ?\u2063
end
end).to not_log_message using_log_level: :INFO
end

it 'should increase line height if height if image height is more than 1.5x line height', visual: true do
to_file = to_pdf_file <<~'EOS', 'image-inline-extends-line-height.pdf'
see tux run +
Expand Down Expand Up @@ -2188,18 +2206,23 @@ def traverse node
(expect to_file).to visually_match 'image-inline-scale-down-height.pdf'
end

it 'should not warn about missing glyph for image placeholder char when using AFM font' do
it 'should not warn about missing image placeholder char in AFM font when image is advanced to next page' do
(expect do
pdf = to_pdf <<~'EOS', attribute_overrides: { 'pdf-theme' => 'base' }, analyze: :image
pdf = to_pdf <<~'EOS', attribute_overrides: { 'pdf-theme' => 'base' }
:pdf-page-size: A6
:pdf-page-layout: landscape
before
image:square.png[pdfwidth=7cm]
EOS
(expect (images = pdf.images)).to have_size 1
(expect images[0][:page_number]).to be 2
(expect pdf.pages).to have_size 2
(expect get_images pdf).to have_size 1
(expect (get_images pdf, 1)).to be_empty
(expect (get_images pdf, 2)).to have_size 1
pdf.pages.each do |page|
(expect page.text).not_to include ?\u2063
end
end).to not_log_message using_log_level: :INFO
end

Expand Down

0 comments on commit 82fa03e

Please sign in to comment.