GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — Improve Type-1 font parsing by jkseppan · Pull Request #20715 · matplotlib/matplotlib Conversation
|
|
Thanks for the review @anntzer! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
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.
25613b9 to
e98bb83
Compare
|
I added some tests and realized that the string escaping was slightly wrong. Now the code also parses string values, although it is unlikely that font properties would include escaped whitespace characters. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I admit I still haven't followed all the logic, but we can always check again later :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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. Give dviread.DviFont a fake filename attribute for character tracking. On top of matplotlib#20715. Closes matplotlib#127.
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. Give dviread.DviFont a fake filename attribute for character tracking. On top of matplotlib#20715. Closes matplotlib#127.
| depth += 1 | ||
| elif match.group() == ')': | ||
| depth -= 1 | ||
| else: # a backslash |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I guess that here you don't really care about handling the backslash escapes, and all you want to do is simply to match the (unescaped) parentheses, so you could perhaps just replace instring_re by something like (?<!\\)[()] (parentheses not preceded by a backslash)?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Ah, I gave this a try but it wouldn't work because the parenthesis can be preceded by backslashes if the backslash is itself escaped (i.e. one would really need to search for "parenthesis not preceded by an even number of backslashes"). So let's forget about this for now.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I'll merge based on @anntzer review. This should not go into 3.5 so that it has time to be used on master...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Improve Type-1 font parsing
Improve Type-1 font parsing
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. Give dviread.DviFont a fake filename attribute for character tracking. On top of matplotlib#20715. Closes matplotlib#127.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.