Skip to content

Commit

Permalink
GRAPHICS: Use Family name instead of font name when reading from BDF …
Browse files Browse the repository at this point in the history
…fonts
  • Loading branch information
sev- committed Oct 6, 2016
1 parent 07316af commit 0d4d545
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions devtools/convbdf.cpp
Expand Up @@ -38,7 +38,7 @@ struct BdfBoundingBox {
};

struct BdfFont {
char *faceName;
char *familyName;
int maxAdvance;
int height;
BdfBoundingBox defaultBox;
Expand All @@ -63,7 +63,7 @@ struct BdfFont {
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
}
};

Expand Down Expand Up @@ -162,12 +162,12 @@ int main(int argc, char *argv[]) {
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 != '"')
font.familyName = new char[line.size()]; // We will definitely fit here
strncpy(font.familyName, &line.c_str()[11], line.size() - 1);
char *p = &font.familyName[strlen(font.familyName)];
while (p != font.familyName && *p != '"')
p--;
if (p == font.faceName)
if (p == font.familyName)
error("Invalid FACE_NAME");
*p = '\0'; // Remove last quote
} else if (hasPrefix(line, "FONT_ASCENT ")) {
Expand Down Expand Up @@ -503,7 +503,7 @@ int main(int argc, char *argv[]) {
"\t%d, // Characters\n"
"\n"
"\tbitmapTable, // Bitmaps\n",
font.faceName, font.maxAdvance, font.height, font.defaultBox.width,
font.familyName, font.maxAdvance, font.height, font.defaultBox.width,
font.defaultBox.height, font.defaultBox.xOffset, font.defaultBox.yOffset,
font.ascent, font.firstCharacter, font.defaultCharacter, font.numCharacters);

Expand Down
40 changes: 20 additions & 20 deletions graphics/fonts/bdf.cpp
Expand Up @@ -41,12 +41,12 @@ BdfFont::~BdfFont() {
delete[] _data.bitmaps;
delete[] _data.advances;
delete[] _data.boxes;
delete[] _data.faceName;
delete[] _data.familyName;
}
}

const char *BdfFont::getFaceName() const {
return _data.faceName;
const char *BdfFont::getFamilyName() const {
return _data.familyName;
}

int BdfFont::getFontHeight() const {
Expand Down Expand Up @@ -290,7 +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;
char *familyName;

int descent = -1;

Expand All @@ -316,7 +316,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
return 0;
}

Expand All @@ -331,7 +331,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
return 0;
}
} else if (line.hasPrefix("FONT_DESCENT ")) {
Expand All @@ -341,7 +341,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
return 0;
}
} else if (line.hasPrefix("DEFAULT_CHAR ")) {
Expand All @@ -351,7 +351,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
return 0;
}
} else if (line.hasPrefix("STARTCHAR ")) {
Expand All @@ -376,7 +376,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
return 0;
}

Expand All @@ -385,19 +385,19 @@ 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 != '"')
} else if (line.hasPrefix("FAMILY_NAME \"")) {
familyName = new char[line.size()]; // We will definitely fit here
Common::strlcpy(familyName, &line.c_str()[11], line.size());
char *p = &familyName[strlen(familyName)];
while (p != familyName && *p != '"')
p--;
if (p == faceName) {
warning("BdfFont::loadFont: Invalid FACE_NAME");
if (p == familyName) {
warning("BdfFont::loadFont: Invalid FAMILY_NAME");
freeBitmaps(bitmaps, font.numCharacters);
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
return 0;
}
*p = '\0'; // Remove last quote
Expand All @@ -412,7 +412,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
delete[] bitmaps;
delete[] advances;
delete[] boxes;
delete[] faceName;
delete[] familyName;
return 0;
}

Expand All @@ -421,7 +421,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
font.bitmaps = bitmaps;
font.advances = advances;
font.boxes = boxes;
font.faceName = faceName;
font.familyName = familyName;

int firstCharacter = font.numCharacters;
int lastCharacter = -1;
Expand Down Expand Up @@ -454,7 +454,7 @@ BdfFont *BdfFont::loadFont(Common::SeekableReadStream &stream) {
delete[] font.bitmaps;
delete[] font.advances;
delete[] font.boxes;
delete[] faceName;
delete[] familyName;
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions graphics/fonts/bdf.h
Expand Up @@ -40,7 +40,7 @@ struct BdfBoundingBox {
};

struct BdfFontData {
const char *faceName;
const char *familyName;

int maxAdvance;
int height;
Expand All @@ -67,7 +67,7 @@ class BdfFont : public Font {
virtual int getCharWidth(uint32 chr) const;
virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const;

const char *getFaceName() const;
const char *getFamilyName() const;

static BdfFont *loadFont(Common::SeekableReadStream &stream);
static bool cacheFontData(const BdfFont &font, const Common::String &filename);
Expand Down
4 changes: 2 additions & 2 deletions graphics/macgui/macwindowmanager.cpp
Expand Up @@ -348,8 +348,8 @@ void MacWindowManager::loadFonts() {
delete stream;

Common::String fontName;
if (font->getFaceName() && *font->getFaceName()) {
fontName = font->getFaceName();
if (font->getFamilyName() && *font->getFamilyName()) {
fontName = font->getFamilyName();
} else { // Get it from the file name
fontName = (*it)->getName();

Expand Down

0 comments on commit 0d4d545

Please sign in to comment.