From 297e9d706d086a6c96c0fb9555bc67f4224caa98 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Thu, 14 Apr 2022 08:17:27 +0200 Subject: [PATCH] Backport PR #22284: Specify font number for TTC font subsetting --- lib/matplotlib/backends/_backend_pdf_ps.py | 6 +++++- lib/matplotlib/tests/test_backend_pdf.py | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/backends/_backend_pdf_ps.py b/lib/matplotlib/backends/_backend_pdf_ps.py index 3224fb90e3a9..cc15d9b7e3f7 100644 --- a/lib/matplotlib/backends/_backend_pdf_ps.py +++ b/lib/matplotlib/backends/_backend_pdf_ps.py @@ -37,7 +37,11 @@ def get_glyphs_subset(fontfile, characters): options = subset.Options(glyph_names=True, recommended_glyphs=True) # prevent subsetting FontForge Timestamp and other tables - options.drop_tables += ['FFTM', 'PfEd'] + options.drop_tables += ['FFTM', 'PfEd', 'BDF'] + + # if fontfile is a ttc, specify font number + if fontfile.endswith(".ttc"): + options.font_number = 0 with subset.load_font(fontfile, options) as font: subsetter = subset.Subsetter(options=options) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 8e16eb2b7b94..410fcf6e2025 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -12,6 +12,7 @@ from matplotlib import dviread, pyplot as plt, checkdep_usetex, rcParams from matplotlib.cbook import _get_data_path from matplotlib.ft2font import FT2Font +from matplotlib.font_manager import findfont, FontProperties from matplotlib.backends._backend_pdf_ps import get_glyphs_subset from matplotlib.backends.backend_pdf import PdfPages @@ -43,12 +44,20 @@ def test_use14corefonts(): ax.axhline(0.5, linewidth=0.5) -def test_type42(): - rcParams['pdf.fonttype'] = 42 +@pytest.mark.parametrize('fontname, fontfile', [ + ('DejaVu Sans', 'DejaVuSans.ttf'), + ('WenQuanYi Zen Hei', 'wqy-zenhei.ttc'), +]) +@pytest.mark.parametrize('fonttype', [3, 42]) +def test_embed_fonts(fontname, fontfile, fonttype): + if Path(findfont(FontProperties(family=[fontname]))).name != fontfile: + pytest.skip(f'Font {fontname!r} may be missing') + rcParams['pdf.fonttype'] = fonttype fig, ax = plt.subplots() ax.plot([1, 2, 3]) - fig.savefig(io.BytesIO()) + ax.set_title('Axes Title', font=fontname) + fig.savefig(io.BytesIO(), format='pdf') def test_multipage_pagecount(): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy