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

Extract a better property dict from TTF fonts #697

Merged
merged 1 commit into from
Mar 10, 2021

Conversation

jwiggins
Copy link
Member

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_dict better.
Before:

In [3]: font = TTFont("/Library/Fonts/Times New Roman Bold.ttf")                

In [4]: get_ttf_prop_dict(font)                                                 
Out[4]: {'name': 'Times New Roman', 'sfnt4': 'Times New Roman Bold'}

After:

In [3]: font = TTFont("/Library/Fonts/Times New Roman Bold.ttf")                

In [4]: get_ttf_prop_dict(font)                                                 
Out[4]: 
{'copyright': '© 2006 The Monotype Corporation. All Rights Reserved.',
 'family': 'Times New Roman',
 'style': 'Bold',
 'unique_subfamily_id': 'Monotype:Times New Roman Bold:Version 5.01 (Microsoft)',
 'full_name': 'Times New Roman Bold',
 'version': 'Version 5.01.3x',
 'postscript_name': 'TimesNewRomanPS-BoldMT'}

Now that style is extracted, we can use it instead of the full_name of the font (which we used to call sfnt4) 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

self.style = style
self.variant = variant
self.weight = weight
self.stretch = stretch
self.face_index = face_index
Copy link
Member Author

Choose a reason for hiding this comment

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

This change is integrating the face_index pieces that we're introduced by #605 to the refactored font parsing code.

kiva/fonttools/tests/test_scan_parse.py Show resolved Hide resolved
variant = "normal"
for value in ("capitals", "small-caps"):
if value in name.lower():
for value in ("capitals", "small-caps", "smallcaps"):
Copy link
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Member Author

Choose a reason for hiding this comment

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

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
Copy link
Member Author

Choose a reason for hiding this comment

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

We need this check to pick up older TTF/TTC files and newer OTF files (which use the Microsoft plaformID)

Copy link
Contributor

@rahulporuri rahulporuri left a comment

Choose a reason for hiding this comment

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

LGTM

@jwiggins
Copy link
Member Author

Okie dokie. Onward and upward I guess...

@jwiggins jwiggins merged commit 93136ba into master Mar 10, 2021
@jwiggins jwiggins deleted the feature/better-ttf-parsing branch March 10, 2021 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants