3434from matplotlib .figure import Figure
3535from matplotlib .font_manager import FontPath , get_font , fontManager as _fontManager
3636from matplotlib ._afm import AFM
37- from matplotlib .ft2font import FT2Font , FaceFlags , Kerning , LoadFlags , StyleFlags
37+ from matplotlib .ft2font import FT2Font , FaceFlags , LoadFlags , StyleFlags
3838from matplotlib .transforms import Affine2D , BboxBase
3939from matplotlib .path import Path
4040from matplotlib .dates import UTC
@@ -469,6 +469,7 @@ class Op(Enum):
469469 textpos = b'Td'
470470 selectfont = b'Tf'
471471 textmatrix = b'Tm'
472+ textrise = b'Ts'
472473 show = b'Tj'
473474 showkern = b'TJ'
474475 setlinewidth = b'w'
@@ -2288,6 +2289,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
22882289 # If fonttype is neither 3 nor 42, emit the whole string at once
22892290 # without manual kerning.
22902291 if fonttype not in [3 , 42 ]:
2292+ if not mpl .rcParams ['pdf.use14corefonts' ]:
2293+ self .file ._character_tracker .track (font , s ,
2294+ features = features , language = language )
22912295 self .file .output (Op .begin_text ,
22922296 self .file .fontName (prop ), fontsize , Op .selectfont )
22932297 self ._setup_textpos (x , y , angle )
@@ -2308,13 +2312,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
23082312 # kerning between chunks.
23092313 else :
23102314 def output_singlebyte_chunk (kerns_or_chars ):
2315+ if not kerns_or_chars :
2316+ return
23112317 self .file .output (
23122318 # See pdf spec "Text space details" for the 1000/fontsize
23132319 # (aka. 1000/T_fs) factor.
23142320 [(- 1000 * next (group ) / fontsize ) if tp == float # a kern
23152321 else self ._encode_glyphs (group , fonttype )
23162322 for tp , group in itertools .groupby (kerns_or_chars , type )],
23172323 Op .showkern )
2324+ kerns_or_chars .clear ()
23182325 # Do the rotation and global translation as a single matrix
23192326 # concatenation up front
23202327 self .file .output (Op .gsave )
@@ -2329,26 +2336,28 @@ def output_singlebyte_chunk(kerns_or_chars):
23292336 # Emit all the characters in a BT/ET group.
23302337 self .file .output (Op .begin_text )
23312338 for item in _text_helpers .layout (s , font , features = features ,
2332- kern_mode = Kerning .UNFITTED ,
23332339 language = language ):
23342340 subset , charcode = self .file ._character_tracker .track_glyph (
23352341 item .ft_object , item .char , item .glyph_index )
23362342 if (item .ft_object , subset ) != prev_font :
2337- if singlebyte_chunk :
2338- output_singlebyte_chunk (singlebyte_chunk )
2343+ output_singlebyte_chunk (singlebyte_chunk )
23392344 font_path = FontPath (item .ft_object .fname ,
23402345 item .ft_object .face_index )
23412346 ft_name = self .file .fontName (font_path , subset )
23422347 self .file .output (ft_name , fontsize , Op .selectfont )
23432348 self ._setup_textpos (item .x , 0 , 0 , prev_start_x , 0 , 0 )
2344- singlebyte_chunk = []
23452349 prev_font = (item .ft_object , subset )
23462350 prev_start_x = item .x
2351+ if item .y :
2352+ output_singlebyte_chunk (singlebyte_chunk )
2353+ self .file .output (item .y , Op .textrise )
23472354 if item .prev_kern :
23482355 singlebyte_chunk .append (item .prev_kern )
23492356 singlebyte_chunk .append (charcode )
2350- if singlebyte_chunk :
2351- output_singlebyte_chunk (singlebyte_chunk )
2357+ if item .y :
2358+ output_singlebyte_chunk (singlebyte_chunk )
2359+ self .file .output (0 , Op .textrise )
2360+ output_singlebyte_chunk (singlebyte_chunk )
23522361 self .file .output (Op .end_text )
23532362 self .file .output (Op .grestore )
23542363
0 commit comments