From 7b740124f0208b2f0e08ab0c0fc1c409d172517e Mon Sep 17 00:00:00 2001 From: Gaktan Date: Sun, 14 Apr 2024 00:29:25 +0200 Subject: [PATCH] Fixed decimal and hex ranges not working with image fonts --- editor/import/resource_importer_imagefont.cpp | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/editor/import/resource_importer_imagefont.cpp b/editor/import/resource_importer_imagefont.cpp index c454ebc6eb0..94e5dd0f120 100644 --- a/editor/import/resource_importer_imagefont.cpp +++ b/editor/import/resource_importer_imagefont.cpp @@ -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(); @@ -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]]; @@ -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;