Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4881758

Browse files
committed
Add kerning to Type 3 font, ASCII strings in PDFs
1 parent 63af5a2 commit 4881758

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,24 +2287,26 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
22872287
}
22882288
self.file._annotations[-1][1].append(link_annotation)
22892289

2290-
# If fonttype != 3 or there are no multibyte characters, emit the whole
2291-
# string at once.
2292-
if fonttype != 3 or all(ord(char) <= 255 for char in s):
2290+
# If fonttype != 3 emit the whole string at once without manual
2291+
# kerning.
2292+
if fonttype != 3:
22932293
self.file.output(Op.begin_text,
22942294
self.file.fontName(prop), fontsize, Op.selectfont)
22952295
self._setup_textpos(x, y, angle)
2296-
self.file.output(self.encode_string(s, fonttype), Op.show,
2297-
Op.end_text)
2296+
self.file.output(self.encode_string(s, fonttype),
2297+
Op.show, Op.end_text)
22982298

22992299
# There is no way to access multibyte characters of Type 3 fonts, as
23002300
# they cannot have a CIDMap. Therefore, in this case we break the
23012301
# string into chunks, where each chunk contains either a string of
2302-
# consecutive 1-byte characters or a single multibyte character. Each
2303-
# chunk is emitted with a separate command: 1-byte characters use the
2304-
# regular text show command (Tj), whereas multibyte characters use
2305-
# the XObject command (Do). (If using Type 42 fonts, all of this
2306-
# complication is avoided, but of course, those fonts can not be
2307-
# subsetted.)
2302+
# consecutive 1-byte characters or a single multibyte character.
2303+
# A sequence of 1-byte characters is broken into multiple chunks to
2304+
# adjust the kerning between adjacent chunks. Each chunk is emitted
2305+
# with a separate command: 1-byte characters use the regular text show
2306+
# command (TJ) with appropriate kerning between chunks, whereas
2307+
# multibyte characters use the XObject command (Do). (If using Type
2308+
# 42 fonts, all of this complication is avoided, but of course, those
2309+
# fonts can not be subsetted.)
23082310
else:
23092311
# List of (start_x, [prev_kern, char, char, ...]), w/o zero kerns.
23102312
singlebyte_chunks = []

0 commit comments

Comments
 (0)