Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Remove uses of font.get_charmap #5410

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 1 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 2 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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is out of date and should have been removed in #5299.


Expand Down
9 changes: 3 additions & 6 deletions 9 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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_char_index, which calls FT_Get_Char_Index in freetype, returns 0 if the ccode doesn't not exist already, hence the removal of the or 0.

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 @@ -2010,7 +2008,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 @@ -2040,7 +2037,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 6 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 8 lib/matplotlib/tests/test_font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import warnings

from matplotlib.font_manager import (
findfont, FontProperties, fontManager, json_dump, json_load)
findfont, FontProperties, fontManager, json_dump, json_load, get_font)
from matplotlib import rc_context


Expand All @@ -21,6 +21,12 @@ def test_font_priority():
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


def test_json_serialization():
with tempfile.NamedTemporaryFile() as temp:
Expand Down
3 changes: 1 addition & 2 deletions 3 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.