-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix exception when guessing the AFM familyname #9760
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
Conversation
|
||
import matplotlib.afm as afm | ||
|
||
|
||
AFM_TEST_DATA = b"""StartFontMetrics 2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use one of the afm files in https://github.com/matplotlib/matplotlib/tree/master/lib/matplotlib/mpl-data/fonts ? I am (with out thinking about it too much) concerned about copyright on including this in the source.
Is there something about this afm file that triggers the bug that does not trigger it otherwise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These files are a bit lengthy in their CharMetrics block, which would make it a bit cumbersome to test their char metrics. I've changed the AFM_TEST_DATA
to a shorter one with invented data. That should prevent any copyright issues.
@@ -503,8 +505,8 @@ def get_familyname(self): | |||
|
|||
# FamilyName not specified so we'll make a guess | |||
name = self.get_fullname() | |||
extras = (br'(?i)([ -](regular|plain|italic|oblique|bold|semibold|' | |||
br'light|ultralight|extra|condensed))+$') | |||
extras = (r'(?i)([ -](regular|plain|italic|oblique|bold|semibold|' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that what ever font was being used in the OP did not have a b'FamilyName'
entry, hence hit this code block, where as most afm do have it and return from this function early?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. the re.sub
would always fail. But it's not reached if the entry has a b'FamilyName'
.
Other than my concern about copyright issues 👍 Thanks for working on this (and if I recall correctly you have at least one other PR in flight?). |
7c9e385
to
712c393
Compare
Thanks! |
This was milestoned for 2.2 but targetted |
Is there a reason, this was milestoned for 2.2 and not for 2.1.x? AFAICS, this is a pure bug fix without any side-effects. I don't see why it should not be released with the next bugfix release. |
as it is already on 2.1.x so re-milestoned. |
PR Summary
Fixes #8347.
As opposed to the suggestion in #8347, it's not the replacement argument that needs to be
bytes
. Instead, the regexp has to bestr
because all header values (here 'FullName') are converted to 'appropriate python types' (herestr
).Cleaned up a docstring and added some tests on the way. The actual fix is just
afm.py
l.508fPR Checklist