-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix rebuilding font cache #13852
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
Fix rebuilding font cache #13852
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1246,10 +1246,7 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default, | |
if fname is not None: | ||
return fname | ||
|
||
if fontext == 'afm': | ||
fontlist = self.afmlist | ||
else: | ||
fontlist = self.ttflist | ||
fontlist = self.afmlist if fontext == 'afm' else self.ttflist | ||
|
||
best_score = 1e64 | ||
best_font = None | ||
|
@@ -1273,36 +1270,37 @@ def _findfont_cached(self, prop, fontext, directory, fallback_to_default, | |
if score == 0: | ||
break | ||
|
||
if best_font is None or best_score >= 10.0: | ||
if fallback_to_default: | ||
_log.warning( | ||
'findfont: Font family %s not found. Falling back to %s.', | ||
prop.get_family(), self.defaultFamily[fontext]) | ||
default_prop = prop.copy() | ||
default_prop.set_family(self.defaultFamily[fontext]) | ||
return self.findfont(default_prop, fontext, directory, False) | ||
else: | ||
# This is a hard fail -- we can't find anything reasonable, | ||
# so just return the DejaVuSans.ttf | ||
_log.warning('findfont: Could not match %s. Returning %s.', | ||
prop, self.defaultFont[fontext]) | ||
result = self.defaultFont[fontext] | ||
else: | ||
if (best_font is not None and os.path.isfile(best_font.fname) | ||
and best_score < 10): | ||
_log.debug('findfont: Matching %s to %s (%r) with score of %f.', | ||
prop, best_font.name, best_font.fname, best_score) | ||
result = best_font.fname | ||
|
||
if not os.path.isfile(result): | ||
if rebuild_if_missing: | ||
_log.info( | ||
'findfont: Found a missing font file. Rebuilding cache.') | ||
_rebuild() | ||
return fontManager.findfont( | ||
prop, fontext, directory, True, False) | ||
else: | ||
raise ValueError("No valid font could be found") | ||
|
||
return result | ||
return best_font.fname | ||
|
||
# No sufficently good font found. | ||
if rebuild_if_missing: | ||
_log.info( | ||
'findfont: Found a missing font file. Rebuilding cache.') | ||
_rebuild() | ||
return self.findfont(prop, fontext, directory, | ||
fallback_to_default=True, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't that be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, sounds reasonable... but why was it not failing before? |
||
rebuild_if_missing=False) | ||
elif fallback_to_default: | ||
_log.warning( | ||
'findfont: Font family %s not found. Falling back to %s.', | ||
prop.get_family(), self.defaultFamily[fontext]) | ||
default_prop = prop.copy() | ||
default_prop.set_family(self.defaultFamily[fontext]) | ||
return self.findfont(default_prop, fontext, directory, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, shouldn't that contain |
||
fallback_to_default=False) | ||
else: | ||
# This is a hard fail -- we can't find anything reasonable, | ||
# so just return the DejaVuSans.ttf | ||
_log.warning('findfont: Could not match %s. Returning %s.', | ||
prop, self.defaultFont[fontext]) | ||
font_filename = self.defaultFont[fontext] | ||
if os.path.isfile(font_filename): | ||
return font_filename | ||
raise ValueError("No valid font could be found") | ||
|
||
|
||
@lru_cache() | ||
|
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 log message no longer corresponds to the condition (previously this was only triggered if
not os.path.isfile(result.fname)
-- perhaps(?) the logic should be changed (dunno), but then the log message should be changed too)