@@ -631,7 +631,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
631
631
if mpl .rcParams ['ps.useafm' ]:
632
632
font = self ._get_font_afm (prop )
633
633
scale = 0.001 * prop .get_size_in_points ()
634
-
634
+ stream = []
635
635
thisx = 0
636
636
last_name = None # kerns returns 0 for None.
637
637
xs_names = []
@@ -647,21 +647,36 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
647
647
thisx += kern * scale
648
648
xs_names .append ((thisx , name ))
649
649
thisx += width * scale
650
+ ps_name = (font .postscript_name
651
+ .encode ("ascii" , "replace" ).decode ("ascii" ))
652
+ stream .append ((ps_name , xs_names ))
650
653
651
654
else :
652
655
font = self ._get_font_ttf (prop )
653
- font .set_text (s , 0 , flags = LOAD_NO_HINTING )
654
656
self ._character_tracker .track (font , s )
655
- xs_names = [(item .x , font .get_glyph_name (item .glyph_idx ))
656
- for item in _text_helpers .layout (s , font )]
657
+ stream = []
658
+ prev_font = curr_stream = None
659
+ for item in _text_helpers .layout (s , font ):
660
+ ps_name = (item .ft_object .postscript_name
661
+ .encode ("ascii" , "replace" ).decode ("ascii" ))
662
+ if item .ft_object is not prev_font :
663
+ if curr_stream :
664
+ stream .append (curr_stream )
665
+ prev_font = item .ft_object
666
+ curr_stream = [ps_name , []]
667
+ curr_stream [1 ].append (
668
+ (item .x , item .ft_object .get_glyph_name (item .glyph_idx ))
669
+ )
670
+ # append the last entry
671
+ stream .append (curr_stream )
657
672
658
673
self .set_color (* gc .get_rgb ())
659
- ps_name = ( font . postscript_name
660
- . encode ( "ascii" , "replace" ). decode ( "ascii" ))
661
- self .set_font (ps_name , prop .get_size_in_points ())
662
- thetext = "\n " .join (f"{ x :g} 0 m /{ name :s} glyphshow"
663
- for x , name in xs_names )
664
- self ._pswriter .write (f"""\
674
+
675
+ for ps_name , xs_names in stream :
676
+ self .set_font (ps_name , prop .get_size_in_points (), False )
677
+ thetext = "\n " .join (f"{ x :g} 0 m /{ name :s} glyphshow"
678
+ for x , name in xs_names )
679
+ self ._pswriter .write (f"""\
665
680
gsave
666
681
{ self ._get_clip_cmd (gc )}
667
682
{ x :g} { y :g} translate
0 commit comments