Support for user-defined TrueType fonts

pull/541/head
Andrei Kortunov 6 years ago
parent c9c0230d2a
commit 7a986f38da

@ -516,7 +516,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
MWGui::WindowManager* window = new MWGui::WindowManager(mViewer, guiRoot, mResourceSystem.get(), mWorkQueue.get(),
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts, mFallbackMap,
Version::getOpenmwVersionDescription(mResDir.string()));
Version::getOpenmwVersionDescription(mResDir.string()), mCfgMgr.getUserConfigPath().string());
mEnvironment.setWindowManager (window);
// Create sound system

@ -290,6 +290,8 @@ namespace MWBase
/// Warning: do not use MyGUI::InputManager::setKeyFocusWidget directly. Instead use this.
virtual void setKeyFocusWidget (MyGUI::Widget* widget) = 0;
virtual void loadUserFonts() = 0;
virtual Loading::Listener* getLoadingScreen() = 0;
/// Should the cursor be visible?

@ -38,6 +38,7 @@
#include <components/translation/translation.hpp>
#include <components/myguiplatform/myguiplatform.hpp>
#include <components/myguiplatform/myguidatamanager.hpp>
#include <components/myguiplatform/myguirendermanager.hpp>
#include <components/myguiplatform/additivelayer.hpp>
#include <components/myguiplatform/scalinglayer.hpp>
@ -131,8 +132,8 @@ namespace MWGui
WindowManager::WindowManager(
osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts,
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string, std::string>& fallbackMap, const std::string& versionDescription)
const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string, std::string>& fallbackMap, const std::string& versionDescription, const std::string& userDataPath)
: mStore(NULL)
, mResourceSystem(resourceSystem)
, mWorkQueue(workQueue)
@ -210,8 +211,8 @@ namespace MWGui
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
// Load fonts
mFontLoader.reset(new Gui::FontLoader(encoding, resourceSystem->getVFS()));
mFontLoader->loadAllFonts(exportFonts);
mFontLoader.reset(new Gui::FontLoader(encoding, resourceSystem->getVFS(), userDataPath));
mFontLoader->loadBitmapFonts(exportFonts);
//Register own widgets with MyGUI
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
@ -245,6 +246,7 @@ namespace MWGui
MyGUI::FactoryManager::getInstance().registerFactory<ResourceImageSetPointerFix>("Resource", "ResourceImageSetPointer");
MyGUI::ResourceManager::getInstance().load("core.xml");
loadUserFonts();
bool keyboardNav = Settings::Manager::getBool("keyboard navigation", "GUI");
mKeyboardNavigation.reset(new KeyboardNavigation());
@ -379,6 +381,11 @@ namespace MWGui
}
}
void WindowManager::loadUserFonts()
{
mFontLoader->loadTrueTypeFonts();
}
void WindowManager::initUI()
{
// Get size info from the Gui object

@ -131,14 +131,15 @@ namespace MWGui
typedef std::vector<Faction> FactionList;
WindowManager(osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts,
Translation::Storage& translationDataStorage, ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string,std::string>& fallbackMap, const std::string& versionDescription);
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
ToUTF8::FromType encoding, bool exportFonts, const std::map<std::string,std::string>& fallbackMap, const std::string& versionDescription, const std::string& localPath);
virtual ~WindowManager();
/// Set the ESMStore to use for retrieving of GUI-related strings.
void setStore (const MWWorld::ESMStore& store);
void initUI();
virtual void loadUserFonts();
virtual Loading::Listener* getLoadingScreen();

@ -676,6 +676,9 @@ namespace MWInput
Settings::Manager::getInt("resolution y", "Video"),
Settings::Manager::getBool("fullscreen", "Video"),
Settings::Manager::getBool("window border", "Video"));
// We should reload TrueType fonts to fit new resolution
MWBase::Environment::get().getWindowManager()->loadUserFonts();
}
}

@ -145,8 +145,9 @@ namespace
namespace Gui
{
FontLoader::FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs)
FontLoader::FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs, const std::string& userDataPath)
: mVFS(vfs)
, mUserDataPath(userDataPath)
{
if (encoding == ToUTF8::WINDOWS_1252)
mEncoding = ToUTF8::CP437;
@ -175,7 +176,7 @@ namespace Gui
mFonts.clear();
}
void FontLoader::loadAllFonts(bool exportToFile)
void FontLoader::loadBitmapFonts(bool exportToFile)
{
const std::map<std::string, VFS::File*>& index = mVFS->getIndex();
@ -198,6 +199,25 @@ namespace Gui
}
}
void FontLoader::loadTrueTypeFonts()
{
osgMyGUI::DataManager* dataManager = dynamic_cast<osgMyGUI::DataManager*>(&osgMyGUI::DataManager::getInstance());
if (!dataManager)
{
Log(Debug::Error) << "Can not load TrueType fonts: osgMyGUI::DataManager is not available.";
return;
}
const std::string cfg = dataManager->getDataPath("");
const std::string fontFile = mUserDataPath + "/" + "Fonts" + "/" + "openmw_font.xml";
if (!boost::filesystem::exists(fontFile))
return;
dataManager->setResourcePath(mUserDataPath + "/" + "Fonts");
MyGUI::ResourceManager::getInstance().load("openmw_font.xml");
dataManager->setResourcePath(cfg);
}
typedef struct
{

@ -1,6 +1,9 @@
#ifndef OPENMW_COMPONENTS_FONTLOADER_H
#define OPENMW_COMPONENTS_FONTLOADER_H
#include "boost/filesystem/operations.hpp"
#include <components/myguiplatform/myguidatamanager.hpp>
#include <components/to_utf8/to_utf8.hpp>
namespace VFS
@ -23,15 +26,17 @@ namespace Gui
class FontLoader
{
public:
FontLoader (ToUTF8::FromType encoding, const VFS::Manager* vfs);
FontLoader (ToUTF8::FromType encoding, const VFS::Manager* vfs, const std::string& userDataPath);
~FontLoader();
/// @param exportToFile export the converted fonts (Images and XML with glyph metrics) to files?
void loadAllFonts (bool exportToFile);
void loadBitmapFonts (bool exportToFile);
void loadTrueTypeFonts ();
private:
ToUTF8::FromType mEncoding;
const VFS::Manager* mVFS;
std::string mUserDataPath;
std::vector<MyGUI::ITexture*> mTextures;
std::vector<MyGUI::ResourceManualFont*> mFonts;

@ -2,8 +2,6 @@
#include <components/debug/debuglog.hpp>
#include <MyGUI_ResourceManager.h>
#include <osgViewer/Viewer>
#include <SDL_video.h>
@ -91,9 +89,6 @@ 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");
}
}

Loading…
Cancel
Save