Skip to content
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

[rtextures] ImageText() scaling spacing incorrect #3105

Closed
fctr opened this issue Jun 11, 2023 · 8 comments
Closed

[rtextures] ImageText() scaling spacing incorrect #3105

fctr opened this issue Jun 11, 2023 · 8 comments

Comments

@fctr
Copy link

fctr commented Jun 11, 2023

rtextures.c, Line 1243:
int spacing = fontSize/defaultFontSize;

As long as the fontSize is identical to the defaultFontSize, all is good. If you try to scale the font to, say, 4x the default size, the you get the spacing squared, so instead of 4 pixels between letters, you get 16.

The line should read:
int spacing = 1;

Code block at line 1303 already scales everything up, so no need to do it twice.

@raysan5 raysan5 changed the title [rtextures] ImageText scaling spacing incorrect [rtextures] ImageText() scaling spacing incorrect Jun 18, 2023
@raysan5
Copy link
Owner

raysan5 commented Jun 18, 2023

@fctr Sorry, I don't understand the issue. If fontSize = 40 and defaultFontSize = 10, then spacing = 4 as expected...

@fctr
Copy link
Author

fctr commented Jun 23, 2023

MeasureText and DrawText don't match. Do a fontSize = 10 and defaultFontSize = 10, and DrawText("Hello World"). Then do a fontSize = 40 and defaultFontSize = 10, and DrawText("Hello World"). You'll notice for the second one, the spacing between the characters is wrong, and MeasureText returns what it SHOULD be, but not what it actually is. Instead of 4 pixels as a space, it's 16 pixels.

@raysan5
Copy link
Owner

raysan5 commented Jun 24, 2023

@fctr Please, could you provide some screenshot or sample code illustrating the issue?

@fctr
Copy link
Author

fctr commented Jun 27, 2023

int main()
{
InitWindow(640, 480, "RayLib Rocks");
Image i = GenImageColor(640, 300, RED);
ImageDrawText(&i, "This is a test", 1, 1, 10, WHITE);
ImageDrawText(&i, "This is a test", 1, 31, 40, WHITE);
SetTargetFPS(60);
while (!WindowShouldClose())
{
Texture2D t = LoadTextureFromImage(i);
BeginDrawing();
DrawText("This is a test", 1, 1, 10, WHITE);
DrawText("This is a test", 1, 51, 40, WHITE);
DrawTexture(t, 0, 100, WHITE);
EndDrawing();
UnloadTexture(t);
}
UnloadImage(i);
CloseWindow();
return 0;
}

@fctr
Copy link
Author

fctr commented Jun 27, 2023

Give that a whirl and you'll see what I mean. You'll need to change line 3158 in rtextures.c to:
ImageDrawTextEx(dst, GetFontDefault(), text, position, (float)fontSize, (float)1.0f, color); // WARNING: Module required: rtext
and change line 1227 in rtext.c to:
textSize.x = (tempTextWidth + (float)((tempByteCounter - 1) * spacing)) * scaleFactor; // Adds chars spacing to measure

raysan5 added a commit that referenced this issue Jul 2, 2023
@raysan5 raysan5 closed this as completed Jul 2, 2023
@fctr
Copy link
Author

fctr commented Jul 2, 2023

THANK YOU SO MUCH FOR EVERYTHING!

@raysan5
Copy link
Owner

raysan5 commented Jul 6, 2023

@fctr I'm afraid the proposed change just broke MeasureTextEx():

image

            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
            DrawRectangle(190, 200, MeasureText("Congrats! You created your first window!", 20), 20, Fade(RED, 0.5f));

I'm reverting the change, please, send a PR with an update when reviewed.

@raysan5 raysan5 reopened this Jul 6, 2023
raysan5 added a commit that referenced this issue Jul 6, 2023
@raysan5
Copy link
Owner

raysan5 commented Jul 23, 2023

Reviewed it and it seems it works as expected

@raysan5 raysan5 closed this as completed Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants