[Scummvm-git-logs] scummvm master -> c6e56a111e7daface7d9611a1065717f6052847c

yuv422 noreply at scummvm.org
Sun Jan 19 21:18:57 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:
c6e56a111e DARKSEED: Add korean font support


Commit: c6e56a111e7daface7d9611a1065717f6052847c
    https://github.com/scummvm/scummvm/commit/c6e56a111e7daface7d9611a1065717f6052847c
Author: Eric Fry (yuv422 at reversedgames.com)
Date: 2025-01-20T08:04:19+11:00

Commit Message:
DARKSEED: Add korean font support

Changed paths:
  A engines/darkseed/kofont.cpp
  A engines/darkseed/kofont.h
    engines/darkseed/console.cpp
    engines/darkseed/console.h
    engines/darkseed/module.mk


diff --git a/engines/darkseed/console.cpp b/engines/darkseed/console.cpp
index c51c24b7759..66222f9301f 100644
--- a/engines/darkseed/console.cpp
+++ b/engines/darkseed/console.cpp
@@ -21,6 +21,7 @@
 
 #include "common/debug.h"
 #include "darkseed/big5font.h"
+#include "darkseed/kofont.h"
 #include "darkseed/console.h"
 #include "darkseed/darkseed.h"
 
@@ -29,15 +30,25 @@ namespace Darkseed {
 static constexpr Common::Rect consoleArea = {{0x70, 279}, 416, 49};
 
 Console::Console(TosText *tosText, Sound *sound) : _tosText(tosText), _sound(sound) {
-	if (g_engine->getLanguage() == Common::ZH_ANY) {
+	switch (g_engine->getLanguage()) {
+	case Common::ZH_ANY :
 		_font = new Big5Font();
+		_lineHeight = 17;
+		_numLines = 3;
 		_isBig5 = true;
-	} else {
+		break;
+	case Common::KO_KOR :
+		_font = new KoFont();
+		_lineHeight = 18;
+		_numLines = 3;
+		break;
+	default:
 		_font = new GameFont();
+		_lineHeight = 11;
+		_numLines = 4;
+		break;
 	}
 
-	_numLines = _isBig5 ? 3 : 4;
-
 	_text.resize(10);
 }
 
@@ -89,7 +100,7 @@ void Console::draw(bool forceRedraw) {
 	int y = 0x139;
 	for (int i = 0; i < _numLines && curIdx != _startIdx && !_text[curIdx].empty(); i++) {
 		drawStringAt(0x70, y, _text[curIdx]);
-		y -= _isBig5 ? 17 : 11;
+		y -= _lineHeight;
 		curIdx = curIdx == 0 ? _text.size() - 1 : curIdx - 1;
 	}
 	_redrawRequired = false;
@@ -109,6 +120,21 @@ void Console::drawStringAt(const int x, const int y, const Common::String &text)
 				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);
 	}
diff --git a/engines/darkseed/console.h b/engines/darkseed/console.h
index 71063faad57..d5dd40404d8 100644
--- a/engines/darkseed/console.h
+++ b/engines/darkseed/console.h
@@ -41,6 +41,7 @@ private:
 	int _startIdx = 0;
 	bool _redrawRequired = false;
 	int _numLines = 4;
+	int _lineHeight = 11;
 
 public:
 	Console(TosText *tostext, Sound *sound);
diff --git a/engines/darkseed/kofont.cpp b/engines/darkseed/kofont.cpp
new file mode 100644
index 00000000000..e5879677f3b
--- /dev/null
+++ b/engines/darkseed/kofont.cpp
@@ -0,0 +1,212 @@
+/* ScummVM - Graphic Adventure Engine
+*
+* ScummVM is the legal property of its developers, whose names
+* are too numerous to list here. Please refer to the COPYRIGHT
+* file distributed with this source distribution.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+#include "darkseed/darkseed.h"
+#include "darkseed/kofont.h"
+
+namespace Darkseed {
+
+KoFont::KoFont() {
+	Common::File fontData;
+	if (!fontData.open("k16.bin")) {
+		error("Error: failed to open k16.bin");
+	}
+
+	loadFontDataSet(_fontDataSet1, 191, fontData);
+	loadFontDataSet(_fontDataSet2, 85, fontData);
+	loadFontDataSet(_fontDataSet3, 109, fontData);
+
+	fontData.close();
+}
+
+void KoFont::loadFontDataSet(Common::Array<Common::Array<uint8> > &dataSet, int size, Common::File &file) {
+	dataSet.resize(size);
+
+	for (int i = 0; i < size; i++) {
+		dataSet[i].resize(16 * 16, 0);
+		loadFontGlyph(dataSet[i], file);
+	}
+}
+
+static constexpr uint8 kFontPal[4] = {0, 2, 4, 11};
+
+void KoFont::loadFontGlyph(Common::Array<uint8> &pixels, Common::File &file) {
+	// Unpack 2bpp font data into 8bpp
+	for (int i = 0; i < 64; i++) {
+		uint8 byte = file.readByte();
+		for (int j = 0; j < 4; j++) {
+			pixels[i * 4 + j] = kFontPal[(byte >> (3 - j) * 2) & 3];
+		}
+	}
+}
+
+
+int KoFont::getFontHeight() const {
+	return 16;
+}
+
+int KoFont::getMaxCharWidth() const {
+	return 16;
+}
+
+int KoFont::getCharWidth(uint32 chr) const {
+	return getMaxCharWidth();
+}
+
+void KoFont::createGlyph(uint8 *pixels, uint32 chr) const {
+	uint16 param1, param2, param3;
+	extractKoIndexComponents(chr, &param1, &param2, &param3);
+	if (param1 < 191) {
+		addToGlyph(pixels, param1);
+	}
+	if (param2 < 85) {
+		addToGlyph(pixels, param2 + 191);
+	}
+	if (param3 < 109) {
+		addToGlyph(pixels, param3 + 276);
+	}
+}
+
+void KoFont::addToGlyph(uint8 *destPixels, int16 index) const {
+	if (index < 192) {
+		addPixels(destPixels, _fontDataSet1[index]);
+	} else if (index < 277) {
+		addPixels(destPixels, _fontDataSet2[index - 191]);
+	} else {
+		addPixels(destPixels, _fontDataSet3[index - 276]);
+	}
+}
+
+void KoFont::addPixels(uint8 *destPixels, const Common::Array<uint8> &pixels) const {
+	for (int i = 0; i < pixels.size(); i++) {
+		if (pixels[i] != 0) {
+			destPixels[i] = pixels[i];
+		}
+	}
+}
+
+int16 SHORT_ARRAY_1000_01ca[32] = {
+	-1, 0, 32, 352,
+	672, 992, 1312, 1632,
+	1952, 2272, 2592, 2912,
+	3232, 3552, 3872, 4192,
+	4512, 4832, 5152, 5472,
+	5792, -1, -1, -1,
+	-1, -1, -1, -1,
+	-1, -1, -1, -1};
+
+int16 SHORT_ARRAY_1000_020a[32] = {
+	-1, -1, 0, 128,
+	256, 384, 512, 640,
+	-1, -1, 768, 896,
+	1024, 1152, 1280, 1408,
+	-1, -1, 1536, 1664,
+	1792, 1920, 2048, 2176,
+	-1, -1, 2304, 2432,
+	2560, 2688, -1, -1};
+
+int16 SHORT_ARRAY_1000_024a[32] = {
+	-1, 0, 128, 256,
+	384, 512, 640, 768,
+	896, 1024, 1152, 1280,
+	1408, 1536, 1664, 1792,
+	1920, 2048, -1, 2176,
+	2304, 2432, 2560, 2688,
+	2816, 2944, 3072, 3200,
+	3328, 3456, -1, -1};
+
+int16 SHORT_ARRAY_1000_028a[32] = {
+	-1, 0, 0, 64,
+	64, 64, 64, 64,
+	64, 64, 64, 64,
+	64, 64, 64, 64,
+	64, 0, 64, 64,
+	64, -1, -1, -1,
+	-1, -1, -1, -1,
+	-1, -1, -1, -1};
+
+int16 SHORT_ARRAY_1000_02ca[32] = {
+	0, 0, 0, 0,
+	0, 0, 0, 0,
+	0, 0, 0, 0,
+	0, 64, 192, 192,
+	0, 0, 192, 64,
+	128, 256, 256, 256,
+	0, 0, 128, 64,
+	192, 0, 0, 0};
+
+int16 SHORT_ARRAY_1000_030a[32] = {
+	0, 0, 0, 0,
+	64, 0, 64, 32,
+	0, 0, 64, 32,
+	64, 96, 0, 64,
+	0, 0, 32, 96,
+	96, 32, 64, 32,
+	0, 0, 96, 96,
+	32, 32, 0, 0};
+
+int16 SHORT_ARRAY_1000_034a[32] = {
+	-1, 0, 32, 32,
+	32, 32, 32, 32,
+	32, 32, 32, 32,
+	32, 32, 32, 32,
+	32, 32, -1, 32,
+	32, 32, 32, 32,
+	32, 32, 32, 32,
+	32, 32, -1, -1};
+
+void KoFont::extractKoIndexComponents(uint32 charIdx, uint16 *param_2, uint16 *param_3, uint16 *param_4) const {
+	int uVar1;
+	int iVar2;
+	int uVar3;
+	int uVar4;
+	int uVar5;
+
+	iVar2 = (charIdx & 31) * 2;
+	uVar5 = (charIdx << 1) >> 5 & 62;
+	uVar4 = (charIdx << 1) >> 10 & 62;
+	uVar1 = SHORT_ARRAY_1000_020a[uVar5/2];
+	if (uVar1 > 0) {
+		uVar1 += SHORT_ARRAY_1000_028a[uVar4/2] + SHORT_ARRAY_1000_034a[iVar2/2] - 3;
+	}
+	uVar4 = SHORT_ARRAY_1000_01ca[uVar4/2];
+	if (uVar4 > 0) {
+		uVar4 += SHORT_ARRAY_1000_02ca[uVar5/2] + SHORT_ARRAY_1000_034a[iVar2/2];
+	}
+	uVar3 = SHORT_ARRAY_1000_024a[iVar2/2];
+	if (uVar3 > 0) {
+		uVar3 += SHORT_ARRAY_1000_030a[uVar5/2] - 3;
+	}
+	*param_2 = uVar4 >> 5;
+	*param_3 = (uVar1 >> 5) - 2;
+	*param_4 = (uVar3 >> 5) - 2;
+}
+
+void KoFont::drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const {
+	uint8 pixels[256];
+	memset(pixels, 0, 256);
+	createGlyph(pixels, chr);
+	g_engine->_screen->copyRectToSurfaceWithKey(pixels, 16, x, y, 16, 16,0xf);
+}
+
+
+
+} // namespace Darkseed
diff --git a/engines/darkseed/kofont.h b/engines/darkseed/kofont.h
new file mode 100644
index 00000000000..ed021c6696a
--- /dev/null
+++ b/engines/darkseed/kofont.h
@@ -0,0 +1,56 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef DARKSEED_KOFONT_H
+#define DARKSEED_KOFONT_H
+
+#include "graphics/font.h"
+#include "common/file.h"
+
+namespace Darkseed {
+
+class KoFont : public Graphics::Font {
+private:
+	Common::Array<Common::Array<uint8>> _fontDataSet1;
+	Common::Array<Common::Array<uint8>> _fontDataSet2;
+	Common::Array<Common::Array<uint8>> _fontDataSet3;
+
+public:
+	KoFont();
+
+	int getFontHeight() const override;
+	int getMaxCharWidth() const override;
+	int getCharWidth(uint32 chr) const override;
+	void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
+
+private:
+	void loadFontDataSet(Common::Array<Common::Array<uint8>> &dataSet, int size, Common::File &file);
+	void loadFontGlyph(Common::Array<uint8> &pixels, Common::File &file);
+
+	void createGlyph(uint8 *pixels, uint32 chr) const;
+	void addToGlyph(uint8 *destPixels, int16 index) const;
+	void addPixels(uint8 *destPixels, const Common::Array<uint8> &pixels) const;
+	void extractKoIndexComponents(uint32 charIdx, uint16 *param_2, uint16 *param_3, uint16 *param_4) const;
+};
+
+} // namespace Darkseed
+
+#endif // DARKSEED_KOFONT_H
diff --git a/engines/darkseed/module.mk b/engines/darkseed/module.mk
index 51cbd04c03f..4b5867ed53f 100644
--- a/engines/darkseed/module.mk
+++ b/engines/darkseed/module.mk
@@ -13,6 +13,7 @@ MODULE_OBJS = \
 	gamefont.o \
 	img.o \
 	inventory.o \
+	kofont.o \
 	langtext.o \
 	menu.o \
 	metaengine.o \




More information about the Scummvm-git-logs mailing list