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,8 @@ 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 )
22882291 self .file .output (Op .begin_text ,
22892292 self .file .fontName (prop ), fontsize , Op .selectfont )
22902293 self ._setup_textpos (x , y , angle )
@@ -2305,13 +2308,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
23052308 # kerning between chunks.
23062309 else :
23072310 def output_singlebyte_chunk (kerns_or_chars ):
2311+ if not kerns_or_chars :
2312+ return
23082313 self .file .output (
23092314 # See pdf spec "Text space details" for the 1000/fontsize
23102315 # (aka. 1000/T_fs) factor.
23112316 [(- 1000 * next (group ) / fontsize ) if tp == float # a kern
23122317 else self ._encode_glyphs (group , fonttype )
23132318 for tp , group in itertools .groupby (kerns_or_chars , type )],
23142319 Op .showkern )
2320+ kerns_or_chars .clear ()
23152321 # Do the rotation and global translation as a single matrix
23162322 # concatenation up front
23172323 self .file .output (Op .gsave )
@@ -2326,24 +2332,26 @@ def output_singlebyte_chunk(kerns_or_chars):
23262332 # Emit all the characters in a BT/ET group.
23272333 self .file .output (Op .begin_text )
23282334 for item in _text_helpers .layout (s , font , features = features ,
2329- kern_mode = Kerning .UNFITTED ,
23302335 language = language ):
23312336 subset , charcode = self .file ._character_tracker .track_glyph (
23322337 item .ft_object , item .char , item .glyph_index )
23332338 if (item .ft_object , subset ) != prev_font :
2334- if singlebyte_chunk :
2335- output_singlebyte_chunk (singlebyte_chunk )
2339+ output_singlebyte_chunk (singlebyte_chunk )
23362340 ft_name = self .file .fontName (item .ft_object .fname , subset )
23372341 self .file .output (ft_name , fontsize , Op .selectfont )
23382342 self ._setup_textpos (item .x , 0 , 0 , prev_start_x , 0 , 0 )
2339- singlebyte_chunk = []
23402343 prev_font = (item .ft_object , subset )
23412344 prev_start_x = item .x
2345+ if item .y :
2346+ output_singlebyte_chunk (singlebyte_chunk )
2347+ self .file .output (item .y , Op .textrise )
23422348 if item .prev_kern :
23432349 singlebyte_chunk .append (item .prev_kern )
23442350 singlebyte_chunk .append (charcode )
2345- if singlebyte_chunk :
2346- output_singlebyte_chunk (singlebyte_chunk )
2351+ if item .y :
2352+ output_singlebyte_chunk (singlebyte_chunk )
2353+ self .file .output (0 , Op .textrise )
2354+ output_singlebyte_chunk (singlebyte_chunk )
23472355 self .file .output (Op .end_text )
23482356 self .file .output (Op .grestore )
23492357
0 commit comments