Class TBGRASVG

Unit

Declaration

type TBGRASVG = class(TSVGCustomElement)

Description

Reading, writing and rendering for an SVG document.

Example of reading and displaying SVG images:

svg_example

uses ..., BGRABitmapTypes, BGRASVG;

procedure DrawSVGImages(ctx: TBGRACanvas2D);
var svg: TBGRASVG;
begin
  svg := TBGRASVG.Create;
  svg.LoadFromFile('Amsterdammertje-icoon.svg');
  svg.StretchDraw(ctx, taCenter,tlCenter, 0,0,ctx.Width/3,ctx.Height);

  svg.LoadFromFile('BespectacledMaleUser.svg');
  svg.StretchDraw(ctx, ctx.Width/3,0,ctx.Width*2/3,ctx.Height/2);

  ctx.save;
  ctx.beginPath;
  ctx.rect(ctx.Width/3,ctx.Height/2,ctx.Width*2/3,ctx.Height/2);
  ctx.clip;
  svg.LoadFromFile('Blue_gyroelongated_pentagonal_pyramid.svg');
  svg.Draw(ctx, taCenter,tlCenter, ctx.Width*2/3,ctx.Height*3/4);
  ctx.restore;

  svg.Free;

  ctx.beginPath;
  ctx.lineWidth:= 1;
  ctx.strokeStyle(BGRABlack);
  ctx.moveTo(ctx.Width/3,0);
  ctx.lineTo(ctx.Width/3,ctx.Height);
  ctx.moveTo(ctx.Width/3,ctx.Height/2);
  ctx.lineTo(ctx.Width,ctx.Height/2);
  ctx.stroke;
end;

Hierarchy

Overview

Fields

Protected FContent: TSVGContent;
Protected FDataLink: TSVGDataLink;
Protected FDefaultDpi: single;
Protected FXml: TXMLDocument;

Methods

Public constructor Create(AFilenameUTF8: string); overload;
Public constructor Create(AWidth,AHeight: single; AUnit: TCSSUnit); overload;
Public constructor Create; overload;
Public constructor Create(AStream: TStream); overload;
Public constructor CreateFromString(AUTF8String: string);
Public destructor Destroy; override;
Public function Duplicate: TBGRASVG;
Public function FindElementById(AID: string; AClass: TSVGFactory): TSVGElement; overload;
Public function FindElementById(AID: string): TSVGElement; overload;
Public function GetPresentationMatrix(AHorizAlign: TAlignment; AVertAlign: TTextLayout; AUnit: TCSSUnit; AScale: boolean): TAffineMatrix;
Public function GetStretchPresentationMatrix(AUnit: TCSSUnit): TAffineMatrix; overload;
Public function GetStretchPresentationMatrix(w,h: single; useSvgAspectRatio: boolean = false): TAffineMatrix; overload;
Public function GetStretchPresentationMatrix(AHorizAlign: TAlignment; AVertAlign: TTextLayout; w,h: single; ASlice: boolean = false): TAffineMatrix; overload;
Public function GetStretchRectF(x,y,w,h: single): TRectF; overload;
Public function GetStretchRectF(AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y,w,h: single; ASlice: boolean = false): TRectF; overload;
Protected function GetViewBoxAlignment(AHorizAlign: TAlignment; AVertAlign: TTextLayout; AUnit: TCSSUnit): TPointF;
Protected function GetViewBoxScale: TPointF;
Public procedure ConvertToUnit(AUnit: TCSSUnit); override;
Public procedure CropToViewBox(AScale: single = 1);
Public procedure Draw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y: single; destDpi: single; AScale: boolean = true); overload;
Public procedure Draw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y: single; destDpi: TPointF; AScale: boolean = true); overload;
Public procedure Draw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y: single; AUnit: TCSSUnit = cuPixel; AScale: boolean = true); overload;
Public procedure Draw(ACanvas2d: TBGRACanvas2D; x,y: single; AUnit: TCSSUnit = cuPixel); overload;
Public procedure Draw(ACanvas2d: TBGRACanvas2D; x,y: single; destDpi: single); overload;
Public procedure Draw(ACanvas2d: TBGRACanvas2D; x,y: single; destDpi: TPointF); overload;
Public procedure IterateElements(ACallback: TIterateElementCallback; AData: pointer; ARecursive: boolean); override;
Public procedure LoadFromFile(AFilenameUTF8: string);
Public procedure LoadFromResource(AFilename: string);
Public procedure LoadFromStream(AStream: TStream; AURI: UnicodeString = 'stream:');
Public procedure SaveToFile(AFilenameUTF8: string);
Public procedure SaveToStream(AStream: TStream);
Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; r: TRectF; useSvgAspectRatio: boolean = false); overload;
Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; x,y,w,h: single; useSvgAspectRatio: boolean = false); overload;
Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; x, y: single; AUnit: TCSSUnit); overload;
Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; r: TRectF; ASlice: boolean = false); overload;
Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y,w,h: single; ASlice: boolean = false); overload;
Protected procedure Init(ACreateEmpty: boolean);
Protected procedure SetAttribute(AName: string; AValue: string); override;
Protected procedure UnitsRecompute(Sender: TObject);

Properties

Public property AsUTF8String: utf8string read GetUTF8String write SetUTF8String;
Public property Attribute[AName: string]: string read GetAttribute write SetAttribute;
Public property AttributeDef[AName: string; ADefault: string]: string read GetAttribute;
Public property Color: TBGRAPixel read GetColor write SetColor;
Public property ComputedHeight: TFloatWithCSSUnit read GetComputedHeight;
Public property ComputedWidth: TFloatWithCSSUnit read GetComputedWidth;
Public property ContainerHeight: TFloatWithCSSUnit read GetContainerHeight write SetContainerHeight;
Public property ContainerHeightAsPixel: single read GetContainerHeightAsPixel write SetContainerHeightAsPixel;
Public property ContainerWidth: TFloatWithCSSUnit read GetContainerWidth write SetContainerWidth;
Public property ContainerWidthAsPixel: single read GetContainerWidthAsPixel write SetContainerWidthAsPixel;
Public property Content: TSVGContent read FContent;
Public property DataLink: TSVGDataLink read FDataLink;
Public property DefaultDpi: single read FDefaultDpi write SetDefaultDpi;
Public property FontSize: TFloatWithCSSUnit read GetFontSize write SetFontSize;
Public property Height: TFloatWithCSSUnit read GetHeight write SetHeight;
Public property HeightAsCm: single read GetHeightAsCm write SetHeightAsCm;
Public property HeightAsInch: single read GetHeightAsInch write SetHeightAsInch;
Public property HeightAsPixel: single read GetHeightAsPixel write SetHeightAsPixel;
Public property Layer[AIndex: integer]: TSVGGroup read GetLayer;
Public property LayerCount: integer read GetLayerCount;
Public property preserveAspectRatio: TSVGPreserveAspectRatio read GetPreserveAspectRatio write SetPreserveAspectRatio;
Public property Units: TSVGUnits read GetUnits;
Public property ViewBox: TSVGViewBox read GetViewBox write SetViewBox;
Public property ViewBoxInUnit[AUnit: TCSSUnit]: TSVGViewBox read GetViewBox;
Public property ViewMinInUnit[AUnit: TCSSUnit]: TPointF read GetViewMin;
Public property ViewSizeInUnit[AUnit: TCSSUnit]: TPointF read GetViewSize;
Public property VisualHeight: TFloatWithCSSUnit read GetVisualHeight;
Public property VisualHeightAsPixel: single read GetVisualHeightAsPixel;
Public property VisualWidth: TFloatWithCSSUnit read GetVisualWidth;
Public property VisualWidthAsPixel: single read GetVisualWidthAsPixel;
Public property Width: TFloatWithCSSUnit read GetWidth write SetWidth;
Public property WidthAsCm: single read GetWidthAsCm write SetWidthAsCm;
Public property WidthAsInch: single read GetWidthAsInch write SetWidthAsInch;
Public property WidthAsPixel: single read GetWidthAsPixel write SetWidthAsPixel;
Public property Zoomable: boolean read GetZoomable write SetZoomable;

Description

Fields

Protected FContent: TSVGContent;

This item has no description.

Protected FDataLink: TSVGDataLink;

This item has no description.

Protected FDefaultDpi: single;

This item has no description.

Protected FXml: TXMLDocument;

This item has no description.

Methods

Public constructor Create(AFilenameUTF8: string); overload;

This item has no description.

Public constructor Create(AWidth,AHeight: single; AUnit: TCSSUnit); overload;

This item has no description.

Public constructor Create; overload;

This item has no description.

Public constructor Create(AStream: TStream); overload;

This item has no description.

Public constructor CreateFromString(AUTF8String: string);

This item has no description.

Public destructor Destroy; override;

This item has no description.

Public function Duplicate: TBGRASVG;

This item has no description.

Public function FindElementById(AID: string; AClass: TSVGFactory): TSVGElement; overload;

This item has no description.

Public function FindElementById(AID: string): TSVGElement; overload;

This item has no description.

Public function GetPresentationMatrix(AHorizAlign: TAlignment; AVertAlign: TTextLayout; AUnit: TCSSUnit; AScale: boolean): TAffineMatrix;

This item has no description.

Public function GetStretchPresentationMatrix(AUnit: TCSSUnit): TAffineMatrix; overload;

This item has no description.

Public function GetStretchPresentationMatrix(w,h: single; useSvgAspectRatio: boolean = false): TAffineMatrix; overload;

This item has no description.

Public function GetStretchPresentationMatrix(AHorizAlign: TAlignment; AVertAlign: TTextLayout; w,h: single; ASlice: boolean = false): TAffineMatrix; overload;

This item has no description.

Public function GetStretchRectF(x,y,w,h: single): TRectF; overload;

This item has no description.

Public function GetStretchRectF(AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y,w,h: single; ASlice: boolean = false): TRectF; overload;

This item has no description.

Protected function GetViewBoxAlignment(AHorizAlign: TAlignment; AVertAlign: TTextLayout; AUnit: TCSSUnit): TPointF;

This item has no description.

Protected function GetViewBoxScale: TPointF;

This item has no description.

Public procedure ConvertToUnit(AUnit: TCSSUnit); override;

This item has no description.

Public procedure CropToViewBox(AScale: single = 1);

This item has no description.

Public procedure Draw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y: single; destDpi: single; AScale: boolean = true); overload;

This item has no description.

Public procedure Draw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y: single; destDpi: TPointF; AScale: boolean = true); overload;

This item has no description.

Public procedure Draw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y: single; AUnit: TCSSUnit = cuPixel; AScale: boolean = true); overload;

This item has no description.

Public procedure Draw(ACanvas2d: TBGRACanvas2D; x,y: single; AUnit: TCSSUnit = cuPixel); overload;

This item has no description.

Public procedure Draw(ACanvas2d: TBGRACanvas2D; x,y: single; destDpi: single); overload;

This item has no description.

Public procedure Draw(ACanvas2d: TBGRACanvas2D; x,y: single; destDpi: TPointF); overload;

This item has no description.

Public procedure IterateElements(ACallback: TIterateElementCallback; AData: pointer; ARecursive: boolean); override;

This item has no description.

Public procedure LoadFromFile(AFilenameUTF8: string);

This item has no description.

Public procedure LoadFromResource(AFilename: string);

This item has no description.

Public procedure LoadFromStream(AStream: TStream; AURI: UnicodeString = 'stream:');

This item has no description.

Public procedure SaveToFile(AFilenameUTF8: string);

This item has no description.

Public procedure SaveToStream(AStream: TStream);

This item has no description.

Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; r: TRectF; useSvgAspectRatio: boolean = false); overload;

This item has no description.

Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; x,y,w,h: single; useSvgAspectRatio: boolean = false); overload;

This item has no description.

Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; x, y: single; AUnit: TCSSUnit); overload;

This item has no description.

Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; r: TRectF; ASlice: boolean = false); overload;

This item has no description.

Public procedure StretchDraw(ACanvas2d: TBGRACanvas2D; AHorizAlign: TAlignment; AVertAlign: TTextLayout; x,y,w,h: single; ASlice: boolean = false); overload;

This item has no description.

Protected procedure Init(ACreateEmpty: boolean);

This item has no description.

Protected procedure SetAttribute(AName: string; AValue: string); override;

This item has no description.

Protected procedure UnitsRecompute(Sender: TObject);

This item has no description.

Properties

Public property AsUTF8String: utf8string read GetUTF8String write SetUTF8String;

except Width, Height, ContainerWidth, ContainerHeight

Public property Attribute[AName: string]: string read GetAttribute write SetAttribute;

This item has no description.

Public property AttributeDef[AName: string; ADefault: string]: string read GetAttribute;

This item has no description.

Public property Color: TBGRAPixel read GetColor write SetColor;

This item has no description.

Public property ComputedHeight: TFloatWithCSSUnit read GetComputedHeight;

This item has no description.

Public property ComputedWidth: TFloatWithCSSUnit read GetComputedWidth;

This item has no description.

Public property ContainerHeight: TFloatWithCSSUnit read GetContainerHeight write SetContainerHeight;

This item has no description.

Public property ContainerHeightAsPixel: single read GetContainerHeightAsPixel write SetContainerHeightAsPixel;

This item has no description.

Public property ContainerWidth: TFloatWithCSSUnit read GetContainerWidth write SetContainerWidth;

This item has no description.

Public property ContainerWidthAsPixel: single read GetContainerWidthAsPixel write SetContainerWidthAsPixel;

This item has no description.

Public property Content: TSVGContent read FContent;

this is not saved in the SVG file

Public property DataLink: TSVGDataLink read FDataLink;

This item has no description.

Public property DefaultDpi: single read FDefaultDpi write SetDefaultDpi;

This item has no description.

Public property FontSize: TFloatWithCSSUnit read GetFontSize write SetFontSize;

This item has no description.

Public property Height: TFloatWithCSSUnit read GetHeight write SetHeight;

This item has no description.

Public property HeightAsCm: single read GetHeightAsCm write SetHeightAsCm;

This item has no description.

Public property HeightAsInch: single read GetHeightAsInch write SetHeightAsInch;

This item has no description.

Public property HeightAsPixel: single read GetHeightAsPixel write SetHeightAsPixel;

This item has no description.

Public property Layer[AIndex: integer]: TSVGGroup read GetLayer;

This item has no description.

Public property LayerCount: integer read GetLayerCount;

This item has no description.

Public property preserveAspectRatio: TSVGPreserveAspectRatio read GetPreserveAspectRatio write SetPreserveAspectRatio;

(for test or internal info)

Public property Units: TSVGUnits read GetUnits;

This item has no description.

Public property ViewBox: TSVGViewBox read GetViewBox write SetViewBox;

This item has no description.

Public property ViewBoxInUnit[AUnit: TCSSUnit]: TSVGViewBox read GetViewBox;

This item has no description.

Public property ViewMinInUnit[AUnit: TCSSUnit]: TPointF read GetViewMin;

This item has no description.

Public property ViewSizeInUnit[AUnit: TCSSUnit]: TPointF read GetViewSize;

This item has no description.

Public property VisualHeight: TFloatWithCSSUnit read GetVisualHeight;

This item has no description.

Public property VisualHeightAsPixel: single read GetVisualHeightAsPixel;

This item has no description.

Public property VisualWidth: TFloatWithCSSUnit read GetVisualWidth;

This item has no description.

Public property VisualWidthAsPixel: single read GetVisualWidthAsPixel;

This item has no description.

Public property Width: TFloatWithCSSUnit read GetWidth write SetWidth;

This item has no description.

Public property WidthAsCm: single read GetWidthAsCm write SetWidthAsCm;

This item has no description.

Public property WidthAsInch: single read GetWidthAsInch write SetWidthAsInch;

This item has no description.

Public property WidthAsPixel: single read GetWidthAsPixel write SetWidthAsPixel;

This item has no description.

Public property Zoomable: boolean read GetZoomable write SetZoomable;

This item has no description.