Setting options:
To render an SVG to a target device:
L_SvgRenderOptions contains the following members:
The destination rectangle, in pixel coordinates. The SVG document will be rendered to fit and center inside this rectangle.
The L_SvgRenderOptions.Transform will be applied to this rectangle.
The clipping rectangle, in pixel coordinates. The engine will apply this clipping into L_SvgRenderOptions.Bounds to exclude all or parts of the objects that do not fit.
The L_SvgRenderOptions.Transform will not be applied to this rectangle.
Transformation to be applied. This is an L_MATRIX structure that you can use to apply zooming, translation and rotation to the final document.
SVG documents do not have a background color. Use this property to fill L_SvgRenderOptions.Bounds (final transformation applied) with a color. Will only be used if L_SvgRenderOptions.UseBackgroundColor is TRUE.
Use L_SvgRenderOptions.BackgroundColor to fill the background of the transformed destination rectangle.
Important Note: L_SvgRenderDocument will return an error if the L_SvgNodeHandle is not flat or does not contain valid bounds. For more information, refer SVG Size, Bounds and Flat.
The following code illustrates how to render a document by automatically checking the flat and bounds states:
void RenderDocument(L_SvgNodeHandle docHandle, HDC hdc, L_SvgRenderOptions* options)
{
L_SvgNodeHandle flatDocHandle = NULL;
// If the document is non-flat, flatten it, automatically calculating the size
L_BOOL isFlat = TRUE;
L_INT nRet = L_SvgIsFlatDocument(docHandle, &isFlat);
if (!isFlat)
L_SvgFlatDocument(docHandle, &flatDocHandle, NULL);
else
flatDocHandle = docHandle;
// If the document does not have a valid bounds, calculate it now automatically
L_SvgBounds bounds;
L_SvgGetBounds(flatDocHandle, &bounds, sizeof(L_SvgBounds));
if (!bounds.IsValid)
L_SvgCalculateBounds(flatDocHandle, FALSE);
// Now, render the document
L_SvgRenderDocument(hdc, flatDocHandle, options);
if(!isFlat)
L_SvgFreeNode(flatDocHandle);
}
LEADTOOLS will create internal data structures to speed up rendering. This data can be cached and re-used by using L_SvgBeginRenderOptimizeDocument and L_SvgEndRenderOptimizeDocument
If the L_SvgNodeHandle will be rendered once, it is recommended to leave the optimization as is. However, if the document will be rendeded many times, then it is recommended to cache this data to enhance the speed.
L_SvgBeginRenderOptimizeDocument may use extra system resources stored in the internal data. L_SvgEndRenderOptimizeDocument can be used to manually free this data at any time.
L_SvgBeginRenderOptimizeDocument and L_SvgEndRenderOptimizeDocument use an internal counter to track the state of the optimization. L_SvgBeginRenderOptimizeDocument increments this counter and L_SvgEndRenderOptimizeDocument decrements it, therefore the optimization is only performed when needed and any number of L_SvgBeginRenderOptimizeDocument and L_SvgEndRenderOptimizeDocument calls can be chained together without affecting the document.
This internal data will automatically be freed by L_SvgFreeNode regardless of the value of the counter.
To determine if the document has optimized render data, use L_SvgIsRenderOptimizedDocument.