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. --- graphics/fonts/bdf.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'graphics/fonts/bdf.cpp') 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; } -- cgit v1.2.3