Skip to content

ISVG Interface ​

Unit: SVGInterfaces

Description ​

ISVG is the core interface for SVG document manipulation and rendering. It is implemented by factory-specific classes (Image32, Skia4Delphi, Direct2D, SVGMagic) and provides a unified API regardless of the underlying rendering engine.

Properties ​

Size Properties (Read-Only) ​

pascal
property Width: Single;
property Height: Single;

Natural size of the SVG document.

Rendering Properties ​

pascal
property Opacity: Single;                      // 0.0 to 1.0
property GrayScale: Boolean;
property FixedColor: TColor;
property ApplyFixedColorToRootOnly: Boolean;

Content ​

pascal
property Source: string;

SVG XML source code.

Methods ​

State ​

pascal
function IsEmpty: Boolean;
procedure Clear;

File/Stream Operations ​

pascal
procedure SaveToStream(Stream: TStream);
procedure SaveToFile(const FileName: string);
procedure LoadFromStream(Stream: TStream);
procedure LoadFromFile(const FileName: string);

Rendering ​

pascal
procedure PaintTo(DC: HDC; R: TRectF; KeepAspectRatio: Boolean = True);

Global Functions ​

Factory Management ​

pascal
function GlobalSVGFactory: ISVGFactory;
procedure SetGlobalSvgFactory(const AFactory: ISVGFactory);

Factory Getters ​

pascal
function GetImage32SVGFactory: ISVGFactory;
function GetD2DSVGFactory: ISVGFactory;
function GetSkiaSVGFactory: ISVGFactory;
function GetSVGMagicFactory: ISVGFactory;

Examples ​

Direct SVG Usage ​

pascal
var
  SVG: ISVG;
begin
  SVG := GlobalSVGFactory.NewSvg;
  SVG.LoadFromFile('icon.svg');
  SVG.FixedColor := clBlue;
  SVG.Opacity := 0.8;
  SVG.PaintTo(Canvas.Handle, TRectF.Create(0, 0, 100, 100));
end;

Change Rendering Engine ​

pascal
// Switch to Skia4Delphi
SetGlobalSvgFactory(GetSkiaSVGFactory);

// All new SVG objects will use Skia
var SVG := GlobalSVGFactory.NewSvg;

See Also ​

Released under Apache License, Version 2.0.