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

Fix text_driver returning wrong size for non Latin-1 characters #170

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

WhyPenguins
Copy link
Contributor

PR duplicated from thoth-tech#40
Commits were rebased.

Description

sk_text_size uses TTF_SizeText internally to calculate the size of the text. This function is only expecting Latin-1 encoded text, and as such doesn't work properly when given most Unicode characters. This PR just replaces TTF_SizeText with TTF_SizeUTF8, which makes it take Unicode now instead, matching the rest of the text_driver.cpp functions.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

The size returned from sk_text_size with various non English strings has been checked and shown to properly fit the returned text. Without the commit, the width returned is too long.

Can be tested with the following:

font fontA = load_font("font 1", "kochi-gothic-subst.ttf");

string testA = "Hello!";
draw_text(testA, COLOR_BLACK, fontA, 15, 0, 10);
draw_rectangle(COLOR_BLACK, 0, 10, text_width(testA, fontA, 15), text_height(testA, fontA, 15));

string testB = "どこへ行っても…ね?";
draw_text(testB, COLOR_BLACK, fontA, 15, 0, 25);
draw_rectangle(COLOR_BLACK, 0, 25, text_width(testB, fontA, 15), text_height(testB, fontA, 15));

refresh_screen();
delay(4000);

With the commit, the rectangles surround the text accurately - without, the rectangle around the Japanese text is too long.

Testing Checklist

  • Tested with sktest
  • Tested with skunit_tests

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • I have requested a review from ... on the Pull Request

@macite macite merged commit 068288c into splashkit:develop Apr 9, 2024
2 of 3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants