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

Conversation

aitikgupta
Copy link
Contributor

PR Summary

Since #20804 isn't merged yet, the commit 1b53070 can go as a hotfix for #21893.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

@QuLogic QuLogic added this to the v3.5.2 milestone Jan 25, 2022
@QuLogic QuLogic linked an issue Jan 25, 2022 that may be closed by this pull request

# 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.

@tacaswell
Copy link
Member

Can you add a comment about why this works? Do we have access to any ttc fonts on CI so we can test this?

@oscargus
Copy link
Member

oscargus commented Mar 4, 2022

It should be possible to add a ttc-file, e.g. embedding the existing ttf-file (and possibly another ttf-file, just to actually make it a collection of ttfs, I can probably make an additional ttf with a single glyph or something...).

@oscargus
Copy link
Member

oscargus commented Mar 4, 2022

Oh, there is a test for ttc already, so there is a ttc font available for testing.

def test_find_ttc():
fp = FontProperties(family=["WenQuanYi Zen Hei"])
if Path(findfont(fp)).name != "wqy-zenhei.ttc":
pytest.skip("Font wqy-zenhei.ttc may be missing")
fig, ax = plt.subplots()
ax.text(.5, .5, "\N{KANGXI RADICAL DRAGON}", fontproperties=fp)
for fmt in ["raw", "svg", "pdf", "ps"]:
fig.savefig(BytesIO(), format=fmt)

Based on #9787 it seems like the first font is already selected, even though it is not clear from the code how that happens.

@QuLogic QuLogic force-pushed the fix/ttc-font-subset branch from 6022e3b to 1b78020 Compare April 7, 2022 19:19
@oscargus oscargus merged commit c1bf6df into matplotlib:main Apr 14, 2022
@oscargus
Copy link
Member

@meeseeksdev backport to v3.5.x

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 14, 2022
QuLogic added a commit that referenced this pull request Apr 14, 2022
…284-on-v3.5.x

Backport PR #22284 on branch v3.5.x (Specify font number for TTC font subsetting)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: backend_pdf gives TTLibError with pdf.fonttype : 42
4 participants