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):
475475textpos = b'Td'
476476selectfont = b'Tf'
477477textmatrix = b'Tm'
478+ textrise = b'Ts'
478479show = b'Tj'
479480showkern = b'TJ'
480481setlinewidth = 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.
22962297if fonttype not in [3 ,42 ]:
2298+ if not mpl .rcParams ['pdf.use14corefonts' ]:
2299+ self .file ._character_tracker .track (font ,s )
22972300self .file .output (Op .begin_text ,
22982301self .file .fontName (prop ),fontsize ,Op .selectfont )
22992302self ._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.
23152318else :
23162319def output_singlebyte_chunk (kerns_or_chars ):
2320+ if not kerns_or_chars :
2321+ return
23172322self .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
23212326else self ._encode_glyphs (group ,fonttype )
23222327for tp ,group in itertools .groupby (kerns_or_chars ,type )],
23232328Op .showkern )
2329+ kerns_or_chars .clear ()
23242330# Do the rotation and global translation as a single matrix
23252331# concatenation up front
23262332self .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.
23362342self .file .output (Op .begin_text )
23372343for item in _text_helpers .layout (s ,font ,features = features ,
2338- kern_mode = Kerning .UNFITTED ,
23392344language = language ):
23402345subset ,charcode = self .file ._character_tracker .track_glyph (
23412346item .ft_object ,item .char ,item .glyph_index )
23422347if (item .ft_object ,subset )!= prev_font :
2343- if singlebyte_chunk :
2344- output_singlebyte_chunk (singlebyte_chunk )
2348+ output_singlebyte_chunk (singlebyte_chunk )
23452349ft_name = self .file .fontName (item .ft_object .fname ,subset )
23462350self .file .output (ft_name ,fontsize ,Op .selectfont )
23472351self ._setup_textpos (item .x ,0 ,0 ,prev_start_x ,0 ,0 )
2348- singlebyte_chunk = []
23492352prev_font = (item .ft_object ,subset )
23502353prev_start_x = item .x
2354+ if item .y :
2355+ output_singlebyte_chunk (singlebyte_chunk )
2356+ self .file .output (item .y ,Op .textrise )
23512357if item .prev_kern :
23522358singlebyte_chunk .append (item .prev_kern )
23532359singlebyte_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 )
23562364self .file .output (Op .end_text )
23572365self .file .output (Op .grestore )
23582366