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

This commit is contained in:
bruvzg 2024-06-13 09:20:04 +03:00
parent 475248d99d
commit db46eac24c
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
1 changed files with 22 additions and 3 deletions

View File

@ -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;
} 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));
}
}
}