Skip to content

Commit 5afd71b

Browse files
committed
Deduplicate CharacterTracker.track implementation
No need to repeat the calculation of subset blocks, but instead offload it to `track_glyph`.
1 parent a1ed4ef commit 5afd71b

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

lib/matplotlib/backends/_backend_pdf_ps.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,10 @@ def track(self, font: FT2Font, s: str) -> list[tuple[int, CharacterCodeType]]:
157157
whole). If *subset_size* is not specified, then the subset will always be 0
158158
and the character codes will be returned from the string unchanged.
159159
"""
160-
font_glyphs = []
161-
char_to_font = font._get_fontmap(s)
162-
for _c, _f in char_to_font.items():
163-
charcode = ord(_c)
164-
glyph_index = _f.get_char_index(charcode)
165-
if self.subset_size != 0:
166-
subset = charcode // self.subset_size
167-
subset_charcode = charcode % self.subset_size
168-
else:
169-
subset = 0
170-
subset_charcode = charcode
171-
self.used.setdefault((_f.fname, subset), {})[subset_charcode] = glyph_index
172-
font_glyphs.append((subset, subset_charcode))
173-
return font_glyphs
160+
return [
161+
self.track_glyph(_f, ord(_c), _f.get_char_index(ord(_c)))
162+
for _c, _f in font._get_fontmap(s).items()
163+
]
174164

175165
def track_glyph(
176166
self, font: FT2Font, charcode: CharacterCodeType,

0 commit comments

Comments
 (0)