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