Fix font weights#919
Merged
Merged
Conversation
Contributor
Author
|
For comparison, the KivaExplorer script in #905 now displays the following on either agg backend: |
rkern
approved these changes
Mar 25, 2022
Member
rkern
left a comment
There was a problem hiding this comment.
Minor readability suggestion, but LGTM!
| if font.style in (constants.BOLD, constants.BOLD_ITALIC): | ||
| weight = agg.FontWeight.Bold | ||
| weight = font_weights.get(font._get_weight(), agg.FontWeight.Regular) | ||
| style = (font.style in constants.italic_styles) |
Member
There was a problem hiding this comment.
This bool should still be named italic, I think. There's no reason why style=True should mean "this font is italic".
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 is a reasonably comprehensive fix for #905 following the suggestions given there. Together with #918 it gives good support for more refined font weights and styles on
qpainterand both agg backends, as well as consistent behaviour on backends which only support bold and normal weights. It is also backwards compatible with code that usesstylefor both italic and bold, raising aDeprectationWarningif thestyleis bold.In making the changes, this PR also cleans up some of the early Python 2-ish idioms and uses more modern constructs where appropriate.
It includes smoke tests for rendering text in all combinations of font families, weights and styles on each backend, as well as adding tests for the
KivaFonttrait. Documentation is also updated.This PR doesn't attempt to update backends which can potentially support more font weights (eg. quartz) but which haven't exposed it in the C/C++ wrappers. It also doesn't attempt to update or improve the font parsers to understand the new weight types - that should be a different PR.
Fixes #905.