Skip to content

Commit

Permalink
backport fix for #2541 don't look for NULL glyph in fallback font as …
Browse files Browse the repository at this point in the history
…this can impact line height
  • Loading branch information
mojavelinux committed Oct 8, 2024
1 parent 04afe55 commit 7e38cb1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Bug Fixes::

* support horizontal alignment on AsciiDoc table cell that only contains paragraphs (#2358)
* don't allow AsciiDoc table cell to overrun bottom of page on which it fits (#2538)
* don't look for NULL glyph in fallback font as this can impact line height (#2541)

== 2.3.18 (2024-07-27) - @mojavelinux

Expand Down
3 changes: 3 additions & 0 deletions docs/modules/theme/pages/prepare-custom-font.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ The fonts used by the default theme in Asciidoctor PDF provide all of these glyp
If the .notdef glyph is non-empty (i.e., contains splines), it will be used as the default glyph when the document requests a character that's missing from the font.
Unlike other glyphs, the .notdef glyph is referenced by name only, meaning it does not have a designated Unicode code point.

Although Asciidoctor PDF uses the \u0000 character as a placeholder for inline anchors, the font is not required to provide this character.
Asciidoctor PDF assumes that the primary font provides this character and uses the font metrics from that font as though it were there.

If you're preparing a font for use in verbatim blocks (e.g., a listing block), you'll also need this range of characters:

* \u2460 to \u2468 - circled numbers
Expand Down
2 changes: 1 addition & 1 deletion lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def analyze_glyphs_for_fallback_font_support fragment_hash
form_fragments_from_like_font_glyph_pairs font_glyph_pairs, fragment_hash
end

# TODO: remove once Prawn 2.5 is released
def find_font_for_this_glyph char, current_font, current_font_opts = {}, fallback_fonts_to_check = [], original_font = current_font
return current_font if char == ?\u0000 # never look for NUL character in fallback fonts as it's not rendered
(doc = @document).font current_font, current_font_opts
if doc.font.glyph_present? char
current_font
Expand Down
22 changes: 22 additions & 0 deletions spec/font_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@
(expect text[:font_name]).to eql 'NotoSerif-Bold'
end

it 'should not look for NUL glyph in fallback font when missing from primary font' do
pdf_theme = {
extends: 'default',
font_catalog: {
'Noto Serif' => {
'normal' => 'notoserif-regular-subset.ttf',
},
'M+ 1p Fallback' => {
'normal' => 'mplus1p-regular-fallback.ttf',
},
},
base_font_family: 'M+ 1p Fallback',
font_fallbacks: ['Noto Serif'],
}
input = '. [[L1]]List item with anchor'
pdf = to_pdf input, analyze: true, pdf_theme: pdf_theme
marker, text = pdf.text
(expect marker[:font_name]).to eql 'mplus-1p-regular'
(expect text[:font_name]).to eql 'mplus-1p-regular'
(expect marker[:y]).to eql text[:y]
end

it 'should include box drawing glyphs in bundled monospace font', visual: true do
input_file = Pathname.new fixture_file 'box-drawing.adoc'
to_file = to_pdf_file input_file, 'font-box-drawing.pdf'
Expand Down

0 comments on commit 7e38cb1

Please sign in to comment.