Choice of Factories - EtheaDev/SVGIconImageList GitHub Wiki

Choice of SVG Factories (Delphi Image32, SKIA4Delphi or Direct2D wrapper)

SVGIconImageList provides three alternative ways of parsing and displaying SVG files:

  1. Delphi Image32 (default): the new implementation, using Image32 library by Angus Johnson (FMX for Windows, Android and iOS)

  2. or choose the use of SKIA4Delphi library, a cross-platform 2D graphics API based on Google's Skia Graphics Library (incomplete support)

  3. Then, it's possibile to "prefer" a native Windows SVG support which is based on Direct2D, written by Kiriakos Vlahos. This is only available in Windows 10 with the Creators Update: if not present the library uses one of the first three choice (TSVG or Image32 or Cairo).

Comparison of the three factories

If you want to compare the three factories you can use the SVG Viewer Demo and look at the resulting rendered images by the engines:

SVGViewer demo

Support for SVG elements and presentation attributes

Delphi Image32 is the most complete library that supports more features not supported into TSVG, like blur, gradient, merge, drop-shadow, markers, simbol, pattern, subpixels, so it's the default choice.

You can see the supported SVG elements and attributes supported by Direct2D here. The most notable ommission are:

Performance

This table shows the performance of the three rendering engines tested with SVGExplorer, using a significant amount of icons from different sets, rendered at 32x32 pixels.

Count Icon set Image32 D2D Skia4Delphi
997 Font-Awesome 1265ms 1453ms 1172ms
654 Papirus 2750ms(1) 937ms 1266ms(1)
5366 Material-Design 11015ms 12001ms 10688ms

As you can see, the three engines perform differently depending on the icons and their complexity.

(1)Notice that Image32 and Skia4Delphi are the only engines capable of rendering blur effect (that is always slow to calculate): this is the reason of "slow" performance to render Papirus icons that contains blur effect.

Default SVG factory

Currently and if you take no action the Image32 factory is the preferred implementation, used also to build packages.

Specifying an SVG factory

You can override the default by calling SetGlobalSVGFactory at the initialization section of any unit. For example to always use the TSVG based factory you use the statement bellow:

  SetGlobalSVGFactory(GetSkiaSVGFactory);

Conditional Defines

In SVGIconImageList.inc under the Source directory you will find following conditional defines:

//Prefer Engine Direct2D by Kiriakos Vlahos
//if supported by Windows Platform (from Windows Creators update)
{.$DEFINE PreferNativeSvgSupport}
{.$DEFINE GPUSupport}
{$IFDEF PreferNativeSvgSupport}
  // Throw an exception if the SVG contains text elements or class attributes
  // which are not supported by Windows SVG. Since it costs some performance,
  // you should only turn it on during debugging or if it's absolutely necessary.
  {.$DEFINE CheckForUnsupportedSvg}
{$ENDIF}

//if PreferNativeSvgSupport not active or not available:
//use Delphi Engine from Image32 library by Angus Johnson (included into Image32 folder)
{$DEFINE Image32_SVGEngine}
//or use Engine Skia with skia4delphi wrapper by Vinícius Felipe Botelho Barbosa (included into skia4delphi folder)
{.$DEFINE Skia_SVGEngine}

If you undefine PreferNativeSvgSupport and you do not call SetGlobalSVGFactory the Image32 or Skia4Delphi factory will always be used.

GPUSupport only applies to the Direct2D factory. Is it is defined Direct2D will be using the GPU if possible. The reason is undefined by default is that with some slow GPUs it may reduce performance.

⚠️ **GitHub.com Fallback** ⚠️