From 076f841526a1cef90fecf3c54bd5a0b4cb1981d8 Mon Sep 17 00:00:00 2001 From: yinsimei Date: Mon, 10 Jul 2017 23:52:11 +0200 Subject: SLUDGE: fix u32string saving error --- engines/sludge/fonttext.cpp | 8 ++++---- engines/sludge/loadsave.cpp | 5 +++-- engines/sludge/moreio.cpp | 4 ++-- engines/sludge/moreio.h | 2 +- engines/sludge/utf8.h | 7 ++++++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/engines/sludge/fonttext.cpp b/engines/sludge/fonttext.cpp index 161c357ba0..721968946b 100644 --- a/engines/sludge/fonttext.cpp +++ b/engines/sludge/fonttext.cpp @@ -32,7 +32,7 @@ namespace Sludge { spriteBank theFont; int fontHeight = 0, numFontColours, loadedFontNum; -Common::U32String fontOrderString; +UTF8Converter fontOrder; int16 fontSpace = -1; uint32 *fontTable = NULL; @@ -57,7 +57,7 @@ bool isInFont(char *theText) { uint32 c = str32[0]; // check if font order contains the utf8 char - return fontOrderString.contains(c); + return fontOrder.getU32String().contains(c); } int stringLength(char *theText) { @@ -161,14 +161,14 @@ void setFontColour(spritePalette &sP, byte r, byte g, byte b) { } bool loadFont(int filenum, const char *charOrder, int h) { - fontOrderString.clear(); - fontOrderString = UTF8Converter::convertUtf8ToUtf32(charOrder); + fontOrder.setUTF8String(charOrder); forgetSpriteBank(theFont); loadedFontNum = filenum; // get max value among all utf8 chars + Common::U32String fontOrderString = fontOrder.getU32String(); fontTableSize = 0; for (uint32 i = 0; i < fontOrderString.size(); ++i) { uint32 c = fontOrderString[i]; diff --git a/engines/sludge/loadsave.cpp b/engines/sludge/loadsave.cpp index 41e0cdba0d..df7bf9bd4d 100644 --- a/engines/sludge/loadsave.cpp +++ b/engines/sludge/loadsave.cpp @@ -44,6 +44,7 @@ #include "sludge/loadsave.h" #include "sludge/bg_effects.h" #include "sludge/thumbnail.h" +#include "sludge/utf8.h" #include "sludge/CommonCode/version.h" namespace Sludge { @@ -63,7 +64,7 @@ extern personaAnimation *mouseCursorAnim; // In cursor.cpp extern int mouseCursorFrameNum; // " " " extern int loadedFontNum, fontHeight, fontTableSize; // In fonttext.cpp extern int numFontColours; // " " " -extern char *fontOrderString; // " " " +extern UTF8Converter fontOrder; // " " " extern FILETIME fileTime; // In sludger.cpp extern int speechMode; // " " " extern int lightMapNumber; // In backdrop.cpp @@ -410,7 +411,7 @@ bool saveGame(char *fname) { if (fontTableSize > 0) { fp->writeUint16BE(loadedFontNum); fp->writeUint16BE(fontHeight); - writeString(fontOrderString, fp); + writeString(fontOrder.getUTF8String(), fp); } putSigned(fontSpace, fp); diff --git a/engines/sludge/moreio.cpp b/engines/sludge/moreio.cpp index 138f709d79..0102b31ffd 100644 --- a/engines/sludge/moreio.cpp +++ b/engines/sludge/moreio.cpp @@ -40,8 +40,8 @@ namespace Sludge { bool allowAnyFilename = true; -void writeString(char *s, Common::WriteStream *stream) { - int a, len = strlen(s); +void writeString(Common::String s, Common::WriteStream *stream) { + int a, len = s.size(); stream->writeUint16BE(len); for (a = 0; a < len; a++) { stream->writeByte(s[a] + 1); diff --git a/engines/sludge/moreio.h b/engines/sludge/moreio.h index 5cf01a2986..462d005141 100644 --- a/engines/sludge/moreio.h +++ b/engines/sludge/moreio.h @@ -30,7 +30,7 @@ float getFloat(Common::SeekableReadStream *stream); int16 getSigned(Common::SeekableReadStream *stream); // Write -void writeString(char *s, Common::WriteStream *stream); +void writeString(Common::String s, Common::WriteStream *stream); void putFloat(float f, Common::WriteStream *stream); void putSigned(int16 f, Common::WriteStream *stream); diff --git a/engines/sludge/utf8.h b/engines/sludge/utf8.h index 4595a6b86f..26a2542afc 100644 --- a/engines/sludge/utf8.h +++ b/engines/sludge/utf8.h @@ -70,7 +70,12 @@ public: /** * get converted U32String */ - Common::U32String getU32String() { return _str32; }; + Common::U32String getU32String() const { return _str32; }; + + /** + * get origin UTF8String + */ + Common::String getUTF8String() const { return _str; }; /** Convert UTF8 String to UTF32 String */ -- cgit v1.2.3