-
Notifications
You must be signed in to change notification settings - Fork 125
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
Text: provide more accurate bounding box info #82
Comments
The I'm not quite following the part about how descenders "change the size of the bbox, but not the position", can you clarify that or attach some screenshots? |
Also, it would help to know more precisely what you're expecting when you say "the actual visual bounding box of the text". Typically in HTML/CSS when you ask for bounds of a text element you get some extra space above and below the glyphs, depending on your line-height. The |
I think I'm going to expose both the layout block bounds, ala CSS, and also the visible bounds of all the glyph paths. Depending on the particular font, the visible bounds may be smaller or larger than the layout bounds, and I can see both being useful in different circumstances. Examples of the two sets of bounds - blue is the layout block bounds, red/purple is the visible bounds. Hopefully one of these, or a union of the two, is what you want? |
Thank you for the quick response. The red bbox is exactly what we need! Great :) |
I definitely don't see that behavior; I'm wondering if maybe you're flipping the Y-axis values when rendering your rectangle, or something like that? The If there's a particular calculation you're wanting to do "so that you can manually align the text and such", let me know what that is; I'm guessing the metrics to do so are already present (or will be once I release these changes) but I want to be sure. |
Closing, as it seems like the mistake was on our side, and it's working after all. Again, thanks for the great work! |
Thanks for following up, I'm glad it wasn't quite as bad as you'd thought. :) However I do think the current metrics are less than ideal, and more precise metrics could be generally useful for others, so I'm going to reopen this as a reminder to improve it. |
See f3340ec |
The textRenderInfo now exposes @asbjornlystrup when you update to 0.34+, you'll need to update your code to use one of the new properties and adjust your padding. |
Hi, a friend and I have spent a lot of time trying to figure out how to get the actual visual bounding box of the text. We need this so we can surround the text perfectly with a rectangular background.
We have tried with renderInfo.totalBounds and using the geometry's bounding box, but they're incorrect in the same way; glyphs with descenders (q, g, j, p etc.) don't affect the position of the bounding box, only the size. We tried setting various anchorX/anchorY values to align it properly, but the descenders are not taken into account. We also tried the renderInfo.glyphBounds, but the same holds for this.
I thought it might just be that this bbox is for highlighting text for selections, and to raycast against, but then it doesn't make sense that the descending glyphs change the size of the bbox, but not the position. We also tried getting the renderInfo.descender to add as an offset, but this holds the same value whether you have a decscending glyph like "p" or not. The same goes for renderInfo.ascender.
Moreover, there's a horizontal gap at the edge of the text as well, and this gap is bigger on the right side than on the left. We just need a perfect visually encapsulating bbox. Any ideas?
Apart from this, the asset has been working wonderfully. Thanks!
The text was updated successfully, but these errors were encountered: