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

Type-1 font subsetting #20716

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Type-1 font subsetting #20716

wants to merge 3 commits into from

Conversation

@jkseppan
Copy link
Member

@jkseppan jkseppan commented Jul 22, 2021

PR Summary

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 #20634 and #20715. Closes #127.

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).
jkseppan added 2 commits Jul 13, 2021
Move Type1Font._tokens into a top-level function _tokenize that is a
coroutine. The parsing stage consuming the tokens can instruct the
tokenizer to return a binary token - this is necessary when decrypting
the CharStrings and Subrs arrays, since the preceding context determines
which parts of the data need to be decrypted.

The function now also parses the encrypted portion of the font file.

To support usage as a coroutine, move the whitespace filtering into the
function, since passing the information about binary tokens would not
easily work through a filter.

The function now returns tokens as subclasses of a new _Token class,
which carry the position and value of the token and can have
token-specific helper methods. The position data will be needed when
modifying the file, as the font is transformed or subsetted.

A new helper function _expression can be used to consume tokens that
form a balanced subexpression delimited by [] or {}. This helps fix a
bug in UniqueID removal: if the font includes PostScript code that
checks if the UniqueID is set in the current dictionary, the previous
code broke that code instead of removing the UniqueID definition. Fonts
can include UniqueID in the encrypted portion as well as the cleartext
one, and removal is now done in both portions.

Fix a bug related to font weight: the key is title-cased and not
lower-cased, so font.prop['weight'] should not exist.
Type-1 fonts are required to have subroutines with specific contents
but their names may vary. They are usually ND, NP and RD but names
like | and |- appear too.
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 #20715. Closes #127.
@jkseppan jkseppan force-pushed the jkseppan:type1-subset branch from 6546417 to 3aaf4c9 Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

1 participant