From 5fb14db3c8b4bf004d2b441e1bf3d18174e7ee9e Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 4 Oct 2020 12:16:11 +0200 Subject: [PATCH] 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. --- lib/matplotlib/backends/backend_pdf.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/lib/matplotlib/backends/backend_pdf.py b/lib/matplotlib/backends/backend_pdf.py index df803f5f06fd..2a4df4a6c967 100644 --- a/lib/matplotlib/backends/backend_pdf.py +++ b/lib/matplotlib/backends/backend_pdf.py @@ -31,7 +31,7 @@ GraphicsContextBase, RendererBase) from matplotlib.backends.backend_mixed import MixedModeRenderer from matplotlib.figure import Figure -from matplotlib.font_manager import findfont, is_opentype_cff_font, get_font +from matplotlib.font_manager import findfont, get_font from matplotlib.afm import AFM import matplotlib.type1font as type1font import matplotlib.dviread as dviread @@ -1348,15 +1348,6 @@ def embedTTFType42(font, characters, descriptor): 'StemV': 0 # ??? } - # The font subsetting to a Type 3 font does not work for - # OpenType (.otf) that embed a Postscript CFF font, so avoid that -- - # save as a (non-subsetted) Type 42 font instead. - if is_opentype_cff_font(filename): - fonttype = 42 - _log.warning("%r can not be subsetted into a Type 3 font. The " - "entire font will be embedded in the output.", - os.path.basename(filename)) - if fonttype == 3: return embedTTFType3(font, characters, descriptor) elif fonttype == 42: @@ -2119,7 +2110,7 @@ def draw_mathtext(self, gc, x, y, s, prop, angle): } self.file._annotations[-1][1].append(link_annotation) - global_fonttype = mpl.rcParams['pdf.fonttype'] + fonttype = mpl.rcParams['pdf.fonttype'] # Set up a global transformation matrix for the whole math expression a = math.radians(angle) @@ -2137,8 +2128,6 @@ def draw_mathtext(self, gc, x, y, s, prop, angle): for font, fontsize, num, ox, oy in glyphs: self.file._character_tracker.track(font, chr(num)) fontname = font.fname - fonttype = ( - 42 if is_opentype_cff_font(fontname) else global_fonttype) if fonttype == 3 and num > 255: # For Type3 fonts, multibyte characters must be emitted # separately (below). @@ -2282,10 +2271,6 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None): font = self._get_font_ttf(prop) self.file._character_tracker.track(font, s) fonttype = mpl.rcParams['pdf.fonttype'] - # We can't subset all OpenType fonts, so switch to Type 42 - # in that case. - if is_opentype_cff_font(font.fname): - fonttype = 42 if gc.get_url() is not None: font.set_text(s)