Skip to content

Commit dff2866

Browse files
committed
[ABCFontFace.get_missing_glyphs] Don't try to convert 0xF020-0xF0FF char to the cmap encoding
1 parent 3e46999 commit dff2866

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

font_collector/font/abc_font_face.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,10 @@ def get_missing_glyphs(
307307
if cmap_encoding == "unicode":
308308
codepoint = ord(char)
309309
else:
310+
symbol_cmap = False
310311
if cmap_encoding == "unknown":
311312
if platform_id == 3 and encoding_id == 0:
313+
symbol_cmap = True
312314
if support_only_ascii_char_for_symbol_font and not char.isascii():
313315
continue
314316
cmap_encoding = FontParser.get_symbol_cmap_encoding(face)
@@ -320,10 +322,15 @@ def get_missing_glyphs(
320322
# cmap not supported
321323
continue
322324

323-
try:
324-
codepoint = int.from_bytes(char.encode(cmap_encoding), "big")
325-
except UnicodeEncodeError:
326-
continue
325+
if symbol_cmap and (0xF020 <= ord(char) and ord(char) <= 0xF0FF):
326+
# If the character is already a "symbol" character (a.k.a is between 0xF020 and 0xF0FF),
327+
# GDI directly use it's codepoint.
328+
codepoint = ord(char)
329+
else:
330+
try:
331+
codepoint = int.from_bytes(char.encode(cmap_encoding), "big")
332+
except UnicodeEncodeError:
333+
continue
327334

328335
# GDI/Libass modify the codepoint for microsoft symbol cmap.
329336
# See: https://github.com/libass/libass/blob/04a208d5d200360d2ac75f8f6cfc43dd58dd9225/libass/ass_font.c#L249-L250

tests/font/test_normal_font_face.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,13 @@ def test_font_get_missing_glyphs_cmap_encoding_0():
137137
missing_glyphs = font_face.get_missing_glyphs("Έκθεση για Απασχόληση Dream Top Co. Οι επιλογές À a", True)
138138
assert missing_glyphs == set("ΈκθεσηγιαπασχόλησηΟιεπιλογέςÀΑ")
139139

140+
# 0xF152 > 0xF0FF and there is a entry of this character in the cmap. We must ignore it.
141+
missing_glyphs = font_face.get_missing_glyphs(chr(0xF152))
142+
assert missing_glyphs == set(chr(0xF152))
143+
144+
# GDI support to directly have the character with the 0xF000 flag
145+
missing_glyphs = font_face.get_missing_glyphs(chr(0xF0FF))
146+
assert missing_glyphs == set()
140147

141148
def test_font_get_missing_glyphs_cmap_encoding_1():
142149
font_cmap_encoding_1 = Path(os.path.join(os.path.dirname(dir_path), "file", "fonts", "font_cmap_encoding_1.ttf"))

0 commit comments

Comments
 (0)