GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement Type-1 decryption by jkseppan · Pull Request #20634 · matplotlib/matplotlib

Conversation

@jkseppan

@jkseppan jkseppan commented Jul 12, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jkseppan
jkseppan force-pushed the type1-decrypt branch from dec2657 to 604c8a4 Compare July 12, 2021 18:16
@jkseppan jkseppan added the topic: text/fonts label Jul 12, 2021
@jkseppan
jkseppan force-pushed the type1-decrypt branch from 604c8a4 to 41bb30c Compare July 12, 2021 19:26
jklymak
jklymak approved these changes Jul 21, 2021
View reviewed changes

@jklymak jklymak left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread doc/users/next_whats_new/type1decrypt.rst Outdated
@@ -0,0 +1,8 @@
Type1Font objects now decrypt the encrypted part

@jklymak jklymak Jul 21, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jkseppan reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread lib/matplotlib/type1font.py
@staticmethod
def _decrypt(ciphertext, key, ndiscard=4):
"""
Decrypt ciphertext using the Type-1 font algorithm

@jklymak jklymak Jul 21, 2021

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@jkseppan jkseppan Jul 22, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jklymak reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@jkseppan
jkseppan force-pushed the type1-decrypt branch from 41bb30c to b81313f Compare July 22, 2021 10:12
@jkseppan jkseppan mentioned this pull request Jul 22, 2021
Improve Type-1 font parsing #20715
Merged
7 tasks
@jkseppan
jkseppan force-pushed the type1-decrypt branch from a1826bb to b9e71c5 Compare July 22, 2021 12:23
@anntzer

anntzer commented Jul 22, 2021

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jkseppan

jkseppan commented Jul 22, 2021

Copy link
Copy Markdown
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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented Jul 22, 2021

Copy link
Copy Markdown
Contributor

OK then.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Jul 22, 2021
View reviewed changes
Comment thread lib/matplotlib/type1font.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Jul 22, 2021
View reviewed changes
Comment thread lib/matplotlib/type1font.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer approved these changes Jul 22, 2021
View reviewed changes

@anntzer anntzer left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
jkseppan added a commit to jkseppan/matplotlib that referenced this pull request Jul 22, 2021
@jkseppan
Type-1 subsetting
b66579d
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
Type-1 font subsetting #20716
Merged
7 tasks
@jkseppan
jkseppan force-pushed the type1-decrypt branch from b9e71c5 to 06845a4 Compare July 22, 2021 13:55
@jkseppan

jkseppan commented Jul 22, 2021

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jklymak

jklymak commented Jul 22, 2021

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anntzer
anntzer reviewed Jul 22, 2021
View reviewed changes
Comment thread lib/matplotlib/type1font.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

jkseppan added 2 commits July 22, 2021 17:24
@jkseppan
Implement Type-1 decryption
3863a75
This is a prerequisite of subsetting.
@jkseppan
Fix two crashes on slightly broken font files
e095ccd
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
jkseppan force-pushed the type1-decrypt branch from 06845a4 to e095ccd Compare July 22, 2021 14:24
jkseppan added a commit to jkseppan/matplotlib that referenced this pull request Jul 22, 2021
@jkseppan
Type-1 subsetting
6546417
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

Reviewers

@anntzer anntzer anntzer approved these changes
@jklymak jklymak jklymak approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

topic: text/fonts

Projects

None yet

Milestone

v3.5.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@jkseppan @anntzer @jklymak @QuLogic
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.