Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c91edb3

Browse files
committed
FT2Font.get_char_index never returns None.
... because its body is ``` FT_UInt index; FT_ULong ccode; if (!PyArg_ParseTuple(args, "k:get_char_index", &ccode)) { return NULL; } index = FT_Get_Char_Index(self->x->get_face(), ccode); return PyLong_FromLong(index); ``` so kill code paths which handle a None-return.
1 parent 4a5c939 commit c91edb3

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,29 +2198,27 @@ def draw_text_woven(chunks):
21982198
for c in chunk:
21992199
ccode = ord(c)
22002200
gind = font.get_char_index(ccode)
2201-
if gind is not None:
2202-
if mode == 2 and chunk_type == 2:
2203-
glyph_name = font.get_glyph_name(gind)
2204-
self.file.output(Op.gsave)
2205-
self.file.output(0.001 * fontsize, 0,
2206-
0, 0.001 * fontsize,
2207-
newx, 0, Op.concat_matrix)
2208-
name = self.file._get_xobject_symbol_name(
2209-
font.fname, glyph_name)
2210-
self.file.output(Name(name), Op.use_xobject)
2211-
self.file.output(Op.grestore)
2212-
2213-
# Move the pointer based on the character width
2214-
# and kerning
2215-
glyph = font.load_char(ccode,
2216-
flags=LOAD_NO_HINTING)
2217-
if lastgind is not None:
2218-
kern = font.get_kerning(
2219-
lastgind, gind, KERNING_UNFITTED)
2220-
else:
2221-
kern = 0
2222-
lastgind = gind
2223-
newx += kern/64.0 + glyph.linearHoriAdvance/65536.0
2201+
if mode == 2 and chunk_type == 2:
2202+
glyph_name = font.get_glyph_name(gind)
2203+
self.file.output(Op.gsave)
2204+
self.file.output(0.001 * fontsize, 0,
2205+
0, 0.001 * fontsize,
2206+
newx, 0, Op.concat_matrix)
2207+
name = self.file._get_xobject_symbol_name(
2208+
font.fname, glyph_name)
2209+
self.file.output(Name(name), Op.use_xobject)
2210+
self.file.output(Op.grestore)
2211+
2212+
# Move the pointer based on the character width
2213+
# and kerning
2214+
glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
2215+
if lastgind is not None:
2216+
kern = font.get_kerning(
2217+
lastgind, gind, KERNING_UNFITTED)
2218+
else:
2219+
kern = 0
2220+
lastgind = gind
2221+
newx += kern / 64 + glyph.linearHoriAdvance / 65536
22242222

22252223
if mode == 1:
22262224
self.file.output(Op.end_text)

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -630,12 +630,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
630630
for c in s:
631631
ccode = ord(c)
632632
gind = font.get_char_index(ccode)
633-
if gind is None:
634-
ccode = ord('?')
635-
name = '.notdef'
636-
gind = 0
637-
else:
638-
name = font.get_glyph_name(gind)
633+
name = font.get_glyph_name(gind)
639634
glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
640635

641636
if lastgind is not None:

lib/matplotlib/textpath.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ def get_glyphs_with_font(self, font, s, glyph_map=None,
183183
for c in s:
184184
ccode = ord(c)
185185
gind = font.get_char_index(ccode)
186-
if gind is None:
187-
ccode = ord('?')
188-
gind = 0
189186

190187
if lastgind is not None:
191188
kern = font.get_kerning(lastgind, gind, KERNING_DEFAULT)

0 commit comments

Comments
 (0)