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
@@ -475,6 +475,7 @@ class Op(Enum):
475
475
textpos = b'Td'
476
476
selectfont = b'Tf'
477
477
textmatrix = b'Tm'
478
+ textrise = b'Ts'
478
479
show = b'Tj'
479
480
showkern = b'TJ'
480
481
setlinewidth = b'w'
@@ -2294,6 +2295,8 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2294
2295
# If fonttype is neither 3 nor 42, emit the whole string at once
2295
2296
# without manual kerning.
2296
2297
if fonttype not in [3 , 42 ]:
2298
+ if not mpl .rcParams ['pdf.use14corefonts' ]:
2299
+ self .file ._character_tracker .track (font , s )
2297
2300
self .file .output (Op .begin_text ,
2298
2301
self .file .fontName (prop ), fontsize , Op .selectfont )
2299
2302
self ._setup_textpos (x , y , angle )
@@ -2314,13 +2317,16 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
2314
2317
# kerning between chunks.
2315
2318
else :
2316
2319
def output_singlebyte_chunk (kerns_or_chars ):
2320
+ if not kerns_or_chars :
2321
+ return
2317
2322
self .file .output (
2318
2323
# See pdf spec "Text space details" for the 1000/fontsize
2319
2324
# (aka. 1000/T_fs) factor.
2320
2325
[(- 1000 * next (group ) / fontsize ) if tp == float # a kern
2321
2326
else self ._encode_glyphs (group , fonttype )
2322
2327
for tp , group in itertools .groupby (kerns_or_chars , type )],
2323
2328
Op .showkern )
2329
+ kerns_or_chars .clear ()
2324
2330
# Do the rotation and global translation as a single matrix
2325
2331
# concatenation up front
2326
2332
self .file .output (Op .gsave )
@@ -2335,24 +2341,26 @@ def output_singlebyte_chunk(kerns_or_chars):
2335
2341
# Emit all the characters in a BT/ET group.
2336
2342
self .file .output (Op .begin_text )
2337
2343
for item in _text_helpers .layout (s , font , features = features ,
2338
- kern_mode = Kerning .UNFITTED ,
2339
2344
language = language ):
2340
2345
subset , charcode = self .file ._character_tracker .track_glyph (
2341
2346
item .ft_object , item .char , item .glyph_index )
2342
2347
if (item .ft_object , subset ) != prev_font :
2343
- if singlebyte_chunk :
2344
- output_singlebyte_chunk (singlebyte_chunk )
2348
+ output_singlebyte_chunk (singlebyte_chunk )
2345
2349
ft_name = self .file .fontName (item .ft_object .fname , subset )
2346
2350
self .file .output (ft_name , fontsize , Op .selectfont )
2347
2351
self ._setup_textpos (item .x , 0 , 0 , prev_start_x , 0 , 0 )
2348
- singlebyte_chunk = []
2349
2352
prev_font = (item .ft_object , subset )
2350
2353
prev_start_x = item .x
2354
+ if item .y :
2355
+ output_singlebyte_chunk (singlebyte_chunk )
2356
+ self .file .output (item .y , Op .textrise )
2351
2357
if item .prev_kern :
2352
2358
singlebyte_chunk .append (item .prev_kern )
2353
2359
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 )
2356
2364
self .file .output (Op .end_text )
2357
2365
self .file .output (Op .grestore )
2358
2366
0 commit comments