-
-
Notifications
You must be signed in to change notification settings - Fork 785
[widget audit] toga.Font #1903
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
[widget audit] toga.Font #1903
Conversation
…on font rendering.
|
Right now |
|
Since this PR has turned into a complete audit of Font, I've renamed it and added the audit checklist to the top comment. |
| def set_alignment(self, value): | ||
| self.native.setGravity(Gravity.CENTER_VERTICAL | align(value)) |
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.
This had no effect because the gravity we actually need to change is that of the TextView within the R__layout.simple_spinner_item. This can be fixed later, along with color and font (#1758).
|
This PR doesn't fix #1038, so I've removed it from the top comment, and I don't think it's worth looking into just now. |
Could this problem still happen if additional children were added to the Box after it was created? |
| def register(family, path, *, weight=NORMAL, style=NORMAL, variant=NORMAL): | ||
| """Registers a file-based font. | ||
| **Note:** This is not currently supported on macOS or iOS. |
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.
Any reason to call it out here, rather than in the Notes section of the docs?
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.
Where a platform limitation affects only a specific method, I think it's more useful to put the note in that method's documentation so the user will see it at the right time. There's some precedent for this in on the WebView page.
This is especially the case now that Font.register is linked from the font_family style property. Anyone following that link is unlikely to see the Notes section before they try to use the method.
In fact, for the same reason I've now moved the notes about obique and small caps under their respective style properties, which are linked from the arguments of the Font APIs.
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.
Fair enough about the navigation/discovery order; however, my inclination would be to include it in both places. What you've described is definitely one mode of API discovery (and an important one), but another is someone evaluating whether this widget will do what they want to do, and needing to know up front what limitations exist.
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.
It occurred to me that the underlying problem here is that the bulk of the documentation for Font isn't in the usage guide for Font - in fact, there is no usage guide for font at present. I've pushed an update that reorganises this documentation.
To the best of my knowledge, no; I've just added an explicit demo of this to the The poking around GTK that I've done since I worked on this PR has provided a little more light on what is going on here. GTK font rendering is based on creating a Pango context; the Pango context is tied to a specific display. If you add the widget after creating the box, it gets an "empty" Pango context because it isn't associated with a Window at the time it is created. If you add it before, the assignment of a Pango context to the box transfers to the child label. This is evidently only an issue with initial window construction; once the window is visible, a new widget added to the layout will get a Pango context that knows about the custom font. I presume this has something to do with the fact that there's now an actual display that is in some way bound to the application, so the default Pango context is the right one. |
I don't follow how avoiding the call to From GTK's point of view, everything is a direct descendant of the container anyway.
What about widgets added after the Box is created, but before it's added to a window: |
|
I'll leave macOS and iOS marked as beta in the widget support table, because they don't yet support loading custom fonts. |
Ok - I swear I'm being gaslit here. At the point where I originally commented about needing to alter the widget creation order, I was definitely seeing issues with font rendering that would only be resolved by creating children before the parent. However, I just undid the creation order change to prove that the change was needed... and... it's not. My best guess is that something in #2020 has subtly changed exactly which redraw calls are being made, and as a result, we can now create the children after the parent. Since that we can remove the branch check of the impl when adding children, I've reverted the change permanently.
It's a moot point now; but I verified this as well - I tried adding a widget before the box is assigned as window content; and I tried adding a widget after the box is assigned as window content, but before the window is created. Both work fine. |
freakboy3742
left a comment
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.
Ok - I'm happy with where this is now. I've pushed some updates addressing my review comments; if you're happy with those changes, feel free to merge.
| global nativeGetFamily, new_FontFamily | ||
|
|
||
| # Bypass non-SDK interface restrictions by looking them up on a background thread | ||
| # with no Java stack frames (https://stackoverflow.com/a/61600526). |
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.
Based on the StackOverflow discussion, I'm utterly petrified about what will happen to this as Android releases new versions... but until then, it's a nice hack. (well, it's an utterly ugly hack, but it's a nice utterly ugly hack :-) )
| def register(family, path, *, weight=NORMAL, style=NORMAL, variant=NORMAL): | ||
| """Registers a file-based font. | ||
| **Note:** This is not currently supported on macOS or iOS. |
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.
Fair enough about the navigation/discovery order; however, my inclination would be to include it in both places. What you've described is definitely one mode of API discovery (and an important one), but another is someone evaluating whether this widget will do what they want to do, and needing to know up front what limitations exist.
| def register(family, path, *, weight=NORMAL, style=NORMAL, variant=NORMAL): | ||
| """Registers a file-based font. | ||
| **Note:** This is not currently supported on macOS or iOS. |
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.
It occurred to me that the underlying problem here is that the bulk of the documentation for Font isn't in the usage guide for Font - in fact, there is no usage guide for font at present. I've pushed an update that reorganises this documentation.
Changes
Notes
gtk/fontshas been increased to 100% coverageRefs #1837.
Audit checklist