L_SvgEnumerateElements

Summary

Enumerates the elements (nodes) of the specified SVG document with the specified options.

Syntax

#include "l_bitmap.h"

L_LTSVG_API L_INT L_SvgEnumerateElements(node, direction, callback, userData)

Parameters

const L_SvgNodeHandle node

Handle referencing the SVG document to enumerate.

L_SvgEnumerateDirection direction

The direction to use when enumerating SVG elements (nodes).

L_SvgEnumerateCallback callback

Callback function for processing each enumerated SVG element. Use the function pointer as the value of this parameter.

L_SvgEnumerateElements calls this callback function for each SVG element. The callback function must adhere to the function prototype described in L_SvgEnumerateCallback Function.

L_VOID* userData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.

To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own userData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure. If the additional parameters are not needed, you can pass NULL in this parameter.

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.

Use this function to enumerate the elements of an SVG document with the specified options.

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

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

This example will use L_SvgEnumerateElements to save out each xlink:href element found in an SVG document.

// SVG enumerate callback function 
L_INT EXT_FUNCTION SvgEnumerateElementsCallback(L_SvgNodeHandle node, L_VOID* userData) 
{ 
   static int count = 0; 
   UNREFERENCED_PARAMETER(userData); 
 
   L_TCHAR* hRef = NULL; 
   L_INT ret = L_SvgGetElementAttributeValue(node, L_TEXT("xlink:href"), &hRef); 
   if(ret != SUCCESS || hRef == NULL) 
      return ret; 
   else 
   { 
      L_TCHAR msg[2048] = {0}; 
      L_TCHAR filename[L_MAXPATH]; 
      count++; 
      wsprintf(filename, L_TEXT("%d.png"), count); 
      wsprintf(msg, L_TEXT("xlink:href found - saved to: %s\n"), filename); 
      wprintf(msg); 
      L_SvgDataUri dataUri = { 0 }; 
      ret = L_SvgParseDataUri(hRef, &dataUri, sizeof(dataUri)); 
      ret = L_SvgDecodeDataUriToFile(&dataUri, filename); 
   } 
 
   if(hRef) 
      L_SvgFreeMemory(hRef); 
 
   return SUCCESS; 
}; 
 
L_INT SvgEnumerateElementsExample(L_VOID) 
{ 
   L_INT ret = SUCCESS; 
   L_TCHAR srcFileName[L_MAXPATH] = MAKE_IMAGE_PATH(TEXT("Leadtools.pdf")); 
 
   // get the number of pages 
   FILEINFO fileInfo = {0}; 
   fileInfo.uStructSize = sizeof(FILEINFO); 
   ret = L_FileInfo(srcFileName, &fileInfo, sizeof(FILEINFO), FILEINFO_TOTALPAGES, NULL); 
   if(ret == SUCCESS) 
   { 
      // Load this page as SVG 
      LOADSVGOPTIONS loadSvgOptions = {0}; 
      loadSvgOptions.uStructSize = sizeof(LOADSVGOPTIONS); 
      loadSvgOptions.uFlags = L_LOADSVGOPTIONS_ALLOWPOLYLINETEXT; 
 
      LOADFILEOPTION loadOptions = {0}; 
      loadOptions.uStructSize = sizeof(LOADFILEOPTION); 
      loadOptions.PageNumber = 1; 
      ret = L_LoadSvg(srcFileName, &loadSvgOptions, &loadOptions); 
      if(ret == SUCCESS) 
      { 
         L_SvgNodeHandle docHandle = loadSvgOptions.SvgHandle; 
         L_SvgNodeHandle flatDocHandle = NULL; 
 
         // Enumerate requires a flat document, so check for that 
         L_BOOL isFlat = TRUE; 
         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); 
 
         wprintf(L_TEXT("Begin Enumerate Elements\n")); 
         L_SvgBeginUpdateDocument(flatDocHandle); 
         wprintf(L_TEXT("******************************************************************\n")); 
         ret = L_SvgEnumerateElements(flatDocHandle, L_SvgEnumerateDirection_TopToBottom, SvgEnumerateElementsCallback, NULL); 
         wprintf(L_TEXT("******************************************************************\n")); 
         wprintf(L_TEXT("End Enumerate Elements\n")); 
         L_SvgEndUpdateDocument(flatDocHandle); 
 
         if(!isFlat) 
            L_SvgFreeNode(flatDocHandle); 
 
         L_SvgFreeNode(docHandle); 
      } 
   } 
   return ret; 
} 

Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

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