Skip to content

Choice of Factories

Carlo Barazzetta edited this page Jul 12, 2021 · 10 revisions

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

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

You can choose two native Delphi implementations (working with VCL and FMX):

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

  2. Delphi TSVG: the first native Delphi code, based on Martin's work which is using GDI+ (FMX only in Windows)

  3. or choose a wrapper to the "Cairo" library (written in C) that work only with VCL on Windows.

  4. 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 four factories

If you want to compare the four factories you can use the project Demo\SVGViewer\SvgViewer.dpr 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:

Delphi TSVG supports pretty much the same elements and attributes as Direct2D with one or two exceptions and it supports the text, textpath, style sheets and class elements. A lot a effort has been invested in improving the TSVG fidelity and accuracy in parsing and rendering SVG files, but it may not yet be at the same level as the Direct2D one.

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 TSVG Image32 D2D Cairo
997 Font-Awesome 453ms 453ms 672ms 516ms
654 Papirus 547ms 781ms 547ms 891ms
5366 Material-Design 5031ms 5094ms 6531ms 5828ms

As you can see, the four engines perform differently depending on the icons and their complexity, but the two native Delphi implementation are the best. Notice that Image32 and Cairo are the only engines capable of rendering blur effect (that is always slow to calculate): this is the reason of "slow" performance to rendere 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(GetPasSVGFactory);

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 TSVG by Martin Walter (included into SVG folder)
{.$DEFINE Delphi_SVGEngine}
//or use Delphi Engine from Image32 library by Angus Johnson (included into Image32 folder)
{$DEFINE Image32_SVGEngine}
//or use Engine Cairo wrapper (included by Lübbe Onken in Cairo folder)
{.$DEFINE Cairo_SVGEngine}

If you undefine PreferNativeSvgSupport and you do not call SetGlobalSVGFactory the Image32 or TSVG or Cairo 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.

Clone this wiki locally