diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index e6cd060c8..627466441 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -52,6 +52,7 @@ Bug Fixes:: * prevent special character substitution from interfering with callouts in plain verbatim block (#2390) * remove deprecated, undocumented `svg-font-family` theme key (the correct key is `svg-fallback-font-family`) * decouple tests from path of PWD (#2444) +* consider inherited styles when analyzing glyphs for fallback font support (#2463) * add fallback character for placeholder character when using AFM font (#2453) == 2.3.9 (2023-06-28) - @mojavelinux diff --git a/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb b/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb index c13bd027a..4b140bdd6 100644 --- a/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb +++ b/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb @@ -32,21 +32,26 @@ def draw_fragment_overlay_styles fragment end end - # TODO: remove when upgrading to prawn-2.5.0 + # help Prawn correctly resolve which font to analyze, including the font style def analyze_glyphs_for_fallback_font_support fragment_hash fragment_font = fragment_hash[:font] || (original_font = @document.font.family) + effective_font_styles = @document.font_styles + fragment_font_opts = {} if (fragment_font_styles = fragment_hash[:styles]) - if fragment_font_styles.include? :bold - fragment_font_opts = { style: (fragment_font_styles.include? :italic) ? :bold_italic : :bold } - elsif fragment_font_styles.include? :italic - fragment_font_opts = { style: :italic } + effective_font_styles.merge fragment_font_styles + if effective_font_styles.include? :bold + fragment_font_opts[:style] = (effective_font_styles.include? :italic) ? :bold_italic : :bold + elsif effective_font_styles.include? :italic + fragment_font_opts[:style] = :italic end + elsif !effective_font_styles.empty? + fragment_font_opts[:style] = @document.resolve_font_style effective_font_styles end fallback_fonts = @fallback_fonts.drop 0 font_glyph_pairs = [] @document.save_font do fragment_hash[:text].each_char do |char| - font_glyph_pairs << [(find_font_for_this_glyph char, fragment_font, fragment_font_opts || {}, (fallback_fonts.drop 0)), char] + font_glyph_pairs << [(find_font_for_this_glyph char, fragment_font, fragment_font_opts, (fallback_fonts.drop 0)), char] end end # NOTE: don't add a :font to fragment if it wasn't there originally diff --git a/spec/fixtures/glyph-font-test.adoc b/spec/fixtures/glyph-font-test.adoc index 2a9221494..41bbebaff 100644 --- a/spec/fixtures/glyph-font-test.adoc +++ b/spec/fixtures/glyph-font-test.adoc @@ -18,6 +18,8 @@ To ∞! // circled numbers `①` to `⑳` `❶` to `⓴` +// ballot boxes +☐ ☑ // greek Α to Ω // cyrillic @@ -38,6 +40,8 @@ fast‑approaching ifeval::["{pdf-theme}"=="default-with-font-fallbacks"] // check mark ✓ done +// bold ballot boxes +*☐ ☑* // upside down e upsidə down // extended monospace punctuation diff --git a/spec/font_spec.rb b/spec/font_spec.rb index e24fb7604..ac3ef92ed 100644 --- a/spec/font_spec.rb +++ b/spec/font_spec.rb @@ -37,6 +37,20 @@ (expect to_file).to visually_match 'font-glyph-fallback-only.pdf' end + it 'should resolve glyph in fallback font when styles are inherited', visual: true do + input = <<~'END' + |=== + |☑ For | ☐ Against + + |Tastes great + |High in sugar + |=== + END + + to_file = to_pdf_file input, 'fallback-font-inherited-styles.pdf', attribute_overrides: { 'pdf-theme' => 'default-with-font-fallbacks' } + (expect to_file).to visually_match 'fallback-font-inherited-styles.pdf' + end + it 'should use notdef from original font of glyph not found in any fallback font', visual: true do input = ?\u0278 * 10 to_file = to_pdf_file input, 'font-notdef-glyph.pdf', attribute_overrides: { 'pdf-theme' => 'default-with-font-fallbacks' } diff --git a/spec/reference/fallback-font-inherited-styles.pdf b/spec/reference/fallback-font-inherited-styles.pdf new file mode 100644 index 000000000..e84b7795e Binary files /dev/null and b/spec/reference/fallback-font-inherited-styles.pdf differ diff --git a/spec/reference/font-glyph-default-with-fallback.pdf b/spec/reference/font-glyph-default-with-fallback.pdf index 581853834..7042204de 100644 Binary files a/spec/reference/font-glyph-default-with-fallback.pdf and b/spec/reference/font-glyph-default-with-fallback.pdf differ diff --git a/spec/reference/font-glyph-default.pdf b/spec/reference/font-glyph-default.pdf index 6c2c8034e..ea2819caa 100644 Binary files a/spec/reference/font-glyph-default.pdf and b/spec/reference/font-glyph-default.pdf differ diff --git a/spec/reference/font-glyph-fallback-only.pdf b/spec/reference/font-glyph-fallback-only.pdf index 3aed96119..7839b8334 100644 Binary files a/spec/reference/font-glyph-fallback-only.pdf and b/spec/reference/font-glyph-fallback-only.pdf differ