diff options
author | craigsc | 2020-01-11 12:08:21 -0800 |
---|---|---|
committer | craigsc | 2020-01-11 12:08:21 -0800 |
commit | 3dd4fb16f017a8eab5c6c11fd119a397b457866e (patch) | |
tree | 5b80b5c5038d8577c2d674a5a4742b335deca515 /graphics/macgui/macfontmanager.cpp | |
parent | f9f81ea9baecb714f26cf1c17a1b0ae58431467b (diff) | |
parent | 5893672b80f00fced33c42e63471d68ba47d7dd4 (diff) | |
download | scummvm-rg350-3dd4fb16f017a8eab5c6c11fd119a397b457866e.tar.gz scummvm-rg350-3dd4fb16f017a8eab5c6c11fd119a397b457866e.tar.bz2 scummvm-rg350-3dd4fb16f017a8eab5c6c11fd119a397b457866e.zip |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'graphics/macgui/macfontmanager.cpp')
-rw-r--r-- | graphics/macgui/macfontmanager.cpp | 51 |
1 files changed, 38 insertions, 13 deletions
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp index e8e3d4314b..ff940384c4 100644 --- a/graphics/macgui/macfontmanager.cpp +++ b/graphics/macgui/macfontmanager.cpp @@ -405,42 +405,67 @@ void MacFontManager::generateFontSubstitute(MacFont &macFont) { // No simple substitute was found. Looking for neighborhood fonts // First we gather all font sizes for this font - Common::Array<int> sizes; + Common::Array<MacFont *> sizes; for (Common::HashMap<Common::String, MacFont *>::iterator i = _fontRegistry.begin(); i != _fontRegistry.end(); ++i) { if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == macFont.getSlant() && !i->_value->isGenerated()) - sizes.push_back(i->_value->getSize()); + sizes.push_back(i->_value); } if (sizes.empty()) { - debug(1, "No viable substitute found for font %s", getFontName(macFont).c_str()); - return; + if (macFont.getSlant() == kMacFontRegular) { + debug(1, "No viable substitute found for font %s", getFontName(macFont).c_str()); + return; + } + + // Now let's try to find a regular font + for (Common::HashMap<Common::String, MacFont *>::iterator i = _fontRegistry.begin(); i != _fontRegistry.end(); ++i) { + if (i->_value->getId() == macFont.getId() && i->_value->getSlant() == kMacFontRegular && !i->_value->isGenerated()) + sizes.push_back(i->_value); + } + + if (sizes.empty()) { + debug(1, "No viable substitute found for font %s", getFontName(macFont).c_str()); + return; + } } - // Now looking next larger font, and store the largest one for next check - int candidate = 1000; - int maxSize = sizes[0]; + // Now looking for the next larger font, and store the largest one for next check + MacFont *candidate = nullptr; + MacFont *maxSize = sizes[0]; for (uint i = 0; i < sizes.size(); i++) { - if (sizes[i] > macFont.getSize() && sizes[i] < candidate) + if (sizes[i]->getSize() == macFont.getSize()) { // Same size but regular slant + candidate = sizes[i]; + break; + } + + if (sizes[i]->getSize() > macFont.getSize() && candidate && sizes[i]->getSize() < candidate->getSize()) candidate = sizes[i]; - if (sizes[i] > maxSize) + if (sizes[i]->getSize() > maxSize->getSize()) maxSize = sizes[i]; } - if (candidate != 1000) { - generateFont(macFont, *_fontRegistry[getFontName(macFont.getId(), candidate, macFont.getSlant())]); + if (candidate) { + generateFont(macFont, *candidate); return; } // Now next smaller font, which is the biggest we have - generateFont(macFont, *_fontRegistry[getFontName(macFont.getId(), maxSize, macFont.getSlant())]); + generateFont(macFont, *maxSize); } void MacFontManager::generateFont(MacFont &toFont, MacFont &fromFont) { debugN("Found font substitute for font '%s' ", getFontName(toFont).c_str()); debug("as '%s'", getFontName(fromFont).c_str()); - MacFONTFont *font = Graphics::MacFONTFont::scaleFont(fromFont.getFont(), toFont.getSize()); + bool bold = false, italic = false; + + if (fromFont.getSlant() == kMacFontRegular) { + bold = toFont.getSlant() == kMacFontBold; + italic = toFont.getSlant() == kMacFontItalic; + } + + MacFONTFont *font = Graphics::MacFONTFont::scaleFont(fromFont.getFont(), toFont.getSize(), bold, italic); if (!font) { warning("Failed to generate font '%s'", getFontName(toFont).c_str()); |