From 41075013b6906b66a89b9e92f2aa44dc477ec321 Mon Sep 17 00:00:00 2001 From: Aitik Gupta Date: Wed, 26 Jan 2022 20:38:19 +0530 Subject: [PATCH 1/2] Specify font number for TTC fonts --- lib/matplotlib/backends/_backend_pdf_ps.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/backends/_backend_pdf_ps.py b/lib/matplotlib/backends/_backend_pdf_ps.py index 440c9ea4893a..65d38eb5a542 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) From 1b7802084515260e555db2016c4282955956401e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Thu, 7 Apr 2022 15:09:36 -0400 Subject: [PATCH 2/2] Improve PDF font testing --- lib/matplotlib/tests/test_backend_pdf.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 092fe0565c54..71a253a20851 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -12,6 +12,7 @@ from matplotlib import 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 from matplotlib.patches import Rectangle @@ -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