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
@@ -475,6 +475,7 @@ class Op(Enum):
475475 textpos = b'Td'
476476 selectfont = b'Tf'
477477 textmatrix = b'Tm'
478+ textrise = b'Ts'
478479 show = b'Tj'
479480 showkern = b'TJ'
480481 setlinewidth = b'w'
@@ -2294,6 +2295,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
22942295 # If fonttype is neither 3 nor 42, emit the whole string at once
22952296 # without manual kerning.
22962297 if fonttype not in [3 , 42 ]:
2298+ if not mpl .rcParams ['pdf.use14corefonts' ]:
2299+ self .file ._character_tracker .track (font , s )
22972300 self .file .output (Op .begin_text ,
22982301 self .file .fontName (prop ), fontsize , Op .selectfont )
22992302 self ._setup_textpos (x , y , angle )
@@ -2314,13 +2317,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
23142317 # kerning between chunks.
23152318 else :
23162319 def output_singlebyte_chunk (kerns_or_chars ):
2320+ if not kerns_or_chars :
2321+ return
23172322 self .file .output (
23182323 # See pdf spec "Text space details" for the 1000/fontsize
23192324 # (aka. 1000/T_fs) factor.
23202325 [(- 1000 * next (group ) / fontsize ) if tp == float # a kern
23212326 else self ._encode_glyphs (group , fonttype )
23222327 for tp , group in itertools .groupby (kerns_or_chars , type )],
23232328 Op .showkern )
2329+ kerns_or_chars .clear ()
23242330 # Do the rotation and global translation as a single matrix
23252331 # concatenation up front
23262332 self .file .output (Op .gsave )
@@ -2335,24 +2341,26 @@ def output_singlebyte_chunk(kerns_or_chars):
23352341 # Emit all the characters in a BT/ET group.
23362342 self .file .output (Op .begin_text )
23372343 for item in _text_helpers .layout (s , font , features = features ,
2338- kern_mode = Kerning .UNFITTED ,
23392344 language = language ):
23402345 subset , charcode = self .file ._character_tracker .track_glyph (
23412346 item .ft_object , item .char , item .glyph_index )
23422347 if (item .ft_object , subset ) != prev_font :
2343- if singlebyte_chunk :
2344- output_singlebyte_chunk (singlebyte_chunk )
2348+ output_singlebyte_chunk (singlebyte_chunk )
23452349 ft_name = self .file .fontName (item .ft_object .fname , subset )
23462350 self .file .output (ft_name , fontsize , Op .selectfont )
23472351 self ._setup_textpos (item .x , 0 , 0 , prev_start_x , 0 , 0 )
2348- singlebyte_chunk = []
23492352 prev_font = (item .ft_object , subset )
23502353 prev_start_x = item .x
2354+ if item .y :
2355+ output_singlebyte_chunk (singlebyte_chunk )
2356+ self .file .output (item .y , Op .textrise )
23512357 if item .prev_kern :
23522358 singlebyte_chunk .append (item .prev_kern )
23532359 singlebyte_chunk .append (charcode )
2354- if singlebyte_chunk :
2355- output_singlebyte_chunk (singlebyte_chunk )
2360+ if item .y :
2361+ output_singlebyte_chunk (singlebyte_chunk )
2362+ self .file .output (0 , Op .textrise )
2363+ output_singlebyte_chunk (singlebyte_chunk )
23562364 self .file .output (Op .end_text )
23572365 self .file .output (Op .grestore )
23582366
0 commit comments