Skip to content

Commit

Permalink
Add fallback '.notdef' glyph
Browse files Browse the repository at this point in the history
  • Loading branch information
spacegaori committed Jan 24, 2025
1 parent ba55184 commit 9fd37a8
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions fpdf/fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,24 @@ def __init__(self, fpdf, font_file_path, fontkey, style):
)

self.scale = 1000 / self.ttfont["head"].unitsPerEm

# check if the font is a TrueType and missing a .notdef glyph
# if it is missing, provide a fallback glyph
if 'glyf' in self.ttfont and ".notdef" not in self.ttfont["glyf"]:
# draw a diagonal cross .notdef glyph
pen = TTGlyphPen(None)
pen.moveTo((0, 0))
pen.lineTo((600, 0))
pen.lineTo((600, 600))
pen.lineTo((0, 600))
pen.moveTo((0, 0))
pen.lineTo((600, 600))
pen.moveTo((600, 0))
pen.lineTo((0, 600))

self.ttfont["glyf"][".notdef"] = pen.glyph()
self.ttfont["hmtx"][".notdef"] = (600, 0)

default_width = round(self.scale * self.ttfont["hmtx"].metrics[".notdef"][0])

os2_table = self.ttfont["OS/2"]
Expand Down

0 comments on commit 9fd37a8

Please sign in to comment.