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

[Image Font Importer] Adds support for \uXXXX in the kerning config strings. #93119

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions editor/import/resource_importer_imagefont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,29 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
WARN_PRINT(vformat("Invalid kerning pairs string: \"%s\"", kp));
continue;
}
String from_tokens;
for (int i = 0; i < kp_tokens[0].length(); i++) {
if (i <= kp_tokens[0].length() - 6 && kp_tokens[0][i] == '\\' && kp_tokens[0][i + 1] == 'u') {
char32_t charcode = kp_tokens[0].substr(i + 2, 4).hex_to_int();
from_tokens += charcode;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bruvzg This bit of code is missing a part to advance past the hex characters and thus includes u and whatever 4 hex characters are included after it. I think it just needs i += 5 here and in the next loop set to fix it. Do I need a demo project for it?

} else {
from_tokens += kp_tokens[0][i];
}
}
String to_tokens;
for (int i = 0; i < kp_tokens[1].length(); i++) {
if (i <= kp_tokens[1].length() - 6 && kp_tokens[1][i] == '\\' && kp_tokens[1][i + 1] == 'u') {
char32_t charcode = kp_tokens[1].substr(i + 2, 4).hex_to_int();
to_tokens += charcode;
} else {
to_tokens += kp_tokens[1][i];
}
}
int offset = kp_tokens[2].to_int();
for (int a = 0; a < kp_tokens[0].length(); a++) {
for (int b = 0; b < kp_tokens[1].length(); b++) {
font->set_kerning(0, chr_height, Vector2i(kp_tokens[0].unicode_at(a), kp_tokens[1].unicode_at(b)), Vector2(offset, 0));

for (int a = 0; a < from_tokens.length(); a++) {
for (int b = 0; b < to_tokens.length(); b++) {
font->set_kerning(0, chr_height, Vector2i(from_tokens.unicode_at(a), to_tokens.unicode_at(b)), Vector2(offset, 0));
}
}
}
Expand Down
Loading