mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-30 09:45:36 +00:00
Introduce font mappings
This commit is contained in:
parent
dd04bfccfb
commit
4ddba5142e
12 changed files with 62 additions and 23 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <components/vfs/manager.hpp>
|
||||
#include <components/misc/stringops.hpp>
|
||||
#include <components/misc/resourcehelpers.hpp>
|
||||
#include <components/fontloader/fontloader.hpp>
|
||||
|
||||
#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())
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace MWGui
|
|||
{
|
||||
TextStyle() :
|
||||
mColour(0,0,0)
|
||||
, mFont("Journalbook Magic Cards")
|
||||
, mFont("Journalbook DefaultFont")
|
||||
, mTextSize(16)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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::ResourceManualFont*>(
|
||||
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<MyGUI::ResourceManualFont*>::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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<MyGUI::ITexture*> mTextures;
|
||||
std::vector<MyGUI::ResourceManualFont*> 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);
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MyGUI type="Resource" version="1.1">
|
||||
<Resource type="ResourceTrueTypeFont" name="MonoFont">
|
||||
<Resource type="ResourceTrueTypeFont" name="dejavusansmono">
|
||||
<Property key="Source" value="Fonts/DejaVuLGCSansMono.ttf"/>
|
||||
<Property key="Antialias" value="false"/>
|
||||
<Property key="TabWidth" value="8"/>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MyGUI type="Resource" version="1.1">
|
||||
<Resource type="ResourceTrueTypeFont" name="Daedric">
|
||||
<Resource type="ResourceTrueTypeFont" name="ayembedt">
|
||||
<Property key="Source" value="Fonts/OMWAyembedt.ttf"/>
|
||||
<Property key="Antialias" value="false"/>
|
||||
<Property key="TabWidth" value="8"/>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MyGUI type="Resource" version="1.1">
|
||||
<Resource type="ResourceTrueTypeFont" name="Magic Cards">
|
||||
<Resource type="ResourceTrueTypeFont" name="pelagiad">
|
||||
<Property key="Source" value="Fonts/Pelagiad.ttf"/>
|
||||
<Property key="Antialias" value="false"/>
|
||||
<Property key="TabWidth" value="8"/>
|
||||
|
|
|
@ -32,13 +32,13 @@
|
|||
</Widget>
|
||||
|
||||
<Widget type="TextBox" skin="NormalText" position="30 358 250 16" name="LeftPageNumber">
|
||||
<Property key="FontName" value="Journalbook Magic Cards"/>
|
||||
<Property key="FontName" value="Journalbook DefaultFont"/>
|
||||
<Property key="TextColour" value="0 0 0"/>
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
<Property key="NeedMouse" value="false"/>
|
||||
</Widget>
|
||||
<Widget type="TextBox" skin="NormalText" position="310 358 250 16" name="RightPageNumber">
|
||||
<Property key="FontName" value="Journalbook Magic Cards"/>
|
||||
<Property key="FontName" value="Journalbook DefaultFont"/>
|
||||
<Property key="TextColour" value="0 0 0"/>
|
||||
<Property key="TextAlign" value="Center"/>
|
||||
<Property key="NeedMouse" value="false"/>
|
||||
|
|
|
@ -25,12 +25,12 @@
|
|||
</Widget>
|
||||
|
||||
<Widget type="TextBox" skin="NormalText" position="150 350 32 16" name="PageOneNum">
|
||||
<Property key="FontName" value="Journalbook Magic Cards"/>
|
||||
<Property key="FontName" value="Journalbook DefaultFont"/>
|
||||
<Property key="TextColour" value="0 0 0"/>
|
||||
</Widget>
|
||||
|
||||
<Widget type="TextBox" skin="NormalText" position="410 350 32 16" name="PageTwoNum">
|
||||
<Property key="FontName" value="Journalbook Magic Cards"/>
|
||||
<Property key="FontName" value="Journalbook DefaultFont"/>
|
||||
<Property key="TextColour" value="0 0 0"/>
|
||||
</Widget>
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<MyGUI type="Resource" version="1.1">
|
||||
<Resource type="ResourceSkin" name="MW_BookClient" size="10 10">
|
||||
<Property key="FontName" value="Journalbook Magic Cards"/>
|
||||
<Property key="FontName" value="Journalbook DefaultFont"/>
|
||||
<Property key="TextAlign" value="Left Top"/>
|
||||
<Property key="TextColour" value="0 0 0"/>
|
||||
<BasisSkin type="EditText" offset="0 0 10 10" align="Stretch"/>
|
||||
|
@ -19,7 +19,7 @@
|
|||
</Resource>
|
||||
|
||||
<Resource type="ResourceSkin" name="MW_QuestLink" size="5 5">
|
||||
<Property key="FontName" value="Journalbook Magic Cards"/>
|
||||
<Property key="FontName" value="Journalbook DefaultFont"/>
|
||||
<Property key="TextAlign" value="Left VCenter"/>
|
||||
|
||||
<BasisSkin type="SimpleText" offset="2 0 1 5" align="Stretch">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<MyGUI>
|
||||
<MyGUI type="Font">
|
||||
<Property key="Default" value="Magic Cards"/>
|
||||
<Property key="Default" value="DefaultFont"/>
|
||||
|
||||
</MyGUI>
|
||||
<MyGUI type="Pointer">
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue