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

Skip to content

Commit 5fb14db

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 319f35b commit 5fb14db

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
@@ -1348,15 +1348,6 @@ def embedTTFType42(font, characters, descriptor):
13481348
'StemV': 0 # ???
13491349
}
13501350

1351-
# The font subsetting to a Type 3 font does not work for
1352-
# OpenType (.otf) that embed a Postscript CFF font, so avoid that --
1353-
# save as a (non-subsetted) Type 42 font instead.
1354-
if is_opentype_cff_font(filename):
1355-
fonttype = 42
1356-
_log.warning("%r can not be subsetted into a Type 3 font. The "
1357-
"entire font will be embedded in the output.",
1358-
os.path.basename(filename))
1359-
13601351
if fonttype == 3:
13611352
return embedTTFType3(font, characters, descriptor)
13621353
elif fonttype == 42:
@@ -2119,7 +2110,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
21192110
}
21202111
self.file._annotations[-1][1].append(link_annotation)
21212112

2122-
global_fonttype = mpl.rcParams['pdf.fonttype']
2113+
fonttype = mpl.rcParams['pdf.fonttype']
21232114

21242115
# Set up a global transformation matrix for the whole math expression
21252116
a = math.radians(angle)
@@ -2137,8 +2128,6 @@ def draw_mathtext(self, gc, x, y, s, prop, angle):
21372128
for font, fontsize, num, ox, oy in glyphs:
21382129
self.file._character_tracker.track(font, chr(num))
21392130
fontname = font.fname
2140-
fonttype = (
2141-
42 if is_opentype_cff_font(fontname) else global_fonttype)
21422131
if fonttype == 3 and num > 255:
21432132
# For Type3 fonts, multibyte characters must be emitted
21442133
# separately (below).
@@ -2282,10 +2271,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
22822271
font = self._get_font_ttf(prop)
22832272
self.file._character_tracker.track(font, s)
22842273
fonttype = mpl.rcParams['pdf.fonttype']
2285-
# We can't subset all OpenType fonts, so switch to Type 42
2286-
# in that case.
2287-
if is_opentype_cff_font(font.fname):
2288-
fonttype = 42
22892274

22902275
if gc.get_url() is not None:
22912276
font.set_text(s)

0 commit comments

Comments
 (0)