Skip to content

BVE.SVG2Elements.FMX

Unit implementation the specifics for the FMX platform for RenderContext and SVG Root element classes.

Unit: BVE.SVG2Elements.FMX

Routines

CanvasMatrixMultiply

procedure CanvasMatrixMultiply(aCanvas: TCanvas; const aMatrix: TSVGMatrix);

Multiplies the current transformation matrix of a FireMonkey canvas by aMatrix.

Note

Use this to draw an SVG into a canvas that already has a transformation, for example inside a control that is scaled or rotated: the SVG matrix is combined with what the canvas already has instead of replacing it. On Delphi XE4 and earlier TCanvas has no MultiplyMatrix, so the matrices are combined by hand and set back with SetMatrix. The result is the same.

SVGRenderToBitmap

procedure SVGRenderToBitmap(
  aSVGRoot: ISVGRoot;
  aBitmap: TBitmap;
  const aRenderOptions: TSVGRenderOptions = [sroClippath];
  const aAutoViewbox: boolean = True;
  const aAspectRatioAlign: TSVGAspectRatioAlign = arXMidYMid;
  const aAspectRatioMeetOrSlice: TSVGAspectRatioMeetOrSlice = arMeet;
  const aOpacity: single = 1.0;
  const aClearColor: TAlphaColor = 0);

Renders an SVG document into a FireMonkey bitmap, at the size the bitmap already has.

Parameter Description
aSVGRoot The document to render. Nothing is drawn if it holds no SVG.
aBitmap The target. Its Width and Height decide the render size, so set them before calling. Nothing is drawn if it is nil or empty.
aRenderOptions Which optional work to do. Note the default here is clip paths only: filters are not included, unlike the VCL and FPC versions of this routine. Pass sroFilters as well if the document needs them.
aAutoViewbox True substitutes a viewBox when the document has none, so a document without one still scales to the bitmap.
aAspectRatioAlign How the graphic is aligned when its aspect ratio differs from the bitmap's.
aAspectRatioMeetOrSlice Whether the graphic is fitted inside the bitmap (arMeet) or covers it and is clipped (arSlice).
aOpacity Not used by this implementation. Render the document at reduced opacity by setting the opacity on the SVG itself instead.
aClearColor The colour the bitmap is cleared with before rendering. The bitmap is always cleared; the default of 0 leaves it fully transparent.

SVGRenderToBitmapDpi

function SVGRenderToBitmapDpi(
  aSVGRoot: ISVGRoot;
  const aDpi: TSVGFloat;
  const aPercentBase: TSVGRect;
  const aRenderOptions: TSVGRenderOptions = [sroFilters, sroClippath]): TBitmap; overload;

function SVGRenderToBitmapDpi(
  aSVGRoot: ISVGRoot;
  const aDpi: TSVGFloat;
  const aRenderOptions: TSVGRenderOptions = [sroFilters, sroClippath]): TBitmap; overload;

Renders a drawing at its real size for a resolution, into a new bitmap: a drawing of 100 by 50 mm gives 1181 by 591 pixels at 300 dpi. The caller frees the bitmap.

Parameter Description
aDpi Resolution in dots per inch.
aPercentBase The area, in SVG pixels (96 to the inch), that a width and height in percentages, or missing, are taken from. The overload without it uses 300 by 150, the size browsers give such a drawing.

Note

The bitmap is at least one pixel in each direction.