summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2021-01-08 04:37:27 -0700
committerDan Allen <dan.j.allen@gmail.com>2021-01-08 04:37:27 -0700
commitab937f907ac8a42d8cba19556cf9fbdba6e278f4 (patch)
tree99360ff52c97199126aa91292beaabdafebb7616
parent93f67b4726f00ba8647a79b6d099f1a6e8494e0b (diff)
backport fix for #1858 deduplicate inline image fragments that have been split up
-rw-r--r--CHANGELOG.adoc1
-rw-r--r--lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb9
-rw-r--r--lib/asciidoctor/pdf/formatted_text/transform.rb1
-rw-r--r--spec/image_spec.rb9
4 files changed, 19 insertions, 1 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc
index ece3c97c..29d6e9ae 100644
--- a/CHANGELOG.adoc
+++ b/CHANGELOG.adoc
@@ -12,6 +12,7 @@ Bug Fixes::
* restore compatiblity with Asciidoctor 2.0.12 when using Pygments (#1846)
* fix numeric assertions in test suite (#1542)
* keep caption with image when image is scaled down to fit page (#1803)
+* prevent inline image from rendering multiple times if fallback font is used for alt text (#1858)
* disable cache tests if open-uri-cache gem is not available
* disable hyphen tests if text-hyphen gem is not available
* compensate for change in how character_spacing is applied in FontMetricCache#width_of after Prawn 2.2.2
diff --git a/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb b/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb
index 32a16fd1..7637eb00 100644
--- a/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb
+++ b/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb
@@ -39,8 +39,14 @@ module Asciidoctor::PDF::FormattedText
scratch = doc.scratch?
available_w = doc.bounds.width
available_h = doc.page.empty? ? doc.cursor : doc.bounds.height
+ last_fragment = {}
raw_image_fragments.each do |fragment|
- drop = scratch
+ if fragment[:object_id] == last_fragment[:object_id]
+ fragments.delete fragment
+ next
+ else
+ drop = scratch
+ end
begin
image_path = fragment[:image_path]
@@ -125,6 +131,7 @@ module Asciidoctor::PDF::FormattedText
# NOTE retain key to indicate we've visited fragment already
fragment[:image_obj] = nil
end
+ last_fragment = fragment
end
end
end
diff --git a/lib/asciidoctor/pdf/formatted_text/transform.rb b/lib/asciidoctor/pdf/formatted_text/transform.rb
index a2d0ca24..bba1c0f5 100644
--- a/lib/asciidoctor/pdf/formatted_text/transform.rb
+++ b/lib/asciidoctor/pdf/formatted_text/transform.rb
@@ -175,6 +175,7 @@ module Asciidoctor
# NOTE: add enclosing square brackets here to avoid errors in parsing
text: %([#{attributes[:alt].delete ZeroWidthSpace}]),
callback: [InlineImageRenderer],
+ object_id: node.object_id, # used to deduplicate if fragment gets split up
}
if inherited && (link = inherited[:link])
fragment[:link] = link
diff --git a/spec/image_spec.rb b/spec/image_spec.rb
index cc91ce53..88ffcc5a 100644
--- a/spec/image_spec.rb
+++ b/spec/image_spec.rb
@@ -788,6 +788,15 @@ describe 'Asciidoctor::PDF::Converter - Image' do
end).to log_message severity: :WARN, message: '~image to embed not found or not readable'
end
+ it 'should only render inline image once if alt text is chunked to apply a fallback font' do
+ pdf = to_pdf <<~'EOS', attribute_overrides: { 'imagesdir' => examples_dir, 'pdf-theme' => 'default-with-fallback-font' }, analyze: :image
+ How many wolpertingers do you see? +
+ image:wolpertinger.jpg[チのデータレプリケーションです。]
+ EOS
+
+ (expect pdf.images).to have_size 1
+ end
+
it 'should warn instead of crash if inline image is unreadable' do
image_file = fixture_file 'logo.png'
old_mode = (File.stat image_file).mode