@@ -19,7 +19,7 @@ class TextToPath(object):
1919
2020 FONT_SCALE = 50.
2121 DPI = 72
22-
22+
2323 def __init__ (self ):
2424 """
2525 Initialization
@@ -44,7 +44,7 @@ def _get_font(self, prop):
4444
4545 def _get_hinting_flag (self ):
4646 return LOAD_NO_HINTING
47-
47+
4848 def _get_char_id (self , font , ccode ):
4949 """
5050 Return a unique id for the given font and character-code set.
@@ -64,7 +64,7 @@ def _get_char_id_ps(self, font, ccode):
6464
6565 def glyph_to_path (self , glyph , currx = 0. ):
6666 """
67- convert the ft2font glyph to vertices and codes.
67+ convert the ft2font glyph to vertices and codes.
6868 """
6969 #Mostly copied from backend_svg.py.
7070
@@ -102,14 +102,14 @@ def get_text_path(self, prop, s, ismath=False, usetex=False):
102102
103103 *s*
104104 text to be converted
105-
105+
106106 *usetex*
107107 If True, use matplotlib usetex mode.
108108
109109 *ismath*
110110 If True, use mathtext parser. Effective only if usetex == False.
111111
112-
112+
113113 """
114114 if usetex == False :
115115 if ismath == False :
@@ -121,26 +121,26 @@ def get_text_path(self, prop, s, ismath=False, usetex=False):
121121 glyph_info , glyph_map , rects = self .get_glyphs_tex (prop , s )
122122
123123 verts , codes = [], []
124-
124+
125125 for glyph_id , xposition , yposition , scale in glyph_info :
126126 verts1 , codes1 = glyph_map [glyph_id ]
127127 if verts1 :
128- verts1 = np .array (verts1 )* scale + [xposition , yposition ]
128+ verts1 = np .array (verts1 )* scale + [xposition , yposition ]
129129 verts .extend (verts1 )
130130 codes .extend (codes1 )
131131
132132 for verts1 , codes1 in rects :
133133 verts .extend (verts1 )
134134 codes .extend (codes1 )
135-
135+
136136 return verts , codes
137137
138-
138+
139139 def get_glyphs_with_font (self , font , s , glyph_map = None ,
140140 return_new_glyphs_only = False ):
141141 """
142142 convert the string *s* to vertices and codes using the
143- provided ttf font.
143+ provided ttf font.
144144 """
145145
146146 # Mostly copied from backend_svg.py.
@@ -151,7 +151,7 @@ def get_glyphs_with_font(self, font, s, glyph_map=None,
151151 currx = 0
152152 xpositions = []
153153 glyph_ids = []
154-
154+
155155 if glyph_map is None :
156156 glyph_map = dict ()
157157
@@ -190,14 +190,14 @@ def get_glyphs_with_font(self, font, s, glyph_map=None,
190190 glyph_ids .append (char_id )
191191
192192 currx += horiz_advance
193-
193+
194194 lastgind = gind
195195
196196 ypositions = [0 ] * len (xpositions )
197197 sizes = [1. ] * len (xpositions )
198198
199199 rects = []
200-
200+
201201 return zip (glyph_ids , xpositions , ypositions , sizes ), glyph_map_new , rects
202202
203203
@@ -275,14 +275,14 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
275275 """
276276
277277 # codes are modstly borrowed from pdf backend.
278-
278+
279279 texmanager = self .get_texmanager ()
280280
281281 if self .tex_font_map is None :
282282 self .tex_font_map = dviread .PsfontsMap (dviread .find_tex_file ('pdftex.map' ))
283283
284284 fontsize = prop .get_size_in_points ()
285- if hasattr (texmanager , "get_dvi" ): #
285+ if hasattr (texmanager , "get_dvi" ): #
286286 dvifilelike = texmanager .get_dvi (s , self .FONT_SCALE )
287287 dvi = dviread .DviFromFileLike (dvifilelike , self .DPI )
288288 else :
@@ -312,6 +312,10 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
312312 if font_and_encoding is None :
313313 font_bunch = self .tex_font_map [dvifont .texname ]
314314 font = FT2Font (font_bunch .filename )
315+ try :
316+ font .select_charmap (1094992451 ) # select ADOBE_CUSTOM
317+ except ValueError :
318+ font .set_charmap (0 )
315319 if font_bunch .encoding :
316320 enc = dviread .Encoding (font_bunch .encoding )
317321 else :
@@ -322,25 +326,15 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
322326 font , enc = font_and_encoding
323327
324328 ft2font_flag = LOAD_TARGET_LIGHT
325- if enc :
326- ng = font .get_name_index (enc .encoding [glyph ])
327- else :
328- ng = glyph
329329
330- char_id = self ._get_char_id_ps (font , ng )
330+ char_id = self ._get_char_id_ps (font , glyph )
331331
332332 if not char_id in glyph_map :
333333 font .clear ()
334334 font .set_size (self .FONT_SCALE , self .DPI )
335335
336- if ng == 0 :
337- # While 0 is a valid index (e.g., "-", "\Gamma"),
338- # font.load_glyph(0) does not seem to work. This
339- # may not be a general solution.
340- glyph0 = font .load_glyph (128 , flags = ft2font_flag )
341- else :
342- glyph0 = font .load_glyph (ng , flags = ft2font_flag )
343-
336+ glyph0 = font .load_char (glyph , flags = ft2font_flag )
337+
344338 glyph_map_new [char_id ] = self .glyph_to_path (glyph0 )
345339
346340 glyph_ids .append (char_id )
@@ -349,7 +343,7 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
349343 sizes .append (dvifont .size / self .FONT_SCALE )
350344
351345 myrects = []
352-
346+
353347 for ox , oy , h , w in page .boxes :
354348 vert1 = [(ox , oy ), (ox + w , oy ), (ox + w , oy + h ), (ox , oy + h ), (ox , oy ), (0 ,0 )]
355349 code1 = [Path .MOVETO ,
@@ -358,12 +352,13 @@ def get_glyphs_tex(self, prop, s, glyph_map=None,
358352 myrects .append ((vert1 , code1 ))
359353
360354
361- return zip (glyph_ids , xpositions , ypositions , sizes ), glyph_map , myrects
355+ return zip (glyph_ids , xpositions , ypositions , sizes ), \
356+ glyph_map_new , myrects
357+
362358
363359
364360
365361
366-
367362
368363from matplotlib .font_manager import FontProperties
369364from matplotlib import rcParams
@@ -384,7 +379,7 @@ def __init__(self, xy, s, size=None, prop=None,
384379 it simply is a path, not an artist. You need to use the
385380 PathPatch (or other artists) to draw this path onto the
386381 canvas.
387-
382+
388383 xy : position of the text.
389384 s : text
390385 size : font size
@@ -437,7 +432,7 @@ def _get_codes(self):
437432 Return the codes
438433 """
439434 return self ._codes
440-
435+
441436 vertices = property (_get_vertices )
442437 codes = property (_get_codes )
443438
@@ -463,7 +458,7 @@ def is_math_text(self, s):
463458 Returns True if the given string *s* contains any mathtext.
464459 """
465460 # copied from Text.is_math_text -JJL
466-
461+
467462 # Did we find an even number of non-escaped dollar signs?
468463 # If so, treat is as math text.
469464 dollar_count = s .count (r'$' ) - s .count (r'\$' )
@@ -489,7 +484,7 @@ def text_get_vertices_codes(self, prop, s, usetex):
489484 else :
490485 clean_line , ismath = self .is_math_text (s )
491486 verts , codes = text_to_path .get_text_path (prop , clean_line , ismath = ismath )
492-
487+
493488 return verts , codes
494489
495490
0 commit comments