[Scummvm-git-logs] scummvm master -> 3f887155e069bc08b10c3bc897e8afe9cefea03b

bluegr noreply at scummvm.org
Tue Mar 10 20:26:56 UTC 2026


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

Summary:
2fbbffb5e0 TINSEL: Parse correct number of font characters
3f887155e0 TINSEL: Fix multibyte string parsing


Commit: 2fbbffb5e000fc1668d9a3f12aa88bb1e2fb64b6
    https://github.com/scummvm/scummvm/commit/2fbbffb5e000fc1668d9a3f12aa88bb1e2fb64b6
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2026-03-10T22:26:51+02:00

Commit Message:
TINSEL: Parse correct number of font characters

Changed paths:
    engines/tinsel/handle.cpp
    engines/tinsel/handle.h
    engines/tinsel/text.h


diff --git a/engines/tinsel/handle.cpp b/engines/tinsel/handle.cpp
index 26b00900fe6..83706c9bd35 100644
--- a/engines/tinsel/handle.cpp
+++ b/engines/tinsel/handle.cpp
@@ -38,6 +38,7 @@
 #include "tinsel/timers.h"	// for DwGetCurrentTime()
 #include "tinsel/tinsel.h"
 #include "tinsel/scene.h"
+#include "tinsel/strres.h"
 #include "tinsel/noir/lzss.h"
 
 namespace Tinsel {
@@ -314,7 +315,8 @@ void Handle::LoadFile(MEMHANDLE *pH) {
 FONT *Handle::GetFont(SCNHANDLE offset) {
 	byte *data = LockMem(offset);
 	const bool isBE = TinselV1Mac || TinselV1Saturn;
-	const uint32 size = ((TinselVersion == 3) ? 12 * 4 : 11 * 4) + 300 * 4;	// FONT struct size
+	const uint32 characterCount = GetFontCharacterCount(offset);
+	const uint32 size = ((TinselVersion == 3) ? 12 * 4 : 11 * 4) + characterCount * 4;	// FONT struct size
 	Common::MemoryReadStreamEndian *stream = new Common::MemoryReadStreamEndian(data, size, isBE);
 
 	FONT *font = new FONT();
@@ -330,7 +332,8 @@ FONT *Handle::GetFont(SCNHANDLE offset) {
 	font->fontInit.objX = stream->readSint32();
 	font->fontInit.objY = stream->readSint32();
 	font->fontInit.objZ = stream->readSint32();
-	for (int i = 0; i < 300; i++)
+	font->fontDef.resize(characterCount);
+	for (uint32 i = 0; i < characterCount; i++)
 		font->fontDef[i] = stream->readUint32();
 
 	delete stream;
@@ -338,6 +341,29 @@ FONT *Handle::GetFont(SCNHANDLE offset) {
 	return font;
 }
 
+uint32 Handle::GetFontCharacterCount(SCNHANDLE offset) const {
+	// All fonts have 256 characters, unless this is a multibyte language
+	if (!g_bMultiByte)
+		return 256;
+
+	// For multibyte languages, different platforms have different characters.
+	// There is only one font per font chunk, so we could use the font offset
+	// to read the chunk header, determine the chunk size, and calculate the
+	// character count. But since there are only three DW1 Japanese versions,
+	// for now we'll just hard-code their known values.
+	// TODO: Update this PSX number once we support its font format.
+	// Japanese PSX stores glyphs in MULTIBYT.FNT and appears to use a
+	// different font header that is larger than the normal header.
+	if (TinselV1Mac)
+		return 815;
+	if (TinselV1PSX)
+		return 667;
+	if (TinselV1Saturn)
+		return 662;
+
+	error("unknown mbs platform");
+}
+
 /**
  * Return a palette specified by a SCNHANDLE
  * Handles endianess internally
diff --git a/engines/tinsel/handle.h b/engines/tinsel/handle.h
index a59580c96f3..75b57ce0dca 100644
--- a/engines/tinsel/handle.h
+++ b/engines/tinsel/handle.h
@@ -50,6 +50,7 @@ public:
 	void SetupHandleTable();
 
 	FONT *GetFont(SCNHANDLE offset);
+	uint32 GetFontCharacterCount(SCNHANDLE offset) const;
 	PALETTE *GetPalette(SCNHANDLE offset);
 	const IMAGE *GetImage(SCNHANDLE offset);
 	void SetImagePalette(SCNHANDLE offset, SCNHANDLE palHandle);
diff --git a/engines/tinsel/text.h b/engines/tinsel/text.h
index 1b41aa8f021..e06f6fdc9e1 100644
--- a/engines/tinsel/text.h
+++ b/engines/tinsel/text.h
@@ -23,6 +23,7 @@
 #ifndef TINSEL_TEXT_H     // prevent multiple includes
 #define TINSEL_TEXT_H
 
+#include "common/array.h"
 #include "common/coroutines.h"
 #include "tinsel/object.h"	// object manager defines
 
@@ -46,8 +47,8 @@ enum {
 
 /**
  * Text font data structure.
- * @note only the pointer is used so the size of fontDef[] is not important.
- * It is currently set at 300 because it suited me for debugging.
+ * Single byte string fonts have 256 fontDef handles.
+ * Multi byte string fonts have more, depending on the version.
  */
 struct FONT {
 	int xSpacing;			///< x spacing between characters
@@ -57,7 +58,7 @@ struct FONT {
 	int spaceSize;			///< x spacing to use for a space character
 	int baseColor;			///< base color which can be replaced, specific to Tinsel 3
 	OBJ_INIT fontInit;		///< structure used to init text objects
-	SCNHANDLE fontDef[300];	///< image handle array for all characters in the font
+	Common::Array<SCNHANDLE> fontDef; ///< image handle array for all characters in the font
 };
 
 


Commit: 3f887155e069bc08b10c3bc897e8afe9cefea03b
    https://github.com/scummvm/scummvm/commit/3f887155e069bc08b10c3bc897e8afe9cefea03b
Author: sluicebox (22204938+sluicebox at users.noreply.github.com)
Date: 2026-03-10T22:26:51+02:00

Commit Message:
TINSEL: Fix multibyte string parsing

16 bit Japanese characters were truncated to 8 bits.

Changed paths:
    engines/tinsel/text.cpp


diff --git a/engines/tinsel/text.cpp b/engines/tinsel/text.cpp
index b69ef749470..f1803658bdb 100644
--- a/engines/tinsel/text.cpp
+++ b/engines/tinsel/text.cpp
@@ -41,14 +41,14 @@ static uint32 g_t3fontBaseColor;
  */
 int StringLengthPix(char *szStr, const FONT *pFont) {
 	int strLen;	// accumulated length of string
-	byte	c;
+	uint16	c;
 	SCNHANDLE	hImg;
 
 	// while not end of string or end of line
-	for (strLen = 0; (c = *szStr) != EOS_CHAR && c != LF_CHAR; szStr++) {
+	for (strLen = 0; (c = (byte)*szStr) != EOS_CHAR && c != LF_CHAR; szStr++) {
 		if (g_bMultiByte) {
 			if (c & 0x80)
-				c = ((c & ~0x80) << 8) + *++szStr;
+				c = ((c & ~0x80) << 8) | (byte)*++szStr;
 		}
 		hImg = pFont->fontDef[c];
 
@@ -116,7 +116,7 @@ OBJECT *ObjectTextOut(OBJECT **pList, char *szStr, int color,
 	int yOffset;	// offset to next line of text
 	OBJECT *pFirst;	// head of multi-object text list
 	OBJECT *pChar = 0;	// object ptr for the character
-	byte c;
+	uint16 c;
 	SCNHANDLE hImg;
 
 	// make sure there is a linked list to add text to
@@ -143,10 +143,10 @@ OBJECT *ObjectTextOut(OBJECT **pList, char *szStr, int color,
 		xJustify = JustifyText(szStr, xPos, pFont, mode);
 
 		// repeat until end of string or end of line
-		while ((c = *szStr) != EOS_CHAR && c != LF_CHAR) {
+		while ((c = (byte)*szStr) != EOS_CHAR && c != LF_CHAR) {
 			if (g_bMultiByte) {
 				if (c & 0x80)
-					c = ((c & ~0x80) << 8) + *++szStr;
+					c = ((c & ~0x80) << 8) | (byte)*++szStr;
 			}
 			hImg = pFont->fontDef[c];
 




More information about the Scummvm-git-logs mailing list