L_OcrDocumentManager_GetFontName

#include "ltocr.h"

L_LTOCR_API L_INT EXT_FUNCTION L_OcrDocumentManager_GetFontName(documentManager, language, documentFontType, value, count)

L_OcrDocumentManager documentManager; handle to the OCR engine document manager
L_OcrLanguage language; language ID
L_OcrDocumentFontType documentFontType; the type of font to get
L_TCHAR* value; allocated string buffer to hold the font name
L_UINT count; number of the allocated string buffer elements

Gets the specific type of font used in the final document.

Parameter Description
documentManager Handle to the OCR engine document manager.
language language ID
documentFontType The type of font to get.
value Allocated string buffer to hold the font name.
count Number of the allocated string buffer elements, this should be _countof(value).

Returns

SUCCESS The function was successful.
< 1

An error occurred. Refer to Return Codes.

Comments

Use L_OcrDocumentManager_GetFontName and L_OcrDocumentManager_SetFontName to get/set the fonts used in the final recognized document (PDF, DOC, HTML, etc). The fonts will not be used when the final document format is text.

The OCR engine uses six different fonts when creating the final output document. For more information, refer to L_OcrDocumentFontType.

The L_OcrCharacter.FontStyles member of each character returned in L_OcrPage_GetRecognizedCharacters determines which font to use with the character. If the zone is MICR (the L_OcrZone.ZoneType member is L_OcrZoneType.MICR) then the character will use the MICR fonts accordingly.

The OCR engine keeps a list of fonts for some languages, for example all the Latin languages currently use the same font. So passing language equals to L_OcrLanguage_EN for English or L_OcrLanguage_DE for German will change the default Latin fonts used in the final document.

If the OCR engine has Asian languages enabled, then each language will have its own font sets and you can get/set these fonts individually. Currently, the LEADTOOLS OCR toolkits supports individual fonts for Latin, Japanese, Korean and Chinese (zh-Hans and zh-Hant). The following table lists the default fonts used for each language:

Language Fonts
Latin (all other languages) including language equals to L_OcrLanguage_None
Font Value
Proportional Serif Times New Roman
Proportional Sans-Serif Arial
Monospace Serif Courier New
Monospace Sans-Serif Courier New
ICR Bookman Old Style
MICR Arial Unicode MS
Japanese (language equals to L_OcrLanguage_JA)
Font Value
Proportional Serif MS PMincho
Proportional Sans-Serif MS PGothic
Monospace Serif MS Gothic
Monospace Sans-Serif SimSun
ICR MS Gothic
MICR SimSun
Chinese (language equals to L_OcrLanguage_ZH_HANS or L_OcrLanguage_ZH_HANT)
Font Value
Proportional Serif SimSun
Proportional Sans-Serif SimHei
Monospace Serif Hei Simplified
Monospace Sans-Serif SimSun
ICR Hei Simplified
MICR SimSun
Korean (language equals to L_OcrLanguage_KO)
Font Value
Proportional Serif Gungsuh
Proportional Sans-Serif Gulim
Monospace Serif Dotum
Monospace Sans-Serif Gungsuh
ICR Dotum
MICR Gungsuh

Note that changing the fonts is not recommended in most cases, the character position and size is calculated based on the default fonts even if the user changes the fonts before the recognition process. After the changing the fonts, it might be required to use L_OcrPage_GetRecognizedCharacters and L_OcrPage_SetRecognizedCharacters to further change the character position and font size to create the final output document.

Required DLLs and Libraries

LTOCR
For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.
See Also
Functions: L_OcrDocumentManager_CreateDocument, L_OcrDocumentManager_AppendDocumentFiles, L_OcrDocumentManager_AppendDocuments, L_OcrDocumentManager_GetFormatOptions, L_OcrDocumentManager_SetFormatOptions, L_OcrDocumentManager_SetFontName
Topics: Programming with LEADTOOLS OCR Module - LEAD Engine
Starting and Shutting Down the OCR Engine
Recognizing OCR Pages

Example

void ShowFonts(L_OcrDocumentManager ocrDocumentManager) 
{ 
   // The OCR engine uses six different fonts when creating the final output document 
   const int engineFonts = 6; 
   L_TCHAR fontName[80] = {0}; 
   for(int fontNum = 0; fontNum < engineFonts; fontNum++)  
   { 
      // Get the default font name for each type 
      L_OcrDocumentManager_GetFontName(ocrDocumentManager, L_OcrLanguage_EN, (L_OcrDocumentFontType)fontNum, fontName, _countof(fontName)); 
 
      switch (fontNum) 
      { 
      case L_OcrDocumentFontType_ProportionalSerif: 
         std::wcout << L"Proportional Serif font:        " << fontName << std::endl; 
         break; 
      case L_OcrDocumentFontType_ProportionalSansSerif: 
         std::wcout << L"Proportional Sans-serif font:   " << fontName << std::endl; 
         break; 
      case L_OcrDocumentFontType_FixedSerif: 
         std::wcout << L"Monospace Serif font:           " << fontName << std::endl; 
         break; 
      case L_OcrDocumentFontType_FixedSansSerif: 
         std::wcout << L"Monospace Sans-serif font:      " << fontName << std::endl; 
         break; 
      case L_OcrDocumentFontType_ICR: 
         std::wcout << L"ICR (hand-written) font:        " << fontName << std::endl; 
         break; 
      case L_OcrDocumentFontType_MICR: 
         std::wcout << L"MICR (Check) font:              " << fontName << std::endl; 
         break; 
      } 
   } 
} 
 
L_INT L_OcrDocumentManager_GetFontNameExample() 
{ 
   BITMAPHANDLE bitmap = { 0 }; 
   L_OcrEngine ocrEngine = NULL; 
   L_OcrPage ocrPage = NULL; 
   L_OcrDocumentManager ocrDocumentManager = NULL; 
   L_OcrDocument ocrDocument = NULL; 
   L_INT retCode = SUCCESS; 
 
   retCode = L_OcrEngineManager_CreateEngine(L_OcrEngineType_Advantage, &ocrEngine); 
   if(retCode != SUCCESS) 
      return retCode; 
 
   // Start the engine using default parameters 
   L_OcrEngine_Startup(ocrEngine, NULL, OCR_ADVANTAGE_RUNTIME_DIR); 
 
   // Load an image to process 
   L_LoadBitmap(MAKE_IMAGE_PATH(L_TEXT("Ocr1.tif")), &bitmap, sizeof(BITMAPHANDLE), 0, ORDER_RGB, NULL, NULL); 
 
   // Add the image to the OCR page  
   L_OcrPage_FromBitmap(ocrEngine, &ocrPage, &bitmap, L_OcrBitmapSharingMode_AutoFree, NULL, NULL); 
 
   // Transfer ownership to OCR page 
   bitmap.Flags.Allocated = 0; 
 
   // Find text in the page 
   L_OcrPage_AutoZone(ocrPage, NULL, NULL); 
 
   // Process page to find text 
   L_OcrPage_Recognize(ocrPage, NULL, NULL); 
 
   // Get the document manager to create a document 
   L_OcrEngine_GetDocumentManager(ocrEngine, &ocrDocumentManager); 
 
   // Create an OCR document 
   L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
 
   // Add the page to a document for output to file 
   L_OcrDocument_AddPage(ocrDocument, ocrPage); 
 
   // Show the current fonts used to save default documents 
   std::cout << "Saving use the following fonts:\n"; 
   ShowFonts(ocrDocumentManager); 
 
   L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Ocr1_DefaultFonts.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL); 
 
   // Now change the fonts to something else 
   // use cambira for proportional serif font - instead of times new roman 
   L_OcrDocumentManager_SetFontName(ocrDocumentManager, L_OcrLanguage_EN, L_OcrDocumentFontType_ProportionalSerif, L_TEXT("Cambria")); 
 
   // Use Calibri for Proportional Sans-serif font - instead of Arial 
   L_OcrDocumentManager_SetFontName(ocrDocumentManager, L_OcrLanguage_EN, L_OcrDocumentFontType_ProportionalSansSerif, L_TEXT("Calibri")); 
 
   // Use Lucida Console for Monospace fonts (both Serif and Sans-serif) 
   L_OcrDocumentManager_SetFontName(ocrDocumentManager, L_OcrLanguage_EN, L_OcrDocumentFontType_FixedSerif, L_TEXT("Courier")); 
   L_OcrDocumentManager_SetFontName(ocrDocumentManager, L_OcrLanguage_EN, L_OcrDocumentFontType_FixedSansSerif, L_TEXT("Lucida Console")); 
 
   // Leave the ICR and MICR fonts the same 
 
   // Show the new fonts used to save default documents 
   std::cout << "Saving use the following fonts:\n"; 
   ShowFonts(ocrDocumentManager); 
 
   //Destroy and re-create document to save a fresh PDF 
   L_OcrDocument_Destroy(ocrDocument); 
   L_OcrDocumentManager_CreateDocument(ocrDocumentManager, &ocrDocument, L_OcrCreateDocumentOptions_AutoDeleteFile, NULL); 
   L_OcrDocument_AddPage(ocrDocument, ocrPage); 
 
   //Now save the new document 
   L_OcrDocument_Save(ocrDocument, MAKE_IMAGE_PATH(L_TEXT("Ocr1_CustomFonts.pdf")), DOCUMENTFORMAT_PDF, NULL, NULL); 
 
   //CLEANUP 
   if(bitmap.Flags.Allocated) 
      L_FreeBitmap(&bitmap); 
 
   if(ocrPage != NULL) 
      L_OcrPage_Destroy(ocrPage); 
 
   if(ocrDocument != NULL) 
      L_OcrDocument_Destroy(ocrDocument); 
 
   if(ocrEngine != NULL) 
      L_OcrEngine_Destroy(ocrEngine); 
 
   return retCode; 
} 

Help Version 20.0.2018.2.22
Products | Support | Contact Us | Copyright Notices
© 1991-2018 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS OCR Module - LEAD Engine C API Help