Professional Documents
Culture Documents
The 4Test functions call functions in a Segue DLL that extends the third-party Textract DLL
from Structu Rise. The Textract DLL uses a font pattern database file to recognize text for
certain sizes and styles of certain fonts that are specified in an initialization file. Although a
default version of the font pattern database is installed with SilkTest, it is strongly
recommended that you configure the font pattern database to include the fonts used by your
application, as explained in the INSTRUCTIONS FOR GENERATING THE FONT PATTERN
DATABASE section toward the bottom of this document.
The following files comprise the OCR module provided with SilkTest. All of the files
must reside in the SilkTest directory:
• Exgui.exe: Utility to generate the font pattern database. Can also be used as
a standalone utility for text recognition.
• OCR.inc: The 4Test include file that provides high-level 4Test functions
based on the functions in SgOcrLib.dll.
• SgOcrLib.dll: Segue extension of Textract.dll that provides higher level
functions.
• SgOcrLib.inc: Declares the functions in SgOcrLib.dll so that they can be
called in 4Test.
• SgOcrPattern.pat: Font pattern database that controls text conversion.
• Textract.dll: Textract OCR DLL provided by Structu Rise.
• Textract.ini: Initialization file for the Textract OCR DLL. Two sections contain
settings that may require modification:
o In the [Options] section, the "Database Path" setting must point to the
OCR pattern file, '<SilkTest directory>\SgOcrPattern.pat'.
o The [Recognition] section contains settings that control which fonts
are used to generate the pattern file.
Page 1 of 5
parameter: wWindow: The window that will be the source of the bitmap
to be converted to text. WINDOW.
parameter: rCapture: The capture region. OPTIONAL. RECT.
notes: Convert a bitmap of a window (or area within a window)
into text. The conversion uses the preconfigured
pattern file, which is specified in the textract.ini file
(Database Path setting).
The sample test script (ocrtest.t) includes a testcase (shown below) that extracts the text from
a Microsoft Word document. Microsoft Office controls are recognized as custom windows
(CustomWin) by SilkTest, so you cannot use the 4Test GetText() method to get the text.
However, you can use the OcrGetTextFromWnd() function to capture a bitmap of the
document window and convert it to text. Notice that if necessary, the testcase will scroll
through the document and capture multiple bitmaps.
Page 2 of 5
[ ] // of down by paging down, then we have reached the
bottom.
[+] if iCurPos <= iLastPos
[ ] break
[ ]
[ ] // Convert the bitmap for the current view.
[ ] iResLen = OcrGetTextFromWnd (sResult, TheDoc.CurrentView)
[ ]
[+] if sResult != NULL
[ ] ListAppend (lsResults, sResult)
[ ] iTotalLen = iTotalLen + Len (sResult)
[ ]
[ ]
[ ] ResPrintList ("Document text ({iTotalLen} chars)", lsResults)
[ ]
If neither of the 4Test functions in OCR.inc provides the functionality that you need, you can
call the DLL functions in the Segue DLL, SgOcrLib.dll, directly using the function declarations
in SgOcrLib.inc. The DLL functions are documented at the top of SgOcrLib.inc, and the
functions in OCR.inc can serve as an example of how to use the DLL functions.
Use the Exgui.exe utility to generate the pattern file (SgOcrPattern.pat). The text conversion
is performed using Windows fonts. Before conversion, the fonts that may be used must be
processed into the pattern file. Before generating the pattern file, the used fonts, their sizes
and styles must first be configured in the Textract.ini file. Open Textract.ini and adjust the
following settings in the [Recognition] section:
After Textract.ini has been adjusted, open the Exgui.exe application and click the "Build font
pattern database" button. When the "Textract - Build Font Base" dialog appears, click OK and
wait for the pattern file to be generated. The file will save the name and path specified in the
"Database Path" setting in the [Options] section of the textract.ini file.
Copy the following files into the directory where the executable that is calling the dll (e.g.,
Partner.exe) resides:
SgOcrLib.dll
SgOcrPattern.pat
Textract.dll
Textract.ini
For convenient pattern file generation, it is recommended that you also copy the exgui.exe file
to that directory.
Open the Textract.ini file and modify the Database Path setting (in the [Options] section) to
point to the correct location of SgOcrPattern.pat.
Have the application (e.g., SilkTest) load SgOcrLib.dll, which contains the functions explained
in the following section.
Interface
Page 3 of 5
OcrInit
int OcrInit(void** ppOcr)
Call once for initialization of the OCR library. This function must be called in advance of any
text conversion.
Return values:
0 Successful
-1 Invalid parameter; ppOcr = 0
-2 Could not load the textract dll
-3 Some functions of the textract dll could not be found
-4 Internal initialization of the textract dll failed; possible
textract.ini file misconfiguration
OcrTerminate
int OcrTerminate(void* pOcr)
Return values:
0 Successful
-1 Invalid parameter; pOcr = 0
OcrConvert
int OcrConvert(void* pOcr, TString sFile)
Call to convert the bmp file into text. The conversion result can be retrieved with the
OcrGetResult function. The conversion uses the preconfigured pattern file that is specified in
the textract.ini file (Database Path).
Return values:
0 Successful
-1 Invalid parameter; pOcr = 0
-2 Library not initialized; Call OcrInit in advance!
-3 Text conversion failed.
OcrGetResult
char* OcrGetResult(void* pOcr)
Return values:
Converted text Successful
0 No result
OcrGetResultLen
unsigned int OcrGetResultLen(void* pOcr)
Return values:
Result length
Page 4 of 5
Pattern file generation
Use the exgui.exe application to generate the appropriate pattern file. The text conversion is
done using Windows fonts. The used fonts must be processed into the pattern file before any
conversion is performed. The used fonts, their sizes and their styles must first be configured
in the textract.ini file. Open textract.ini and adjust following sections:
Then open the exgui.exe application and press the “Build font pattern database...” button.
Press OK and wait for the pattern file to be generated. The generated file will have the name
and the location specified in the Database Path section of the textract.ini file.
Page 5 of 5