Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 1 commit into from
Nov 21, 2017

Conversation

timhoffm
Copy link
Member

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 be str because all header values (here 'FullName') are converted to 'appropriate python types' (here str).

Cleaned up a docstring and added some tests on the way. The actual fix is just afm.py l.508f

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant


import matplotlib.afm as afm


AFM_TEST_DATA = b"""StartFontMetrics 2.0
Copy link
Member

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?

Copy link
Member Author

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

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?

Copy link
Member Author

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'.

@tacaswell
Copy link
Member

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?).

@tacaswell tacaswell added this to the v2.2 milestone Nov 13, 2017
@timhoffm timhoffm force-pushed the fix-guess-afm-familyname branch from 7c9e385 to 712c393 Compare November 13, 2017 20:27
@dstansby
Copy link
Member

Thanks!

@dstansby dstansby merged commit 6eda9ea into matplotlib:v2.1.x Nov 21, 2017
@QuLogic
Copy link
Member

QuLogic commented Nov 22, 2017

This was milestoned for 2.2 but targetted v2.1.x.

@timhoffm
Copy link
Member Author

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.

@tacaswell tacaswell modified the milestones: v2.2, v2.1.1 Nov 22, 2017
@tacaswell
Copy link
Member

as it is already on 2.1.x so re-milestoned.

@timhoffm timhoffm deleted the fix-guess-afm-familyname branch November 22, 2017 09:07
@timhoffm timhoffm mentioned this pull request Dec 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants