L_SvgRenderDocument

#include "l_bitmap.h"

L_LTSVG_API L_INT L_SvgRenderDocument(hdc, flatDocHandle, options)

Renders the specified SVG document to the specified device context.

Parameters

L_HDC 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.

const L_SvgNodeHandle flatDocHandle

Handle to the SVG document to be rendered.

const L_SvgRenderOptions* options

Options to use during rendering. Can be NULL.

Returns

Value Meaning
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

Platforms

Win32, x64.

See Also

Functions

Topics

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); 
   // 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); 
   renderOptions.Bounds = srcBounds; 
 
   // 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 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS SVG C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.