Products | Support | Email a link to this topic. | Send comments on this topic. | Back to Introduction - All Topics | Help Version 19.0.6.9
|
Leadtools.Forms.Ocr Assembly > Leadtools.Forms.Ocr Namespace > IOcrDocumentManager Interface : GetFontName Method |
string GetFontName( string languageName, OcrDocumentFontType fontType )
'Declaration
Function GetFontName( _ ByVal languageName As String, _ ByVal fontType As OcrDocumentFontType _ ) As String
'Usage
Dim instance As IOcrDocumentManager Dim languageName As String Dim fontType As OcrDocumentFontType Dim value As String value = instance.GetFontName(languageName, fontType)
string GetFontName( string languageName, OcrDocumentFontType fontType )
- (nullable NSString *)fontNameForLanguage:(LTOcrLanguage)language fontType:(LTOcrDocumentFontType)fontType error:(NSError **)error
public String getFontName(String languageName, OcrDocumentFontType fontType)
function Leadtools.Forms.Ocr.IOcrDocumentManager.GetFontName( languageName , fontType )
String^ GetFontName( String^ languageName, OcrDocumentFontType fontType )
You can also use GetFontNames and SetFontNames to get or set the font names using an array.
Use GetFontName and 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 as follows: description:
OcrDocumentFontType | Description |
---|---|
OcrDocumentFontType.ProportionalSerif | The font used with proportional serif characters |
OcrDocumentFontType.ProportionalSansSerif | The font used with proportional sans-serif characters |
OcrDocumentFontType.FixedSerif | The font used with monospaced serif characters |
OcrDocumentFontType.FixedSansSerif | The font used with monospaced sans-serif characters |
OcrDocumentFontType.MICR | 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.Micrthen 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 Visual Basic).
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 |
|
||||||||||||||
Japanese (languageName equals to "ja") |
|
||||||||||||||
Chinese (languageName equals to "zh-Hans" or "zh-Hant") |
|
||||||||||||||
Korean (languageName equals to "ko") |
|
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.
Imports Leadtools Imports Leadtools.Codecs Imports Leadtools.Forms.Ocr Imports Leadtools.Forms Imports Leadtools.Forms.DocumentWriters Imports Leadtools.WinForms <TestMethod> Public Sub DocumentFontsTest() Using codecs As New RasterCodecs() Using ocrEngine As IOcrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, False) ocrEngine.Startup(codecs, Nothing, Nothing, LEAD_VARS.OcrAdvantageRuntimeDir) Dim ocrDocumentManager As IOcrDocumentManager = ocrEngine.DocumentManager Using ocrDocument As IOcrDocument = ocrEngine.DocumentManager.CreateDocument() ' Add a page to OCR Dim ocrPage As IOcrPage = ocrDocument.Pages.AddPage(Path.Combine(LEAD_VARS.ImagesDir, "Ocr1.tif"), Nothing) ocrPage.AutoZone(Nothing) ocrPage.Recognize(Nothing) ' 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, Nothing) ' Now change the fonts to something else Dim newFonts As String() = ocrDocumentManager.GetFontNames(Nothing) ' 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(Nothing, 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, Nothing) End Using End Using End Using End Sub Private Shared Sub ShowFonts(ocrDocumentManager As IOcrDocumentManager) ' Get the default fonts ' The default fonts will be used for all Latin languages Dim fonts As String() = ocrDocumentManager.GetFontNames(Nothing) ' 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)) End Sub Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" Public Const OcrAdvantageRuntimeDir As String = "C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime" End Class
using Leadtools; using Leadtools.Codecs; using Leadtools.Forms.Ocr; using Leadtools.Forms; using Leadtools.Forms.DocumentWriters; using Leadtools.WinForms; public void DocumentFontsTest() { using (RasterCodecs codecs = new RasterCodecs()) { using (IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Advantage, false)) { ocrEngine.Startup(codecs, null, null, LEAD_VARS.OcrAdvantageRuntimeDir); 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:\Users\Public\Documents\LEADTOOLS Images"; public const string OcrAdvantageRuntimeDir = @"C:\LEADTOOLS 19\Bin\Common\OcrAdvantageRuntime"; }