L_AnnGetDistance2

Summary

Gets the length of each ruler that makes up an object, and the total length of all rulers. It works for ANNOBJECT_RULER, ANNOBJECT_PROTRACTOR, ANNOBJECT_CROSSPRODUCT, and ANNOBJECT_POLYRULER annotation objects.

Syntax

#include "l_bitmap.h"

L_LTANN_API L_INT L_AnnGetDistance2(hObject, puCount, pDistance, pTotalDistance, uStructSize)

Parameters

HANNOBJECT hObject

Handle to the annotation object.

L_UINT *puCount

Address of an unsigned integer to be updated with the total number of rulers that make up the object. This indicates the size of the pDistance array (number of total rulers).

pANNSMARTDISTANCE pDistance

Pointer to array of ANNSMARTDISTANCE elements. You must allocate an array that is (*puCount) elements in length. Pass NULL if you do not want this information.

pANNSMARTDISTANCE pTotalDistance

Address of an ANNSMARTDISTANCE variable. Returns the total length of all rulers that make up the annotation object. Pass NULL if you do not want this information.

L_UINT uStructSize

Size of the ANNSMARTDISTANCE structure. Use sizeof(ANNSMARTDISTANCE).

Returns

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

Comments

This function works only for the following objects:

The ANNOBJECT_POLYRULER object is composed of a variable number of rulers. The other ruler objects are composed of a predetermined number of rulers, as follows:

ANNOBJECT_RULER always has one distance

ANNOBJECT_PROTRACTOR and ANNOBJECT_CROSSPRODUCT always have two distances

ANNOBJECT_POLYRULER can have from one to any number of distances

To use this function with the ANNOBJECT_POLYRULER, call it twice, as shown in the following code excerpt. For the first call, pass NULL for pDistance and pTotalDistance. This Returns the total number of rulers that make up the object. Allocate the appropriately sized array, and then call the function again.

L_UINT uCount; 
pANNSMARTDISTANCE pDistance; 
ANNSMARTDISTANCE TotalDistance; 
L_AnnGetDistance2(hObject, &uCount, NULL, NULL, sizeof(ANNSMARTDISTANCE)); 
pDistance = (pANNSMARTDISTANCE)malloc(uCount * sizeof(ANNSMARTDISTANCE)); 
L_AnnGetDistance2(hObject, &uCount, pDistance, &TotalDistance, sizeof(ANNSMARTDISTANCE)); 

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

This sample calls L_AnnGetDistance2 on the object. It displays the number of rulers and the length of each ruler.

L_TCHAR* annGetObjectString(L_UINT uObjectType) 
{ 
   L_TCHAR* pszType = TEXT("Unknown"); 
   switch (uObjectType) 
   { 
   case ANNOBJECT_CONTAINER: 
      pszType = TEXT("ANNOBJECT_CONTAINER"); 
      break; 
 
   case ANNOBJECT_POINTER: 
      pszType = TEXT("ANNOBJECT_POINTER"); 
      break; 
 
   case ANNOBJECT_AUDIO: 
      pszType = TEXT("ANNOBJECT_AUDIO"); 
      break; 
 
   case ANNOBJECT_BUTTON: 
      pszType = TEXT("ANNOBJECT_BUTTON"); 
      break; 
 
   case ANNOBJECT_ELLIPSE: 
      pszType = TEXT("ANNOBJECT_ELLIPSE"); 
      break; 
 
   case ANNOBJECT_FREEHAND: 
      pszType = TEXT("ANNOBJECT_FREEHAND"); 
      break; 
 
   case ANNOBJECT_HILITE: 
      pszType = TEXT("ANNOBJECT_HILITE"); 
      break; 
 
   case ANNOBJECT_HOTSPOT: 
      pszType = TEXT("ANNOBJECT_HOTSPOT"); 
      break; 
 
   case ANNOBJECT_LINE: 
      pszType = TEXT("ANNOBJECT_LINE"); 
      break; 
 
   case ANNOBJECT_NOTE: 
      pszType = TEXT("ANNOBJECT_NOTE"); 
      break; 
 
   case ANNOBJECT_POLYGON: 
      pszType = TEXT("ANNOBJECT_POLYGON"); 
      break; 
 
   case ANNOBJECT_POLYLINE: 
      pszType = TEXT("ANNOBJECT_POLYLINE"); 
      break; 
 
   case ANNOBJECT_RECT: 
      pszType = TEXT("ANNOBJECT_RECT"); 
      break; 
 
   case ANNOBJECT_REDACT: 
      pszType = TEXT("ANNOBJECT_REDACT"); 
      break; 
 
   case ANNOBJECT_STAMP: 
      pszType = TEXT("ANNOBJECT_STAMP"); 
      break; 
 
   case ANNOBJECT_TEXT: 
      pszType = TEXT("ANNOBJECT_TEXT"); 
      break; 
 
   case ANNOBJECT_AUTOMATION: 
      pszType = TEXT("ANNOBJECT_AUTOMATION"); 
      break; 
 
   case ANNOBJECT_RULER: 
      pszType = TEXT("ANNOBJECT_RULER"); 
      break; 
 
   case ANNOBJECT_CROSSPRODUCT: 
      pszType = TEXT("ANNOBJECT_CROSSPRODUCT"); 
      break; 
 
   case ANNOBJECT_POINT: 
      pszType = TEXT("ANNOBJECT_POINT"); 
      break; 
 
   case ANNOBJECT_PROTRACTOR: 
      pszType = TEXT("ANNOBJECT_PROTRACTOR"); 
      break; 
 
   case ANNOBJECT_VIDEO: 
      pszType = TEXT("ANNOBJECT_VIDEO"); 
      break; 
 
   case ANNOBJECT_PUSHPIN: 
      pszType = TEXT("ANNOBJECT_PUSHPIN"); 
      break; 
 
   case ANNOBJECT_FREEHANDHOTSPOT: 
      pszType = TEXT("ANNOBJECT_FREEHANDHOTSPOT"); 
      break; 
 
   case ANNOBJECT_CURVE: 
      pszType = TEXT("ANNOBJECT_CURVE"); 
      break; 
 
   case ANNOBJECT_CURVECLOSED: 
      pszType = TEXT("ANNOBJECT_CURVECLOSED"); 
      break; 
 
   case ANNOBJECT_ENCRYPT: 
      pszType = TEXT("ANNOBJECT_ENCRYPT"); 
      break; 
 
   case ANNOBJECT_TEXTPOINTER: 
      pszType = TEXT("ANNOBJECT_TEXTPOINTER"); 
      break; 
 
   case ANNOBJECT_POLYRULER: 
      pszType = TEXT("ANNOBJECT_POLYRULER"); 
      break; 
   } 
   return pszType; 
} 
 
L_TCHAR* annGetRulerUnitString(L_UINT uRulerUnit) 
{ 
   L_TCHAR* pszRulerUnit = TEXT("Unknown"); 
 
   switch (uRulerUnit) 
   { 
   case ANNUNIT_INCHES: 
      pszRulerUnit = TEXT("ANNUNIT_INCHES"); 
      break; 
 
   case ANNUNIT_FEET: 
      pszRulerUnit = TEXT("ANNUNIT_FEET"); 
      break; 
 
   case ANNUNIT_YARDS: 
      pszRulerUnit = TEXT("ANNUNIT_YARDS"); 
      break; 
 
   case ANNUNIT_MICROMETERS: 
      pszRulerUnit = TEXT("ANNUNIT_MICROMETERS"); 
      break; 
 
   case ANNUNIT_MILLIMETERS: 
      pszRulerUnit = TEXT("ANNUNIT_MILLIMETERS"); 
      break; 
 
   case ANNUNIT_CENTIMETERS: 
      pszRulerUnit = TEXT("ANNUNIT_CENTIMETERS"); 
      break; 
 
   case ANNUNIT_METERS: 
      pszRulerUnit = TEXT("ANNUNIT_METERS"); 
      break; 
 
   case ANNUNIT_TWIPS: 
      pszRulerUnit = TEXT("ANNUNIT_TWIPS"); 
      break; 
 
   case ANNUNIT_POINTS: 
      pszRulerUnit = TEXT("ANNUNIT_POINTS"); 
      break; 
 
   case ANNUNIT_PIXELS: 
      pszRulerUnit = TEXT("ANNUNIT_PIXELS"); 
      break; 
 
   case ANNUNIT_SMART_METRIC: 
      pszRulerUnit = TEXT("ANNUNIT_SMART_METRIC"); 
      break; 
 
   case ANNUNIT_SMART_ENGLISH: 
      pszRulerUnit = TEXT("ANNUNIT_SMART_ENGLISH"); 
      break; 
   } 
   return pszRulerUnit; 
} 
 
// Formats a string with smart distance information 
// uLength is the length of the input string 
L_VOID annDumpSmartDistance(ANNSMARTDISTANCE sdSmartDistance, L_TCHAR* pszSmartDistance, L_UINT* puLength) 
{ 
   L_TCHAR* pszRulerUnit; 
   L_TCHAR* pszSmartUnit; 
   L_TCHAR  szMsg[200]; 
   L_UINT   uLength; 
 
   pszRulerUnit = annGetRulerUnitString(sdSmartDistance.uRulerUnit); 
   pszSmartUnit = annGetRulerUnitString(sdSmartDistance.uSmartUnit); 
 
   _stprintf_s(szMsg, TEXT("[%-10f] uRulerUnit[%-15s] uSmartUnit[%-15s]\n"), 
      sdSmartDistance.dDistance, 
      pszRulerUnit, 
      pszSmartUnit); 
 
   uLength = lstrlen(szMsg) * sizeof(L_TCHAR); 
 
   if (pszSmartDistance) 
      lstrcpy(pszSmartDistance, szMsg); 
 
   if (puLength) 
      *puLength = uLength; 
} 
 
L_INT AnnGetDistance2Example(HANNOBJECT hObject) 
{ 
   L_UINT            uCount = 0; 
   L_TCHAR*          pszObject; 
   L_UINT            uType = 0; 
   L_INT             nRet = SUCCESS; 
   L_TCHAR           szMsg[500]; 
   ANNSMARTDISTANCE  sdTotalDistance; 
   pANNSMARTDISTANCE pDistance = NULL; 
 
   nRet = L_AnnGetType(hObject, &uType); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   pszObject = annGetObjectString(uType); 
   nRet = L_AnnGetDistance2(hObject, &uCount, NULL, &sdTotalDistance, sizeof(ANNSMARTDISTANCE)); 
   if (nRet != SUCCESS) 
   { 
      wsprintf(szMsg, TEXT("Error: L_AnnGetDistance2 Failed[%d]: [%d]%10s"), 
         nRet, uType, pszObject); 
      _tprintf(_T("%s"), szMsg); 
      return nRet; 
   } 
 
   // We know the number of rulers 
   pDistance = (pANNSMARTDISTANCE)malloc(uCount * sizeof(ANNSMARTDISTANCE)); 
   if (!pDistance) 
      _tprintf(_T("%s"), TEXT("Error: Not enough memory")); 
 
   nRet = L_AnnGetDistance2(hObject, &uCount, pDistance, &sdTotalDistance, sizeof(ANNSMARTDISTANCE)); 
   if (nRet != SUCCESS) 
   { 
      wsprintf(szMsg, TEXT("Error: L_AnnGetDistance2 Failed[%d]: [%d]%10s"), 
         nRet, uType, pszObject); 
      _tprintf(_T("%s"), szMsg); 
      return nRet; 
   } 
 
   free(pDistance); 
   return SUCCESS; 
} 

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

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