Skip to content

Commit

Permalink
GRAPHICS: Try to generate font names from slant in MacFontManager
Browse files Browse the repository at this point in the history
  • Loading branch information
sev- committed Feb 4, 2017
1 parent 91d85fe commit 1a4be95
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
34 changes: 31 additions & 3 deletions graphics/macgui/macfontmanager.cpp
Expand Up @@ -74,6 +74,17 @@ static const char *const fontNames[] = {
"New Century Schoolbook"
};

static const char *const fontStyleSuffixes[] = {
"",
"Bold",
"Italic",
"Underline",
"Outline",
"Shadow",
"Condense",
"Extend"
};

MacFontManager::MacFontManager() {
for (uint i = 0; i < ARRAYSIZE(fontNames); i++)
if (fontNames[i])
Expand Down Expand Up @@ -244,8 +255,14 @@ const Font *MacFontManager::getFont(MacFont macFont) {
if (macFont.getName().empty())
macFont.setName(getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant()));

if (!_fontRegistry.contains(macFont.getName()))
generateFontSubstitute(macFont);
if (!_fontRegistry.contains(macFont.getName())) {
// Let's try to generate name
if (macFont.getSlant() != kMacFontRegular)
macFont.setName(getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant(), true));

if (!_fontRegistry.contains(macFont.getName()))
generateFontSubstitute(macFont);
}

font = FontMan.getFontByName(macFont.getName());

Expand Down Expand Up @@ -286,7 +303,7 @@ void MacFontManager::clearFontMapping() {
_extraFontIds.clear();
}

const char *MacFontManager::getFontName(int id, int size, int slant) {
const char *MacFontManager::getFontName(int id, int size, int slant, bool tryGen) {
static char name[128];
Common::String n;

Expand All @@ -299,6 +316,17 @@ const char *MacFontManager::getFontName(int id, int size, int slant) {
n = fontNames[0]; // Fallback to Chicago
}

if (tryGen && slant != kMacFontRegular) {
for (int i = 0; i < 7; i++) {
if (slant & (1 << i)) {
n += ' ';
n += fontStyleSuffixes[i + 1];
}
}

slant = 0;
}

snprintf(name, 128, "%s-%d-%d", n.c_str(), slant, size);

return name;
Expand Down
2 changes: 1 addition & 1 deletion graphics/macgui/macfontmanager.h
Expand Up @@ -123,7 +123,7 @@ class MacFontManager {
* @param size size of the font
* @return the font name or NULL if ID goes beyond the mapping
*/
const char *getFontName(int id, int size, int slant = kMacFontRegular);
const char *getFontName(int id, int size, int slant = kMacFontRegular, bool tryGen = false);
const char *getFontName(MacFont &font);
int getFontIdByName(Common::String name);

Expand Down

0 comments on commit 1a4be95

Please sign in to comment.