L_SvgRenderDocument

#include "l_bitmap.h"

L_LTSVG_API L_INT L_SvgRenderDocument(hdc, flatDocHandle, options)

L_HDC hDC;

handle to the target device context

const L_SvgNodeHandle flatDocHandle;

SVG document handle

const L_SvgNodeHandle* options;

pointer to options structure

Renders the specified SVG document to the specified device context.

Parameter

Description

hdc Handle to a device context, such as a screen, to use as the display surface. The mapping mode of the device context must be MM_TEXT.
flatDocHandle Handle to the SVG document to be rendered.
options Options to use during rendering. Can be NULL.

Returns

SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

Support for SVG is only available in the Document and Medical Imaging toolkits.

For more information, refer to SVG Rendering.

This function will return an error if the specified SVG document is not flat or if it does not have valid physical (pixel) bounds.

If the options is NULL, then these default options will be used:

Member

Value

Bounds The current physical bounds of document.
ClipBounds Empty rectangle to render the whole document.
Transform Identity
UseBackgroundColor TRUE
BackgroundColor White color

Required DLLs and Libraries

LTSVG
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also
Functions: L_SvgRenderDocument, L_SvgBeginRenderOptimizeDocument, L_SvgEndRenderOptimizeDocument, L_SvgIsRenderOptimizedDocument, L_SvgIsRenderOptimizedDocument
Topics: Working with SVG
SVG Rendering

Example

This example will render an SVG document.

L_INT SvgDocumentRenderExample(L_SvgNodeHandle docHandle, HDC hdc, L_RECTD* dstBounds) 
{ 
   L_SvgNodeHandle flatDocHandle = docHandle; 
   // 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); 
   L_SvgBounds bounds; 
   L_SvgGetBounds(flatDocHandle, &bounds, sizeof(L_SvgBounds)); 
   if (!bounds.IsValid) 
      L_SvgCalculateBounds(flatDocHandle, FALSE); 
   // Optimize it for rendering to increase the speed 
   L_BOOL optimized = L_SvgIsRenderOptimizedDocument(flatDocHandle); 
   if(!optimized) 
      L_SvgBeginRenderOptimizeDocument(flatDocHandle); 
   // This is our paint code 
   // We will fit and center this SVG document in the client area of the picture box 
   if (dstBounds->width < 1 || dstBounds->height < 1) 
      return FAILURE; 
   // Create the transformation matrix 
   L_MATRIX transform; 
   L_Matrix_Identity(&transform); 
   L_SvgGetBounds(flatDocHandle, &bounds, sizeof(L_SvgBounds)); 
   L_RECTD srcBounds = bounds.Bounds; 
   // Calculate the zoom so we can fit 
   L_DOUBLE zoom = 1.0; 
   if (dstBounds->width > dstBounds->height) 
   { 
      zoom = dstBounds->width / srcBounds.width; 
      if ((zoom * srcBounds.height) > dstBounds->height) 
         zoom = dstBounds->height / srcBounds.height; 
   } 
   else 
   { 
      zoom = dstBounds->height / srcBounds.height; 
      if ((zoom * srcBounds.width) > dstBounds->width) 
         zoom = dstBounds->width / srcBounds.width; 
   } 
   // We have the zoom factor, set it in the transform 
   L_Matrix_Scale(&transform, zoom, zoom); 
   // Center 
   L_DOUBLE xOffset = (dstBounds->width - (zoom * srcBounds.width)) / 2.0; 
   L_DOUBLE yOffset = (dstBounds->height - (zoom * srcBounds.height)) / 2.0; 
   L_Matrix_Translate(&transform, xOffset, yOffset); 
   // Now setup the rendering options 
   L_SvgRenderOptions renderOptions = {0}; 
   renderOptions.StructSize = sizeof(L_SvgRenderOptions); 
   // All of the document 
   renderOptions.Bounds = srcBounds; 
   // Use our transform 
   renderOptions.Transform = transform; 
   // no clipping 
   L_RectD_FromLTRB(&renderOptions.ClipBounds, 0, 0, dstBounds->width, dstBounds->height); 
   // Fill the background with a white color 
   renderOptions.UseBackgroundColor = TRUE; 
   renderOptions.BackgroundColor = RGB(255,255,255); 
   // Render the document 
   nRet = L_SvgRenderDocument(hdc, flatDocHandle, &renderOptions); 
   if (nRet != SUCCESS) 
   { 
      if (!isFlat) 
         L_SvgFreeNode(flatDocHandle); 
      return nRet; 
   } 
   if (!optimized) 
      nRet = L_SvgEndRenderOptimizeDocument(flatDocHandle); 
   if(!isFlat) 
      L_SvgFreeNode(flatDocHandle); 
   return nRet; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS SVG C API Help