-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Improve Text Measuring API #7283
Comments
Hey @araid , I am new to OpenSource contribution..can you help me contributing to it ? |
Hi all. So these are actually two different functions, with different intended behavior. The latter operates on a custom/loaded font only, and returns the exact bounds for a specific string of text, based on the actual paths of the various characters. The former measures the width similarly for a loaded-font, but uses |
Thanks for the clarification @dhowe. I understand the differences, and still think the API is potentially confusing for newcomers. Why offer only Glad to know that's being rethought for 2.0. Would love to be a part of those conversations. |
v2.0 will provide |
Increasing access
This would make the text API more redundant and accessible to those not familiar with OOP.
Most appropriate sub-area of p5.js?
Feature enhancement details
Problem
Right now, there are 2 ways to measure text in p5.js:
textWidth()
andFont.textBounds()
. These 2 calls sit in different parts of the API, and have slightly different behaviors across renderers and font types:A couple additional issues:
textWidth
andtextBounds.w
show slightly different values (bounds often feels like the more precise one)textWidth
on WebGL + system font returns 0 with no errorSuggestion
This separation of functionality feels arbitrary and potentially confusing to new users. These small changes could be implemented as part of the 2.0 typography push or just as an improvement to the current API:
Make both functions available in the global scope and in p5.Font. This should ensure backwards compatibility.
textWidth
to p5.FonttextBounds
to p5.RendererAllow
textBounds
to work with system fonts in P2D by using the native measureTextThe text was updated successfully, but these errors were encountered: