From c9fbfab5d06fbaf583afe32cc63df924631304fd Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 5 Nov 2015 10:34:55 -0500 Subject: [PATCH] Merge pull request #5410 from mdboom/get-charmap-removal MNT: Remove uses of font.get_charmap Conflicts: lib/matplotlib/tests/test_font_manager.py Conflicts with merging the tests, resloved to add only relavent code. --- examples/misc/ftface_props.py | 1 - lib/matplotlib/_mathtext_data.py | 2 -- lib/matplotlib/backends/backend_pdf.py | 9 +++------ lib/matplotlib/backends/backend_ps.py | 6 ++---- lib/matplotlib/tests/test_font_manager.py | 8 +++++++- lib/matplotlib/textpath.py | 3 +-- 6 files changed, 13 insertions(+), 16 deletions(-) diff --git a/examples/misc/ftface_props.py b/examples/misc/ftface_props.py index 1a821cb531e4..acc28482dd15 100755 --- a/examples/misc/ftface_props.py +++ b/examples/misc/ftface_props.py @@ -63,5 +63,4 @@ print(dir(font)) -cmap = font.get_charmap() print(font.get_kerning) diff --git a/lib/matplotlib/_mathtext_data.py b/lib/matplotlib/_mathtext_data.py index a8379e30c9b3..81e1f579f3aa 100644 --- a/lib/matplotlib/_mathtext_data.py +++ b/lib/matplotlib/_mathtext_data.py @@ -1,8 +1,6 @@ """ font data tables for truetype and afm computer modern fonts """ -# this dict maps symbol names to fontnames, glyphindex. To get the -# glyph index from the character code, you have to use get_charmap from __future__ import (absolute_import, division, print_function, unicode_literals) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index 59c4cf6b8337..bd45bb5f4728 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -883,13 +883,12 @@ def get_char_width(charcode): # Make the "Differences" array, sort the ccodes < 255 from # the multi-byte ccodes, and build the whole set of glyph ids # that we need from this font. - cmap = font.get_charmap() glyph_ids = [] differences = [] multi_byte_chars = set() for c in characters: ccode = c - gind = cmap.get(ccode) or 0 + gind = font.get_char_index(ccode) glyph_ids.append(gind) glyph_name = font.get_glyph_name(gind) if ccode <= 255: @@ -999,12 +998,11 @@ def embedTTFType42(font, characters, descriptor): # Make the 'W' (Widths) array, CidToGidMap and ToUnicode CMap # at the same time cid_to_gid_map = ['\u0000'] * 65536 - cmap = font.get_charmap() widths = [] max_ccode = 0 for c in characters: ccode = c - gind = cmap.get(ccode) or 0 + gind = font.get_char_index(ccode) glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) widths.append((ccode, glyph.horiAdvance / 6)) if ccode < 65536: @@ -2011,7 +2009,6 @@ def draw_text_woven(chunks): between chunks of 1-byte characters and 2-byte characters. Only used for Type 3 fonts.""" chunks = [(a, ''.join(b)) for a, b in chunks] - cmap = font.get_charmap() # Do the rotation and global translation as a single matrix # concatenation up front @@ -2041,7 +2038,7 @@ def draw_text_woven(chunks): lastgind = None for c in chunk: ccode = ord(c) - gind = cmap.get(ccode) + 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) diff --git a/lib/matplotlib/backends/backend_ps.py b/lib/matplotlib/backends/backend_ps.py index bb6f83afc667..4c4daeb33df5 100644 --- a/lib/matplotlib/backends/backend_ps.py +++ b/lib/matplotlib/backends/backend_ps.py @@ -762,7 +762,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): ps_name = ps_name.encode('ascii', 'replace').decode('ascii') self.set_font(ps_name, prop.get_size_in_points()) - cmap = font.get_charmap() lastgind = None #print 'text', s lines = [] @@ -770,7 +769,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): thisy = 0 for c in s: ccode = ord(c) - gind = cmap.get(ccode) + gind = font.get_char_index(ccode) if gind is None: ccode = ord('?') name = '.notdef' @@ -1138,10 +1137,9 @@ def print_figure_impl(): for font_filename, chars in six.itervalues(ps_renderer.used_characters): if len(chars): font = get_font(font_filename) - cmap = font.get_charmap() glyph_ids = [] for c in chars: - gind = cmap.get(c) or 0 + gind = font.get_char_index(c) glyph_ids.append(gind) fonttype = rcParams['ps.fonttype'] diff --git a/lib/matplotlib/tests/test_font_manager.py b/lib/matplotlib/tests/test_font_manager.py index dac0710fd855..37f6671bc7ab 100644 --- a/lib/matplotlib/tests/test_font_manager.py +++ b/lib/matplotlib/tests/test_font_manager.py @@ -6,7 +6,7 @@ import os -from matplotlib.font_manager import findfont, FontProperties +from matplotlib.font_manager import (findfont, FontProperties, get_font) from matplotlib import rc_context @@ -17,3 +17,9 @@ def test_font_priority(): font = findfont( FontProperties(family=["sans-serif"])) assert_equal(os.path.basename(font), 'cmmi10.ttf') + + # Smoketest get_charmap, which isn't used internally anymore + font = get_font(font) + cmap = font.get_charmap() + assert len(cmap) == 131 + assert cmap[8729] == 30 diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index 79fbcc6c2da0..64b44c0726e1 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -173,7 +173,6 @@ def get_glyphs_with_font(self, font, s, glyph_map=None, # Mostly copied from backend_svg.py. - cmap = font.get_charmap() lastgind = None currx = 0 @@ -192,7 +191,7 @@ def get_glyphs_with_font(self, font, s, glyph_map=None, for c in s: ccode = ord(c) - gind = cmap.get(ccode) + gind = font.get_char_index(ccode) if gind is None: ccode = ord('?') gind = 0 pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy