@@ -640,6 +640,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
640
640
if ismath :
641
641
return self .draw_mathtext (gc , x , y , s , prop , angle )
642
642
643
+ self .set_color (* gc .get_rgb ())
644
+
643
645
if mpl .rcParams ['ps.useafm' ]:
644
646
font = self ._get_font_afm (prop )
645
647
scale = 0.001 * prop .get_size_in_points ()
@@ -662,18 +664,27 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
662
664
663
665
else :
664
666
font = self ._get_font_ttf (prop )
665
- font .set_text (s , 0 , flags = LOAD_NO_HINTING )
666
- self ._character_tracker .track (font , s )
667
- xs_names = [(item .x , font .get_glyph_name (item .glyph_idx ))
668
- for item in _text_helpers .layout (s , font )]
669
-
670
- self .set_color (* gc .get_rgb ())
671
- ps_name = (font .postscript_name
672
- .encode ("ascii" , "replace" ).decode ("ascii" ))
673
- self .set_font (ps_name , prop .get_size_in_points ())
674
- thetext = "\n " .join (f"{ x :f} 0 m /{ name :s} glyphshow"
675
- for x , name in xs_names )
676
- self ._pswriter .write (f"""\
667
+ char_to_font = font .fill_glyphs (s , 0 , flags = LOAD_NO_HINTING )
668
+ for char , font in char_to_font .items ():
669
+ self ._character_tracker .track (font , chr (char ))
670
+ stream = []
671
+ prev_font = curr_stream = None
672
+ for item in _text_helpers .layout (s , font ):
673
+ ps_name = (item .ft_object .postscript_name .encode ("ascii" , "replace" ).decode ("ascii" ))
674
+ if item .ft_object is not prev_font :
675
+ if curr_stream :
676
+ stream .append (curr_stream )
677
+ prev_font = item .ft_object
678
+ curr_stream = [ps_name , []]
679
+ curr_stream [1 ].append ((item .x , item .ft_object .get_glyph_name (item .glyph_idx )))
680
+ # append the last entry
681
+ stream .append (curr_stream )
682
+
683
+ for ps_name , xs_names in stream :
684
+ self .set_font (ps_name , prop .get_size_in_points (), False )
685
+ thetext = "\n " .join (f"{ x :f} 0 m /{ name :s} glyphshow"
686
+ for x , name in xs_names )
687
+ self ._pswriter .write (f"""\
677
688
gsave
678
689
{ self ._get_clip_cmd (gc )}
679
690
{ x :f} { y :f} translate
0 commit comments