DIRECTOR: Better handling of empty STXT resources

This commit is contained in:
Eugene Sandulenko 2023-12-26 02:00:44 +01:00
parent 5d2d393c4b
commit 77582aa823
No known key found for this signature in database
GPG Key ID: 014D387312D34F08

View File

@ -68,6 +68,8 @@ Stxt::Stxt(Cast *cast, Common::SeekableReadStreamEndian &textStream) : _cast(cas
debugC(3, kDebugText, "Stxt init: formattingCount: %u", formattingCount);
uint16 totalFormatting = formattingCount;
Common::U32String logText;
while (formattingCount) {
@ -94,12 +96,15 @@ Stxt::Stxt(Cast *cast, Common::SeekableReadStreamEndian &textStream) : _cast(cas
_ftext += u32TextPart;
logText += Common::toPrintable(u32TextPart);
// Do not add formatting of empty blocks
if (textPart.size()) {
// Reset formatting if the text is completely empty
if (totalFormatting == 1 && textPart.empty()) {
_style = FontStyle();
debugC(4, kDebugText, "Stxt init: the font formatting was reset due to empty string");
}
Common::String format = Common::String::format("\001\016%04x%02x%04x%04x%04x%04x", _style.fontId, _style.textSlant, _style.fontSize, _style.r, _style.g, _style.b);
_ftext += format;
logText += Common::toPrintable(format);
}
formattingCount--;
}
@ -111,12 +116,6 @@ Stxt::Stxt(Cast *cast, Common::SeekableReadStreamEndian &textStream) : _cast(cas
_ftext += u32Text;
logText += Common::toPrintable(u32Text);
// Reset style if there is no text
if (_ftext.empty()) {
debugC(4, kDebugText, "Stxt init: the font formatting was reset due to empty string");
_style = FontStyle();
}
debugC(4, kDebugText, "#### text:\n%s\n####", logText.encode(Common::kUtf8).c_str());
}