Skip to content

Commit

Permalink
resolves asciidoctor#2463 consider inherited styles when analyzing gl…
Browse files Browse the repository at this point in the history
…yphs for fallback font support
  • Loading branch information
mojavelinux committed Nov 28, 2023
1 parent 86afa0f commit ec81082
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 11 additions & 6 deletions lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/glyph-font-test.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ To &#x221e;!
// circled numbers
`&#x2460;` to `&#x2473;`
`&#x2776;` to `&#x24f4;`
// ballot boxes
&#x2610; &#x2611;
// greek
&#x0391; to &#x03a9;
// cyrillic
Expand All @@ -38,6 +40,8 @@ fast&#x2011;approaching
ifeval::["{pdf-theme}"=="default-with-font-fallbacks"]
// check mark
&#x2713; done
// bold ballot boxes
*&#x2610; &#x2611;*
// upside down e
upsid&#x0259; down
// extended monospace punctuation
Expand Down
14 changes: 14 additions & 0 deletions spec/font_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
|===
|&#x2611; For | &#x2610; 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' }
Expand Down
Binary file added spec/reference/fallback-font-inherited-styles.pdf
Binary file not shown.
Binary file modified spec/reference/font-glyph-default-with-fallback.pdf
Binary file not shown.
Binary file modified spec/reference/font-glyph-default.pdf
Binary file not shown.
Binary file modified spec/reference/font-glyph-fallback-only.pdf
Binary file not shown.

0 comments on commit ec81082

Please sign in to comment.