From c91edb35fc37c543d23e4967e0141605799e2b35 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 23 Jul 2019 09:58:48 +0200 Subject: [PATCH] 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. --- lib/matplotlib/backends/backend_pdf.py | 44 ++++++++++++-------------- lib/matplotlib/backends/backend_ps.py | 7 +--- lib/matplotlib/textpath.py | 3 -- 3 files changed, 22 insertions(+), 32 deletions(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 662b27d890c9..c26fd70002da 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -2198,29 +2198,27 @@ def draw_text_woven(chunks): for c in chunk: ccode = ord(c) gind = font.get_char_index(ccode) - if gind is not None: - if mode == 2 and chunk_type == 2: - glyph_name = font.get_glyph_name(gind) - self.file.output(Op.gsave) - self.file.output(0.001 * fontsize, 0, - 0, 0.001 * fontsize, - newx, 0, Op.concat_matrix) - name = self.file._get_xobject_symbol_name( - font.fname, glyph_name) - self.file.output(Name(name), Op.use_xobject) - self.file.output(Op.grestore) - - # Move the pointer based on the character width - # and kerning - glyph = font.load_char(ccode, - flags=LOAD_NO_HINTING) - if lastgind is not None: - kern = font.get_kerning( - lastgind, gind, KERNING_UNFITTED) - else: - kern = 0 - lastgind = gind - newx += kern/64.0 + glyph.linearHoriAdvance/65536.0 + if mode == 2 and chunk_type == 2: + glyph_name = font.get_glyph_name(gind) + self.file.output(Op.gsave) + self.file.output(0.001 * fontsize, 0, + 0, 0.001 * fontsize, + newx, 0, Op.concat_matrix) + name = self.file._get_xobject_symbol_name( + font.fname, glyph_name) + self.file.output(Name(name), Op.use_xobject) + self.file.output(Op.grestore) + + # Move the pointer based on the character width + # and kerning + glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) + if lastgind is not None: + kern = font.get_kerning( + lastgind, gind, KERNING_UNFITTED) + else: + kern = 0 + lastgind = gind + newx += kern / 64 + glyph.linearHoriAdvance / 65536 if mode == 1: self.file.output(Op.end_text) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index 6cc7f9322e74..9125ef4cdc62 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -630,12 +630,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): for c in s: ccode = ord(c) gind = font.get_char_index(ccode) - if gind is None: - ccode = ord('?') - name = '.notdef' - gind = 0 - else: - name = font.get_glyph_name(gind) + name = font.get_glyph_name(gind) glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) if lastgind is not None: diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index 5f52cd0b778b..1f652940c261 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -183,9 +183,6 @@ def get_glyphs_with_font(self, font, s, glyph_map=None, for c in s: ccode = ord(c) gind = font.get_char_index(ccode) - if gind is None: - ccode = ord('?') - gind = 0 if lastgind is not None: kern = font.get_kerning(lastgind, gind, KERNING_DEFAULT)