Skip to content

Merge pull request #5410 from mdboom/get-charmap-removal #5412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 5, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/misc/ftface_props.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,4 @@

print(dir(font))

cmap = font.get_charmap()
print(font.get_kerning)
2 changes: 0 additions & 2 deletions lib/matplotlib/_mathtext_data.py
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
9 changes: 3 additions & 6 deletions lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,15 +762,14 @@ 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 = []
thisx = 0
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'
Expand Down Expand Up @@ -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']
Expand Down
8 changes: 7 additions & 1 deletion lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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
3 changes: 1 addition & 2 deletions lib/matplotlib/textpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down