From e23b16afd4d8e164ea593f198e1d25de40ca473c Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 12 Feb 2024 03:12:21 -0700 Subject: [PATCH] resolves #2492 don't warn about missing character in fallback font when inline image is advanced to next page skip fragment for inline image when analyzing fragment for font support --- CHANGELOG.adoc | 1 + .../pdf/ext/prawn/formatted_text/box.rb | 2 ++ spec/image_spec.rb | 31 ++++++++++++++++--- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index a8486d4bb..4a7deb1f1 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -41,6 +41,7 @@ Improvements:: Bug Fixes:: +* don't warn about missing character in fallback font when inline image is advanced to next page (#2492) * correctly map all icons from FontAwesome 4 (#2373) * resolve remote image in document title or section title with autogenerated ID * keep caret between items in menu macro with previous item if items wrap diff --git a/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb b/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb index 4b140bdd6..0bdaa0ad1 100644 --- a/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb +++ b/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb @@ -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 = {} diff --git a/spec/image_spec.rb b/spec/image_spec.rb index bdfcf873c..4fb1abdc0 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -2230,6 +2230,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 <<~END, pdf_theme: { extends: 'default-with-font-fallbacks' } + #{filler} + + #{'x' * 200} Look for the image:square.png[]. + END + (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).not_to 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 <<~'END', 'image-inline-extends-line-height.pdf' see tux run + @@ -2268,9 +2286,9 @@ 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 <<~'END', attribute_overrides: { 'pdf-theme' => 'base' }, analyze: :image + pdf = to_pdf <<~'END', attribute_overrides: { 'pdf-theme' => 'base' } :pdf-page-size: A6 :pdf-page-layout: landscape @@ -2278,8 +2296,13 @@ def traverse node image:square.png[pdfwidth=7cm] END - (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).not_to log_message using_log_level: :INFO end