Canvas: deprecate write_text, add fill_text & stroke_text#4432
Canvas: deprecate write_text, add fill_text & stroke_text#4432HalfWhitt wants to merge 6 commits into
Conversation
| self.interface.style == other.interface.style, | ||
| ] | ||
| ) | ||
| except AttributeError: |
There was a problem hiding this comment.
Never occurred to me that Dummy has its own font implementation that never got beeware/travertino#233.
| # percentage to get both stroke and fill. | ||
| # Stroke width is expressed as a percentage of the font size | ||
| stroke_width = line_width / font.native.pointSize * 100 | ||
| if fill_style: |
There was a problem hiding this comment.
This can't happen anymore, since it'll always be either a stroke or a fill, but not both.
corranwebster
left a comment
There was a problem hiding this comment.
Overall looks good and the changes make sense. The new API still doesn't quite match the HTML Canvas API in that font, baseline, etc. aren't properties of the current state, like color, etc. I understand if that's too big a change for this PR, but we probably want to make that change eventually.
One change that is needed before merging is that I think there are some uses of write_text in the examples that still need conversion.
| ( | ||
| self.font._impl | ||
| if self.font is not None | ||
| else Font(family=SYSTEM, size=SYSTEM_DEFAULT_FONT_SIZE)._impl |
There was a problem hiding this comment.
Not for this PR, but it seems like there ought to be a simpler way of saying "default system font".
D'oh, thank you for reminding me. I do think I'll add the actual attributes in a subsequent PR, but I should go ahead and make the non-HTML-matching parameters keyword-only from the start.
I always forget about these... we really do need a way to automatically test them. |
Part of #3994
While there are still various HTML canvas context methods and attributes we haven't implemented, I believe this fixes the last one that we have but is significantly different than its inspiration.
I've put deprecation warnings in both the
write_textmethod and theWriteTextdrawing action; calling the former internally suppresses the warning from the latter.Also converted a number ifs/elifs to match/case, because I have a fever, and the only cure is more pattern matching.
PR Checklist: