@@ -457,8 +457,9 @@ def writeFonts(self):
457457 fontdictObject = self ._write_afm_font (filename )
458458 else :
459459 realpath , stat_key = get_realpath_and_stat (filename )
460- fontdictObject = self .embedTTF (
461- * self .used_characters [stat_key ])
460+ chars = self .used_characters .get (stat_key )
461+ if chars is not None and len (chars [1 ]):
462+ fontdictObject = self .embedTTF (realpath , chars [1 ])
462463 fonts [Fx ] = fontdictObject
463464 #print >>sys.stderr, filename
464465 self .writeObject (self .fontObject , fonts )
@@ -1092,37 +1093,36 @@ def _setup_textpos(self, x, y, angle, oldx=0, oldy=0, oldangle=0):
10921093
10931094 def draw_mathtext (self , gc , x , y , s , prop , angle ):
10941095 # TODO: fix positioning and encoding
1095- fontsize = prop .get_size_in_points ()
10961096 width , height , pswriter , used_characters = \
1097- math_parse_s_pdf (s , 72 , fontsize , 0 )
1097+ math_parse_s_pdf (s , 72 , prop , 0 )
10981098 self .merge_used_characters (used_characters )
1099-
1099+
11001100 self .check_gc (gc , gc ._rgb )
11011101 self .file .output (Op .begin_text )
11021102 prev_font = None , None
11031103 oldx , oldy = 0 , 0
1104- for ox , oy , fontname , fontsize , glyph in pswriter :
1105- #print ox, oy, glyph
1106- fontname = fontname .lower ()
1107- a = angle / 180.0 * pi
1108- newx = x + cos (a )* ox - sin (a )* oy
1109- newy = y + sin (a )* ox + cos (a )* oy
1110- self ._setup_textpos (newx , newy , angle , oldx , oldy )
1111- oldx , oldy = newx , newy
1112- if (fontname , fontsize ) != prev_font :
1113- self .file .output (self .file .fontName (fontname ), fontsize ,
1114- Op .selectfont )
1115- prev_font = fontname , fontsize
1116-
1117- #if fontname.endswith('cmsy10.ttf') or \
1118- #fontname.endswith('cmmi10.ttf') or \
1119- #fontname.endswith('cmex10.ttf'):
1120- # string = '\0' + chr(glyph)
1121-
1122- string = chr (glyph )
1123- self .file .output (string , Op .show )
1104+ for record in pswriter :
1105+ if record [0 ] == 'glyph' :
1106+ rec_type , ox , oy , fontname , fontsize , glyph = record
1107+ a = angle / 180.0 * pi
1108+ newx = x + cos (a )* ox - sin (a )* oy
1109+ newy = y + sin (a )* ox + cos (a )* oy
1110+ self ._setup_textpos (newx , newy , angle , oldx , oldy )
1111+ oldx , oldy = newx , newy
1112+ if (fontname , fontsize ) != prev_font :
1113+ self .file .output (self .file .fontName (fontname ), fontsize ,
1114+ Op .selectfont )
1115+ prev_font = fontname , fontsize
1116+
1117+ string = chr (glyph )
1118+ self .file .output (string , Op .show )
11241119 self .file .output (Op .end_text )
11251120
1121+ for record in pswriter :
1122+ if record [0 ] == 'rect' :
1123+ rec_type , ox , oy , width , height = record
1124+ self .file .output (Op .gsave , x + ox , y + oy , width , height , Op .rectangle , Op .fill , Op .grestore )
1125+
11261126 def _draw_tex (self , gc , x , y , s , prop , angle ):
11271127 # Rename to draw_tex to enable, but note the following:
11281128 # TODO:
@@ -1208,9 +1208,7 @@ def get_text_width_height(self, s, prop, ismath):
12081208 s = s .encode ('cp1252' , 'replace' )
12091209
12101210 if ismath :
1211- fontsize = prop .get_size_in_points ()
1212- w , h , pswriter , used_characters = math_parse_s_pdf (
1213- s , 72 , fontsize , 0 )
1211+ w , h , pswriter , used_characters = math_parse_s_pdf (s , 72 , prop , 0 )
12141212
12151213 elif rcParams ['pdf.use14corefonts' ]:
12161214 font = self ._get_font_afm (prop )
0 commit comments