-
-
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
textBounds on multiline text breaks if global textLeading does not match the provided font size #7147
Comments
Thanks @davepagurek -- this is a known-issue discussed in #6967 |
Hey @dhowe! Do you know if this is currently in 2.0, or if we should open this up to contributors? |
The API is a bit different now, as
So if one wanted to use But this does suggest that let f, g, pts;
p.setup = async function () {
p.createCanvas(400, 300);
f = await p.loadFont("https://fonts.gstatic.com/s/opensans/v40/memSYaGs126MiZpBA-UvWbX2vVnXBbObj2OVZyOOSr4dVJWUgsg-1y4nY1M2xLER.ttf");
g = p.createGraphics(p.width, p.height)
g.background(220);
g.textAlign(p.CENTER, p.CENTER)
g.textFont(f, 50);
g.text('Serendipity', g.width / 2, g.height / 2);
let bb = g.textBounds('Serendipity', g.width / 2, g.height / 2);
// let bb = f.textBounds('Serendipity', g.width / 2, g.height / 2, { graphics: g });
g.noFill();
g.stroke(0);
g.rect(bb.x, bb.y, bb.w, bb.h);
pts = f.textToPoints('Serendipity', g.width / 2, g.height / 2, { graphics: g });
pts.forEach((pt, i) => {
g.fill(0);
g.circle(pt.x, pt.y, 2);
});
p.image(g, 0, 0); This is now implemented in 2.0 so that |
Type: implement #7147 and minor refactors
@dhowe is this one good to close now? |
all good |
Most appropriate sub-area of p5.js?
p5.js version
1.9.4
Web browser and version
Firefox, Chrome
Operating system
MacOS
Steps to reproduce this
Steps:
textBounds()
of multiline text, passing in a larger font size than the default (e.g. 50)Snippet:
In this example, I'm setting the font size on a graphic, so the main canvas still has the default text size:
Result:
Expected:
Cause
In the implementation of
textBounds
, it gets the text leading from the main instance's renderer:p5.js/src/typography/p5.Font.js
Line 209 in 6781c1d
I'm not sure the best way to fix this; if you're drawing text onto a different renderer like a graphic, there's not a deterministic way to figure out which renderer to use ahead of time. The best option might be to let you pass that value in, which might require a change to the arguments to this function to not have an overwhelmingly long parameter list.
The text was updated successfully, but these errors were encountered: