Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

textpath tries the adobe standard encoding as a default for fonts#112

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
efiring merged 1 commit intomatplotlib:masterfromleejjoon:fix_textpath
Jul 7, 2011
Merged
Changes fromall 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
45 changes: 37 additions & 8 deletionslib/matplotlib/textpath.py
View file
Open in desktop
Original file line numberDiff line numberDiff 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 DownExpand 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

[8]ページ先頭

©2009-2025 Movatter.jp