←Select platform

SetFontNames Method

Summary
Sets the font names used in the final document.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public void SetFontNames( 
   string languageName, 
   string[] fontNames 
) 
- (BOOL)setFontNames:(NSArray<NSString *> *)fontNames  
         forLanguage:(LTOcrLanguage)language  
               error:(NSError **)error 
public void setFontNames(String languageName, 
                         String[] fontNames) 
void SetFontNames(  
   String^ languageName, 
   array<String^>^ fontNames 
)  
def SetFontNames(self,languageName,fontNames): 

Parameters

languageName
The language name. See remarks for more information.

fontNames
An array of six string values that contains the font names used in the final document.

Remarks

You can also use GetFontName and SetFontName to get or set the font names individually.

Use GetFontNames and SetFontNames 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 as follows. The following table shows the array index and the font description:

Index Description
0 The font used with proportional serif characters
1 The font used with proportional sans-serif characters
2 The font used with monospaced serif characters
3 The font used with monospaced sans-serif characters
4 The font used with ICR (hand-written) characters
5 The font used with MICR (check font) characters

The OcrCharacter.FontStyle member of each character returned in IOcrPage.GetRecognizedCharacters determines which font to use with the character. If the zone is ICR or MICR (the OcrZone.ZoneType member is OcrZoneType.Icr or OcrZoneType.Micr then the character will use the ICR or 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  languageName equals to "en" for English or "de" for German will change the default Latin fonts used in the final document. This is the equivalent of passing null (Nothing in VB).

If the OCR engine supports Asian languages, 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 (null), Japanese (ja), Korean (ko), Chinese (zh-Hans and zh-Hant) and Korean (ko). The following table lists the default fonts used for each language:

Language Fonts
Latin (all other languages) including languageName equals to null
Font Value
Proportional Serif Times New Roman
Proportional Sans-Serif Arial
Monospace Serif Courier New
Monospace Sans-Serif Arial
ICR Bookman Old Style
MICR Arial Unicode MS
Japanese (languageName equals to "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 (languageName equals to "zh-Hans" or "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 (languageName equals to "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 IOcrPage.GetRecognizedCharacters and IOcrPage.SetRecognizedCharacters to further change the character position and font size to create the final output document.

Example
C#
Java
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Ocr; 
using Leadtools.Forms.Common; 
using Leadtools.Document.Writer; 
using Leadtools.WinForms; 
 
public void DocumentFontsTest() 
{ 
   using (RasterCodecs codecs = new RasterCodecs()) 
   { 
      using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.LEAD)) 
      { 
         ocrEngine.Startup(codecs, null, null, LEAD_VARS.OcrLEADRuntimeDir); 
 
         IOcrDocumentManager ocrDocumentManager = ocrEngine.DocumentManager; 
 
         using (IOcrDocument ocrDocument = ocrEngine.DocumentManager.CreateDocument()) 
         { 
            // Add a page to OCR 
            IOcrPage ocrPage = ocrDocument.Pages.AddPage(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"), null); 
 
            ocrPage.AutoZone(null); 
            ocrPage.Recognize(null); 
 
            // Show the current fonts used to save default documents 
            Console.WriteLine("Saving use the following fonts:"); 
            ShowFonts(ocrDocumentManager); 
            ocrDocument.Save(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_DefaultFonts.pdf"), DocumentFormat.Pdf, null); 
 
            // Now change the fonts to something else 
            string[] newFonts = ocrDocumentManager.GetFontNames(null); 
 
            // Use Cambira for Proportional Serif font - instead of Times New Roman 
            newFonts[0] = "Cambria"; 
            // Use Calibri for Proportional Sans-serif font - instead of Arial 
            newFonts[1] = "Calibri"; 
            // Use Lucida Console for Monospace fonts (both Serif and Sans-serif) 
            newFonts[2] = "Lucida Console"; 
            newFonts[3] = "Lucida Console"; 
            // Leave the ICR and MICR fonts the same 
 
            ocrDocumentManager.SetFontNames(null, newFonts); 
 
            // Show the new fonts used to save default documents 
            Console.WriteLine("Saving use the following fonts:"); 
            ShowFonts(ocrDocumentManager); 
            ocrDocument.Save(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1_CustomFonts.pdf"), DocumentFormat.Pdf, null); 
         } 
      } 
   } 
} 
 
private static void ShowFonts(IOcrDocumentManager ocrDocumentManager) 
{ 
   // Get the default fonts 
   // The default fonts will be used for all Latin languages 
   string[] fonts = ocrDocumentManager.GetFontNames(null); 
 
   // This should return an array of 6 items, as follows: 
   Console.WriteLine("Proportional Serif font:        " + fonts[0]); 
   Console.WriteLine("Proportional Sans-serif font:   " + fonts[1]); 
   Console.WriteLine("Monospace Serif font:           " + fonts[2]); 
   Console.WriteLine("Monospace Sans-serif font:      " + fonts[3]); 
   Console.WriteLine("ICR (hand-written) font:        " + fonts[4]); 
   Console.WriteLine("MICR (Check) font:              " + fonts[5]); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
   public const string OcrLEADRuntimeDir = @"C:\LEADTOOLS23\Bin\Common\OcrLEADRuntime"; 
} 
 
import java.io.File; 
import java.io.IOException; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
 
import java.util.ArrayList; 
import java.util.List; 
 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.assertTrue; 
 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.document.writer.*; 
import leadtools.ocr.*; 
 
 
// // public void OcrDocumentManagerGetFontNamesExample() { 
//    final var LEAD_VARS_ImagesDir = "C:\\LEADTOOLS23\\Resources\\Images"; 
//    final var LEAD_VARS_OcrLEADRuntimeDir = "C:\\LEADTOOLS23\\Bin\\Common\\OcrLEADRuntime";   
//    ILeadStream leadStream = LeadStreamFactory.create(combine(LEAD_VARS_ImagesDir, "Ocr1.tif")); 
//    RasterCodecs codecs = new RasterCodecs(); 
       
//    // Add a page to OCR 
//    OcrEngine ocrEngine = OcrEngineManager.createEngine(OcrEngineType.LEAD); 
//    ocrEngine.startup(codecs, null, null, LEAD_VARS_OcrLEADRuntimeDir); 
//    assertTrue("OCR engine startup unsuccessful", ocrEngine.isStarted()); 
//    OcrDocumentManager ocrDocumentManager = ocrEngine.getDocumentManager(); 
//    OcrDocument ocrDocument = ocrEngine.getDocumentManager().createDocument(); 
//    OcrPage ocrPage = ocrDocument.getPages().addPage(leadStream, null); 
 
//    ocrPage.autoZone(null); 
//    ocrPage.recognize(null); 
 
//    // Show the current fonts used to save default documents 
//    System.out.println("Saving use the following fonts:"); 
//    ShowFonts(ocrDocumentManager); 
//    ocrDocument.save(combine(LEAD_VARS_ImagesDir, "Ocr1_DefaultFonts.pdf"), DocumentFormat.PDF, null); 
 
//    // Now change the fonts to something else 
//    ArrayList<String> newFonts = ocrDocumentManager.getFontNames(null); 
 
//    // Use Cambira for Proportional Serif font - instead of Times New Roman 
//    newFonts.set(0, "Cambria"); 
//    // Use Calibri for Proportional Sans-serif font - instead of Arial 
//    newFonts.set(1, "Calibri"); 
//    // Use Lucida Console for Monospace fonts (both Serif and Sans-serif) 
//    newFonts.set(2, "Lucida Console"); 
//    newFonts.set(3, "Lucida Console"); 
//    // Leave the ICR and MICR fonts the same 
 
//    ocrDocumentManager.setFontNames(null, newFonts); 
       
//    // Show the new fonts used to save default documents 
//    System.out.println("Saving use the following fonts:"); 
//    ShowFonts(ocrDocumentManager); 
//    ocrDocument.save(combine(LEAD_VARS_ImagesDir, "Ocr1_CustomFonts.pdf"), DocumentFormat.PDF, null); 
// } 
 
// private static void ShowFonts(OcrDocumentManager ocrDocumentManager) { 
//    // Get the default fonts 
//    // The default fonts will be used for all Latin languages 
//    ArrayList<String> fonts = ocrDocumentManager.getFontNames(null); 
 
//    // This should return an array of 6 items, as follows: 
//    System.out.println("Proportional Serif font:        " + fonts.get(0)); 
//    System.out.println("Proportional Sans-serif font:   " + fonts.get(1)); 
//    System.out.println("Monospace Serif font:           " + fonts.get(2)); 
//    System.out.println("Monospace Sans-serif font:      " + fonts.get(3)); 
//    System.out.println("ICR (hand-written) font:        " + fonts.get(4)); 
//    System.out.println("MICR (Check) font:              " + fonts.get(5)); 
// } 
Requirements

Target Platforms

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

Leadtools.Ocr Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.