Implement Type-1 decryption#20634
Conversation
jklymak
left a comment
There was a problem hiding this comment.
Seems fine to me beyond the small minor points.
| @@ -0,0 +1,8 @@ | |||
| Type1Font objects now decrypt the encrypted part | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Is there a reference to the "encryption" we can add here? Also is decrypt the right word? Its really just obfuscated at this point?
There was a problem hiding this comment.
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.
|
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. |
|
OK then. |
anntzer
left a comment
There was a problem hiding this comment.
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.
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.
|
Thanks for the review @anntzer - I made the changes. I'll wait for the CI to complete before merging. |
|
@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.
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.
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
pytestpasses).flake8on changed files to check).flake8-docstringsand runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).