[Scummvm-git-logs] scummvm master -> 2853c357ccd1e8e9e3a679c3083d1869807b03e9
lephilousophe
lephilousophe at users.noreply.github.com
Tue Dec 1 19:11:34 UTC 2020
This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4c833495d4 Revert "CRYOMNI3D: Don't use U32String with non UTF-32 codepoints"
2853c357cc CRYOMNI3D: Simple fix for encoding problems
Commit: 4c833495d4ffcf3408e47345608df5a15b0adacd
https://github.com/scummvm/scummvm/commit/4c833495d4ffcf3408e47345608df5a15b0adacd
Author: Ano Nymous (anonymous at anonymous.com)
Date: 2020-12-01T20:09:22+01:00
Commit Message:
Revert "CRYOMNI3D: Don't use U32String with non UTF-32 codepoints"
This reverts commits 83b7fe01eac2898f96a2d55057be4d83f5cbdb0a and
20533b819bd55ec77f27599c8f0a45be1347cf0a.
Changed paths:
engines/cryomni3d/font_manager.cpp
engines/cryomni3d/font_manager.h
engines/cryomni3d/versailles/data.cpp
engines/cryomni3d/versailles/engine.h
engines/cryomni3d/versailles/logic.cpp
diff --git a/engines/cryomni3d/font_manager.cpp b/engines/cryomni3d/font_manager.cpp
index 65554f5633..421d3b486d 100644
--- a/engines/cryomni3d/font_manager.cpp
+++ b/engines/cryomni3d/font_manager.cpp
@@ -155,7 +155,7 @@ void FontManager::loadTTFList(const Common::String &ttfList, Common::CodePage co
#endif
}
-CryoString FontManager::toU32(const Common::String &str) const {
+Common::U32String FontManager::toU32(const Common::String &str) const {
assert(_codepage != Common::kCodePageInvalid);
if (_toUnicode) {
@@ -170,7 +170,7 @@ CryoString FontManager::toU32(const Common::String &str) const {
case Common::kWindows950: {
/* if high-order bit is 1, then character is 2 bytes else it's 1 byte
* We don't check validity of the codepoint */
- CryoString ret;
+ Common::U32String ret;
for (uint32 i = 0; i < str.size(); i++) {
uint32 c = (byte)str[i];
if ((c & 0x80) && (i + 1 < str.size())) {
@@ -208,18 +208,18 @@ void FontManager::setSpaceWidth(uint additionalSpace) {
}
uint FontManager::displayStr_(uint x, uint y,
- const CryoString &text) const {
+ const Common::U32String &text) const {
uint offset = 0;
- for (CryoString::const_iterator it = text.begin(); it != text.end(); it++) {
+ for (Common::U32String::const_iterator it = text.begin(); it != text.end(); it++) {
_currentFont->drawChar(_currentSurface, *it, x + offset, y, _foreColor);
offset += _currentFont->getCharWidth(*it) + _charSpacing;
}
return offset;
}
-uint FontManager::getStrWidth(const CryoString &text) const {
+uint FontManager::getStrWidth(const Common::U32String &text) const {
uint width = 0;
- for (CryoString::const_iterator it = text.begin(); it != text.end(); it++) {
+ for (Common::U32String::const_iterator it = text.begin(); it != text.end(); it++) {
uint32 c = *it;
if (c == ' ') {
width += _spaceWidth;
@@ -230,11 +230,11 @@ uint FontManager::getStrWidth(const CryoString &text) const {
return width;
}
-bool FontManager::displayBlockText(const CryoString &text,
- CryoString::const_iterator begin) {
+bool FontManager::displayBlockText(const Common::U32String &text,
+ Common::U32String::const_iterator begin) {
bool notEnoughSpace = false;
- CryoString::const_iterator ptr = begin;
- Common::Array<CryoString> words;
+ Common::U32String::const_iterator ptr = begin;
+ Common::Array<Common::U32String> words;
if (begin != text.end()) {
_blockTextRemaining = nullptr;
@@ -251,7 +251,7 @@ bool FontManager::displayBlockText(const CryoString &text,
} else {
spaceWidthPerWord = (double)spacesWidth / (double)words.size();
}
- Common::Array<CryoString>::const_iterator word;
+ Common::Array<Common::U32String>::const_iterator word;
uint word_i;
for (word = words.begin(), word_i = 0; word != words.end(); word++, word_i++) {
_blockPos.x += displayStr_(_blockPos.x, _blockPos.y, *word);
@@ -276,7 +276,7 @@ bool FontManager::displayBlockText(const CryoString &text,
return notEnoughSpace;
}
-uint FontManager::getLinesCount(const CryoString &text, uint width) {
+uint FontManager::getLinesCount(const Common::U32String &text, uint width) {
if (text.size() == 0) {
// One line even if it's empty
return 1;
@@ -287,11 +287,11 @@ uint FontManager::getLinesCount(const CryoString &text, uint width) {
}
uint lineCount = 0;
- CryoString::const_iterator textP = text.begin();
+ Common::U32String::const_iterator textP = text.begin();
uint len = text.size();
while (len > 0) {
- CryoString buffer;
+ Common::U32String buffer;
uint lineWidth = 0;
lineCount++;
while (lineWidth < width && len > 0 && *textP != '\r') {
@@ -348,14 +348,14 @@ uint FontManager::getLinesCount(const CryoString &text, uint width) {
return lineCount;
}
-void FontManager::calculateWordWrap(const CryoString &text,
- CryoString::const_iterator *position, uint *finalPos, bool *hasCr,
- Common::Array<CryoString> &words) const {
+void FontManager::calculateWordWrap(const Common::U32String &text,
+ Common::U32String::const_iterator *position, uint *finalPos, bool *hasCr,
+ Common::Array<Common::U32String> &words) const {
*hasCr = false;
uint offset = 0;
bool wordWrap = false;
uint lineWidth = _blockRect.right - _blockRect.left;
- CryoString::const_iterator ptr = *position;
+ Common::U32String::const_iterator ptr = *position;
words.clear();
@@ -368,9 +368,9 @@ void FontManager::calculateWordWrap(const CryoString &text,
}
while (!wordWrap) {
- CryoString::const_iterator begin = ptr;
+ Common::U32String::const_iterator begin = ptr;
for (; ptr != text.end() && *ptr != '\r' && (!_useSpaceDelimiter || *ptr != ' '); ptr++) { }
- CryoString word(begin, ptr);
+ Common::U32String word(begin, ptr);
uint width = getStrWidth(word);
if (width + offset >= lineWidth) {
wordWrap = true;
@@ -391,10 +391,10 @@ void FontManager::calculateWordWrap(const CryoString &text,
offset -= _spaceWidth;
} /**/ else {
// couldn't get a word (too long): we are at start of line
- CryoString::const_iterator begin = ptr;
+ Common::U32String::const_iterator begin = ptr;
// Start with one character
for (ptr++; ptr != text.end(); ptr++) {
- CryoString word(begin, ptr);
+ Common::U32String word(begin, ptr);
uint width = getStrWidth(word);
if (width >= lineWidth) {
break;
@@ -406,7 +406,7 @@ void FontManager::calculateWordWrap(const CryoString &text,
ptr--;
}
if (_keepASCIIjoined) {
- CryoString::const_iterator end = ptr;
+ Common::U32String::const_iterator end = ptr;
// Until now ptr was pointing after the last character
// As we want to look at it, go back
if (ptr != begin) {
@@ -429,7 +429,7 @@ void FontManager::calculateWordWrap(const CryoString &text,
ptr++;
}
}
- CryoString word(begin, ptr);
+ Common::U32String word(begin, ptr);
words.push_back(word);
} /**/
*finalPos = offset;
diff --git a/engines/cryomni3d/font_manager.h b/engines/cryomni3d/font_manager.h
index f4871a5393..6e0b7c6615 100644
--- a/engines/cryomni3d/font_manager.h
+++ b/engines/cryomni3d/font_manager.h
@@ -37,71 +37,6 @@ class ManagedSurface;
namespace CryOmni3D {
-// This is a special simplified U32String which can contain either conforming UTF-32 data, 16-bits CJK codepoints or 8-bits characters
-// We must use this because depending on the localization, all of those were used and we don't always know which encoding is which
-// This class is only used when displaying stuff, hence its location
-class CryoString : public Common::BaseString<Common::u32char_type_t> {
-public:
- CryoString() : Common::BaseString<Common::u32char_type_t>() {}
-
- CryoString(const CryoString &str) : Common::BaseString<Common::u32char_type_t>(str) {}
- CryoString &operator=(const CryoString &str) {
- assign(str);
- return *this;
- }
-
- // Constructor to build UTF-32 based strings
- CryoString(const Common::U32String &ustr) : Common::BaseString<Common::u32char_type_t>(ustr) {}
-
- // Constructors to build 8-bits strings
- CryoString(const char *str, uint32 len) {
- initWithChars(str, len);
- }
- explicit CryoString(const char *str) {
- if (str == nullptr) {
- return;
- }
- uint32 len = 0;
- const char *s = str;
- while (*s++) {
- ++len;
- }
- initWithChars(str, len);
- }
- CryoString(const Common::String &str) {
- initWithChars(str.c_str(), str.size());
- }
-
- // Used when building 16-bits CJK strings
- CryoString &operator+=(value_type c) {
- assignAppend(c);
- return *this;
- }
-
- // Various constructors
- CryoString(const value_type *beginP, const value_type *endP) :
- Common::BaseString<Common::u32char_type_t>(beginP, endP) {}
- CryoString(const value_type *str, uint32 len) :
- Common::BaseString<Common::u32char_type_t>(str, len) {}
-#ifdef USE_CXX11
- explicit CryoString(const uint32 *str) :
- Common::BaseString<Common::u32char_type_t>((const value_type *) str) {}
- CryoString(const uint32 *str, uint32 len) :
- Common::BaseString<Common::u32char_type_t>((const value_type *) str, len) {}
- CryoString(const uint32 *beginP, const uint32 *endP) :
- Common::BaseString<Common::u32char_type_t>((const value_type *) beginP,
- (const value_type *) endP) {}
-#endif
-private:
- void initWithChars(const char *str, uint32 len) {
- ensureCapacity(len, false);
- for (; len > 0; str++, len--) {
- _str[_size++] = (uint8)(*str);
- }
- _str[_size] = 0;
- }
-};
-
class FontManager {
public:
FontManager();
@@ -126,9 +61,9 @@ public:
toU32(Common::String::format("%d", value)));
}
void displayStr(uint x, uint y, const Common::String &text) const { displayStr_(x, y, toU32(text)); }
- void displayStr(uint x, uint y, const CryoString &text) const { displayStr_(x, y, text); }
+ void displayStr(uint x, uint y, const Common::U32String &text) const { displayStr_(x, y, text); }
uint getStrWidth(const Common::String &text) const { return getStrWidth(toU32(text)); }
- uint getStrWidth(const CryoString &text) const;
+ uint getStrWidth(const Common::U32String &text) const;
uint getLinesCount(const Common::String &text, uint width) { return getLinesCount(toU32(text), width); }
@@ -146,13 +81,13 @@ public:
Common::Point blockTextLastPos() { return _blockPos; }
private:
- CryoString toU32(const Common::String &text) const;
+ Common::U32String toU32(const Common::String &text) const;
- uint displayStr_(uint x, uint y, const CryoString &text) const;
- uint getLinesCount(const CryoString &text, uint width);
- bool displayBlockText(const CryoString &text, CryoString::const_iterator begin);
- void calculateWordWrap(const CryoString &text, CryoString::const_iterator *position,
- uint *finalPos, bool *has_br, Common::Array<CryoString> &words) const;
+ uint displayStr_(uint x, uint y, const Common::U32String &text) const;
+ uint getLinesCount(const Common::U32String &text, uint width);
+ bool displayBlockText(const Common::U32String &text, Common::U32String::const_iterator begin);
+ void calculateWordWrap(const Common::U32String &text, Common::U32String::const_iterator *position,
+ uint *finalPos, bool *has_br, Common::Array<Common::U32String> &words) const;
Common::CodePage _codepage;
bool _toUnicode;
@@ -171,8 +106,8 @@ private:
Common::Point _blockPos;
int _lineHeight;
bool _justifyText;
- CryoString _blockTextStr;
- CryoString::const_iterator _blockTextRemaining;
+ Common::U32String _blockTextStr;
+ Common::U32String::const_iterator _blockTextRemaining;
// Specific parameters for non alphabetic languages
void setupWrapParameters();
diff --git a/engines/cryomni3d/versailles/data.cpp b/engines/cryomni3d/versailles/data.cpp
index 7256086aa5..d04420bc01 100644
--- a/engines/cryomni3d/versailles/data.cpp
+++ b/engines/cryomni3d/versailles/data.cpp
@@ -102,12 +102,11 @@ void CryOmni3DEngine_Versailles::loadStaticData() {
_epigraphContent = data->readString16();
_epigraphPassword = data->readString16();
- // Japanese is the only language (for now) where the password isn't 8-bit ASCII string
if (getLanguage() == Common::JA_JPN) {
_bombAlphabet = data->readString16().decode(Common::kWindows932);
_bombPassword = data->readString16().decode(Common::kWindows932);
} else {
- _bombAlphabet = CryoString("ABCDEFGHIJKLMNOPQRSTUVWXYZ '");
+ _bombAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ '";
_bombPassword = data->readString16();
}
diff --git a/engines/cryomni3d/versailles/engine.h b/engines/cryomni3d/versailles/engine.h
index 430fcd799d..3b6823df96 100644
--- a/engines/cryomni3d/versailles/engine.h
+++ b/engines/cryomni3d/versailles/engine.h
@@ -246,7 +246,7 @@ public:
return prepareFileName(baseName, extensions);
}
Common::String prepareFileName(const Common::String &baseName,
- const char *const *extensions) const override;
+ const char *const *extensions) const override;
void setupPalette(const byte *colors, uint start, uint num) override { setupPalette(colors, start, num, true); }
void makeTranslucent(Graphics::Surface &dst, const Graphics::Surface &src) const override;
@@ -560,8 +560,8 @@ private:
IMG_CB(88003d);
IMG_CB(88003e);
IMG_CB(88003f);
- CryoString _bombAlphabet; // For Japanese edition
- CryoString _bombPassword;
+ Common::U32String _bombAlphabet; // For Japanese edition
+ Common::U32String _bombPassword;
static const uint kBombPasswordSmallLength = 40;
static const uint kBombPasswordMaxLength = 60;
static const uint16 kBombLettersPos[2][kBombPasswordMaxLength][2];
diff --git a/engines/cryomni3d/versailles/logic.cpp b/engines/cryomni3d/versailles/logic.cpp
index 8354e46460..3e583ea11f 100644
--- a/engines/cryomni3d/versailles/logic.cpp
+++ b/engines/cryomni3d/versailles/logic.cpp
@@ -3222,7 +3222,7 @@ void CryOmni3DEngine_Versailles::drawBombLetters(Graphics::ManagedSurface &surfa
surface.fillRect(rct, 239);
uint32 letter = bombPossibilites[i][bombCurrentLetters[i]];
- CryoString str(&letter, 1);
+ Common::U32String str(&letter, 1);
_fontManager.displayStr(rct.left + (34 - _fontManager.getStrWidth(str)) / 2,
rct.top + 5, str);
Commit: 2853c357ccd1e8e9e3a679c3083d1869807b03e9
https://github.com/scummvm/scummvm/commit/2853c357ccd1e8e9e3a679c3083d1869807b03e9
Author: Ano Nymous (anonymous at anonymous.com)
Date: 2020-12-01T20:09:22+01:00
Commit Message:
CRYOMNI3D: Simple fix for encoding problems
That's simpler than reimplementing an U32String object
Changed paths:
engines/cryomni3d/font_manager.cpp
diff --git a/engines/cryomni3d/font_manager.cpp b/engines/cryomni3d/font_manager.cpp
index 421d3b486d..fffe3ff002 100644
--- a/engines/cryomni3d/font_manager.cpp
+++ b/engines/cryomni3d/font_manager.cpp
@@ -162,6 +162,7 @@ Common::U32String FontManager::toU32(const Common::String &str) const {
return str.decode(_codepage);
}
+ // Beware: when not using Unicode, U32String will contain codepoints not corresponding to Unicode
switch (_codepage) {
case Common::kUtf8:
error("UTF-8 not supported");
@@ -184,7 +185,8 @@ Common::U32String FontManager::toU32(const Common::String &str) const {
}
default:
// All other codepages are SBCS: one byte is one character
- return str;
+ // We use kISO8859_1 as it's the identity function [0-255] to [0-255]
+ return str.decode(Common::kISO8859_1);
}
}
More information about the Scummvm-git-logs
mailing list