FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

textpath tries the adobe standard encoding as a default for fonts by leejjoon · Pull Request #112 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
45 changes: 37 additions & 8 deletions lib/matplotlib/textpath.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

import numpy as np

import warnings

class TextToPath(object):
"""
A class that convert a given text to a path using ttf fonts.
Expand All @@ -32,6 +34,14 @@ def __init__(self):

self._texmanager = None

self._adobe_standard_encoding = self._get_adobe_standard_encoding()


def _get_adobe_standard_encoding(self):
enc_name = dviread.find_tex_file('8a.enc')
enc = dviread.Encoding(enc_name)
return dict([(c, i) for i, c in enumerate(enc.encoding)])

def _get_font(self, prop):
"""
find a ttf font.
Expand Down Expand Up @@ -312,14 +322,25 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
if font_and_encoding is None:
font_bunch = self.tex_font_map[dvifont.texname]
font = FT2Font(str(font_bunch.filename))
try:
font.select_charmap(1094992451) # select ADOBE_CUSTOM
except ValueError:
font.set_charmap(0)
if font_bunch.encoding:
enc = dviread.Encoding(font_bunch.encoding)

for charmap_name, charmap_code in [("ADOBE_CUSTOM", 1094992451),
("ADOBE_STANDARD", 1094995778)]:
try:
font.select_charmap(charmap_code)
except ValueError:
pass
else:
break
else:
enc = None
charmap_name = ""
warnings.warn("No supported encoding in font (%s)." % font_bunch.filename)

if charmap_name == "ADOBE_STANDARD" and font_bunch.encoding:
enc0 = dviread.Encoding(font_bunch.encoding)
enc = dict([(i, self._adobe_standard_encoding.get(c, None)) \
for i, c in enumerate(enc0.encoding)])
else:
enc = dict()
self._ps_fontd[dvifont.texname] = font, enc

else:
Expand All @@ -332,11 +353,19 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
if not char_id in glyph_map:
font.clear()
font.set_size(self.FONT_SCALE, self.DPI)
if enc: charcode = enc.get(glyph, None)
else: charcode = glyph

glyph0 = font.load_char(glyph, flags=ft2font_flag)
if charcode:
glyph0 = font.load_char(charcode, flags=ft2font_flag)
else:
warnings.warn("The glyph (%d) of font (%s) cannot be converted with the encoding. Glyph may be wrong" % (glyph, font_bunch.filename))

glyph0 = font.load_char(glyph, flags=ft2font_flag)

glyph_map_new[char_id] = self.glyph_to_path(glyph0)


glyph_ids.append(char_id)
xpositions.append(x1)
ypositions.append(y1)
Expand Down

Back | FazBrowse Home | New Git URL