diff --git a/apps/openmw/mwgui/formatting.cpp b/apps/openmw/mwgui/formatting.cpp index c9a9da6066..64e3847887 100644 --- a/apps/openmw/mwgui/formatting.cpp +++ b/apps/openmw/mwgui/formatting.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "../mwbase/environment.hpp" #include "../mwbase/windowmanager.hpp" @@ -367,7 +368,9 @@ namespace MWGui::Formatting if (attr.find("face") != attr.end()) { std::string face = attr.at("face"); - mTextStyle.mFont = "Journalbook "+face; + std::string name = Gui::FontLoader::getFontForFace(face); + + mTextStyle.mFont = "Journalbook "+name; } if (attr.find("size") != attr.end()) { diff --git a/apps/openmw/mwgui/formatting.hpp b/apps/openmw/mwgui/formatting.hpp index 12a3d46caa..387acd58c8 100644 --- a/apps/openmw/mwgui/formatting.hpp +++ b/apps/openmw/mwgui/formatting.hpp @@ -14,7 +14,7 @@ namespace MWGui { TextStyle() : mColour(0,0,0) - , mFont("Journalbook Magic Cards") + , mFont("Journalbook DefaultFont") , mTextSize(16) { } diff --git a/components/fontloader/fontloader.cpp b/components/fontloader/fontloader.cpp index ab4ca24eee..d7d16f0aa1 100644 --- a/components/fontloader/fontloader.cpp +++ b/components/fontloader/fontloader.cpp @@ -304,13 +304,7 @@ namespace Gui fail(*bitmapFile, bitmapFilename, "File too small to be a valid bitmap"); bitmapFile.reset(); - std::string resourceName; - if (name.size() >= 5 && Misc::StringUtils::ciEqual(name.substr(0, 5), "magic")) - resourceName = "Magic Cards"; - else if (name.size() >= 7 && Misc::StringUtils::ciEqual(name.substr(0, 7), "century")) - resourceName = "Century Gothic"; - else if (name.size() >= 7 && Misc::StringUtils::ciEqual(name.substr(0, 7), "daedric")) - resourceName = "Daedric"; + std::string resourceName = name; if (exportToFile) { @@ -346,7 +340,9 @@ namespace Gui // We need to emulate loading from XML because the data members are private as of mygui 3.2.0 MyGUI::xml::Document xmlDocument; MyGUI::xml::ElementPtr root = xmlDocument.createRoot("ResourceManualFont"); - root->addAttribute("name", resourceName); + + const std::string baseName = Misc::StringUtils::lowerCase(std::filesystem::path(mVFS->getAbsoluteFileName(fileName)).stem().string()); + root->addAttribute("name", getInternalFontName(baseName)); MyGUI::xml::ElementPtr defaultHeight = root->createChild("Property"); defaultHeight->addAttribute("key", "DefaultHeight"); @@ -506,12 +502,11 @@ namespace Gui font->deserialization(root, MyGUI::Version(3,2,0)); - // Setup "book" version of font as fallback if we will not use TrueType fonts MyGUI::ResourceManualFont* bookFont = static_cast( MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceManualFont")); mFonts.push_back(bookFont); bookFont->deserialization(root, MyGUI::Version(3,2,0)); - bookFont->setResourceName("Journalbook " + resourceName); + bookFont->setResourceName("Journalbook " + getInternalFontName(baseName)); // Remove automatically registered fonts for (std::vector::iterator it = mFonts.begin(); it != mFonts.end();) @@ -564,6 +559,8 @@ namespace Gui MyGUI::xml::ElementPtr sizeNode = resourceNode->createChild("Property"); sizeNode->addAttribute("key", "Size"); sizeNode->addAttribute("value", std::to_string(mFontHeight)); + + resourceNode->setAttribute("name", getInternalFontName(name)); } else if (Misc::StringUtils::ciEqual(type, "ResourceSkin") || Misc::StringUtils::ciEqual(type, "AutoSizedResourceSkin")) @@ -611,7 +608,7 @@ namespace Gui resolutionNode->addAttribute("key", "Resolution"); resolutionNode->addAttribute("value", std::to_string(resolution)); - copyFont->setAttribute("name", "Journalbook " + name); + copyFont->setAttribute("name", "Journalbook " + getInternalFontName(name)); } } @@ -623,4 +620,30 @@ namespace Gui { return mFontHeight; } + + std::string FontLoader::getInternalFontName(const std::string& name) + { + if (name == Settings::Manager::getString("default font", "GUI")) + return "DefaultFont"; + if (name == Settings::Manager::getString("scroll font", "GUI")) + return "ScrollFont"; + if (name == Settings::Manager::getString("mono font", "GUI")) + return "MonoFont"; + + return name; + } + + std::string FontLoader::getFontForFace(const std::string& face) + { + const std::string lowerFace = Misc::StringUtils::lowerCase(face); + + if (lowerFace == "magic cards") + return "DefaultFont"; + if (lowerFace == "daedric") + return "ScrollFont"; + if (lowerFace == "century gothic") + return "MonoFont"; + + return face; + } } diff --git a/components/fontloader/fontloader.hpp b/components/fontloader/fontloader.hpp index ee54e077a5..652f9bdf43 100644 --- a/components/fontloader/fontloader.hpp +++ b/components/fontloader/fontloader.hpp @@ -36,6 +36,8 @@ namespace Gui int getFontHeight(); + static std::string getFontForFace(const std::string& face); + private: ToUTF8::FromType mEncoding; const VFS::Manager* mVFS; @@ -46,6 +48,8 @@ namespace Gui std::vector mTextures; std::vector mFonts; + std::string getInternalFontName(const std::string& name); + /// @param exportToFile export the converted font (Image and XML with glyph metrics) to files? void loadBitmapFont (const std::string& fileName, bool exportToFile); diff --git a/files/data/fonts/DejaVuLGCSansMono.omwfont b/files/data/fonts/DejaVuLGCSansMono.omwfont index 6511877656..184c8a0d8f 100644 --- a/files/data/fonts/DejaVuLGCSansMono.omwfont +++ b/files/data/fonts/DejaVuLGCSansMono.omwfont @@ -1,6 +1,6 @@ - + diff --git a/files/data/fonts/OMWAyembedt.omwfont b/files/data/fonts/OMWAyembedt.omwfont index c8ac1c2ecb..9af8f655d8 100644 --- a/files/data/fonts/OMWAyembedt.omwfont +++ b/files/data/fonts/OMWAyembedt.omwfont @@ -1,6 +1,6 @@ - + diff --git a/files/data/fonts/Pelagiad.omwfont b/files/data/fonts/Pelagiad.omwfont index 38dc29e09d..4b01a9f308 100644 --- a/files/data/fonts/Pelagiad.omwfont +++ b/files/data/fonts/Pelagiad.omwfont @@ -1,6 +1,6 @@ - + diff --git a/files/mygui/openmw_book.layout b/files/mygui/openmw_book.layout index e6f0f858c0..c0b19783c4 100644 --- a/files/mygui/openmw_book.layout +++ b/files/mygui/openmw_book.layout @@ -32,13 +32,13 @@ - + - + diff --git a/files/mygui/openmw_journal.layout b/files/mygui/openmw_journal.layout index 3752897f97..c93fbb3329 100644 --- a/files/mygui/openmw_journal.layout +++ b/files/mygui/openmw_journal.layout @@ -25,12 +25,12 @@ - + - + diff --git a/files/mygui/openmw_journal.skin.xml b/files/mygui/openmw_journal.skin.xml index 0702d8c5eb..ddf9497f28 100644 --- a/files/mygui/openmw_journal.skin.xml +++ b/files/mygui/openmw_journal.skin.xml @@ -2,7 +2,7 @@ - + @@ -19,7 +19,7 @@ - + diff --git a/files/mygui/openmw_settings.xml b/files/mygui/openmw_settings.xml index 37d2359683..1bd0e25437 100644 --- a/files/mygui/openmw_settings.xml +++ b/files/mygui/openmw_settings.xml @@ -1,7 +1,7 @@ - + diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 2675004907..d42c093f0a 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -234,6 +234,15 @@ color topic specific = 0.45 0.5 0.8 1 # Default to grey color topic exhausted = 0.3 0.3 0.3 1 +# Font used by UI and books +default font = pelagiad + +# Font used by magic scrolls +scroll font = ayembedt + +# Font used by console and debug log +mono font = dejavusansmono + [HUD] # Displays the crosshair or reticle when not in GUI mode.