mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-11-03 23:56:47 +00:00 
			
		
		
		
	Scale journal fonts separately from common ones
This commit is contained in:
		
							parent
							
								
									f89393fd62
								
							
						
					
					
						commit
						c9c0230d2a
					
				
					 11 changed files with 102 additions and 24 deletions
				
			
		| 
						 | 
				
			
			@ -264,18 +264,29 @@ struct TypesetBookImpl::Typesetter : BookTypesetter
 | 
			
		|||
    {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    Style * createStyle (char const * fontName, const Colour& fontColour)
 | 
			
		||||
    Style * createStyle (const std::string& fontName, const Colour& fontColour)
 | 
			
		||||
    {
 | 
			
		||||
        if (strcmp(fontName, "") == 0)
 | 
			
		||||
            return createStyle(MyGUI::FontManager::getInstance().getDefaultFont().c_str(), fontColour);
 | 
			
		||||
        const std::string templateName = "Journalbook ";
 | 
			
		||||
        std::string bookFont;
 | 
			
		||||
        if (fontName.empty())
 | 
			
		||||
        {
 | 
			
		||||
            bookFont = MyGUI::FontManager::getInstance().getDefaultFont();
 | 
			
		||||
            bookFont = templateName + bookFont;
 | 
			
		||||
            return createStyle(bookFont, fontColour);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (fontName.compare(0, templateName.size(), templateName) == 0)
 | 
			
		||||
            bookFont = fontName;
 | 
			
		||||
        else
 | 
			
		||||
            bookFont = templateName + bookFont;
 | 
			
		||||
 | 
			
		||||
        for (Styles::iterator i = mBook->mStyles.begin (); i != mBook->mStyles.end (); ++i)
 | 
			
		||||
            if (i->match (fontName, fontColour, fontColour, fontColour, 0))
 | 
			
		||||
            if (i->match (bookFont.c_str(), fontColour, fontColour, fontColour, 0))
 | 
			
		||||
                return &*i;
 | 
			
		||||
 | 
			
		||||
        MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(fontName);
 | 
			
		||||
        MyGUI::IFont* font = MyGUI::FontManager::getInstance().getByName(bookFont);
 | 
			
		||||
        if (!font)
 | 
			
		||||
            throw std::runtime_error(std::string("can't find font ") + fontName);
 | 
			
		||||
            throw std::runtime_error(std::string("can't find font ") + bookFont);
 | 
			
		||||
 | 
			
		||||
        StyleImpl & style = *mBook->mStyles.insert (mBook->mStyles.end (), StyleImpl ());
 | 
			
		||||
        style.mFont = font;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -102,7 +102,7 @@ namespace MWGui
 | 
			
		|||
        static Ptr create (int pageWidth, int pageHeight);
 | 
			
		||||
 | 
			
		||||
        /// Create a simple text style consisting of a font and a text color.
 | 
			
		||||
        virtual Style* createStyle (char const * Font, const Colour& Colour) = 0;
 | 
			
		||||
        virtual Style* createStyle (const std::string& fontName, const Colour& colour) = 0;
 | 
			
		||||
 | 
			
		||||
        /// Create a hyper-link style with a user-defined identifier based on an
 | 
			
		||||
        /// existing style. The unique flag forces a new instance of this style
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -377,7 +377,7 @@ namespace MWGui
 | 
			
		|||
            if (attr.find("face") != attr.end())
 | 
			
		||||
            {
 | 
			
		||||
                std::string face = attr.at("face");
 | 
			
		||||
                mTextStyle.mFont = face;
 | 
			
		||||
                mTextStyle.mFont = "Journalbook "+face;
 | 
			
		||||
            }
 | 
			
		||||
            if (attr.find("size") != attr.end())
 | 
			
		||||
            {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ namespace MWGui
 | 
			
		|||
        {
 | 
			
		||||
            TextStyle() :
 | 
			
		||||
                mColour(0,0,0)
 | 
			
		||||
                , mFont("Default")
 | 
			
		||||
                , mFont("")
 | 
			
		||||
                , mTextSize(16)
 | 
			
		||||
            {
 | 
			
		||||
            }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -293,47 +293,90 @@ namespace MWGui
 | 
			
		|||
 | 
			
		||||
    void WindowManager::loadFontDelegate(MyGUI::xml::ElementPtr _node, const std::string& _file, MyGUI::Version _version)
 | 
			
		||||
    {
 | 
			
		||||
        MyGUI::xml::ElementEnumerator root = _node->getElementEnumerator();
 | 
			
		||||
        while (root.next("Resource"))
 | 
			
		||||
        const std::string templateName = "Journalbook ";
 | 
			
		||||
        MyGUI::xml::ElementEnumerator font = _node->getElementEnumerator();
 | 
			
		||||
        bool createCopy = false;
 | 
			
		||||
        while (font.next("Resource"))
 | 
			
		||||
        {
 | 
			
		||||
            std::string type, name;
 | 
			
		||||
            root->findAttribute("type", type);
 | 
			
		||||
            root->findAttribute("name", name);
 | 
			
		||||
            font->findAttribute("type", type);
 | 
			
		||||
            font->findAttribute("name", name);
 | 
			
		||||
 | 
			
		||||
            if (name.empty())
 | 
			
		||||
                continue;
 | 
			
		||||
 | 
			
		||||
            if (Misc::StringUtils::ciEqual(type, "ResourceTrueTypeFont"))
 | 
			
		||||
            {
 | 
			
		||||
                createCopy = true;
 | 
			
		||||
 | 
			
		||||
                // For TrueType fonts we should override Size and Resolution properties
 | 
			
		||||
                // to allow to configure font size via config file, without need to edit XML file.
 | 
			
		||||
                // Also we should take UI scaling factor in account
 | 
			
		||||
                // to allow to configure font size via config file, without need to edit XML files.
 | 
			
		||||
                // Also we should take UI scaling factor in account.
 | 
			
		||||
                int resolution = Settings::Manager::getInt("ttf resolution", "GUI");
 | 
			
		||||
                resolution = std::min(960, std::max(48, resolution));
 | 
			
		||||
 | 
			
		||||
                float uiScale = Settings::Manager::getFloat("scaling factor", "GUI");
 | 
			
		||||
                resolution *= uiScale;
 | 
			
		||||
 | 
			
		||||
                if (uiScale > 1.0f)
 | 
			
		||||
                    resolution *= uiScale;
 | 
			
		||||
 | 
			
		||||
                MyGUI::xml::ElementPtr resolutionNode = root->createChild("Property");
 | 
			
		||||
                MyGUI::xml::ElementPtr resolutionNode = font->createChild("Property");
 | 
			
		||||
                resolutionNode->addAttribute("key", "Resolution");
 | 
			
		||||
                resolutionNode->addAttribute("value", std::to_string(resolution));
 | 
			
		||||
 | 
			
		||||
                MyGUI::xml::ElementPtr sizeNode = root->createChild("Property");
 | 
			
		||||
                MyGUI::xml::ElementPtr sizeNode = font->createChild("Property");
 | 
			
		||||
                sizeNode->addAttribute("key", "Size");
 | 
			
		||||
                sizeNode->addAttribute("value", std::to_string(mFontHeight));
 | 
			
		||||
            }
 | 
			
		||||
            else if (Misc::StringUtils::ciEqual(type, "ResourceSkin"))
 | 
			
		||||
            {
 | 
			
		||||
                // We should adjust line height for MyGUI widgets depending on font size
 | 
			
		||||
                MyGUI::xml::ElementPtr heightNode = root->createChild("Property");
 | 
			
		||||
                MyGUI::xml::ElementPtr heightNode = font->createChild("Property");
 | 
			
		||||
                heightNode->addAttribute("key", "HeightLine");
 | 
			
		||||
                heightNode->addAttribute("value", std::to_string(mFontHeight+2));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MyGUI::ResourceManager::getInstance().loadFromXmlNode(_node, _file, _version);
 | 
			
		||||
 | 
			
		||||
        if (createCopy)
 | 
			
		||||
        {
 | 
			
		||||
            MyGUI::xml::ElementPtr copy = _node->createCopy();
 | 
			
		||||
 | 
			
		||||
            MyGUI::xml::ElementEnumerator copyFont = copy->getElementEnumerator();
 | 
			
		||||
            while (copyFont.next("Resource"))
 | 
			
		||||
            {
 | 
			
		||||
                std::string type, name;
 | 
			
		||||
                copyFont->findAttribute("type", type);
 | 
			
		||||
                copyFont->findAttribute("name", name);
 | 
			
		||||
 | 
			
		||||
                if (name.empty())
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                if (Misc::StringUtils::ciEqual(type, "ResourceTrueTypeFont"))
 | 
			
		||||
                {
 | 
			
		||||
                    // Since the journal and books use the custom scaling factor depending on resolution,
 | 
			
		||||
                    // setup separate fonts with different Resolution to fit these windows.
 | 
			
		||||
                    // These fonts have an internal prefix.
 | 
			
		||||
                    int resolution = Settings::Manager::getInt("ttf resolution", "GUI");
 | 
			
		||||
                    resolution = std::min(960, std::max(48, resolution));
 | 
			
		||||
 | 
			
		||||
                    float currentX = Settings::Manager::getInt("resolution x", "Video");
 | 
			
		||||
                    float currentY = Settings::Manager::getInt("resolution y", "Video");
 | 
			
		||||
                    // TODO: read size from openmw_layout.xml
 | 
			
		||||
                    float heightScale = (currentY / 520);
 | 
			
		||||
                    float widthScale = (currentX / 600);
 | 
			
		||||
                    float uiScale = std::min(widthScale, heightScale);
 | 
			
		||||
                    resolution *= uiScale;
 | 
			
		||||
 | 
			
		||||
                    MyGUI::xml::ElementPtr resolutionNode = copyFont->createChild("Property");
 | 
			
		||||
                    resolutionNode->addAttribute("key", "Resolution");
 | 
			
		||||
                    resolutionNode->addAttribute("value", std::to_string(resolution));
 | 
			
		||||
 | 
			
		||||
                    copyFont->setAttribute("name", "Journalbook " + name);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            MyGUI::ResourceManager::getInstance().loadFromXmlNode(copy, _file, _version);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void WindowManager::initUI()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -480,6 +480,14 @@ 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);
 | 
			
		||||
 | 
			
		||||
        // Remove automatically registered fonts
 | 
			
		||||
        for (std::vector<MyGUI::ResourceManualFont*>::iterator it = mFonts.begin(); it != mFonts.end();)
 | 
			
		||||
        {
 | 
			
		||||
            if ((*it)->getResourceName() == font->getResourceName())
 | 
			
		||||
| 
						 | 
				
			
			@ -487,10 +495,17 @@ namespace Gui
 | 
			
		|||
                MyGUI::ResourceManager::getInstance().removeByName(font->getResourceName());
 | 
			
		||||
                it = mFonts.erase(it);
 | 
			
		||||
            }
 | 
			
		||||
            else if ((*it)->getResourceName() == bookFont->getResourceName())
 | 
			
		||||
            {
 | 
			
		||||
                MyGUI::ResourceManager::getInstance().removeByName(bookFont->getResourceName());
 | 
			
		||||
                it = mFonts.erase(it);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
                ++it;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        MyGUI::ResourceManager::getInstance().addResource(font);
 | 
			
		||||
        MyGUI::ResourceManager::getInstance().addResource(bookFont);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,6 +2,8 @@
 | 
			
		|||
 | 
			
		||||
#include <components/debug/debuglog.hpp>
 | 
			
		||||
 | 
			
		||||
#include <MyGUI_ResourceManager.h>
 | 
			
		||||
 | 
			
		||||
#include <osgViewer/Viewer>
 | 
			
		||||
 | 
			
		||||
#include <SDL_video.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +91,9 @@ namespace SDLUtil
 | 
			
		|||
            SDL_SetWindowSize(mWindow, width, height);
 | 
			
		||||
            SDL_SetWindowBordered(mWindow, windowBorder ? SDL_TRUE : SDL_FALSE);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // We should reload TrueType fonts for new resolution
 | 
			
		||||
        MyGUI::ResourceManager::getInstance().load("openmw_font.xml");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -31,7 +31,7 @@ ttf resolution
 | 
			
		|||
:Default:	96
 | 
			
		||||
 | 
			
		||||
Allows to specify resolution for in-game TrueType fonts.
 | 
			
		||||
Note: actual resolution depends on "scaling factor" setting value, this value is for 1.0 or lower scaling factor.
 | 
			
		||||
Note: actual resolution depends on "scaling factor" setting value, this value is for 1.0 scaling factor.
 | 
			
		||||
 | 
			
		||||
menu transparency
 | 
			
		||||
-----------------
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,11 +32,13 @@
 | 
			
		|||
            </Widget>
 | 
			
		||||
 | 
			
		||||
            <Widget type="TextBox" skin="NormalText" position="30 358 250 16" name="LeftPageNumber">
 | 
			
		||||
                <Property key="FontName" value="Journalbook Magic Cards"/>
 | 
			
		||||
                <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="TextColour" value="0 0 0"/>
 | 
			
		||||
                <Property key="TextAlign" value="Center"/>
 | 
			
		||||
                <Property key="NeedMouse" value="false"/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -25,10 +25,12 @@
 | 
			
		|||
      </Widget>
 | 
			
		||||
 | 
			
		||||
      <Widget type="TextBox" skin="NormalText" position="150 350 32 16" name="PageOneNum">
 | 
			
		||||
        <Property key="FontName" value="Journalbook Magic Cards"/>
 | 
			
		||||
        <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="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="Default"/>
 | 
			
		||||
            <Property key="FontName" value="Journalbook Magic Cards"/>
 | 
			
		||||
            <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="Default"/>
 | 
			
		||||
        <Property key="FontName" value="Journalbook Magic Cards"/>
 | 
			
		||||
        <Property key="TextAlign" value="Left VCenter"/>
 | 
			
		||||
 | 
			
		||||
        <BasisSkin type="SimpleText" offset="2 0 1 5" align="Stretch">
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue