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

Skip to content

Commit 240850a

Browse files
committed
Merge pull request #5410 from mdboom/get-charmap-removal
MNT: Remove uses of font.get_charmap
2 parents c53c58c + cce95bc commit 240850a

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

examples/misc/ftface_props.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,4 @@
6363

6464
print(dir(font))
6565

66-
cmap = font.get_charmap()
6766
print(font.get_kerning)

lib/matplotlib/_mathtext_data.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
"""
22
font data tables for truetype and afm computer modern fonts
33
"""
4-
# this dict maps symbol names to fontnames, glyphindex. To get the
5-
# glyph index from the character code, you have to use get_charmap
64
from __future__ import (absolute_import, division, print_function,
75
unicode_literals)
86

lib/matplotlib/backends/backend_pdf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -883,13 +883,12 @@ def get_char_width(charcode):
883883
# Make the "Differences" array, sort the ccodes < 255 from
884884
# the multi-byte ccodes, and build the whole set of glyph ids
885885
# that we need from this font.
886-
cmap = font.get_charmap()
887886
glyph_ids = []
888887
differences = []
889888
multi_byte_chars = set()
890889
for c in characters:
891890
ccode = c
892-
gind = cmap.get(ccode) or 0
891+
gind = font.get_char_index(ccode)
893892
glyph_ids.append(gind)
894893
glyph_name = font.get_glyph_name(gind)
895894
if ccode <= 255:
@@ -999,12 +998,11 @@ def embedTTFType42(font, characters, descriptor):
999998
# Make the 'W' (Widths) array, CidToGidMap and ToUnicode CMap
1000999
# at the same time
10011000
cid_to_gid_map = ['\u0000'] * 65536
1002-
cmap = font.get_charmap()
10031001
widths = []
10041002
max_ccode = 0
10051003
for c in characters:
10061004
ccode = c
1007-
gind = cmap.get(ccode) or 0
1005+
gind = font.get_char_index(ccode)
10081006
glyph = font.load_char(ccode, flags=LOAD_NO_HINTING)
10091007
widths.append((ccode, glyph.horiAdvance / 6))
10101008
if ccode < 65536:
@@ -2010,7 +2008,6 @@ def draw_text_woven(chunks):
20102008
between chunks of 1-byte characters and 2-byte characters.
20112009
Only used for Type 3 fonts."""
20122010
chunks = [(a, ''.join(b)) for a, b in chunks]
2013-
cmap = font.get_charmap()
20142011

20152012
# Do the rotation and global translation as a single matrix
20162013
# concatenation up front
@@ -2040,7 +2037,7 @@ def draw_text_woven(chunks):
20402037
lastgind = None
20412038
for c in chunk:
20422039
ccode = ord(c)
2043-
gind = cmap.get(ccode)
2040+
gind = font.get_char_index(ccode)
20442041
if gind is not None:
20452042
if mode == 2 and chunk_type == 2:
20462043
glyph_name = font.get_glyph_name(gind)

lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -762,15 +762,14 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
762762
ps_name = ps_name.encode('ascii', 'replace').decode('ascii')
763763
self.set_font(ps_name, prop.get_size_in_points())
764764

765-
cmap = font.get_charmap()
766765
lastgind = None
767766
#print 'text', s
768767
lines = []
769768
thisx = 0
770769
thisy = 0
771770
for c in s:
772771
ccode = ord(c)
773-
gind = cmap.get(ccode)
772+
gind = font.get_char_index(ccode)
774773
if gind is None:
775774
ccode = ord('?')
776775
name = '.notdef'
@@ -1138,10 +1137,9 @@ def print_figure_impl():
11381137
for font_filename, chars in six.itervalues(ps_renderer.used_characters):
11391138
if len(chars):
11401139
font = get_font(font_filename)
1141-
cmap = font.get_charmap()
11421140
glyph_ids = []
11431141
for c in chars:
1144-
gind = cmap.get(c) or 0
1142+
gind = font.get_char_index(c)
11451143
glyph_ids.append(gind)
11461144

11471145
fonttype = rcParams['ps.fonttype']

lib/matplotlib/tests/test_font_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import warnings
1010

1111
from matplotlib.font_manager import (
12-
findfont, FontProperties, fontManager, json_dump, json_load)
12+
findfont, FontProperties, fontManager, json_dump, json_load, get_font)
1313
from matplotlib import rc_context
1414

1515

@@ -21,6 +21,12 @@ def test_font_priority():
2121
FontProperties(family=["sans-serif"]))
2222
assert_equal(os.path.basename(font), 'cmmi10.ttf')
2323

24+
# Smoketest get_charmap, which isn't used internally anymore
25+
font = get_font(font)
26+
cmap = font.get_charmap()
27+
assert len(cmap) == 131
28+
assert cmap[8729] == 30
29+
2430

2531
def test_json_serialization():
2632
with tempfile.NamedTemporaryFile() as temp:

lib/matplotlib/textpath.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ def get_glyphs_with_font(self, font, s, glyph_map=None,
173173

174174
# Mostly copied from backend_svg.py.
175175

176-
cmap = font.get_charmap()
177176
lastgind = None
178177

179178
currx = 0
@@ -192,7 +191,7 @@ def get_glyphs_with_font(self, font, s, glyph_map=None,
192191

193192
for c in s:
194193
ccode = ord(c)
195-
gind = cmap.get(ccode)
194+
gind = font.get_char_index(ccode)
196195
if gind is None:
197196
ccode = ord('?')
198197
gind = 0

0 commit comments

Comments
 (0)