[Scummvm-git-logs] scummvm master -> b9888e723f1f2e45c00c62b8cfcd5a5886055285
yuv422
noreply at scummvm.org
Wed Jan 22 08:09:17 UTC 2025
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
b9888e723f DARKSEED: Refactored console to work in U32Strings This simplifies multi-byte languages.
Commit: b9888e723f1f2e45c00c62b8cfcd5a5886055285
https://github.com/scummvm/scummvm/commit/b9888e723f1f2e45c00c62b8cfcd5a5886055285
Author: Eric Fry (yuv422 at reversedgames.com)
Date: 2025-01-22T18:43:43+11:00
Commit Message:
DARKSEED: Refactored console to work in U32Strings This simplifies multi-byte languages.
Changed paths:
engines/darkseed/console.cpp
engines/darkseed/console.h
engines/darkseed/kofont.cpp
engines/darkseed/kofont.h
engines/darkseed/menu.cpp
engines/darkseed/tostext.cpp
engines/darkseed/tostext.h
diff --git a/engines/darkseed/console.cpp b/engines/darkseed/console.cpp
index 66222f9301f..c3222dfef5c 100644
--- a/engines/darkseed/console.cpp
+++ b/engines/darkseed/console.cpp
@@ -35,7 +35,6 @@ Console::Console(TosText *tosText, Sound *sound) : _tosText(tosText), _sound(sou
_font = new Big5Font();
_lineHeight = 17;
_numLines = 3;
- _isBig5 = true;
break;
case Common::KO_KOR :
_font = new KoFont();
@@ -57,33 +56,37 @@ Console::~Console() {
}
void Console::printTosText(int tosIndex) {
- const Common::String &text = _tosText->getText(tosIndex);
+ const Common::U32String &text = _tosText->getText(tosIndex);
// debugN("tos %d: ", tosIndex);
// for (int i = 0; i < text.size(); i++) {
// debugN("%02x,", (unsigned char)text[i]);
// }
// debug("");
debug("%s", text.c_str());
- addTextLine(text);
+ addTextLineU32(text);
_sound->playTosSpeech(tosIndex);
}
void Console::addTextLine(const Common::String &text) {
- Common::StringArray lines;
- if (_isBig5) {
- big5WordWrap(text, 23, lines);
- } else {
- _font->wordWrapText(text, consoleArea.width(), lines);
- }
+ addTextLineU32(Common::U32String(text));
+}
+
+void Console::addToCurrentLine(const Common::String &text) {
+ addToCurrentLineU32(Common::U32String(text));
+}
+
+void Console::addTextLineU32(const Common::U32String &text) {
+ Common::U32StringArray lines;
+ _font->wordWrapText(text, consoleArea.width(), lines);
for (auto &line : lines) {
addLine(line);
}
}
-void Console::addToCurrentLine(const Common::String &text) {
+void Console::addToCurrentLineU32(const Common::U32String &text) {
int curIdx = _startIdx == 0 ? _text.size() - 1 : _startIdx - 1;
_startIdx = curIdx;
- addTextLine(_text[_startIdx] + text);
+ addTextLineU32(_text[_startIdx] + text);
}
void Console::addI18NText(const I18nText &text) {
@@ -107,69 +110,14 @@ void Console::draw(bool forceRedraw) {
g_engine->_screen->addDirtyRect(consoleArea);
}
-void Console::drawStringAt(const int x, const int y, const Common::String &text) const {
- if (_isBig5) {
- Common::Point charPos = {(int16)x, (int16)y};
- for (const char *curCharPtr = text.c_str(); *curCharPtr; ++curCharPtr) {
- byte curChar = *curCharPtr;
- byte nextChar = curCharPtr[1];
- if ((curChar & 0x80) && nextChar) {
- curCharPtr++;
- uint16 point = (curChar << 8) | nextChar;
- _font->drawChar(g_engine->_screen, point, charPos.x, charPos.y, 0);
- charPos.x += (int16)_font->getCharWidth(point) + 1;
- }
- }
- } else if (g_engine->getLanguage() == Common::KO_KOR) {
- Common::Point charPos = {(int16)x, (int16)y};
- for (const char *curCharPtr = text.c_str(); *curCharPtr; ++curCharPtr) {
- byte curChar = *curCharPtr;
- uint16 point = 0;
- if ((curChar & 0x80)) {
- curCharPtr++;
- byte nextChar = *curCharPtr;
- point = (curChar << 8) | nextChar;
- _font->drawChar(g_engine->_screen, point, charPos.x, charPos.y, 0);
- charPos.x += (int16)_font->getCharWidth(point) + 1;
- } else if (curChar == ' ') {
- charPos.x += 17;
- }
- }
- } else {
- _font->drawString(g_engine->_screen, text, x, y, consoleArea.width(), 0);
- }
+void Console::drawStringAt(const int x, const int y, const Common::U32String &text) const {
+ _font->drawString(g_engine->_screen, text, x, y, consoleArea.width(), 0);
}
-void Console::addLine(const Common::String &line) {
+void Console::addLine(const Common::U32String &line) {
_text[_startIdx] = line;
_startIdx = (_startIdx + 1) % _text.size();
_redrawRequired = true;
}
-void Console::big5WordWrap(const Common::String &str, int maxWidth, Common::StringArray &lines) {
- Common::String line;
- int charCount = 0;
- for (const char *curCharPtr = str.c_str(); *curCharPtr; ++curCharPtr) {
- byte curChar = *curCharPtr;
- byte nextChar = curCharPtr[1];
- if ((curChar & 0x80) && nextChar) {
- curCharPtr++;
- if (charCount < maxWidth) {
- line += (char)curChar;
- line += (char)nextChar;
- charCount++;
- } else {
- lines.push_back(line);
- line.clear();
- line += (char)curChar;
- line += (char)nextChar;
- charCount = 1;
- }
- }
- }
- if (!line.empty()) {
- lines.push_back(line);
- }
-}
-
} // End of namespace Darkseed
diff --git a/engines/darkseed/console.h b/engines/darkseed/console.h
index d5dd40404d8..c531dba2cf3 100644
--- a/engines/darkseed/console.h
+++ b/engines/darkseed/console.h
@@ -22,22 +22,20 @@
#ifndef DARKSEED_CONSOLE_H
#define DARKSEED_CONSOLE_H
-#include "graphics/big5.h"
-#include "darkseed/gamefont.h"
+#include "graphics/font.h"
#include "darkseed/sound.h"
#include "darkseed/tostext.h"
#include "darkseed/langtext.h"
namespace Darkseed {
-class Console {
+class Console {
private:
TosText *_tosText;
Graphics::Font *_font;
- bool _isBig5 = false;
Sound *_sound;
- Common::StringArray _text;
+ Common::U32StringArray _text;
int _startIdx = 0;
bool _redrawRequired = false;
int _numLines = 4;
@@ -54,11 +52,12 @@ public:
void addI18NText(const I18nText &text);
void draw(bool forceRedraw = false);
- void drawStringAt(int x, int y, const Common::String &text) const;
+ void drawStringAt(int x, int y, const Common::U32String &text) const;
private:
- void addLine(const Common::String &line);
- void big5WordWrap(const Common::String &str, int maxWidth, Common::StringArray &lines);
+ void addTextLineU32(const Common::U32String &text);
+ void addToCurrentLineU32(const Common::U32String &text);
+ void addLine(const Common::U32String &line);
};
} // End of namespace Darkseed
diff --git a/engines/darkseed/kofont.cpp b/engines/darkseed/kofont.cpp
index b88052f870c..1d7fa97f602 100644
--- a/engines/darkseed/kofont.cpp
+++ b/engines/darkseed/kofont.cpp
@@ -35,6 +35,12 @@ KoFont::KoFont() {
loadFontDataSet(_fontDataSet3, 109, fontData);
fontData.close();
+
+ _gameFont = new GameFont();
+}
+
+KoFont::~KoFont() {
+ delete _gameFont;
}
void KoFont::loadFontDataSet(Common::Array<Common::Array<uint8> > &dataSet, int size, Common::File &file) {
@@ -68,6 +74,9 @@ int KoFont::getMaxCharWidth() const {
}
int KoFont::getCharWidth(uint32 chr) const {
+ if (chr < 128) {
+ return _gameFont->getCharWidth(chr);
+ }
return getMaxCharWidth();
}
@@ -201,6 +210,10 @@ void KoFont::extractKoIndexComponents(uint32 charIdx, uint16 *param_2, uint16 *p
}
void KoFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const {
+ if (chr < 128) {
+ _gameFont->drawChar(dst, chr, x, y, color);
+ return;
+ }
uint8 pixels[256];
memset(pixels, 0, 256);
createGlyph(pixels, chr);
diff --git a/engines/darkseed/kofont.h b/engines/darkseed/kofont.h
index ed021c6696a..7cb954fbbe6 100644
--- a/engines/darkseed/kofont.h
+++ b/engines/darkseed/kofont.h
@@ -24,6 +24,7 @@
#include "graphics/font.h"
#include "common/file.h"
+#include "darkseed/gamefont.h"
namespace Darkseed {
@@ -32,9 +33,11 @@ private:
Common::Array<Common::Array<uint8>> _fontDataSet1;
Common::Array<Common::Array<uint8>> _fontDataSet2;
Common::Array<Common::Array<uint8>> _fontDataSet3;
+ GameFont *_gameFont;
public:
KoFont();
+ ~KoFont();
int getFontHeight() const override;
int getMaxCharWidth() const override;
diff --git a/engines/darkseed/menu.cpp b/engines/darkseed/menu.cpp
index b93737f5d8b..e32f35d8dd9 100644
--- a/engines/darkseed/menu.cpp
+++ b/engines/darkseed/menu.cpp
@@ -71,7 +71,7 @@ constexpr I18NTextWithPosition kMenu_quit = {
void drawMenuItem(const I18NTextWithPosition &menuText) {
const TextWithPosition &textWithPosition = getI18NTextWithPosition(menuText);
- g_engine->_console->drawStringAt(textWithPosition.x, textWithPosition.y, textWithPosition.text);
+ g_engine->_console->drawStringAt(textWithPosition.x, textWithPosition.y, Common::U32String(textWithPosition.text));
}
void Menu::drawSoundMenuItem() {
diff --git a/engines/darkseed/tostext.cpp b/engines/darkseed/tostext.cpp
index 2e0d9b9f6ca..f85af34bae8 100644
--- a/engines/darkseed/tostext.cpp
+++ b/engines/darkseed/tostext.cpp
@@ -20,6 +20,7 @@
*/
#include "common/file.h"
+#include "darkseed/darkseed.h"
#include "darkseed/tostext.h"
namespace Darkseed {
@@ -38,21 +39,37 @@ bool TosText::load() {
return true;
}
-const Common::String &TosText::getText(uint16 textIndex) {
+const Common::U32String &TosText::getText(uint16 textIndex) {
assert(textIndex < _numEntries);
return _textArray[textIndex];
}
-Common::String TosText::loadString(Common::File &file, uint16 index) const {
- Common::String str;
+Common::U32String TosText::loadString(Common::File &file, uint16 index) const {
+ Common::U32String str;
file.seek(index * 2, SEEK_SET);
auto startOffset = file.readUint16LE();
uint16 strLen = index == _numEntries - 1
? file.size() - startOffset
: file.readUint16LE() - startOffset;
file.seek(startOffset, SEEK_SET);
- for (int i = 0; i < strLen; i++) {
- str += (char)file.readByte();
+ if (g_engine->getLanguage() == Common::KO_KOR || g_engine->getLanguage() == Common::ZH_ANY) {
+ // handle multi-byte languages
+ for (int i = 0; i < strLen; i++) {
+ uint8 byte = (char)file.readByte();
+ if (byte & 0x80) {
+ if (i < strLen - 1) {
+ uint8 byte2 = (char)file.readByte();
+ str += (int)byte << 8 | byte2;
+ i++;
+ }
+ } else {
+ str += byte;
+ }
+ }
+ } else {
+ for (int i = 0; i < strLen; i++) {
+ str += (char)file.readByte();
+ }
}
return str;
}
diff --git a/engines/darkseed/tostext.h b/engines/darkseed/tostext.h
index 366953858ea..d1bd60d017d 100644
--- a/engines/darkseed/tostext.h
+++ b/engines/darkseed/tostext.h
@@ -29,17 +29,17 @@
namespace Darkseed {
class TosText {
- Common::StringArray _textArray;
+ Common::U32StringArray _textArray;
uint16 _numEntries = 0;
public:
bool load();
uint16 getNumEntries() const;
- const Common::String &getText(uint16 textIndex);
+ const Common::U32String &getText(uint16 textIndex);
private:
- Common::String loadString(Common::File &file, uint16 index) const;
+ Common::U32String loadString(Common::File &file, uint16 index) const;
};
} // namespace Darkseed
More information about the Scummvm-git-logs
mailing list