Extract a better property dict from TTF fonts#697
Merged
Conversation
jwiggins
commented
Mar 10, 2021
| self.variant = variant | ||
| self.weight = weight | ||
| self.stretch = stretch | ||
| self.face_index = face_index |
Member
Author
There was a problem hiding this comment.
This change is integrating the face_index pieces that we're introduced by #605 to the refactored font parsing code.
| variant = "normal" | ||
| for value in ("capitals", "small-caps"): | ||
| if value in name.lower(): | ||
| for value in ("capitals", "small-caps", "smallcaps"): |
Member
Author
There was a problem hiding this comment.
I made this addition because there's a font named "Bodoni 72 Smallcaps Book" on macOS.
Comment on lines
+217
to
+218
| # For backwards compatibility with previous parsing behavior | ||
| style_prop = full_name |
Member
Author
There was a problem hiding this comment.
We used to use the full_name when checking the style and weight of a font.
Comment on lines
+55
to
+59
| # We only care about records in English | ||
| plat, lang = rec.platformID, rec.langID | ||
| if not ((plat in _plat_ids and lang == _english_id) | ||
| or (plat == _ms_plat_id and lang in _ms_english_ids)): | ||
| continue |
Member
Author
There was a problem hiding this comment.
We need this check to pick up older TTF/TTC files and newer OTF files (which use the Microsoft plaformID)
Member
Author
|
Okie dokie. Onward and upward I guess... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This fixes the font properties bugs pointed out by #391, but since it's happening in the refactored font code the issue remains open.
The core change here is to make
get_ttf_prop_dictbetter.Before:
After:
Now that
styleis extracted, we can use it instead of thefull_nameof the font (which we used to callsfnt4) when checking the weight of the font.As an added bonus, we're now using fonttools string decoding instead of the ad-hoc decoding implemented in #365