@@ -227,9 +227,10 @@ namespace
227
227
namespace Gui
228
228
{
229
229
230
- FontLoader::FontLoader (ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor)
230
+ FontLoader::FontLoader (ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor, bool exportFonts )
231
231
: mVFS (vfs)
232
232
, mScalingFactor (scalingFactor)
233
+ , mExportFonts (exportFonts)
233
234
{
234
235
if (encoding == ToUTF8::WINDOWS_1252)
235
236
mEncoding = ToUTF8::CP437;
@@ -407,7 +408,8 @@ namespace Gui
407
408
file.reset ();
408
409
409
410
// Create the font texture
410
- std::string bitmapFilename = " fonts/" + std::string (name_) + " .tex" ;
411
+ const std::string name (name_);
412
+ const std::string bitmapFilename = " fonts/" + name + " .tex" ;
411
413
412
414
Files::IStreamPtr bitmapFile = mVFS ->get (bitmapFilename);
413
415
@@ -429,6 +431,19 @@ namespace Gui
429
431
<< bitmapFile->gcount () << " /" << (width * height * 4 ) << " bytes)" ;
430
432
bitmapFile.reset ();
431
433
434
+ if (mExportFonts )
435
+ {
436
+ osg::ref_ptr<osg::Image> image = new osg::Image;
437
+ image->allocateImage (width, height, 1 , GL_RGBA, GL_UNSIGNED_BYTE);
438
+ assert (image->isDataContiguous ());
439
+ memcpy (image->data (), textureData.data (), textureData.size ());
440
+ // Convert to OpenGL origin for sensible output
441
+ image->flipVertical ();
442
+
443
+ Log (Debug::Info) << " Writing " << name + " .png" ;
444
+ osgDB::writeImageFile (*image, name + " .png" );
445
+ }
446
+
432
447
MyGUI::ITexture* tex = MyGUI::RenderManager::getInstance ().createTexture (bitmapFilename);
433
448
tex->createManual (width, height, MyGUI::TextureUsage::Write, MyGUI::PixelFormat::R8G8B8A8);
434
449
unsigned char * texData = reinterpret_cast <unsigned char *>(tex->lock (MyGUI::TextureUsage::Write));
@@ -626,6 +641,13 @@ namespace Gui
626
641
code->addAttribute (" size" , " 0 0" );
627
642
}
628
643
644
+ if (mExportFonts )
645
+ {
646
+ Log (Debug::Info) << " Writing " << name + " .xml" ;
647
+ xmlDocument.createDeclaration ();
648
+ xmlDocument.save (name + " .xml" );
649
+ }
650
+
629
651
// Register the font with MyGUI
630
652
MyGUI::ResourceManualFont* font = static_cast <MyGUI::ResourceManualFont*>(
631
653
MyGUI::FactoryManager::getInstance ().createObject (" Resource" , " ResourceManualFont" ));
0 commit comments