Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve Type-1 font parsing#20715

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jklymak merged 2 commits intomatplotlib:masterfromjkseppan:type1-improved-parsing
Oct 4, 2021

Conversation

jkseppan
Copy link
Member

@jkseppanjkseppan commentedJul 22, 2021
edited
Loading

PR Summary

Parse font properties also from the encrypted part of the file, and reimplement the parsing so it understands more of PostScript's syntax. This fixes a bug whereType1Font.transform would not remove the UniqueID key but break some PostScript code referring to UniqueID instead.

Incidentally, fix the bug where every font had aweight property with value'Normal' - the correct property is spelledWeight with a capital letter.

This is a prerequisite for subsetting Type-1 fonts (#127).

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings and runflake8 --docstring-convention=all).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

@jkseppanjkseppanforce-pushed thetype1-improved-parsing branch 4 times, most recently from981ef67 to90b5889CompareJuly 22, 2021 12:46
jkseppan added a commit to jkseppan/matplotlib that referenced this pull requestJul 22, 2021
With this I can produce smaller pdf files with usetex in some smalltests, but this obviously needs more extensive testing, thus markingas draft.On top ofmatplotlib#20634 andmatplotlib#20715.Closesmatplotlib#127.
@jkseppanjkseppan mentioned this pull requestJul 22, 2021
7 tasks
jkseppan added a commit to jkseppan/matplotlib that referenced this pull requestJul 22, 2021
With this I can produce smaller pdf files with usetex in some smalltests, but this obviously needs more extensive testing, thus markingas draft.On top ofmatplotlib#20634 andmatplotlib#20715.Closesmatplotlib#127.
@jkseppanjkseppanforce-pushed thetype1-improved-parsing branch 2 times, most recently frome35728b to9418b35CompareJuly 22, 2021 15:59
jkseppan added a commit to jkseppan/matplotlib that referenced this pull requestJul 22, 2021
With this I can produce smaller pdf files with usetex in some smalltests, but this obviously needs more extensive testing, thus markingas draft.On top ofmatplotlib#20715.Closesmatplotlib#127.
@jkseppanjkseppanforce-pushed thetype1-improved-parsing branch 2 times, most recently from19119d8 to25613b9CompareAugust 28, 2021 18:15
@jkseppan
Copy link
MemberAuthor

Thanks for the review@anntzer!

Move Type1Font._tokens into a top-level function _tokenize that is acoroutine. The parsing stage consuming the tokens can instruct thetokenizer to return a binary token - this is necessary when decryptingthe CharStrings and Subrs arrays, since the preceding context determineswhich 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 thefunction, since passing the information about binary tokens would noteasily 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 havetoken-specific helper methods. The position data will be needed whenmodifying the file, as the font is transformed or subsetted.A new helper function _expression can be used to consume tokens thatform a balanced subexpression delimited by [] or {}. This helps fix abug in UniqueID removal: if the font includes PostScript code thatchecks if the UniqueID is set in the current dictionary, the previouscode broke that code instead of removing the UniqueID definition. Fontscan include UniqueID in the encrypted portion as well as the cleartextone, and removal is now done in both portions.Fix a bug related to font weight: the key is title-cased and notlower-cased, so font.prop['weight'] should not exist.
Type-1 fonts are required to have subroutines with specific contentsbut their names may vary. They are usually ND, NP and RD but nameslike | and |- appear too.
@jkseppan
Copy link
MemberAuthor

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.

Copy link
Contributor

@anntzeranntzer left a comment

Choose a reason for hiding this comment

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

I admit I still haven't followedall the logic, but we can always check again later :)

jkseppan added a commit to jkseppan/matplotlib that referenced this pull requestAug 29, 2021
With this I can produce smaller pdf files with usetex in some smalltests, but this obviously needs more extensive testing, thus markingas draft.Give dviread.DviFont a fake filename attribute for character tracking.On top ofmatplotlib#20715.Closesmatplotlib#127.
jkseppan added a commit to jkseppan/matplotlib that referenced this pull requestAug 30, 2021
With this I can produce smaller pdf files with usetex in some smalltests, but this obviously needs more extensive testing, thus markingas draft.Give dviread.DviFont a fake filename attribute for character tracking.On top ofmatplotlib#20715.Closesmatplotlib#127.
depth += 1
elif match.group() == ')':
depth -= 1
else: # a backslash
Copy link
Contributor

Choose a reason for 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)?

Copy link
Contributor

Choose a reason for 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 parenthesiscan 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.

Copy link
Member

@jklymakjklymak left a comment

Choose a reason for hiding this comment

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

I'll merge based on@anntzer review. This shouldnot go into 3.5 so that it has time to be used on master...

@jklymakjklymak added this to thev3.6.0 milestoneOct 4, 2021
@jklymakjklymak merged commite9bd017 intomatplotlib:masterOct 4, 2021
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull requestOct 12, 2021
tacaswell pushed a commit that referenced this pull requestOct 20, 2021
jkseppan added a commit to jkseppan/matplotlib that referenced this pull requestMay 4, 2025
With this I can produce smaller pdf files with usetex in some smalltests, but this obviously needs more extensive testing, thus markingas draft.Give dviread.DviFont a fake filename attribute for character tracking.On top ofmatplotlib#20715.Closesmatplotlib#127.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@anntzeranntzeranntzer approved these changes

@jklymakjklymakjklymak approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.6.0
Development

Successfully merging this pull request may close these issues.

3 participants
@jkseppan@anntzer@jklymak

[8]ページ先頭

©2009-2025 Movatter.jp