-
Notifications
You must be signed in to change notification settings - Fork 779
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
NanoVG string width #627
Comments
It should work on all sizes. Can you show the code you use and explain more in detail what you'd expect to get. Also worth taking a look at |
hi, thanks for your reply! here is my code (note this is the LWJGL bind, in java): I'll be sure to look over that, thanks! |
The font settings affect the text bounds, you will need to set them before you measure. Also, what values you get and what do you expect? How to you use the value and which way it does not match? |
Hi, thanks for your help! Just setting the font size using the nvg function before made it calculate correctly.
public static void drawSVGImage(long vg, String fileName, float x, float y, float width, float height) {
if (ImageLoader.INSTANCE.loadSVGImage(fileName)) {
try {
NSVGImage image = ImageLoader.INSTANCE.getSVG(fileName);
NSVGShape shape;
NSVGPath path;
int i;
for (shape = image.shapes(); shape != null; shape.next()) {
//if ((shape.flags() == NSVG_FLAGS_VISIBLE)) {
// continue;
//}
nvgFillColor(vg, color(vg, shape.fill().color()));
nvgStrokeColor(vg, color(vg, shape.stroke().color()));
nvgStrokeWidth(vg, shape.strokeWidth());
for (path = shape.paths(); path != null; path.next()) {
nvgBeginPath(vg);
FloatBuffer points = path.pts();
nvgMoveTo(vg, points.get(0), points.get(1));
for (i = 0; i < path.npts() - 1; i += 3) {
float[] p = new float[10];
for (int j = 0; j < i * 2 + 3; j++) { // THIS WONT WORK
p[j] = points.get(j);
System.out.println(j + " " + p[j]);
}
nvgBezierTo(vg, p[2], p[3], p[4], p[5], p[6], p[7]);
}
if (path.closed() == 1) {
nvgLineTo(vg, points.get(0), points.get(1));
}
nvgStroke(vg);
}
}
} catch (Exception e ) {
//e.printStackTrace();
}
}
}``` |
Sneaky! You should not make me do your debugging ;)
The loop starts from 1 since you submitted the first point already. The data for the splines are stored like this:
And
When drawing the first point of the bezier is the previous draw location (i.e. moveTo, or last point of previously drawn path). |
hi, thanks for your help! I tried this earlier, but still nothing :( Thanks you so much for your help :) |
If the svg has a lot of small details, then the AA in nanovg wont work. Rasterization is safe bet. |
Okay, thanks. Is there any major performance impact to rasterization? I haven't been wanting to use it because I was concerned about lag when the GUI opens, and high memory usage. Is this actually an issue? |
It should not be a problem, but you should of course profile it if you're concerned. |
AFAIK Font characters are designed so you can place consecutive lines below each other and that there is enough vertical spacing between the characters. So some space is to be expected. |
Okay, yet why would this differ from many other programs, such as figma? It appears nanoVG calculates the font size as the maximum ascend and descend height scaled to the font size you specified, yet many other programs use the font size as the standard/baseline height, and the ascend/descend extend beyond that. Is there any way to change this in NanoVG? |
@nxtdaydelivery @memononen thank you very much! Sorry for the ping, but you absolutely saved me! I'm working on an actually readable debug screen in Kotlin, and just couldn't find out how to have both bold and regular text on the same line. Thank you! |
Hi. I am currently trying to calculate the width of my text using nvgTextBounds, however it seems to only work with a font size of 12px. I have tried to divide the result by 12 then multiply it by the target font size, yet this still leads to small deviations especially after a lot of characters.
Is there any other way to get string width, or how can I improve my current method?
Can anyone help me?
The text was updated successfully, but these errors were encountered: