[Scummvm-cvs-logs] scummvm-tools master -> f423d95f9d584d85d6e1dc63168cd545d0c9e5b2

lordhoto lordhoto at gmail.com
Fri Jul 1 05:45:23 CEST 2011


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

Summary:
9d591ca90c TOOLS: Prepare create_sjisfnt for PCE font generation.
f423d95f9d TOOLS: Create 12x12 KANJI chars for PCE in create_sjisfnt.


Commit: 9d591ca90cc71ab7508522a138605394bfaf2ea7
    https://github.com/scummvm/scummvm-tools/commit/9d591ca90cc71ab7508522a138605394bfaf2ea7
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-06-30T18:50:15-07:00

Commit Message:
TOOLS: Prepare create_sjisfnt for PCE font generation.

Changed paths:
    create_sjisfnt.cpp
    create_sjisfnt.h



diff --git a/create_sjisfnt.cpp b/create_sjisfnt.cpp
index 635e70a..01383b5 100644
--- a/create_sjisfnt.cpp
+++ b/create_sjisfnt.cpp
@@ -52,64 +52,35 @@ int main(int argc, char *argv[]) {
 	atexit(deinitSJIStoUTF32Conversion);
 
 	TrueTypeFont *ttf = new TrueTypeFont();
-	if (!ttf->load(font, 16)) {
+	if (!ttf->load(font)) {
 		delete ttf;
 		error("Could not initialize FreeType library.");
 		return -1;
 	}
 
+	if (!ttf->setSize(16)) {
+		delete ttf;
+		error("Could not setup font '%s' to size 16", font);
+		return -1;
+	}
+
 	GlyphList glyphs;
 	int chars8x16 = 0;
 	int chars16x16 = 0;
 
-	for (uint8 fB = 0x00; fB <= 0xDF; ++fB) {
-		if (mapASCIItoChunk(fB) == -1)
-			continue;
-
-		++chars8x16;
-
-		Glyph data;
-		if (ttf->renderGlyph(fB, 0, data))
-			glyphs.push_back(data);
-	}
-
-	for (uint8 fB = 0x81; fB <= 0xEF; ++fB) {
-		if (mapSJIStoChunk(fB, 0x40) == -1)
-			continue;
-
-		for (uint8 sB = 0x40; sB <= 0xFC; ++sB) {
-			if (mapSJIStoChunk(fB, sB) == -1)
-				continue;
-
-			++chars16x16;
-
-			Glyph data;
-			if (ttf->renderGlyph(fB, sB, data))
-				glyphs.push_back(data);
-		}
-	}
+	ttf->renderASCIIGlyphs(glyphs, chars8x16);
+	ttf->renderKANJIGlyphs(glyphs, chars16x16);
 
 	delete ttf;
 	ttf = 0;
 
-	// We try to find the minimum y offset here so we can substract it to make it 0 in the end.
-	// We need to do this, since otherwise the characters will take up too much vertical space.
-	int minYOffset = 16;
-	for (GlyphList::const_iterator i = glyphs.begin(); i != glyphs.end(); ++i) {
-		if (i->pitch == 0)
-			continue;
-
-		minYOffset = std::min(minYOffset, i->yOffset);
-	}
+	fixYOffset(glyphs);
 
 	// Check whether we have an character which does not fit within the boundaries6
-	for (GlyphList::iterator i = glyphs.begin(); i != glyphs.end(); ++i) {
+	for (GlyphList::const_iterator i = glyphs.begin(); i != glyphs.end(); ++i) {
 		if (i->pitch == 0)
 			continue;
 
-		// Substract our minimum y offset
-		i->yOffset -= minYOffset;
-
 		if ((isASCII(i->fB) && !i->checkSize(8, 16)) ||
 			(!isASCII(i->fB) && !i->checkSize(16, 16))) {
 			for (GlyphList::iterator j = glyphs.begin(); j != glyphs.end(); ++j)
@@ -292,7 +263,7 @@ inline int ftCeil26_6(FT_Pos x) {
 	return (x + 63) / 64;
 }
 
-bool TrueTypeFont::load(const char *font, int height) {
+bool TrueTypeFont::load(const char *font) {
 	FT_Error err = FT_Init_FreeType(&_library);
 	if (err) {
 		warning("Could not initialize FreeType2 library.");
@@ -316,8 +287,11 @@ bool TrueTypeFont::load(const char *font, int height) {
 		return false;
 	}
 
-	err = FT_Set_Char_Size(_sjisFont, 0, height * 64, 0, 0);
-	if (err) {
+	return true;
+}
+
+bool TrueTypeFont::setSize(int height) {
+	if (FT_Set_Char_Size(_sjisFont, 0, height * 64, 0, 0)) {
 		warning("Could not initialize font for height %d", height);
 		return false;
 	}
@@ -332,6 +306,41 @@ bool TrueTypeFont::load(const char *font, int height) {
 	return true;
 }
 
+void TrueTypeFont::renderASCIIGlyphs(GlyphList &glyphs, int &count) {
+	count = 0;
+
+	for (uint8 fB = 0x00; fB <= 0xDF; ++fB) {
+		if (mapASCIItoChunk(fB) == -1)
+			continue;
+
+		++count;
+
+		Glyph data;
+		if (renderGlyph(fB, 0, data))
+			glyphs.push_back(data);
+	}
+}
+
+void TrueTypeFont::renderKANJIGlyphs(GlyphList &glyphs, int &count) {
+	count = 0;
+
+	for (uint8 fB = 0x81; fB <= 0xEF; ++fB) {
+		if (mapSJIStoChunk(fB, 0x40) == -1)
+			continue;
+
+		for (uint8 sB = 0x40; sB <= 0xFC; ++sB) {
+			if (mapSJIStoChunk(fB, sB) == -1)
+				continue;
+
+			++count;
+
+			Glyph data;
+			if (renderGlyph(fB, sB, data))
+				glyphs.push_back(data);
+		}
+	}
+}
+
 bool TrueTypeFont::renderGlyph(uint8 fB, uint8 sB, Glyph &glyph) {
 	uint32 utf32 = convertSJIStoUTF32(fB, sB);
 	if (utf32 == (uint32)-1) {
@@ -386,6 +395,10 @@ bool TrueTypeFont::renderGlyph(uint32 unicode, Glyph &glyph) {
 	glyph.pitch = bitmap.pitch;
 	glyph.plainData = 0;
 
+	// We only accept monochrome characters.
+	if (bitmap.pixel_mode != FT_PIXEL_MODE_MONO)
+		return false;
+
 	if (glyph.height) {
 		glyph.plainData = new uint8[glyph.height * abs(glyph.pitch)];
 		if (!glyph.plainData)
@@ -503,3 +516,24 @@ void Glyph::convertChar16x16(uint8 *dst) const {
 	}
 }
 
+void fixYOffset(GlyphList &glyphs) {
+	// We try to find the minimum y offset here so we can substract it to make it 0 in the end.
+	// We need to do this, since otherwise the characters will take up too much vertical space.
+	int minYOffset = 0xFFFF;
+
+	for (GlyphList::const_iterator i = glyphs.begin(), end = glyphs.end(); i != end; ++i) {
+		if (i->pitch == 0)
+			continue;
+
+		minYOffset = std::min(minYOffset, i->yOffset);
+	}
+
+	// Adapt all glyphs
+	for (GlyphList::iterator i = glyphs.begin(), end = glyphs.end(); i != end; ++i) {
+		if (i->pitch == 0)
+			continue;
+
+		i->yOffset -= minYOffset;
+	}
+}
+
diff --git a/create_sjisfnt.h b/create_sjisfnt.h
index 44088ec..86d2418 100644
--- a/create_sjisfnt.h
+++ b/create_sjisfnt.h
@@ -64,15 +64,21 @@ struct Glyph {
 };
 
 typedef std::list<Glyph> GlyphList;
+void fixYOffset(GlyphList &glyphs);
 
 class TrueTypeFont {
 public:
 	TrueTypeFont();
 	~TrueTypeFont();
 
-	bool load(const char *filename, int height);
-	bool renderGlyph(uint8 fb, uint8 sB, Glyph &glyph);
+	bool load(const char *filename);
+	bool setSize(int height);
+
+	void renderASCIIGlyphs(GlyphList &glyphs, int &count);
+	void renderKANJIGlyphs(GlyphList &glyphs, int &count);
+
 private:
+	bool renderGlyph(uint8 fb, uint8 sB, Glyph &glyph);
 	bool renderGlyph(uint32 unicode, Glyph &glyph);
 
 	FT_Library _library;


Commit: f423d95f9d584d85d6e1dc63168cd545d0c9e5b2
    https://github.com/scummvm/scummvm-tools/commit/f423d95f9d584d85d6e1dc63168cd545d0c9e5b2
Author: Johannes Schickel (lordhoto at scummvm.org)
Date: 2011-06-30T19:16:49-07:00

Commit Message:
TOOLS: Create 12x12 KANJI chars for PCE in create_sjisfnt.

Changed paths:
    create_sjisfnt.cpp



diff --git a/create_sjisfnt.cpp b/create_sjisfnt.cpp
index 01383b5..9ae73b2 100644
--- a/create_sjisfnt.cpp
+++ b/create_sjisfnt.cpp
@@ -71,27 +71,47 @@ int main(int argc, char *argv[]) {
 	ttf->renderASCIIGlyphs(glyphs, chars8x16);
 	ttf->renderKANJIGlyphs(glyphs, chars16x16);
 
+	if (!ttf->setSize(12)) {
+		delete ttf;
+		error("Could not setup font '%s' to size 12", font);
+		return -1;
+	}
+
+	GlyphList pceGlyphs;
+	int chars12x12 = 0;
+	ttf->renderKANJIGlyphs(pceGlyphs, chars12x12);
+
 	delete ttf;
 	ttf = 0;
 
 	fixYOffset(glyphs);
+	fixYOffset(pceGlyphs);
 
-	// Check whether we have an character which does not fit within the boundaries6
+	// Check whether we have a character which does not fit within the boundaries
 	for (GlyphList::const_iterator i = glyphs.begin(); i != glyphs.end(); ++i) {
 		if (i->pitch == 0)
 			continue;
 
 		if ((isASCII(i->fB) && !i->checkSize(8, 16)) ||
 			(!isASCII(i->fB) && !i->checkSize(16, 16))) {
-			for (GlyphList::iterator j = glyphs.begin(); j != glyphs.end(); ++j)
-				delete[] j->plainData;
-
 			error("Could not fit glyph for %.2X %.2X top: %d bottom: %d, left: %d right: %d, xOffset: %d, yOffset: %d, width: %d, height: %d",
 				   i->fB, i->sB, i->yOffset, i->yOffset + i->height, i->xOffset, i->xOffset + i->width,
 				   i->xOffset, i->yOffset, i->width, i->height);
 		}
 	}
 
+	// Check whether we have a character which does not fit within the boundaries
+	for (GlyphList::const_iterator i = pceGlyphs.begin(); i != pceGlyphs.end(); ++i) {
+		if (i->pitch == 0)
+			continue;
+
+		if (!isASCII(i->fB) && !i->checkSize(12, 12)) {
+			error("Could not fit pce glyph for %.2X %.2X top: %d bottom: %d, left: %d right: %d, xOffset: %d, yOffset: %d, width: %d, height: %d",
+				   i->fB, i->sB, i->yOffset, i->yOffset + i->height, i->xOffset, i->xOffset + i->width,
+				   i->xOffset, i->yOffset, i->width, i->height);
+		}
+	}
+
 	const int sjis8x16DataSize = chars8x16 * 16;
 	uint8 *sjis8x16FontData = new uint8[sjis8x16DataSize];
 
@@ -106,8 +126,18 @@ int main(int argc, char *argv[]) {
 		error("Out of memory");
 	}
 
+	const int sjis12x12DataSize = chars12x12 * 24;
+	uint8 *sjis12x12FontData = new uint8[sjis16x16DataSize];
+
+	if (!sjis12x12FontData) {
+		delete[] sjis8x16FontData;
+		delete[] sjis16x16FontData;
+		error("Out of memory");
+	}
+
 	memset(sjis8x16FontData, 0, sjis8x16DataSize);
 	memset(sjis16x16FontData, 0, sjis16x16DataSize);
+	memset(sjis12x12FontData, 0, sjis12x12DataSize);
 
 	for (GlyphList::const_iterator i = glyphs.begin(); i != glyphs.end(); ++i) {
 		if (isASCII(i->fB)) {
@@ -123,6 +153,13 @@ int main(int argc, char *argv[]) {
 		}
 	}
 
+	for (GlyphList::const_iterator i = pceGlyphs.begin(), end = pceGlyphs.end(); i != end; ++i) {
+		int chunk = mapSJIStoChunk(i->fB, i->sB);
+
+		if (chunk != -1)
+			i->convertChar16x16(sjis12x12FontData + chunk * 24);
+	}
+
 	Common::File sjisFont(out, "wb");
 	if (sjisFont.isOpen()) {
 		// Write our magic bytes
@@ -130,23 +167,27 @@ int main(int argc, char *argv[]) {
 		sjisFont.writeUint32BE(MKID_BE('SJIS'));
 
 		// Write version
-		sjisFont.writeUint32BE(0x00000002);
+		sjisFont.writeUint32BE(0x00000003);
 
 		// Write character count
 		sjisFont.writeUint16BE(chars16x16);
 		sjisFont.writeUint16BE(chars8x16);
+		sjisFont.writeUint16BE(chars12x12);
 
 		sjisFont.write(sjis16x16FontData, sjis16x16DataSize);
 		sjisFont.write(sjis8x16FontData, sjis8x16DataSize);
+		sjisFont.write(sjis12x12FontData, sjis12x12DataSize);
 
 		delete[] sjis8x16FontData;
 		delete[] sjis16x16FontData;
+		delete[] sjis12x12FontData;
 
 		if (sjisFont.err())
 			error("Error while writing to font file: '%s'", out);
 	} else {
 		delete[] sjis8x16FontData;
 		delete[] sjis16x16FontData;
+		delete[] sjis12x12FontData;
 		error("Could not open file '%s' for writing", out);
 	}
 






More information about the Scummvm-git-logs mailing list