Skip to content

Fix TTF headers for type 42 stix font - #20597

Merged
QuLogic merged 1 commit into
matplotlib:masterfrom
sauerburger:stix-type-42-eps
Jul 13, 2021
Merged

QuLogic merged 1 commit into
matplotlib:masterfrom
sauerburger:stix-type-42-eps

Conversation

@sauerburger

@sauerburger sauerburger commented Jul 7, 2021 •

Copy link
Copy Markdown
Member

PR Summary

The combination of Type 42 font, STIX math font and EPS output format leads to broken output files, see #20612.

The embedded TTF font is damaged due to missing bytes in the file header. The embedded font contains 6 tables which causes this if to omit the values for searchRange, entrySelection and rangeShift.

I agree with the comment that the values are "silly" but for a valid TTF font, these values need to be present. In fact, the numbers written in the case of exactly 9 tables are not correct either. For 9 tables, the correct values would be 128, 3 and 16, see Table 4 in the reference manual.

This PR implements the correct computation for searchRange, entrySelection and rangeShift regardless of the number of tables and ensures correctly formatted TTF fonts. With this change, STIX Type 42 fonts are correctly embedded in EPS files.

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • [N/A] New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jkseppan jkseppan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Wow, that's been broken for a long time. I wonder if this explains the brokenness we saw with @aitikgupta when using this with subsetted fonts?

sfnts_pputUSHORT(stream, entry_sel); /* entrySelector */
sfnts_pputUSHORT(stream, range_shift); /* rangeShift */

debug("only %d tables selected",count);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure that this debug message is needed. I'm guessing it was in the code to warn in the case that there were fewer than 9 tables, in which case the header was the wrong length.

@QuLogic

QuLogic commented Jul 13, 2021

Copy link
Copy Markdown
Member

Can you add a test for this? It looks like the example in the issue fails with Ghostscript as well, so it should be sufficient to use it and have our normal comparison break on error.

@QuLogic

QuLogic commented Jul 13, 2021

Copy link
Copy Markdown
Member

OK, I see we need #20629 too before testing.

@QuLogic QuLogic added this to the v3.4.3 milestone Jul 13, 2021
@QuLogic
QuLogic merged commit 9e0bb9c into matplotlib:master Jul 13, 2021
@lumberbot-app

lumberbot-app Bot commented Jul 13, 2021

Copy link
Copy Markdown

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.4.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 9e0bb9c72121a7c3ba85c55368ae402bbfdd7782
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #20597: Fix TTF headers for type 42 stix font'
  1. Push to a named branch :
git push YOURFORK v3.4.x:auto-backport-of-pr-20597-on-v3.4.x
  1. Create a PR against branch v3.4.x, I would have named this PR:

"Backport PR #20597 on branch v3.4.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@aitikgupta

aitikgupta commented Jul 13, 2021 •

Copy link
Copy Markdown
Contributor

I wonder if this explains the brokenness we saw with @aitikgupta when using this with subsetted fonts?

I can maybe create a PR with the local changes that broke ttconv, and rebase once these changes are merged in (and maybe we can get a second review from @sauerburger!)

Just to give an idea about what broke ttconv, we tried to change the input signature of convert_ttf_to_ps from a 'font-path' (str) to a 'file-object' (bytes). After long debugging sessions and a sweet patch from @anntzer we were able to compile and run everything. The only problem was/is:
The output only contains 'dot' in place of actual characters. (will probably make sense with an image)

jkseppan pushed a commit to jkseppan/matplotlib that referenced this pull request Jul 13, 2021
QuLogic added a commit that referenced this pull request Jul 13, 2021
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.

4 participants