Skip to content

Commit 08cb870

Browse files
authored
Merge pull request #22846 from meeseeksmachine/auto-backport-of-pr-22284-on-v3.5.x
Backport PR #22284 on branch v3.5.x (Specify font number for TTC font subsetting)
2 parents 5835252 + 297e9d7 commit 08cb870

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/matplotlib/backends/_backend_pdf_ps.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ def get_glyphs_subset(fontfile, characters):
3737
options = subset.Options(glyph_names=True, recommended_glyphs=True)
3838

3939
# prevent subsetting FontForge Timestamp and other tables
40-
options.drop_tables += ['FFTM', 'PfEd']
40+
options.drop_tables += ['FFTM', 'PfEd', 'BDF']
41+
42+
# if fontfile is a ttc, specify font number
43+
if fontfile.endswith(".ttc"):
44+
options.font_number = 0
4145

4246
with subset.load_font(fontfile, options) as font:
4347
subsetter = subset.Subsetter(options=options)

lib/matplotlib/tests/test_backend_pdf.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from matplotlib import dviread, pyplot as plt, checkdep_usetex, rcParams
1313
from matplotlib.cbook import _get_data_path
1414
from matplotlib.ft2font import FT2Font
15+
from matplotlib.font_manager import findfont, FontProperties
1516
from matplotlib.backends._backend_pdf_ps import get_glyphs_subset
1617
from matplotlib.backends.backend_pdf import PdfPages
1718

@@ -43,12 +44,20 @@ def test_use14corefonts():
4344
ax.axhline(0.5, linewidth=0.5)
4445

4546

46-
def test_type42():
47-
rcParams['pdf.fonttype'] = 42
47+
@pytest.mark.parametrize('fontname, fontfile', [
48+
('DejaVu Sans', 'DejaVuSans.ttf'),
49+
('WenQuanYi Zen Hei', 'wqy-zenhei.ttc'),
50+
])
51+
@pytest.mark.parametrize('fonttype', [3, 42])
52+
def test_embed_fonts(fontname, fontfile, fonttype):
53+
if Path(findfont(FontProperties(family=[fontname]))).name != fontfile:
54+
pytest.skip(f'Font {fontname!r} may be missing')
4855

56+
rcParams['pdf.fonttype'] = fonttype
4957
fig, ax = plt.subplots()
5058
ax.plot([1, 2, 3])
51-
fig.savefig(io.BytesIO())
59+
ax.set_title('Axes Title', font=fontname)
60+
fig.savefig(io.BytesIO(), format='pdf')
5261

5362

5463
def test_multipage_pagecount():

0 commit comments

Comments
 (0)