Magnum::Trade::LunaSvgImporter class new in Git master

SVG importer plugin using LunaSVG.

Rasterizes Scalable Vector Graphics (*.svg) using the LunaSVG library. See also the PlutoSvgImporter which is an alternative that claims to be specifically designed for parsing and rendering SVG documents embedded in OpenType fonts.

This plugin provides the SvgImporter plugin.

Usage

This plugin depends on the Trade library and is built if MAGNUM_WITH_LUNASVGIMPORTER is enabled when building Magnum Plugins. To use as a dynamic plugin, load "LunaSvgImporter" via Corrade::PluginManager::Manager.

Additionally, if you're using Magnum as a CMake subproject, bundle the magnum-plugins repository and do the following. Using LunaSVG itself as a CMake subproject isn't tested at the moment, so you need to provide it as a system dependency and point CMAKE_PREFIX_PATH to its installation dir if necessary.

set(MAGNUM_WITH_LUNASVGIMPORTER ON CACHE BOOL "" FORCE)
add_subdirectory(magnum-plugins EXCLUDE_FROM_ALL)

# So the dynamically loaded plugin gets built implicitly
add_dependencies(your-app MagnumPlugins::LunaSvgImporter)

To use as a static plugin or as a dependency of another plugin with CMake, put FindMagnumPlugins.cmake into your modules/ directory, request the LunaSvgImporter component of the MagnumPlugins package in CMake and link to the MagnumPlugins::LunaSvgImporter target:

find_package(MagnumPlugins REQUIRED LunaSvgImporter)

# ...
target_link_libraries(your-app PRIVATE MagnumPlugins::LunaSvgImporter)

See Downloading and building plugins, Plugin usage with CMake, Loading and using plugins and File format support for more information.

Behavior and limitations

The output is always PixelFormat::RGBA8Unorm and the rasterized size by default corresponds to what's specified in <svg viewBox="...">. Use the dpi configuration option to rasterize at a different size.

Like PlutoSvgImporter, the LunaSVG library doesn't provide any error status or message in case an import fails, so the plugin will always print a generic error. Compared to ResvgImporter, <image> elements are supported only if the image file is embedded. External references are silently ignored without any error or warning. SVGZ files are not supported, use the ResvgImporter plugin instead.

Plugin-specific configuration

It's possible to tune various import options through configuration(). See below for all options and their default values:

[configuration]
# DPI at which to rasterize the file. Default matches what e.g. Inkscape
# uses, and causes SVG viewBox to be interpreted as literal pixels. Setting
# to e.g. 192 makes the image twice as large, 48 half the size. Fractional
# values are accepted as well.
dpi=96

# LunaSVG takes the SVG colors, which are encoded as 8-bit sRGB values, and
# premultiplies them with the alpha linearly, i.e. not by decoding the sRGB
# value first, then premultiplying and then encoding a sRGB value back. For
# consistency with other formats that produce unpremultiplied RGBA output
# this premultiplication is undone on import. Set to `premultipliedLinear` to
# import directly the pixels produced by LunaSvg without any processing.
alphaMode=

See Editing plugin-specific configuration for more information and an example showing how to edit the configuration values.

Base classes

class AbstractImporter
Base for importer plugins.

Constructors, destructors, conversion operators

LunaSvgImporter(PluginManager::AbstractManager& manager, const Containers::StringView& plugin) explicit
Plugin manager constructor.