Skip to content
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

Implement Type-1 decryption #20634

Merged
merged 2 commits into from Jul 22, 2021
Merged

Conversation

jkseppan
Copy link
Member

@jkseppan jkseppan commented Jul 12, 2021

PR Summary

Implement decryption of the encrypted part of Type-1 fonts. This is a prerequisite of subsetting (#127) although that will need a lot more code.

I looked at using fonttools for Type-1 subsetting, but it seems to lack much of the functionality needed for that, although it does implement this decryption algorithm. (The code in this PR is completely my own implementation.)

cc @aitikgupta - subsetting TTF fonts is more important than Type-1 since it affects a lot more users, but if you want to take a look at Type-1 subsetting, this is the first step

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • 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).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Seems fine to me beyond the small minor points.

@@ -0,0 +1,8 @@
Type1Font objects now decrypt the encrypted part
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this should be an API note rather than whats-new. I'm not sure this is really a user-facing feature, even if it is public.

@staticmethod
def _decrypt(ciphertext, key, ndiscard=4):
"""
Decrypt ciphertext using the Type-1 font algorithm
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reference to the "encryption" we can add here? Also is decrypt the right word? Its really just obfuscated at this point?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reference is the manual referenced in the file docstring. The manual uses the words "encrypt" and "decrypt", so I think it is best to follow its terminology.

@anntzer
Copy link
Contributor

anntzer commented Jul 22, 2021

Could we consider defering most of type1's handling to fonttools as well instead?

@jkseppan
Copy link
Member Author

Could we consider defering most of type1's handling to fonttools as well instead?

I tried - its type-1 implementation is very incomplete and not sufficient for subsetting.

@anntzer
Copy link
Contributor

anntzer commented Jul 22, 2021

OK then.

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

Just some minor points, please address them (or explicitly reject them if you don't want to make the changes), then this can be self-merged.

jkseppan added a commit to jkseppan/matplotlib that referenced this pull request Jul 22, 2021
With this I can produce smaller pdf files with usetex in some small
tests, but this obviously needs more extensive testing, thus marking
as draft.

On top of matplotlib#20634 and matplotlib#20715. Closes matplotlib#127.
@jkseppan jkseppan mentioned this pull request Jul 22, 2021
7 tasks
@jkseppan
Copy link
Member Author

Thanks for the review @anntzer - I made the changes. I'll wait for the CI to complete before merging.

@jklymak
Copy link
Member

jklymak commented Jul 22, 2021

@jkseppan if one of us doesn't get to it, feel free to self-merge when CI is all green.

This is a prerequisite of subsetting.
The zeros at the end are not needed by our implementation so don't
crash if there are too few.

Always pass an even number of bytes to unhexlify.
jkseppan added a commit to jkseppan/matplotlib that referenced this pull request Jul 22, 2021
With this I can produce smaller pdf files with usetex in some small
tests, but this obviously needs more extensive testing, thus marking
as draft.

On top of matplotlib#20634 and matplotlib#20715. Closes matplotlib#127.
@jkseppan jkseppan merged commit 57db5a7 into matplotlib:master Jul 22, 2021
@jkseppan jkseppan deleted the type1-decrypt branch July 22, 2021 15:56
@QuLogic QuLogic added this to the v3.5.0 milestone Aug 12, 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.

None yet

4 participants