Fonts Property

Applies to TestComplete 15.69, last modified on November 13, 2024
This property is provided by the legacy OCR plugin. In version 12.60, the plugin was replaced with the new Optical Character Recognition plugin powered by Google Cloud Vision API. To learn more, see Optical Character Recognition.
The legacy OCR plugin was removed from TestComplete in version 12.60. If you need to use objects, methods, and properties provided by the legacy plugin with this version of TestComplete, please contact our Customer Care team. The legacy OCR plugin was restored in TestComplete version 14.0. To use the objects, methods, and properties with this or later TestComplete version, you need to install and enable the plugin manually.

Description

The OCROptions.Fonts property lets you get a FontCollection object to configure a custom collection of fonts and their attributes to be used during character recognition. To learn more about the role of fonts for character recognition in TestComplete, see Optical Character Recognition.

Declaration

OCROptionsObj.Fonts

Read-Only Property A FontCollection object
OCROptionsObj An expression, variable or parameter that specifies a reference to an OCROptions object

Applies To

The property is applied to the following object:

Property Value

A FontCollection object.

Example

The following example obtains information on the font that is currently used in Windows Notepad and adds the font to the font collection to be used during the character recognition. After that, it recognizes the text written in Windows Notepad and posts it to the test log.

JavaScript, JScript

function OCROptionsSample()
{
  // Obtains the Notepad window
  var notepad = Sys.Process("notepad");
  var Window = notepad.Window("Notepad", "*").Window("Edit");

  // Captures an image of the Notepad window
  var Rect = Window.Picture();
  Log.Picture(Rect, "Region with the text to be recognized");

  // Creates an OCR object
  var OCRObj = OCR.CreateObject(Rect);

  // Calls the Font dialog and obtains the font currently used in Notepad
  notepad.Window("Notepad", "*").MainMenu.Click("Format|Font...");
  var FWindow = notepad.Window("*", "Font");
  var FontName = FWindow.Window("ComboBox", "", 1).wText;
  var FontSize = aqConvert.VarToInt(FWindow.Window("ComboBox", "", 3).wText);
  Log.Message("The " + FontName + " " + aqConvert.IntToStr(FontSize) + " font is used");
  FWindow.Window("Button", "OK").ClickButton();

  // Creates an OCROptions object
  var OCROptions = OCRObj.CreateOptions();
  // Adds the font to the font collection to be used for the recognition
  NewFont = OCROptions.Fonts.Add();
  NewFont.Name = FontName;
  NewFont.Sizes.Add(FontSize);

  // Recognizes the text and posts it to the test log
  Log.Message("Recognized characters:", OCRObj.GetText(OCROptions));

}

Python

def OCROptionsSample():
  # Obtains the Notepad window
  notepad = Sys.Process("notepad")
  Window = notepad.Window("Notepad", "*").Window("Edit")
  # Captures an image of the Notepad window
  Rect = Window.Picture()
  Log.Picture(Rect, "Region with the text to be recognized")
  # Creates an OCR object
  OCRObj = OCR.CreateObject(Rect)
  # Calls the Font dialog and obtains the font currently used in Notepad
  notepad.Window("Notepad", "*").MainMenu.Click("Format|Font...")
  FWindow = notepad.Window("*", "Font")
  FontName = FWindow.Window("ComboBox", "", 1).wText
  FontSize = aqConvert.VarToInt(FWindow.Window("ComboBox", "", 3).wText)
  Log.Message("The " + FontName + " " + aqConvert.IntToStr(FontSize) + " font is used")
  FWindow.Window("Button", "OK").ClickButton()
  # Creates an OCROptions object
  OCROptions = OCRObj.CreateOptions()
  # Adds the font to the font collection to be used for the recognition
  NewFont = OCROptions.Fonts.Add()
  NewFont.Name = FontName
  NewFont.Sizes.Add(FontSize)
  # Recognizes the text and posts it to the test log
  Log.Message("Recognized characters:", OCRObj.GetText(OCROptions))

VBScript

Sub OCROptionsSample

  ' Obtains the Notepad window
  Set notepad = Sys.Process("notepad")
  Set Window = notepad.Window("Notepad", "*").Window("Edit")

  ' Captures an image of the Notepad window
  Set Rect = Window.Picture
  Call Log.Picture(Rect, "Region with the text to be recognized")

  ' Creates an OCR object
  Set OCRObj = OCR.CreateObject(Rect)

  ' Calls the Font dialog and obtains the font currently used in Notepad
  Call notepad.Window("Notepad", "*").MainMenu.Click("Format|Font...")
  Set FWindow = notepad.Window("*", "Font")
  FontName = FWindow.Window("ComboBox", "", 1).wText
  FontSize = aqConvert.VarToInt(FWindow.Window("ComboBox", "", 3).wText)
  Log.Message("The " & FontName & " " & aqConvert.IntToStr(FontSize) & " font is used")
  FWindow.Window("Button", "OK").ClickButton

  ' Creates an OCROptions object
  Set OCROptions = OCRObj.CreateOptions
  ' Adds the font to the font collection to be used for the recognition
  Set NewFont = OCROptions.Fonts.Add
  NewFont.Name = FontName
  NewFont.Sizes.Add(FontSize)

  ' Recognizes the text and posts it to the test log
  Call Log.Message("Recognized characters:", OCRObj.GetText(OCROptions))

End Sub

DelphiScript

function OCROptionsSample();
var
  notepad, Window, Rect, OCRObj, OCROptions, FWindow, NewFont: OleVariant;
  FontName: string;
  FontSize: integer;
begin
  // Obtains the Notepad window
  notepad := Sys.Process('notepad');
  Window := notepad.Window('Notepad', '*').Window('Edit');

  // Captures an image of the Notepad window
  Rect := Window.Picture;
  Log.Picture(Rect, 'Region with the text to be recognized');

  // Creates an OCR object
  OCRObj := OCR.CreateObject(Rect);

  // Calls the Font dialog and obtains the font currently used in Notepad
  notepad.Window('Notepad', '*').MainMenu.Click('Format|Font...');
  FWindow := notepad.Window('*', 'Font');
  FontName := FWindow.Window('ComboBox', '', 1).wText;
  FontSize := aqConvert.VarToInt(FWindow.Window('ComboBox', '', 3).wText);
  Log.Message('The ' + FontName + ' ' + aqConvert.IntToStr(FontSize) + ' font is used');
  FWindow.Window('Button', 'OK').ClickButton();

  // Creates an OCROptions object
  OCROptions := OCRObj.CreateOptions;
  // Adds the font to the font collection to be used for the recognition
  NewFont := OCROptions.Fonts.Add();
  NewFont.Name := FontName;
  NewFont.Sizes.Add(FontSize);

  // Recognizes the text and posts it to the test log
  Log.Message('Recognized characters:', OCRObj.GetText(OCROptions));

end;

C++Script, C#Script

function OCROptionsSample()
{
  // Obtains the Notepad window
  var notepad = Sys["Process"]("notepad");
  var Window = notepad["Window"]("Notepad", "*")["Window"]("Edit");

  // Captures an image of the Notepad window
  var Rect = Window["Picture"]();
  Log["Picture"](Rect, "Region with the text to be recognized");

  // Creates an OCR object
  var OCRObj = OCR["CreateObject"](Rect);

  // Calls the Font dialog and obtains the font currently used in Notepad
  notepad["Window"]("Notepad", "*")["MainMenu"]["Click"]("Format|Font...");
  var FWindow = notepad["Window"]("*", "Font");
  var FontName = FWindow["Window"]("ComboBox", "", 1)["wText"];
  var FontSize = aqConvert["VarToInt"](FWindow["Window"]("ComboBox", "", 3)["wText"]);
  Log["Message"]("The " + FontName + " " + aqConvert["IntToStr"](FontSize) + " font is used");
  FWindow["Window"]("Button", "OK")["ClickButton"]();

  // Creates an OCROptions object
  var OCROptions = OCRObj["CreateOptions"]();
  // Adds the font to the font collection to be used for the recognition
  NewFont = OCROptions["Fonts"]["Add"]();
  NewFont["Name"] = FontName;
  NewFont["Sizes"]["Add"](FontSize);

  // Recognizes the text and posts it to the test log
  Log["Message"]("Recognized characters:", OCRObj["GetText"](OCROptions));

}

See Also

Optical Character Recognition
FontCollection Object
Using Optical Character Recognition - Tips

Highlight search results