Skip to content

Commit

Permalink
remove redundant calls to fonttools (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersonhc committed Aug 31, 2023
1 parent 78a2ddf commit b74a590
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions fpdf/fonts.py
Expand Up @@ -150,7 +150,7 @@ def __init__(self, fpdf, font_file_path, fontkey, style):
# fonttools cmap = unicode char to glyph name
# saving only the keys we have a tuple with
# the unicode characters available on the font
self.cmap = tuple(self.ttfont.getBestCmap().keys())
self.cmap = self.ttfont.getBestCmap()

# saving a list of glyph ids to char to allow
# subset by unicode (regular) and by glyph
Expand All @@ -159,7 +159,7 @@ def __init__(self, fpdf, font_file_path, fontkey, style):

for char in self.cmap:
# take glyph associated to char
glyph = self.ttfont.getBestCmap()[char]
glyph = self.cmap[char]

# take width associated to glyph
w = self.ttfont["hmtx"].metrics[glyph][0]
Expand Down Expand Up @@ -420,11 +420,11 @@ def get_glyph(
return Glyph(
self.font.glyph_ids[unicode],
tuple([unicode]),
self.font.ttfont.getBestCmap()[unicode],
self.font.cmap[unicode],
self.font.cw[unicode],
)
if unicode == 0x00:
return Glyph(self.font.cmap[0], tuple([0x00]), ".notdef", 0)
return Glyph(next(iter(self.font.cmap)), tuple([0x00]), ".notdef", 0)
return None

def get_glyph_by_id(self, cid) -> Glyph:
Expand Down

0 comments on commit b74a590

Please sign in to comment.