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

Skip to content

Specify font number for TTC font subsetting #22284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/matplotlib/backends/_backend_pdf_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extracting from the first font in the collection correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so; the count starts from 0.


with subset.load_font(fontfile, options) as font:
subsetter = subset.Subsetter(options=options)
Expand Down
15 changes: 12 additions & 3 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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():
Expand Down