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):
469469textpos = b'Td'
470470selectfont = b'Tf'
471471textmatrix = b'Tm'
472+ textrise = b'Ts'
472473show = b'Tj'
473474showkern = b'TJ'
474475setlinewidth = 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.
22872288if fonttype not in [3 ,42 ]:
2289+ if not mpl .rcParams ['pdf.use14corefonts' ]:
2290+ self .file ._character_tracker .track (font ,s )
22882291self .file .output (Op .begin_text ,
22892292self .file .fontName (prop ),fontsize ,Op .selectfont )
22902293self ._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.
23062309else :
23072310def output_singlebyte_chunk (kerns_or_chars ):
2311+ if not kerns_or_chars :
2312+ return
23082313self .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
23122317else self ._encode_glyphs (group ,fonttype )
23132318for tp ,group in itertools .groupby (kerns_or_chars ,type )],
23142319Op .showkern )
2320+ kerns_or_chars .clear ()
23152321# Do the rotation and global translation as a single matrix
23162322# concatenation up front
23172323self .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.
23272333self .file .output (Op .begin_text )
23282334for item in _text_helpers .layout (s ,font ,features = features ,
2329- kern_mode = Kerning .UNFITTED ,
23302335language = language ):
23312336subset ,charcode = self .file ._character_tracker .track_glyph (
23322337item .ft_object ,item .char ,item .glyph_index )
23332338if (item .ft_object ,subset )!= prev_font :
2334- if singlebyte_chunk :
2335- output_singlebyte_chunk (singlebyte_chunk )
2339+ output_singlebyte_chunk (singlebyte_chunk )
23362340ft_name = self .file .fontName (item .ft_object .fname ,subset )
23372341self .file .output (ft_name ,fontsize ,Op .selectfont )
23382342self ._setup_textpos (item .x ,0 ,0 ,prev_start_x ,0 ,0 )
2339- singlebyte_chunk = []
23402343prev_font = (item .ft_object ,subset )
23412344prev_start_x = item .x
2345+ if item .y :
2346+ output_singlebyte_chunk (singlebyte_chunk )
2347+ self .file .output (item .y ,Op .textrise )
23422348if item .prev_kern :
23432349singlebyte_chunk .append (item .prev_kern )
23442350singlebyte_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 )
23472355self .file .output (Op .end_text )
23482356self .file .output (Op .grestore )
23492357