GRAPHICS: Remove obsolete genLocalizedFontFilename FontManager

This function supported loading alternative bdf fonts when we were
using 8 bits encodings for the translations. Now that we are using
unicode for all language, this is no longer needed.
This commit is contained in:
Thierry Crozat 2021-09-20 21:43:17 +01:00
parent 6043a4e40c
commit f3829243a1
3 changed files with 10 additions and 65 deletions

View file

@ -195,30 +195,4 @@ const Font *FontManager::getFontByUsage(FontUsage usage) const {
return 0; return 0;
} }
Common::String FontManager::genLocalizedFontFilename(const Common::String &filename) const {
#ifndef USE_TRANSLATION
return filename;
#else
// We will transform the font filename in the following way:
// name.bdf
// will become:
// name-charset.bdf
// Note that name should not contain any dot here!
// In the first step we look for the dot. In case there is none we will
// return the normal filename.
Common::String::const_iterator dot = Common::find(filename.begin(), filename.end(), '.');
if (dot == filename.end())
return filename;
// Put the translated font filename string back together.
Common::String result(filename.begin(), dot);
result += '-';
result += TransMan.getCurrentCharset();
result += dot;
return result;
#endif
}
} // End of namespace Graphics } // End of namespace Graphics

View file

@ -105,15 +105,6 @@ public:
*/ */
const Font *getFontByUsage(FontUsage usage) const; const Font *getFontByUsage(FontUsage usage) const;
/**
* Get the localized font for the current TranslationManager charset from the
* non localized font name
*
* @param filename the non-localized font file name.
* @return The localized font file name.
*/
Common::String genLocalizedFontFilename(const Common::String &filename) const;
//const Font *getFontBySize(int size???) const; //const Font *getFontBySize(int size???) const;
private: private:

View file

@ -544,47 +544,22 @@ bool ThemeEngine::addFont(TextData textId, const Common::String &language, const
if (file == "default") { if (file == "default") {
_texts[textId]->_fontPtr = _font; _texts[textId]->_fontPtr = _font;
} else { } else {
Common::String localized = FontMan.genLocalizedFontFilename(file); _texts[textId]->_fontPtr = loadFont(file, scalableFile, pointsize, textId == kTextDataDefault);
// Try localized fonts
_texts[textId]->_fontPtr = loadFont(localized, scalableFile, pointsize, textId == kTextDataDefault);
if (!_texts[textId]->_fontPtr) { if (!_texts[textId]->_fontPtr) {
warning("Failed to load localized font '%s'", localized.c_str()); warning("Couldn't load font '%s'/'%s'", file.c_str(), scalableFile.empty()? "(none)" : scalableFile.c_str());
// Try standard fonts
_texts[textId]->_fontPtr = loadFont(file, scalableFile, pointsize, textId == kTextDataDefault);
if (!_texts[textId]->_fontPtr) {
error("Couldn't load font '%s'/'%s'", file.c_str(), scalableFile.c_str());
#ifdef USE_TRANSLATION
TransMan.setLanguage("en");
Common::TextToSpeechManager *ttsMan;
if ((ttsMan = g_system->getTextToSpeechManager()) != nullptr)
ttsMan->setLanguage("en");
#endif // USE_TRANSLATION
// No font, cleanup TextDrawData
delete _texts[textId];
_texts[textId] = nullptr;
return false; // fall-back attempt failed
}
// Success in fall-back attempt to standard (non-localized) font.
// However, still returns false here, probably to avoid ugly / garbage glyphs side-effects
// FIXME If we return false anyway why would we attempt the fall-back in the first place?
#ifdef USE_TRANSLATION #ifdef USE_TRANSLATION
TransMan.setLanguage("en"); TransMan.setLanguage("en");
Common::TextToSpeechManager *ttsMan; Common::TextToSpeechManager *ttsMan;
if ((ttsMan = g_system->getTextToSpeechManager()) != nullptr) if ((ttsMan = g_system->getTextToSpeechManager()) != nullptr)
ttsMan->setLanguage("en"); ttsMan->setLanguage("en");
#endif // USE_TRANSLATION #endif // USE_TRANSLATION
// Returning true here, would allow falling back to standard fonts for the missing ones,
// but that leads to "garbage" glyphs being displayed on screen for non-Latin languages
// No font, cleanup TextDrawData // No font, cleanup TextDrawData
delete _texts[textId]; delete _texts[textId];
_texts[textId] = nullptr; _texts[textId] = nullptr;
return false; return false; // fall-back attempt failed
} }
} }
@ -1733,7 +1708,12 @@ const Graphics::Font *ThemeEngine::loadFont(const Common::String &filename, cons
if (!scalableFilename.empty()) if (!scalableFilename.empty())
font = loadScalableFont(scalableFilename, pointsize, fontName); font = loadScalableFont(scalableFilename, pointsize, fontName);
if (!font) // We can use non-scalable fonts, but only for English
bool allowNonScalable = true;
#ifdef USE_TRANSLATION
allowNonScalable = TransMan.currentIsBuiltinLanguage();
#endif
if (!font && allowNonScalable)
font = loadFont(filename, fontName); font = loadFont(filename, fontName);
// If the font is successfully loaded store it in the font manager. // If the font is successfully loaded store it in the font manager.