int FontConverter::exec() { /* Font converter dependencies */ PluginManager::Manager<Trade::AbstractImageConverter> imageConverterManager(Utility::Directory::join(args.value("plugin-dir"), "imageconverters/")); /* Load font */ PluginManager::Manager<Text::AbstractFont> fontManager(Utility::Directory::join(args.value("plugin-dir"), "fonts/")); if(!(fontManager.load(args.value("font")) & PluginManager::LoadState::Loaded)) std::exit(1); std::unique_ptr<Text::AbstractFont> font = fontManager.instance(args.value("font")); /* Load font converter */ PluginManager::Manager<Text::AbstractFontConverter> converterManager(Utility::Directory::join(args.value("plugin-dir"), "fontconverters/")); if(!(converterManager.load(args.value("converter")) & PluginManager::LoadState::Loaded)) std::exit(1); std::unique_ptr<Text::AbstractFontConverter> converter = converterManager.instance(args.value("converter")); /* Open font */ if(!font->openFile(args.value("input"), args.value<Float>("font-size"))) { Error() << "Cannot open font" << args.value("input"); std::exit(1); } /* Create distance field glyph cache if radius is specified */ std::unique_ptr<Text::GlyphCache> cache; if(!args.value<Vector2i>("output-size").isZero()) { Debug() << "Populating distance field glyph cache..."; cache.reset(new Text::DistanceFieldGlyphCache( args.value<Vector2i>("atlas-size"), args.value<Vector2i>("output-size"), args.value<Int>("radius"))); /* Otherwise use normal cache */ } else { Debug() << "Zero-size distance field output specified, populating normal glyph cache..."; cache.reset(new Text::GlyphCache(args.value<Vector2i>("atlas-size"))); } /* Fill the cache */ font->fillGlyphCache(*cache, args.value("characters")); Debug() << "Converting font..."; /* Convert the font */ if(!converter->exportFontToFile(*font, *cache, args.value("output"), args.value("characters"))) { Error() << "Cannot export font to" << args.value("output"); std::exit(1); } Debug() << "Done."; return 0; }
int DistanceFieldConverter::exec() { /* Load plugins */ PluginManager::Manager<Trade::AbstractImporter> importerManager(MAGNUM_IMPORTER_PLUGIN_DIR); if(!(importerManager.load(args.value("importer")) & PluginManager::LoadState::Loaded)) { Error() << "Cannot load importer plugin" << args.value("importer") << "from" << MAGNUM_IMPORTER_PLUGIN_DIR; return 1; } PluginManager::Manager<Trade::AbstractImageConverter> converterManager(MAGNUM_IMAGECONVERTER_PLUGIN_DIR); if(!(converterManager.load(args.value("converter")) & PluginManager::LoadState::Loaded)) { Error() << "Cannot load converter plugin" << args.value("converter") << "from" << MAGNUM_IMAGECONVERTER_PLUGIN_DIR; return 1; } /* Instance plugins */ std::unique_ptr<Trade::AbstractImporter> importer = importerManager.instance(args.value("importer")); CORRADE_INTERNAL_ASSERT(importer); std::unique_ptr<Trade::AbstractImageConverter> converter = converterManager.instance(args.value("converter")); CORRADE_INTERNAL_ASSERT(converter); /* Open input file */ std::optional<Trade::ImageData2D> image; if(!importer->openFile(args.value("input")) || !(image = importer->image2D(0))) { Error() << "Cannot open file" << args.value("input"); return 1; } if(image->format() != ColorFormat::Red) { Error() << "Unsupported image format" << image->format(); return 1; } /* Input texture */ Texture2D input; input.setMinificationFilter(Sampler::Filter::Linear) .setMagnificationFilter(Sampler::Filter::Linear) .setWrapping(Sampler::Wrapping::ClampToEdge) .setImage(0, TextureFormat::R8, *image); /* Output texture */ Texture2D output; output.setStorage(1, TextureFormat::R8, args.value<Vector2i>("output-size")); CORRADE_INTERNAL_ASSERT(Renderer::error() == Renderer::Error::NoError); /* Do it */ Debug() << "Converting image of size" << image->size() << "to distance field..."; TextureTools::distanceField(input, output, {{}, args.value<Vector2i>("output-size")}, args.value<Int>("radius"), image->size()); /* Save image */ Image2D result(ColorFormat::Red, ColorType::UnsignedByte); output.image(0, result); if(!converter->exportToFile(result, args.value("output"))) { Error() << "Cannot save file" << args.value("output"); return 1; } return 0; }
int DistanceFieldConverter::exec() { /* Load importer plugin */ PluginManager::Manager<Trade::AbstractImporter> importerManager(Utility::Directory::join(args.value("plugin-dir"), "importers/")); if(!(importerManager.load(args.value("importer")) & PluginManager::LoadState::Loaded)) return 1; std::unique_ptr<Trade::AbstractImporter> importer = importerManager.instance(args.value("importer")); /* Load converter plugin */ PluginManager::Manager<Trade::AbstractImageConverter> converterManager(Utility::Directory::join(args.value("plugin-dir"), "imageconverters/")); if(!(converterManager.load(args.value("converter")) & PluginManager::LoadState::Loaded)) return 1; std::unique_ptr<Trade::AbstractImageConverter> converter = converterManager.instance(args.value("converter")); /* Open input file */ std::optional<Trade::ImageData2D> image; if(!importer->openFile(args.value("input")) || !(image = importer->image2D(0))) { Error() << "Cannot open file" << args.value("input"); return 1; } /* Decide about internal format */ TextureFormat internalFormat; if(image->format() == PixelFormat::Red) internalFormat = TextureFormat::R8; else if(image->format() == PixelFormat::RGB) internalFormat = TextureFormat::RGB8; else if(image->format() == PixelFormat::RGBA) internalFormat = TextureFormat::RGBA8; else { Error() << "Unsupported image format" << image->format(); return 1; } /* Input texture */ Texture2D input; input.setMinificationFilter(Sampler::Filter::Linear) .setMagnificationFilter(Sampler::Filter::Linear) .setWrapping(Sampler::Wrapping::ClampToEdge) .setStorage(1, internalFormat, image->size()) .setSubImage(0, {}, *image); /* Output texture */ Texture2D output; output.setStorage(1, TextureFormat::R8, args.value<Vector2i>("output-size")); CORRADE_INTERNAL_ASSERT(Renderer::error() == Renderer::Error::NoError); /* Do it */ Debug() << "Converting image of size" << image->size() << "to distance field..."; TextureTools::distanceField(input, output, {{}, args.value<Vector2i>("output-size")}, args.value<Int>("radius"), image->size()); /* Save image */ Image2D result(PixelFormat::Red, PixelType::UnsignedByte); output.image(0, result); if(!converter->exportToFile(result, args.value("output"))) { Error() << "Cannot save file" << args.value("output"); return 1; } return 0; }