Skip to content

Commit 696abf7

Browse files
committed
Allow Type3 subsetting of otf fonts in pdf backend.
This is supported since 19359c1, results in smaller files (*much* smaller when using CJK fonts), and avoids running into issues with type 42 embedding and certain pdf readers such as Acrobat Reader.
1 parent dd15dc0 commit 696abf7

File tree

1 file changed

+2
-17
lines changed

1 file changed

+2
-17
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
GraphicsContextBase, RendererBase)
3232
from matplotlib.backends.backend_mixed import MixedModeRenderer
3333
from matplotlib.figure import Figure
34-
from matplotlib.font_manager import findfont, is_opentype_cff_font, get_font
34+
from matplotlib.font_manager import findfont, get_font
3535
from matplotlib.afm import AFM
3636
import matplotlib.type1font as type1font
3737
import matplotlib.dviread as dviread
@@ -1337,15 +1337,6 @@ def embedTTFType42(font, characters, descriptor):
13371337
'StemV': 0 # ???
13381338
}
13391339

1340-
# The font subsetting to a Type 3 font does not work for
1341-
# OpenType (.otf) that embed a Postscript CFF font, so avoid that --
1342-
# save as a (non-subsetted) Type 42 font instead.
1343-
if is_opentype_cff_font(filename):
1344-
fonttype = 42
1345-
_log.warning("%r can not be subsetted into a Type 3 font. The "
1346-
"entire font will be embedded in the output.",
1347-
os.path.basename(filename))
1348-
13491340
if fonttype == 3:
13501341
return embedTTFType3(font, characters, descriptor)
13511342
elif fonttype == 42:
@@ -2095,7 +2086,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
20952086
width, height, descent, glyphs, rects = \
20962087
self._text2path.mathtext_parser.parse(s, 72, prop)
20972088

2098-
global_fonttype = mpl.rcParams['pdf.fonttype']
2089+
fonttype = mpl.rcParams['pdf.fonttype']
20992090

21002091
# Set up a global transformation matrix for the whole math expression
21012092
a = math.radians(angle)
@@ -2113,8 +2104,6 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
21132104
for font, fontsize, num, ox, oy in glyphs:
21142105
self.file._character_tracker.track(font, chr(num))
21152106
fontname = font.fname
2116-
fonttype = (
2117-
42 if is_opentype_cff_font(fontname) else global_fonttype)
21182107
if fonttype == 3 and num > 255:
21192108
# For Type3 fonts, multibyte characters must be emitted
21202109
# separately (below).
@@ -2245,10 +2234,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
22452234
font = self._get_font_ttf(prop)
22462235
self.file._character_tracker.track(font, s)
22472236
fonttype = mpl.rcParams['pdf.fonttype']
2248-
# We can't subset all OpenType fonts, so switch to Type 42
2249-
# in that case.
2250-
if is_opentype_cff_font(font.fname):
2251-
fonttype = 42
22522237

22532238
# If fonttype != 3 or there are no multibyte characters, emit the whole
22542239
# string at once.

0 commit comments

Comments
 (0)