Skip to content

Commit 9fd37a8

Browse files
committed
Add fallback '.notdef' glyph
1 parent ba55184 commit 9fd37a8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

fpdf/fonts.py

+18
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,24 @@ def __init__(self, fpdf, font_file_path, fontkey, style):
267267
)
268268

269269
self.scale = 1000 / self.ttfont["head"].unitsPerEm
270+
271+
# check if the font is a TrueType and missing a .notdef glyph
272+
# if it is missing, provide a fallback glyph
273+
if 'glyf' in self.ttfont and ".notdef" not in self.ttfont["glyf"]:
274+
# draw a diagonal cross .notdef glyph
275+
pen = TTGlyphPen(None)
276+
pen.moveTo((0, 0))
277+
pen.lineTo((600, 0))
278+
pen.lineTo((600, 600))
279+
pen.lineTo((0, 600))
280+
pen.moveTo((0, 0))
281+
pen.lineTo((600, 600))
282+
pen.moveTo((600, 0))
283+
pen.lineTo((0, 600))
284+
285+
self.ttfont["glyf"][".notdef"] = pen.glyph()
286+
self.ttfont["hmtx"][".notdef"] = (600, 0)
287+
270288
default_width = round(self.scale * self.ttfont["hmtx"].metrics[".notdef"][0])
271289

272290
os2_table = self.ttfont["OS/2"]

0 commit comments

Comments
 (0)