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

TTF_MeasureString returns 1 more character than what can fit without harfbaz #429

Open
ahmed-AEK opened this issue Nov 1, 2024 · 0 comments
Milestone

Comments

@ahmed-AEK
Copy link

ahmed-AEK commented Nov 1, 2024

Hello, i am really grateful for the work you are putting into SDL3_ttf, i was trying SDL3_ttf, i downloaded freetype from the linked tag, and compiled with it with SDL3_ttf (so no harfbaz), and i noticed TTF_MeasureString was returning 1 more character than could fit, an example below

I am using latest version, so commit 2554dd7 (3 days ago), also using the same version of freetype that is linked to this repository

#include <iostream>
#include <cassert>
#include <SDL3_ttf/SDL_ttf.h>
#include <string>

int main()
{
	bool init = TTF_Init();
	assert(init);

	TTF_Font* font = TTF_OpenFont("FreeSans.ttf", 16);
	assert(font);

	int measured_width;
	size_t measured_length;
	std::string str{ "ABCD" };
	bool success = TTF_MeasureString(font, str.c_str(), str.size(), 1, &measured_width, &measured_length);
	assert(success);

	std::cout << "width = " << measured_width << '\n';
	std::cout << "length = " << measured_length << '\n';
}

what is printed is width = 0 and length = 1 , for 1 pixel i expected 0 characters to be possible, i tried different fonts and got the same result.

i am using windows with MSVC verion 19.39.33523 (though i think the issue doesn't seem compiler specific)

i tried tracking down what may have caused this and this commit 40e606f seems to remove a comment with // The last character didn't fit along with the line that subtracts 1 from the result in that function, so ... maybe that's causing this issue ? i can't tell for sure.

using SDL3_TTF with harfbaz correctly produces width = 0 and length = 0 , so the issue is specific to using freetype implementation, i will use harfbaz for now so this is not a blocking issue for me.

using Roboto-Regular.ttf font also gives the same result if you want a lightweight font to test with.

@slouken slouken added this to the 3.0 milestone Nov 1, 2024
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