mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-03-14 01:19:59 +00:00
Merge branch 'fontexport' into 'master'
Restore --export-fonts option functionality See merge request OpenMW/openmw!4561
This commit is contained in:
commit
ac5a27d972
@ -373,6 +373,7 @@ OMW::Engine::Engine(Files::ConfigurationManager& configurationManager)
|
||||
, mScriptConsoleMode(false)
|
||||
, mActivationDistanceOverride(-1)
|
||||
, mGrab(true)
|
||||
, mExportFonts(false)
|
||||
, mRandomSeed(0)
|
||||
, mNewGame(false)
|
||||
, mCfgMgr(configurationManager)
|
||||
@ -807,7 +808,7 @@ void OMW::Engine::prepareEngine()
|
||||
rootNode->addChild(guiRoot);
|
||||
|
||||
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);
|
||||
mEnvironment.setWindowManager(*mWindowManager);
|
||||
|
||||
@ -1109,6 +1110,11 @@ void OMW::Engine::setWarningsMode(int mode)
|
||||
mWarningsMode = mode;
|
||||
}
|
||||
|
||||
void OMW::Engine::enableFontExport(bool exportFonts)
|
||||
{
|
||||
mExportFonts = exportFonts;
|
||||
}
|
||||
|
||||
void OMW::Engine::setSaveGameFile(const std::filesystem::path& savegame)
|
||||
{
|
||||
mSaveGameFile = savegame;
|
||||
|
@ -171,6 +171,7 @@ namespace OMW
|
||||
// Grab mouse?
|
||||
bool mGrab;
|
||||
|
||||
bool mExportFonts;
|
||||
unsigned int mRandomSeed;
|
||||
|
||||
Compiler::Extensions mExtensions;
|
||||
@ -251,6 +252,8 @@ namespace OMW
|
||||
|
||||
void setWarningsMode(int mode);
|
||||
|
||||
void enableFontExport(bool exportFonts);
|
||||
|
||||
/// Set the save game file to load after initialising the engine.
|
||||
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);
|
||||
engine.setSoundUsage(!variables["no-sound"].as<bool>());
|
||||
engine.setActivationDistanceOverride(variables["activate-dist"].as<int>());
|
||||
engine.enableFontExport(variables["export-fonts"].as<bool>());
|
||||
engine.setRandomSeed(variables["random-seed"].as<unsigned int>());
|
||||
|
||||
return true;
|
||||
|
@ -146,7 +146,7 @@ namespace MWGui
|
||||
WindowManager::WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot,
|
||||
Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue, const std::filesystem::path& logpath,
|
||||
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)
|
||||
, mOldCullMask(0)
|
||||
, mStore(nullptr)
|
||||
@ -215,7 +215,8 @@ namespace MWGui
|
||||
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
|
||||
|
||||
// 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
|
||||
MyGUI::FactoryManager::getInstance().registerFactory<MWGui::Widgets::MWSkill>("Widget");
|
||||
|
@ -128,7 +128,7 @@ namespace MWGui
|
||||
WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot,
|
||||
Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
||||
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);
|
||||
virtual ~WindowManager();
|
||||
|
||||
|
@ -227,9 +227,10 @@ namespace
|
||||
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)
|
||||
, mScalingFactor(scalingFactor)
|
||||
, mExportFonts(exportFonts)
|
||||
{
|
||||
if (encoding == ToUTF8::WINDOWS_1252)
|
||||
mEncoding = ToUTF8::CP437;
|
||||
@ -407,7 +408,8 @@ namespace Gui
|
||||
file.reset();
|
||||
|
||||
// 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);
|
||||
|
||||
@ -429,6 +431,19 @@ namespace Gui
|
||||
<< bitmapFile->gcount() << "/" << (width * height * 4) << " bytes)";
|
||||
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);
|
||||
tex->createManual(width, height, MyGUI::TextureUsage::Write, MyGUI::PixelFormat::R8G8B8A8);
|
||||
unsigned char* texData = reinterpret_cast<unsigned char*>(tex->lock(MyGUI::TextureUsage::Write));
|
||||
@ -626,6 +641,13 @@ namespace Gui
|
||||
code->addAttribute("size", "0 0");
|
||||
}
|
||||
|
||||
if (mExportFonts)
|
||||
{
|
||||
Log(Debug::Info) << "Writing " << name + ".xml";
|
||||
xmlDocument.createDeclaration();
|
||||
xmlDocument.save(name + ".xml");
|
||||
}
|
||||
|
||||
// Register the font with MyGUI
|
||||
MyGUI::ResourceManualFont* font = static_cast<MyGUI::ResourceManualFont*>(
|
||||
MyGUI::FactoryManager::getInstance().createObject("Resource", "ResourceManualFont"));
|
||||
|
@ -25,7 +25,8 @@ namespace Gui
|
||||
class FontLoader
|
||||
{
|
||||
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);
|
||||
|
||||
@ -35,6 +36,7 @@ namespace Gui
|
||||
ToUTF8::FromType mEncoding;
|
||||
const VFS::Manager* mVFS;
|
||||
float mScalingFactor;
|
||||
bool mExportFonts;
|
||||
|
||||
void loadFonts();
|
||||
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.
|
||||
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>`_).
|
||||
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:
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user