3434from matplotlib .figure import Figure
3535from matplotlib .font_manager import 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'
@@ -2285,6 +2286,9 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
22852286 # If fonttype is neither 3 nor 42, emit the whole string at once
22862287 # without manual kerning.
22872288 if fonttype not in [3 , 42 ]:
2289+ if not mpl .rcParams ['pdf.use14corefonts' ]:
2290+ self .file ._character_tracker .track (font , s ,
2291+ features = features , language = language )
22882292 self .file .output (Op .begin_text ,
22892293 self .file .fontName (prop ), fontsize , Op .selectfont )
22902294 self ._setup_textpos (x , y , angle )
@@ -2305,13 +2309,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
23052309 # kerning between chunks.
23062310 else :
23072311 def output_singlebyte_chunk (kerns_or_chars ):
2312+ if not kerns_or_chars :
2313+ return
23082314 self .file .output (
23092315 # See pdf spec "Text space details" for the 1000/fontsize
23102316 # (aka. 1000/T_fs) factor.
23112317 [(- 1000 * next (group ) / fontsize ) if tp == float # a kern
23122318 else self ._encode_glyphs (group , fonttype )
23132319 for tp , group in itertools .groupby (kerns_or_chars , type )],
23142320 Op .showkern )
2321+ kerns_or_chars .clear ()
23152322 # Do the rotation and global translation as a single matrix
23162323 # concatenation up front
23172324 self .file .output (Op .gsave )
@@ -2326,24 +2333,26 @@ def output_singlebyte_chunk(kerns_or_chars):
23262333 # Emit all the characters in a BT/ET group.
23272334 self .file .output (Op .begin_text )
23282335 for item in _text_helpers .layout (s , font , features = features ,
2329- kern_mode = Kerning .UNFITTED ,
23302336 language = language ):
23312337 subset , charcode = self .file ._character_tracker .track_glyph (
23322338 item .ft_object , item .char , item .glyph_index )
23332339 if (item .ft_object , subset ) != prev_font :
2334- if singlebyte_chunk :
2335- output_singlebyte_chunk (singlebyte_chunk )
2340+ output_singlebyte_chunk (singlebyte_chunk )
23362341 ft_name = self .file .fontName (item .ft_object .fname , subset )
23372342 self .file .output (ft_name , fontsize , Op .selectfont )
23382343 self ._setup_textpos (item .x , 0 , 0 , prev_start_x , 0 , 0 )
2339- singlebyte_chunk = []
23402344 prev_font = (item .ft_object , subset )
23412345 prev_start_x = item .x
2346+ if item .y :
2347+ output_singlebyte_chunk (singlebyte_chunk )
2348+ self .file .output (item .y , Op .textrise )
23422349 if item .prev_kern :
23432350 singlebyte_chunk .append (item .prev_kern )
23442351 singlebyte_chunk .append (charcode )
2345- if singlebyte_chunk :
2346- output_singlebyte_chunk (singlebyte_chunk )
2352+ if item .y :
2353+ output_singlebyte_chunk (singlebyte_chunk )
2354+ self .file .output (0 , Op .textrise )
2355+ output_singlebyte_chunk (singlebyte_chunk )
23472356 self .file .output (Op .end_text )
23482357 self .file .output (Op .grestore )
23492358
0 commit comments