34
34
from matplotlib .figure import Figure
35
35
from matplotlib .font_manager import get_font , fontManager as _fontManager
36
36
from matplotlib ._afm import AFM
37
- from matplotlib .ft2font import FT2Font , FaceFlags , Kerning , LoadFlags , StyleFlags
37
+ from matplotlib .ft2font import FT2Font , FaceFlags , LoadFlags , StyleFlags
38
38
from matplotlib .transforms import Affine2D , BboxBase
39
39
from matplotlib .path import Path
40
40
from matplotlib .dates import UTC
@@ -469,6 +469,7 @@ class Op(Enum):
469
469
textpos = b'Td'
470
470
selectfont = b'Tf'
471
471
textmatrix = b'Tm'
472
+ textrise = b'Ts'
472
473
show = b'Tj'
473
474
showkern = b'TJ'
474
475
setlinewidth = b'w'
@@ -2285,6 +2286,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2285
2286
# If fonttype is neither 3 nor 42, emit the whole string at once
2286
2287
# without manual kerning.
2287
2288
if fonttype not in [3 , 42 ]:
2289
+ if not mpl .rcParams ['pdf.use14corefonts' ]:
2290
+ self .file ._character_tracker .track (font , s )
2288
2291
self .file .output (Op .begin_text ,
2289
2292
self .file .fontName (prop ), fontsize , Op .selectfont )
2290
2293
self ._setup_textpos (x , y , angle )
@@ -2305,13 +2308,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2305
2308
# kerning between chunks.
2306
2309
else :
2307
2310
def output_singlebyte_chunk (kerns_or_chars ):
2311
+ if not kerns_or_chars :
2312
+ return
2308
2313
self .file .output (
2309
2314
# See pdf spec "Text space details" for the 1000/fontsize
2310
2315
# (aka. 1000/T_fs) factor.
2311
2316
[(- 1000 * next (group ) / fontsize ) if tp == float # a kern
2312
2317
else self ._encode_glyphs (group , fonttype )
2313
2318
for tp , group in itertools .groupby (kerns_or_chars , type )],
2314
2319
Op .showkern )
2320
+ kerns_or_chars .clear ()
2315
2321
# Do the rotation and global translation as a single matrix
2316
2322
# concatenation up front
2317
2323
self .file .output (Op .gsave )
@@ -2326,24 +2332,26 @@ def output_singlebyte_chunk(kerns_or_chars):
2326
2332
# Emit all the characters in a BT/ET group.
2327
2333
self .file .output (Op .begin_text )
2328
2334
for item in _text_helpers .layout (s , font , features = features ,
2329
- kern_mode = Kerning .UNFITTED ,
2330
2335
language = language ):
2331
2336
subset , charcode = self .file ._character_tracker .track_glyph (
2332
2337
item .ft_object , item .char , item .glyph_index )
2333
2338
if (item .ft_object , subset ) != prev_font :
2334
- if singlebyte_chunk :
2335
- output_singlebyte_chunk (singlebyte_chunk )
2339
+ output_singlebyte_chunk (singlebyte_chunk )
2336
2340
ft_name = self .file .fontName (item .ft_object .fname , subset )
2337
2341
self .file .output (ft_name , fontsize , Op .selectfont )
2338
2342
self ._setup_textpos (item .x , 0 , 0 , prev_start_x , 0 , 0 )
2339
- singlebyte_chunk = []
2340
2343
prev_font = (item .ft_object , subset )
2341
2344
prev_start_x = item .x
2345
+ if item .y :
2346
+ output_singlebyte_chunk (singlebyte_chunk )
2347
+ self .file .output (item .y , Op .textrise )
2342
2348
if item .prev_kern :
2343
2349
singlebyte_chunk .append (item .prev_kern )
2344
2350
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 )
2347
2355
self .file .output (Op .end_text )
2348
2356
self .file .output (Op .grestore )
2349
2357
0 commit comments