mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-28 21:07:59 +03:00
Restore --export-fonts option functionality
This commit is contained in:
parent
a6676fd6f3
commit
dc3264a3a5
8 changed files with 44 additions and 7 deletions
|
@ -373,6 +373,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
|
||||||
, mScriptConsoleMode(false)
|
, mScriptConsoleMode(false)
|
||||||
, mActivationDistanceOverride(-1)
|
, mActivationDistanceOverride(-1)
|
||||||
, mGrab(true)
|
, mGrab(true)
|
||||||
|
, mExportFonts(false)
|
||||||
, mRandomSeed(0)
|
, mRandomSeed(0)
|
||||||
, mNewGame(false)
|
, mNewGame(false)
|
||||||
, mCfgMgr(configurationManager)
|
, mCfgMgr(configurationManager)
|
||||||
|
@ -807,7 +808,7 @@ void OMW::Engine::prepareEngine()
|
||||||
rootNode->addChild(guiRoot);
|
rootNode->addChild(guiRoot);
|
||||||
|
|
||||||
mWindowManager = std::make_unique<MWGui::WindowManager>(mWindow, mViewer, guiRoot, mResourceSystem.get(),
|
mWindowManager = std::make_unique<MWGui::WindowManager>(mWindow, mViewer, guiRoot, mResourceSystem.get(),
|
||||||
mWorkQueue.get(), mCfgMgr.getLogPath(), mScriptConsoleMode, mTranslationDataStorage, mEncoding,
|
mWorkQueue.get(), mCfgMgr.getLogPath(), mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts,
|
||||||
Version::getOpenmwVersionDescription(), shadersSupported, mCfgMgr);
|
Version::getOpenmwVersionDescription(), shadersSupported, mCfgMgr);
|
||||||
mEnvironment.setWindowManager(*mWindowManager);
|
mEnvironment.setWindowManager(*mWindowManager);
|
||||||
|
|
||||||
|
@ -1109,6 +1110,11 @@ void OMW::Engine::setWarningsMode(int mode)
|
||||||
mWarningsMode = mode;
|
mWarningsMode = mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OMW::Engine::enableFontExport(bool exportFonts)
|
||||||
|
{
|
||||||
|
mExportFonts = exportFonts;
|
||||||
|
}
|
||||||
|
|
||||||
void OMW::Engine::setSaveGameFile(const std::filesystem::path& savegame)
|
void OMW::Engine::setSaveGameFile(const std::filesystem::path& savegame)
|
||||||
{
|
{
|
||||||
mSaveGameFile = savegame;
|
mSaveGameFile = savegame;
|
||||||
|
|
|
@ -171,6 +171,7 @@ namespace OMW
|
||||||
// Grab mouse?
|
// Grab mouse?
|
||||||
bool mGrab;
|
bool mGrab;
|
||||||
|
|
||||||
|
bool mExportFonts;
|
||||||
unsigned int mRandomSeed;
|
unsigned int mRandomSeed;
|
||||||
|
|
||||||
Compiler::Extensions mExtensions;
|
Compiler::Extensions mExtensions;
|
||||||
|
@ -251,6 +252,8 @@ namespace OMW
|
||||||
|
|
||||||
void setWarningsMode(int mode);
|
void setWarningsMode(int mode);
|
||||||
|
|
||||||
|
void enableFontExport(bool exportFonts);
|
||||||
|
|
||||||
/// Set the save game file to load after initialising the engine.
|
/// Set the save game file to load after initialising the engine.
|
||||||
void setSaveGameFile(const std::filesystem::path& savegame);
|
void setSaveGameFile(const std::filesystem::path& savegame);
|
||||||
|
|
||||||
|
|
|
@ -155,6 +155,7 @@ bool parseOptions(int argc, char** argv, OMW::Engine& engine, Files::Configurati
|
||||||
Fallback::Map::init(variables["fallback"].as<FallbackMap>().mMap);
|
Fallback::Map::init(variables["fallback"].as<FallbackMap>().mMap);
|
||||||
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
||||||
engine.setActivationDistanceOverride(variables["activate-dist"].as<int>());
|
engine.setActivationDistanceOverride(variables["activate-dist"].as<int>());
|
||||||
|
engine.enableFontExport(variables["export-fonts"].as<bool>());
|
||||||
engine.setRandomSeed(variables["random-seed"].as<unsigned int>());
|
engine.setRandomSeed(variables["random-seed"].as<unsigned int>());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -146,7 +146,7 @@ namespace MWGui
|
||||||
WindowManager::WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot,
|
WindowManager::WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot,
|
||||||
Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue, const std::filesystem::path& logpath,
|
Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue, const std::filesystem::path& logpath,
|
||||||
bool consoleOnlyScripts, Translation::Storage& translationDataStorage, ToUTF8::FromType encoding,
|
bool consoleOnlyScripts, Translation::Storage& translationDataStorage, ToUTF8::FromType encoding,
|
||||||
const std::string& versionDescription, bool useShaders, Files::ConfigurationManager& cfgMgr)
|
bool exportFonts, const std::string& versionDescription, bool useShaders, Files::ConfigurationManager& cfgMgr)
|
||||||
: mOldUpdateMask(0)
|
: mOldUpdateMask(0)
|
||||||
, mOldCullMask(0)
|
, mOldCullMask(0)
|
||||||
, mStore(nullptr)
|
, mStore(nullptr)
|
||||||
|
@ -215,7 +215,8 @@ namespace MWGui
|
||||||
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
|
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
|
||||||
|
|
||||||
// Load fonts
|
// Load fonts
|
||||||
mFontLoader = std::make_unique<Gui::FontLoader>(encoding, resourceSystem->getVFS(), mScalingFactor);
|
mFontLoader
|
||||||
|
= std::make_unique<Gui::FontLoader>(encoding, resourceSystem->getVFS(), mScalingFactor, exportFonts);
|
||||||
|
|
||||||
// Register own widgets with MyGUI
|
// Register own widgets with MyGUI
|
||||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
|
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
|
||||||
|
|
|
@ -128,7 +128,7 @@ namespace MWGui
|
||||||
WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot,
|
WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot,
|
||||||
Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
||||||
const std::filesystem::path& logpath, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
|
const std::filesystem::path& logpath, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
|
||||||
ToUTF8::FromType encoding, const std::string& versionDescription, bool useShaders,
|
ToUTF8::FromType encoding, bool exportFonts, const std::string& versionDescription, bool useShaders,
|
||||||
Files::ConfigurationManager& cfgMgr);
|
Files::ConfigurationManager& cfgMgr);
|
||||||
virtual ~WindowManager();
|
virtual ~WindowManager();
|
||||||
|
|
||||||
|
|
|
@ -227,9 +227,10 @@ namespace
|
||||||
namespace Gui
|
namespace Gui
|
||||||
{
|
{
|
||||||
|
|
||||||
FontLoader::FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor)
|
FontLoader::FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor, bool exportFonts)
|
||||||
: mVFS(vfs)
|
: mVFS(vfs)
|
||||||
, mScalingFactor(scalingFactor)
|
, mScalingFactor(scalingFactor)
|
||||||
|
, mExportFonts(exportFonts)
|
||||||
{
|
{
|
||||||
if (encoding == ToUTF8::WINDOWS_1252)
|
if (encoding == ToUTF8::WINDOWS_1252)
|
||||||
mEncoding = ToUTF8::CP437;
|
mEncoding = ToUTF8::CP437;
|
||||||
|
@ -407,7 +408,8 @@ namespace Gui
|
||||||
file.reset();
|
file.reset();
|
||||||
|
|
||||||
// Create the font texture
|
// Create the font texture
|
||||||
std::string bitmapFilename = "fonts/" + std::string(name_) + ".tex";
|
const std::string name(name_);
|
||||||
|
const std::string bitmapFilename = "fonts/" + name + ".tex";
|
||||||
|
|
||||||
Files::IStreamPtr bitmapFile = mVFS->get(bitmapFilename);
|
Files::IStreamPtr bitmapFile = mVFS->get(bitmapFilename);
|
||||||
|
|
||||||
|
@ -428,6 +430,19 @@ namespace Gui
|
||||||
fail(*bitmapFile, bitmapFilename, "File too small to be a valid bitmap");
|
fail(*bitmapFile, bitmapFilename, "File too small to be a valid bitmap");
|
||||||
bitmapFile.reset();
|
bitmapFile.reset();
|
||||||
|
|
||||||
|
if (mExportFonts)
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||||
|
image->allocateImage(width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE);
|
||||||
|
assert(image->isDataContiguous());
|
||||||
|
memcpy(image->data(), textureData.data(), textureData.size());
|
||||||
|
// Convert to OpenGL origin for sensible output
|
||||||
|
image->flipVertical();
|
||||||
|
|
||||||
|
Log(Debug::Info) << "Writing " << name + ".png";
|
||||||
|
osgDB::writeImageFile(*image, name + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
MyGUI::ITexture* tex = MyGUI::RenderManager::getInstance().createTexture(bitmapFilename);
|
MyGUI::ITexture* tex = MyGUI::RenderManager::getInstance().createTexture(bitmapFilename);
|
||||||
tex->createManual(width, height, MyGUI::TextureUsage::Write, MyGUI::PixelFormat::R8G8B8A8);
|
tex->createManual(width, height, MyGUI::TextureUsage::Write, MyGUI::PixelFormat::R8G8B8A8);
|
||||||
unsigned char* texData = reinterpret_cast<unsigned char*>(tex->lock(MyGUI::TextureUsage::Write));
|
unsigned char* texData = reinterpret_cast<unsigned char*>(tex->lock(MyGUI::TextureUsage::Write));
|
||||||
|
@ -647,6 +662,13 @@ namespace Gui
|
||||||
cursorCode->addAttribute("size", "0 0");
|
cursorCode->addAttribute("size", "0 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mExportFonts)
|
||||||
|
{
|
||||||
|
Log(Debug::Info) << "Writing " << name + ".xml";
|
||||||
|
xmlDocument.createDeclaration();
|
||||||
|
xmlDocument.save(name + ".xml");
|
||||||
|
}
|
||||||
|
|
||||||
// Register the font with MyGUI
|
// Register the font with MyGUI
|
||||||
MyGUI::ResourceManualFont* font = static_cast<MyGUI::ResourceManualFont*>(
|
MyGUI::ResourceManualFont* font = static_cast<MyGUI::ResourceManualFont*>(
|
||||||
MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceManualFont"));
|
MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceManualFont"));
|
||||||
|
|
|
@ -25,7 +25,8 @@ namespace Gui
|
||||||
class FontLoader
|
class FontLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor);
|
/// @param exportFonts export the converted fonts (Images and XML with glyph metrics) to files?
|
||||||
|
FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor, bool exportFonts);
|
||||||
|
|
||||||
void overrideLineHeight(MyGUI::xml::ElementPtr _node, std::string_view _file, MyGUI::Version _version);
|
void overrideLineHeight(MyGUI::xml::ElementPtr _node, std::string_view _file, MyGUI::Version _version);
|
||||||
|
|
||||||
|
@ -35,6 +36,7 @@ namespace Gui
|
||||||
ToUTF8::FromType mEncoding;
|
ToUTF8::FromType mEncoding;
|
||||||
const VFS::Manager* mVFS;
|
const VFS::Manager* mVFS;
|
||||||
float mScalingFactor;
|
float mScalingFactor;
|
||||||
|
bool mExportFonts;
|
||||||
|
|
||||||
void loadFonts();
|
void loadFonts();
|
||||||
void loadFont(const std::string& fontName, const std::string& fontId);
|
void loadFont(const std::string& fontName, const std::string& fontId);
|
||||||
|
|
|
@ -15,6 +15,8 @@ Morrowind .fnt fonts
|
||||||
Morrowind uses a custom ``.fnt`` file format. It is not compatible with the Windows Font File ``.fnt`` format.
|
Morrowind uses a custom ``.fnt`` file format. It is not compatible with the Windows Font File ``.fnt`` format.
|
||||||
To our knowledge, the format is undocumented. OpenMW can load this format and convert it on the fly into something usable
|
To our knowledge, the format is undocumented. OpenMW can load this format and convert it on the fly into something usable
|
||||||
(see font loader `source code <https://gitlab.com/OpenMW/openmw/blob/master/components/fontloader/fontloader.cpp>`_).
|
(see font loader `source code <https://gitlab.com/OpenMW/openmw/blob/master/components/fontloader/fontloader.cpp>`_).
|
||||||
|
You can use --export-fonts command line option to write the converted font
|
||||||
|
(a PNG image and an XML file describing the position of each glyph in the image) to the current directory.
|
||||||
|
|
||||||
They can be used instead of TrueType fonts if needed by specifying their ``.fnt`` files names in the ``openmw.cfg``. For example:
|
They can be used instead of TrueType fonts if needed by specifying their ``.fnt`` files names in the ``openmw.cfg``. For example:
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue