@@ -2095,9 +2095,6 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
2095
2095
width , height , descent , glyphs , rects = \
2096
2096
self ._text2path .mathtext_parser .parse (s , 72 , prop )
2097
2097
2098
- # When using Type 3 fonts, we can't use character codes higher
2099
- # than 255, so we use the "Do" command to render those
2100
- # instead.
2101
2098
global_fonttype = mpl .rcParams ['pdf.fonttype' ]
2102
2099
2103
2100
# Set up a global transformation matrix for the whole math expression
@@ -2108,18 +2105,21 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
2108
2105
x , y , Op .concat_matrix )
2109
2106
2110
2107
self .check_gc (gc , gc ._rgb )
2111
- self .file .output (Op .begin_text )
2112
2108
prev_font = None , None
2113
2109
oldx , oldy = 0 , 0
2110
+ type3_multibytes = []
2111
+
2112
+ self .file .output (Op .begin_text )
2114
2113
for font , fontsize , num , ox , oy in glyphs :
2115
2114
self .file ._character_tracker .track (font , chr (num ))
2116
2115
fontname = font .fname
2117
- if is_opentype_cff_font (fontname ):
2118
- fonttype = 42
2116
+ fonttype = (
2117
+ 42 if is_opentype_cff_font (fontname ) else global_fonttype )
2118
+ if fonttype == 3 and num > 255 :
2119
+ # For Type3 fonts, multibyte characters must be emitted
2120
+ # separately (below).
2121
+ type3_multibytes .append ((font , fontsize , ox , oy , num ))
2119
2122
else :
2120
- fonttype = global_fonttype
2121
-
2122
- if fonttype == 42 or num <= 255 :
2123
2123
self ._setup_textpos (ox , oy , 0 , oldx , oldy )
2124
2124
oldx , oldy = ox , oy
2125
2125
if (fontname , fontsize ) != prev_font :
@@ -2130,27 +2130,9 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
2130
2130
Op .show )
2131
2131
self .file .output (Op .end_text )
2132
2132
2133
- # If using Type 3 fonts, render all of the multi-byte characters
2134
- # as XObjects using the 'Do' command.
2135
- if global_fonttype == 3 :
2136
- for font , fontsize , num , ox , oy in glyphs :
2137
- fontname = font .fname
2138
- if is_opentype_cff_font (fontname ):
2139
- fonttype = 42
2140
- else :
2141
- fonttype = global_fonttype
2142
-
2143
- if fonttype == 3 and num > 255 :
2144
- self .file .fontName (fontname )
2145
- self .file .output (Op .gsave ,
2146
- 0.001 * fontsize , 0 ,
2147
- 0 , 0.001 * fontsize ,
2148
- ox , oy , Op .concat_matrix )
2149
- symbol_name = font .get_glyph_name (font .get_char_index (num ))
2150
- name = self .file ._get_xobject_symbol_name (
2151
- fontname , symbol_name )
2152
- self .file .output (Name (name ), Op .use_xobject )
2153
- self .file .output (Op .grestore )
2133
+ for font , fontsize , ox , oy , num in type3_multibytes :
2134
+ self ._draw_xobject_glyph (
2135
+ font , fontsize , font .get_char_index (num ), ox , oy )
2154
2136
2155
2137
# Draw any horizontal lines in the math layout
2156
2138
for ox , oy , width , height in rects :
@@ -2328,17 +2310,20 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2328
2310
self .file .output (Op .end_text )
2329
2311
# Then emit all the multibyte characters, one at a time.
2330
2312
for start_x , glyph_idx in multibyte_glyphs :
2331
- glyph_name = font .get_glyph_name (glyph_idx )
2332
- self .file .output (Op .gsave )
2333
- self .file .output (0.001 * fontsize , 0 ,
2334
- 0 , 0.001 * fontsize ,
2335
- start_x , 0 , Op .concat_matrix )
2336
- name = self .file ._get_xobject_symbol_name (
2337
- font .fname , glyph_name )
2338
- self .file .output (Name (name ), Op .use_xobject )
2339
- self .file .output (Op .grestore )
2313
+ self ._draw_xobject_glyph (font , fontsize , glyph_idx , start_x , 0 )
2340
2314
self .file .output (Op .grestore )
2341
2315
2316
+ def _draw_xobject_glyph (self , font , fontsize , glyph_idx , x , y ):
2317
+ """Draw a multibyte character from a Type 3 font as an XObject."""
2318
+ symbol_name = font .get_glyph_name (glyph_idx )
2319
+ name = self .file ._get_xobject_symbol_name (font .fname , symbol_name )
2320
+ self .file .output (
2321
+ Op .gsave ,
2322
+ 0.001 * fontsize , 0 , 0 , 0.001 * fontsize , x , y , Op .concat_matrix ,
2323
+ Name (name ), Op .use_xobject ,
2324
+ Op .grestore ,
2325
+ )
2326
+
2342
2327
def new_gc (self ):
2343
2328
# docstring inherited
2344
2329
return GraphicsContextPdf (self .file )
0 commit comments