Skip to content

Commit

Permalink
Merge pull request #90647 from Gaktan/master
Browse files Browse the repository at this point in the history
Fix decimal and hex ranges not working with image fonts
  • Loading branch information
akien-mga committed May 17, 2024
2 parents d3e2615 + 7b74012 commit 54b2e5d
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions editor/import/resource_importer_imagefont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,16 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
c++; // Skip "+".
continue;
}
} else if (range[c] == '0') {
if ((c <= range.length() - 2) && range[c + 1] == 'x') {
token = String();
if (step == STEP_START_BEGIN) {
step = STEP_START_READ_HEX;
} else {
step = STEP_END_READ_HEX;
}
c++; // Skip "x".
continue;
} else if (range[c] == '0' && (c <= range.length() - 2) && range[c + 1] == 'x') {
// Read hexadecimal value, start.
token = String();
if (step == STEP_START_BEGIN) {
step = STEP_START_READ_HEX;
} else {
step = STEP_END_READ_HEX;
}
c++; // Skip "x".
continue;
} else if (range[c] == '\'' || range[c] == '\"') {
if ((c <= range.length() - 3) && (range[c + 2] == '\'' || range[c + 2] == '\"')) {
token = String();
Expand All @@ -184,14 +183,13 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
}
} else if (is_digit(range[c])) {
// Read decimal value, start.
c++;
token = String();
token += range[c];
if (step == STEP_START_BEGIN) {
step = STEP_START_READ_DEC;
} else {
step = STEP_END_READ_DEC;
}
token += range[c];
continue;
}
[[fallthrough]];
Expand Down Expand Up @@ -254,9 +252,19 @@ Error ResourceImporterImageFont::import(const String &p_source_file, const Strin
} break;
}
}
if (step == STEP_START_READ_HEX) {
start = token.hex_to_int();
} else if (step == STEP_START_READ_DEC) {
start = token.to_int();
} else if (step == STEP_END_READ_HEX) {
end = token.hex_to_int();
} else if (step == STEP_END_READ_DEC) {
end = token.to_int();
}
if (end == -1) {
end = start;
}

if (start == -1) {
WARN_PRINT(vformat("Invalid range: \"%s\"", range));
continue;
Expand Down

0 comments on commit 54b2e5d

Please sign in to comment.