Skip to content

Commit

Permalink
Merge pull request #25 from moi15moi/Use-the-same-method-as-GDI-for-g…
Browse files Browse the repository at this point in the history
…et_decoded_name

Use the same method as GDI for get_decoded_name
  • Loading branch information
moi15moi authored Aug 8, 2023
2 parents 3613deb + 8a87c9f commit 438b8e1
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions font_collector/font_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,12 +421,13 @@ def get_decoded_name(name: NameRecord) -> str:

encoding = FontParser.get_name_encoding(name)

try:
return name.string.decode(encoding)
except UnicodeDecodeError:
utf_16_decoded = name.string.decode("utf_16_be")
to_decode = bytes(utf_16_decoded, encoding="raw_unicode_escape")
return to_decode.decode(encoding)
if name.platformID == 3 and encoding != "utf_16_be":
# I spoke with a Microsoft employee and he told me that GDI performed this processing:
name_to_decode = name.string.replace(b"\x00", b"")
else:
name_to_decode = name.string

return name_to_decode.decode(encoding)

@staticmethod
def get_font_postscript_property(font_path: str, font_index: int) -> Optional[str]:
Expand Down

0 comments on commit 438b8e1

Please sign in to comment.