From 15e499772032ae050627e1558904f119815ec51f Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 5 Oct 2016 23:24:53 +0200 Subject: GRAPHICS: Load Face Name from BDF files Also adjust the devtools and built-in fonts accordingly. --- devtools/convbdf.cpp | 14 +++++++++++++- graphics/fonts/bdf.cpp | 30 ++++++++++++++++++++++++++++++ graphics/fonts/bdf.h | 4 ++++ graphics/fonts/consolefont.cpp | 1 + graphics/fonts/newfont.cpp | 1 + graphics/fonts/newfont_big.cpp | 1 + 6 files changed, 50 insertions(+), 1 deletion(-) diff --git a/devtools/convbdf.cpp b/devtools/convbdf.cpp index 59ea5cc4e5..c84907659d 100644 --- a/devtools/convbdf.cpp +++ b/devtools/convbdf.cpp @@ -38,6 +38,7 @@ struct BdfBoundingBox { }; struct BdfFont { + char *faceName; int maxAdvance; int height; BdfBoundingBox defaultBox; @@ -62,6 +63,7 @@ struct BdfFont { delete[] bitmaps; delete[] advances; delete[] boxes; + delete[] faceName; } }; @@ -159,6 +161,15 @@ int main(int argc, char *argv[]) { memset(font.bitmaps, 0, sizeof(unsigned char *) * font.numCharacters); font.advances = new unsigned char[font.numCharacters]; font.boxes = new BdfBoundingBox[font.numCharacters]; + } else if (hasPrefix(line, "FACE_NAME \"")) { + font.faceName = new char[line.size()]; // We will definitely fit here + strncpy(font.faceName, &line.c_str()[11], line.size() - 1); + char *p = &font.faceName[strlen(font.faceName)]; + while (p != font.faceName && *p != '"') + p--; + if (p == font.faceName) + error("Invalid FACE_NAME"); + *p = '\0'; // Remove last quote } else if (hasPrefix(line, "FONT_ASCENT ")) { if (sscanf(line.c_str(), "FONT_ASCENT %d", &font.ascent) != 1) error("Invalid FONT_ASCENT"); @@ -481,6 +492,7 @@ int main(int argc, char *argv[]) { printf("// Font structure\n" "static const BdfFontData desc = {\n" + "\"%s\", // Face name\n" "\t%d, // Max advance\n" "\t%d, // Height\n" "\t{ %d, %d, %d, %d }, // Bounding box\n" @@ -491,7 +503,7 @@ int main(int argc, char *argv[]) { "\t%d, // Characters\n" "\n" "\tbitmapTable, // Bitmaps\n", - font.maxAdvance, font.height, font.defaultBox.width, + font.faceName, font.maxAdvance, font.height, font.defaultBox.width, font.defaultBox.height, font.defaultBox.xOffset, font.defaultBox.yOffset, font.ascent, font.firstCharacter, font.defaultCharacter, font.numCharacters); diff --git a/graphics/fonts/bdf.cpp b/graphics/fonts/bdf.cpp index 3476838911..59a4ddb24f 100644 --- a/graphics/fonts/bdf.cpp +++ b/graphics/fonts/bdf.cpp @@ -41,9 +41,14 @@ BdfFont::~BdfFont() { delete[] _data.bitmaps; delete[] _data.advances; delete[] _data.boxes; + delete[] _data.faceName; } } +const char *BdfFont::getFaceName() const { + return _data.faceName; +} + int BdfFont::getFontHeight() const { return _data.height; } @@ -285,6 +290,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { memset(bitmaps, 0, sizeof(byte *) * font.numCharacters); byte *advances = new byte[font.numCharacters]; BdfBoundingBox *boxes = new BdfBoundingBox[font.numCharacters]; + char *faceName; int descent = -1; @@ -310,6 +316,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { delete[] bitmaps; delete[] advances; delete[] boxes; + delete[] faceName; return 0; } @@ -324,6 +331,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { delete[] bitmaps; delete[] advances; delete[] boxes; + delete[] faceName; return 0; } } else if (line.hasPrefix("FONT_DESCENT ")) { @@ -333,6 +341,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { delete[] bitmaps; delete[] advances; delete[] boxes; + delete[] faceName; return 0; } } else if (line.hasPrefix("DEFAULT_CHAR ")) { @@ -342,6 +351,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { delete[] bitmaps; delete[] advances; delete[] boxes; + delete[] faceName; return 0; } } else if (line.hasPrefix("STARTCHAR ")) { @@ -366,6 +376,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { delete[] bitmaps; delete[] advances; delete[] boxes; + delete[] faceName; return 0; } @@ -374,6 +385,22 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { advances[encoding] = advance; boxes[encoding] = box; } + } else if (line.hasPrefix("FACE_NAME \"")) { + faceName = new char[line.size()]; // We will definitely fit here + Common::strlcpy(faceName, &line.c_str()[11], line.size()); + char *p = &faceName[strlen(faceName)]; + while (p != faceName && *p != '"') + p--; + if (p == faceName) { + warning("BdfFont::loadFont: Invalid FACE_NAME"); + freeBitmaps(bitmaps, font.numCharacters); + delete[] bitmaps; + delete[] advances; + delete[] boxes; + delete[] faceName; + return 0; + } + *p = '\0'; // Remove last quote } else if (line == "ENDFONT") { break; } @@ -385,6 +412,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { delete[] bitmaps; delete[] advances; delete[] boxes; + delete[] faceName; return 0; } @@ -393,6 +421,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { font.bitmaps = bitmaps; font.advances = advances; font.boxes = boxes; + font.faceName = faceName; int firstCharacter = font.numCharacters; int lastCharacter = -1; @@ -425,6 +454,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) { delete[] font.bitmaps; delete[] font.advances; delete[] font.boxes; + delete[] faceName; return 0; } diff --git a/graphics/fonts/bdf.h b/graphics/fonts/bdf.h index b91834785f..4e3295ca5f 100644 --- a/graphics/fonts/bdf.h +++ b/graphics/fonts/bdf.h @@ -40,6 +40,8 @@ struct BdfBoundingBox { }; struct BdfFontData { + const char *faceName; + int maxAdvance; int height; BdfBoundingBox defaultBox; @@ -65,6 +67,8 @@ public: virtual int getCharWidth(uint32 chr) const; virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const; + const char *getFaceName() const; + static BdfFont *loadFont(Common::SeekableReadStream &stream); static bool cacheFontData(const BdfFont &font, const Common::String &filename); static BdfFont *loadFromCache(Common::SeekableReadStream &stream); diff --git a/graphics/fonts/consolefont.cpp b/graphics/fonts/consolefont.cpp index 748aa08a5c..4d66b09e80 100644 --- a/graphics/fonts/consolefont.cpp +++ b/graphics/fonts/consolefont.cpp @@ -5850,6 +5850,7 @@ const byte *const bitmapTable[] = { // Font structure static const BdfFontData desc = { + "Fixed", // Face name 5, // Max advance 8, // Height { 5, 8, 0, -1 }, // Bounding box diff --git a/graphics/fonts/newfont.cpp b/graphics/fonts/newfont.cpp index 4922e24676..af68ca03b5 100644 --- a/graphics/fonts/newfont.cpp +++ b/graphics/fonts/newfont.cpp @@ -7634,6 +7634,7 @@ const byte *const bitmapTable[] = { // Font structure static const BdfFontData desc = { + "Schumacher", // Face name 6, // Max advance 12, // Height { 6, 12, 0, -3 }, // Bounding box diff --git a/graphics/fonts/newfont_big.cpp b/graphics/fonts/newfont_big.cpp index 550d6dbfa9..3f6866ac00 100644 --- a/graphics/fonts/newfont_big.cpp +++ b/graphics/fonts/newfont_big.cpp @@ -5829,6 +5829,7 @@ static const BdfBoundingBox boxes[] = { // Font structure static const BdfFontData desc = { + "Helvetica", // Face name 13, // Max advance 14, // Height { 13, 15, -1, -3 }, // Bounding box -- cgit v1.2.3