[Scummvm-git-logs] scummvm master -> 19466d352e95bca25f7de5c684f9958249fa77ba

aquadran noreply at scummvm.org
Sat Dec 9 07:38:53 UTC 2023


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
f098f7a040 GRIM: Fix support for Korean translation for Grim Fandango
55f6e9333f GRIM: Fix code formatting
19466d352e GRIM: Fixed compile error


Commit: f098f7a040c338504d28e2142cd98cf6245c2f74
    https://github.com/scummvm/scummvm/commit/f098f7a040c338504d28e2142cd98cf6245c2f74
Author: Youngjun, Choi (british2 at naver.com)
Date: 2023-12-09T08:38:49+01:00

Commit Message:
GRIM: Fix support for Korean translation for Grim Fandango

Changed paths:
    engines/grim/detection.cpp
    engines/grim/font.cpp
    engines/grim/font.h
    engines/grim/grim.cpp
    engines/grim/localize.cpp
    engines/grim/md5check.cpp
    engines/grim/resource.cpp
    engines/grim/textobject.cpp


diff --git a/engines/grim/detection.cpp b/engines/grim/detection.cpp
index 53fd3cdab22..0901893be6c 100644
--- a/engines/grim/detection.cpp
+++ b/engines/grim/detection.cpp
@@ -229,6 +229,20 @@ static const GrimGameDescription gameDescriptions[] = {
 		},
 		GType_GRIM
 	},
+	{
+		// Grim Fandango Korean Fan translation (patched)
+		{
+			"grim",
+			"",
+			AD_ENTRY2s("VOX0001.LAB", "444f05f2af689c1bffd179b8b6a632bd", 57993159,
+					   "grim.ko.tab", NULL, -1),
+			Common::KO_KOR,
+			Common::kPlatformWindows,
+			ADGF_NO_FLAGS,
+			GUI_OPTIONS_GRIME
+		},
+		GType_GRIM
+	},
 /*	{
 		// Grim Fandango German version (patched)
 		{
diff --git a/engines/grim/font.cpp b/engines/grim/font.cpp
index e7e0802c28e..c98b07f1e0b 100644
--- a/engines/grim/font.cpp
+++ b/engines/grim/font.cpp
@@ -353,8 +353,31 @@ void FontTTF::restoreState(SaveGame *state) {
 	g_driver->destroyFont(this);
 	delete _font;
 
-	stream = g_resourceloader->openNewStreamFile(fname.c_str(), true);
-	loadTTF(fname, stream, size);
+	if (g_grim->getGameType() == GType_GRIM && g_grim->getGameLanguage() == Common::KO_KOR) {
+		Common::String name = fname + ".txt";
+		stream = g_resourceloader->openNewStreamFile(name, true);
+		if (stream) {
+			Common::String line = stream->readLine();
+			Common::String font;
+			Common::String fsize;
+			for (uint i = 0; i < line.size(); ++i) {
+				if (line[i] == ' ') {
+					font = Common::String(line.c_str(), i);
+					fsize = Common::String(line.c_str() + i + 1, line.size() - i - 2);
+				}
+			}
+
+			int s = atoi(fsize.c_str());
+			delete stream;
+			stream = g_resourceloader->openNewStreamFile(font.c_str(), true);
+			loadTTF(fname, stream, s);
+		} else {
+			error("Cannot load korean ttf font");
+		}
+	} else {
+		stream = g_resourceloader->openNewStreamFile(fname.c_str(), true);
+		loadTTF(fname, stream, size);
+	}
 	delete stream;
 }
 
@@ -403,12 +426,31 @@ void FontTTF::loadTTF(const Common::String &filename, Common::SeekableReadStream
 #endif
 }
 
+int FontTTF::getKernedStringLength(const Common::String &text) const {
+	if (g_grim->getGameLanguage() == Common::KO_KOR) {
+		return _font->getStringWidth(convertToU32String(text.c_str(), Common::kWindows949));
+	}
+	return _font->getStringWidth(text);
+}
+
 void FontTTF::render(Graphics::Surface &surface, const Common::String &currentLine, const Graphics::PixelFormat &pixelFormat, uint32 blackColor, uint32 color, uint32 colorKey) const {
 #ifdef USE_FREETYPE2
-	Common::Rect bbox = _font->getBoundingBox(currentLine);
-	surface.create(bbox.right, bbox.bottom, pixelFormat);
-	surface.fillRect(Common::Rect(0, 0, bbox.right, bbox.bottom), colorKey);
-	_font->drawString(&surface, currentLine, 0, 0, bbox.right, 0xFFFFFFFF);
+	if (g_grim->getGameLanguage() == Common::KO_KOR) {
+		Common::U32String u32CurrentLine(currentLine, Common::kWindows949);
+		int width = _font->getStringWidth(u32CurrentLine);
+		int height = _font->getFontHeight();
+		surface.create(width, height, pixelFormat);
+		surface.fillRect(Common::Rect(0, 0, width, height), colorKey);
+		_font->drawString(&surface, u32CurrentLine, 0, 0, width, 0xFFFFFFFF);
+
+	} else {
+		Common::Rect bbox = _font->getBoundingBox(currentLine);
+
+		surface.create(bbox.right, bbox.bottom, pixelFormat);
+		surface.fillRect(Common::Rect(0, 0, bbox.right, bbox.bottom), colorKey);
+
+		_font->drawString(&surface, currentLine, 0, 0, bbox.right, 0xFFFFFFFF);
+	}
 #endif
 }
 
diff --git a/engines/grim/font.h b/engines/grim/font.h
index 76c0027ba98..4a141f99f11 100644
--- a/engines/grim/font.h
+++ b/engines/grim/font.h
@@ -50,6 +50,10 @@ public:
 	virtual bool is8Bit() const = 0;
 	const Common::String &getFilename() const { return _filename; }
 
+	// for Korean Translate
+	int32 getWCharKernedWidth(unsigned char hi, unsigned char lo) const { return getCharKernedWidth(hi) + getCharKernedWidth(lo); }
+	bool isKoreanChar(const byte hi, const byte lo) const { return (hi >= 0xB0 && hi <= 0xC8 && lo >= 0xA1 && lo <= 0xFE); }
+
 	static Font *getByFileName(const Common::String& fileName);
 	static Font *getFirstFont();
 	static void save(const Font *font, SaveGame *state);
@@ -137,13 +141,16 @@ public:
 	int32 getCharKernedWidth(uint32 c) const override { return _font->getCharWidth(c); }
 	int32 getFontWidth() const override { return getCharKernedWidth('w'); }
 
-	int getKernedStringLength(const Common::String &text) const override { return _font->getStringWidth(text); }
+	int getKernedStringLength(const Common::String &text) const override;
 	void render(Graphics::Surface &buf, const Common::String &currentLine, const Graphics::PixelFormat &pixelFormat, uint32 blackColor, uint32 color, uint32 colorKey) const override;
 	bool is8Bit() const override { return false; }
 
 	void saveState(SaveGame *state) const;
 	void restoreState(SaveGame *state);
 
+	// for Korean Translate
+	int32 getWCharKernedWidth(unsigned char hi, unsigned char lo) const { return _font->getCharWidth(Common::convertUHCToUCS(hi, lo)); }
+
 private:
 	Graphics::Font *_font;
 	int _size;
diff --git a/engines/grim/grim.cpp b/engines/grim/grim.cpp
index 62430a8c39e..a5b78d082b5 100644
--- a/engines/grim/grim.cpp
+++ b/engines/grim/grim.cpp
@@ -274,6 +274,12 @@ GfxBase *GrimEngine::createRenderer(int screenW, int screenH) {
 #endif
 			0;
 
+	// For Grim Fandango, Korean fan translation can only use OpenGL renderer
+	if (getGameType() == GType_GRIM && g_grim->getGameLanguage() == Common::KO_KOR) {
+		availableRendererTypes &= ~Graphics::kRendererTypeOpenGLShaders;
+		availableRendererTypes &= ~Graphics::kRendererTypeTinyGL;
+	}
+
 	// For Grim Fandango, OpenGL renderer without shaders is preferred if available
 	if (desiredRendererType == Graphics::kRendererTypeDefault &&
 		(availableRendererTypes & Graphics::kRendererTypeOpenGL) &&
diff --git a/engines/grim/localize.cpp b/engines/grim/localize.cpp
index 1eac0a1b751..012b1c04518 100644
--- a/engines/grim/localize.cpp
+++ b/engines/grim/localize.cpp
@@ -40,6 +40,7 @@ Localizer::Localizer() {
 	bool isFrench = g_grim->getGameLanguage() == Common::FR_FRA;
 	bool isItalian = g_grim->getGameLanguage() == Common::IT_ITA;
 	bool isSpanish = g_grim->getGameLanguage() == Common::ES_ESP;
+	bool isKorean = g_grim->getGameLanguage() == Common::KO_KOR;	// Korean Fan Translation
 	bool isTranslatedGrimDemo = (isGerman || isFrench || isItalian || isSpanish) && isGrimDemo;
 	bool isPS2 = g_grim->getGamePlatform() == Common::kPlatformPS2;
 
@@ -54,6 +55,8 @@ Localizer::Localizer() {
 			filename = Common::String("grim.") + g_grim->getLanguagePrefix() + Common::String(".tab"); // TODO: Detect based on language.
 		} else if (isTranslatedGrimDemo) {
 			filename = "language.tab";
+		} else if (isKorean) {
+			filename = "grim.ko.tab";
 		} else {
 			filename = "grim.tab";
 		}
diff --git a/engines/grim/md5check.cpp b/engines/grim/md5check.cpp
index a0224de7ef2..dfff0f89803 100644
--- a/engines/grim/md5check.cpp
+++ b/engines/grim/md5check.cpp
@@ -483,7 +483,10 @@ void MD5Check::init() {
 			MD5SUM("data001.lab", data001)
 			MD5SUM("data000.lab", data000)
 			MD5SUM("credits.lab", credits)
-			if (g_grim->getGameLanguage() != Common::EN_ANY && g_grim->getGameLanguage() != Common::ZH_CHN && g_grim->getGameLanguage() != Common::RU_RUS) {
+			if (g_grim->getGameLanguage() != Common::EN_ANY 
+				&& g_grim->getGameLanguage() != Common::ZH_CHN 
+				&& g_grim->getGameLanguage() != Common::RU_RUS
+				&& g_grim->getGameLanguage() != Common::KO_KOR) {
 				MD5SUM("local.lab", local)
 			}
 			if (g_grim->getGameLanguage() == Common::ZH_CHN) {
diff --git a/engines/grim/resource.cpp b/engines/grim/resource.cpp
index afb45fac94c..29eb6e9937c 100644
--- a/engines/grim/resource.cpp
+++ b/engines/grim/resource.cpp
@@ -390,6 +390,29 @@ Font *ResourceLoader::loadFont(const Common::String &filename) {
 			stream = openNewStreamFile(font.c_str(), true);
 			FontTTF *result = new FontTTF();
 			result->loadTTF(font, stream, s);
+			return result;
+		}
+	} else if (g_grim->getGameType() == GType_GRIM && g_grim->getGameLanguage() == Common::KO_KOR) {
+		Common::String name = filename + ".txt";
+		stream = openNewStreamFile(name, true);
+		if (stream) {
+			Common::String line = stream->readLine();
+			Common::String font;
+			Common::String size;
+			for (uint i = 0; i < line.size(); ++i) {
+				if (line[i] == ' ') {
+					font = Common::String(line.c_str(), i);
+					size = Common::String(line.c_str() + i + 1, line.size() - i - 2);
+				}
+			}
+
+			int s = atoi(size.c_str());
+			delete stream;
+			stream = openNewStreamFile(font.c_str(), true);
+			FontTTF *result = new FontTTF();
+			result->loadTTF(filename, stream, s);
+			delete stream;
+
 			return result;
 		}
 	}
diff --git a/engines/grim/textobject.cpp b/engines/grim/textobject.cpp
index ba6b087f7ce..a868d59a4b2 100644
--- a/engines/grim/textobject.cpp
+++ b/engines/grim/textobject.cpp
@@ -214,30 +214,50 @@ void TextObject::setupTextReal(S msg, Common::String (*convert)(const S &s)) {
 	S currLine;
 	_numberLines = 1;
 	int lineWidth = 0;
+	bool isMultiByte = false;
 	for (uint i = 0; i < msg.size(); i++) {
 		message += msg[i];
 		currLine += msg[i];
-		lineWidth += _font->getCharKernedWidth(msg[i]);
+		if (i < msg.size()-1 && g_grim->getGameType() == GType_GRIM && g_grim->getGameLanguage() == Common::KO_KOR && _font->isKoreanChar(msg[i], msg[i+1])) {
+			isMultiByte = true;
+			message += msg[i+1];
+			currLine += msg[i+1];
+			lineWidth += _font->getWCharKernedWidth(msg[i], msg[i+1]);
+			i++;
+		} else {
+			isMultiByte = false;
+			lineWidth += _font->getCharKernedWidth(msg[i]);
+		}
 
 		if (currLine.size() > 1 && lineWidth > maxWidth) {
-			if (currLine.contains(' ')) {
-				while (currLine.lastChar() != ' ' && currLine.size() > 1) {
-					lineWidth -= _font->getCharKernedWidth(currLine.lastChar());
-					message.deleteLastChar();
-					currLine.deleteLastChar();
-					--i;
-				}
-			} else { // if it is a unique word
-				bool useDash = !(g_grim->getGameLanguage() == Common::Language::ZH_CHN || g_grim->getGameLanguage() == Common::Language::ZH_TWN);
-				int dashWidth = useDash ? _font->getCharKernedWidth('-') : 0;
-				while (lineWidth + dashWidth > maxWidth && currLine.size() > 1) {
-					lineWidth -= _font->getCharKernedWidth(currLine.lastChar());
-					message.deleteLastChar();
-					currLine.deleteLastChar();
-					--i;
+			if (isMultiByte) {
+				// Remove 2byte code
+				lineWidth -= _font->getWCharKernedWidth(msg[i-1], msg[i]);
+				message.deleteLastChar();
+				message.deleteLastChar();
+				currLine.deleteLastChar();
+				currLine.deleteLastChar();
+				i-=2;
+			} else {
+				if (currLine.contains(' ')) {
+					while (currLine.lastChar() != ' ' && currLine.size() > 1) {
+						lineWidth -= _font->getCharKernedWidth(currLine.lastChar());
+						message.deleteLastChar();
+						currLine.deleteLastChar();
+						--i;
+					}
+				} else { // if it is a unique word
+					bool useDash = !(g_grim->getGameLanguage() == Common::Language::ZH_CHN || g_grim->getGameLanguage() == Common::Language::ZH_TWN);
+					int dashWidth = useDash ? _font->getCharKernedWidth('-') : 0;
+					while (lineWidth + dashWidth > maxWidth && currLine.size() > 1) {
+						lineWidth -= _font->getCharKernedWidth(currLine.lastChar());
+						message.deleteLastChar();
+						currLine.deleteLastChar();
+						--i;
+					}
+					if (useDash)
+						message += '-';
 				}
-				if (useDash)
-					message += '-';
 			}
 			message += '\n';
 			currLine.clear();


Commit: 55f6e9333f353c197eff738e03f285113569cf4a
    https://github.com/scummvm/scummvm/commit/55f6e9333f353c197eff738e03f285113569cf4a
Author: Youngjun, Choi (british2 at naver.com)
Date: 2023-12-09T08:38:49+01:00

Commit Message:
GRIM: Fix code formatting

Changed paths:
    engines/grim/font.h
    engines/grim/textobject.cpp


diff --git a/engines/grim/font.h b/engines/grim/font.h
index 4a141f99f11..8fc025e18d8 100644
--- a/engines/grim/font.h
+++ b/engines/grim/font.h
@@ -51,7 +51,7 @@ public:
 	const Common::String &getFilename() const { return _filename; }
 
 	// for Korean Translate
-	int32 getWCharKernedWidth(unsigned char hi, unsigned char lo) const { return getCharKernedWidth(hi) + getCharKernedWidth(lo); }
+	int32 getWCharKernedWidth(byte hi, byte char lo) const { return getCharKernedWidth(hi) + getCharKernedWidth(lo); }
 	bool isKoreanChar(const byte hi, const byte lo) const { return (hi >= 0xB0 && hi <= 0xC8 && lo >= 0xA1 && lo <= 0xFE); }
 
 	static Font *getByFileName(const Common::String& fileName);
@@ -149,7 +149,7 @@ public:
 	void restoreState(SaveGame *state);
 
 	// for Korean Translate
-	int32 getWCharKernedWidth(unsigned char hi, unsigned char lo) const { return _font->getCharWidth(Common::convertUHCToUCS(hi, lo)); }
+	int32 getWCharKernedWidth(byte hi, byte lo) const { return _font->getCharWidth(Common::convertUHCToUCS(hi, lo)); }
 
 private:
 	Graphics::Font *_font;
diff --git a/engines/grim/textobject.cpp b/engines/grim/textobject.cpp
index a868d59a4b2..3e921f226d5 100644
--- a/engines/grim/textobject.cpp
+++ b/engines/grim/textobject.cpp
@@ -218,11 +218,11 @@ void TextObject::setupTextReal(S msg, Common::String (*convert)(const S &s)) {
 	for (uint i = 0; i < msg.size(); i++) {
 		message += msg[i];
 		currLine += msg[i];
-		if (i < msg.size()-1 && g_grim->getGameType() == GType_GRIM && g_grim->getGameLanguage() == Common::KO_KOR && _font->isKoreanChar(msg[i], msg[i+1])) {
+		if (i < msg.size() - 1 && g_grim->getGameType() == GType_GRIM && g_grim->getGameLanguage() == Common::KO_KOR && _font->isKoreanChar(msg[i], msg[i + 1])) {
 			isMultiByte = true;
-			message += msg[i+1];
-			currLine += msg[i+1];
-			lineWidth += _font->getWCharKernedWidth(msg[i], msg[i+1]);
+			message += msg[i + 1];
+			currLine += msg[i + 1];
+			lineWidth += _font->getWCharKernedWidth(msg[i], msg[i + 1]);
 			i++;
 		} else {
 			isMultiByte = false;
@@ -232,12 +232,12 @@ void TextObject::setupTextReal(S msg, Common::String (*convert)(const S &s)) {
 		if (currLine.size() > 1 && lineWidth > maxWidth) {
 			if (isMultiByte) {
 				// Remove 2byte code
-				lineWidth -= _font->getWCharKernedWidth(msg[i-1], msg[i]);
+				lineWidth -= _font->getWCharKernedWidth(msg[i - 1], msg[i]);
 				message.deleteLastChar();
 				message.deleteLastChar();
 				currLine.deleteLastChar();
 				currLine.deleteLastChar();
-				i-=2;
+				i -= 2;
 			} else {
 				if (currLine.contains(' ')) {
 					while (currLine.lastChar() != ' ' && currLine.size() > 1) {


Commit: 19466d352e95bca25f7de5c684f9958249fa77ba
    https://github.com/scummvm/scummvm/commit/19466d352e95bca25f7de5c684f9958249fa77ba
Author: Youngjun, Choi (british2 at naver.com)
Date: 2023-12-09T08:38:49+01:00

Commit Message:
GRIM: Fixed compile error

Changed paths:
    engines/grim/font.h


diff --git a/engines/grim/font.h b/engines/grim/font.h
index 8fc025e18d8..5e6ca1d634d 100644
--- a/engines/grim/font.h
+++ b/engines/grim/font.h
@@ -51,7 +51,7 @@ public:
 	const Common::String &getFilename() const { return _filename; }
 
 	// for Korean Translate
-	int32 getWCharKernedWidth(byte hi, byte char lo) const { return getCharKernedWidth(hi) + getCharKernedWidth(lo); }
+	int32 getWCharKernedWidth(byte hi, byte lo) const { return getCharKernedWidth(hi) + getCharKernedWidth(lo); }
 	bool isKoreanChar(const byte hi, const byte lo) const { return (hi >= 0xB0 && hi <= 0xC8 && lo >= 0xA1 && lo <= 0xFE); }
 
 	static Font *getByFileName(const Common::String& fileName);




More information about the Scummvm-git-logs mailing list