Skip to content

Commit bb37cf9

Browse files
authored
Merge pull request #30520 from QuLogic/pdf-simplify-type3
pdf: Simplify Type 3 font character encoding
2 parents 04c8eef + 258de53 commit bb37cf9

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,13 +1180,11 @@ def embedTTFType3(font, characters, descriptor):
11801180
'Widths': widthsObject
11811181
}
11821182

1183-
from encodings import cp1252
1184-
11851183
# Make the "Widths" array
11861184
def get_char_width(charcode):
1187-
s = ord(cp1252.decoding_table[charcode])
11881185
width = font.load_char(
1189-
s, flags=LoadFlags.NO_SCALE | LoadFlags.NO_HINTING).horiAdvance
1186+
charcode,
1187+
flags=LoadFlags.NO_SCALE | LoadFlags.NO_HINTING).horiAdvance
11901188
return cvt(width)
11911189
with warnings.catch_warnings():
11921190
# Ignore 'Required glyph missing from current font' warning
@@ -2331,9 +2329,13 @@ def draw_tex(self, gc, x, y, s, prop, angle, *, mtext=None):
23312329
self.draw_path(boxgc, path, mytrans, gc._rgb)
23322330

23332331
def encode_string(self, s, fonttype):
2334-
if fonttype in (1, 3):
2335-
return s.encode('cp1252', 'replace')
2336-
return s.encode('utf-16be', 'replace')
2332+
match fonttype:
2333+
case 1:
2334+
return s.encode('cp1252', 'replace')
2335+
case 3:
2336+
return s.encode('latin-1', 'replace')
2337+
case _:
2338+
return s.encode('utf-16be', 'replace')
23372339

23382340
def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
23392341
# docstring inherited

0 commit comments

Comments
 (0)