forked from charlesw/tesseract
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some preliminary tests for the new ResultIterator functionality.
- Loading branch information
Showing
3 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
98 changes: 98 additions & 0 deletions
98
src/Tesseract.Tests/ResultIteratorTests/FontAttributesTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tesseract.Tests.ResultIteratorTests | ||
{ | ||
[TestFixture] | ||
public class FontAttributesTests : TesseractTestBase | ||
{ | ||
private TesseractEngine Engine { get; set; } | ||
private Pix TestImage { get; set; } | ||
|
||
[SetUp] | ||
public void Init() | ||
{ | ||
Engine = CreateEngine(); | ||
TestImage = LoadTestPix("Ocr\\Fonts.tif"); | ||
} | ||
|
||
[TearDown] | ||
public void Dispose() | ||
{ | ||
if (TestImage != null) { | ||
TestImage.Dispose(); | ||
TestImage = null; | ||
} | ||
|
||
if (Engine != null) { | ||
Engine.Dispose(); | ||
Engine = null; | ||
} | ||
} | ||
|
||
private void Debug(ResultIterator iter, FontAttributes fontAttrs) { | ||
Console.WriteLine("Word: {0}", iter.GetText(PageIteratorLevel.Word)); | ||
Console.WriteLine("IsBold: {0}", fontAttrs.FontInfo.IsBold); | ||
Console.WriteLine("IsItalic: {0}", fontAttrs.FontInfo.IsItalic); | ||
Console.WriteLine("IsFixedPitch: {0}", fontAttrs.FontInfo.IsFixedPitch); | ||
Console.WriteLine("IsSerif: {0}", fontAttrs.FontInfo.IsSerif); | ||
|
||
Console.WriteLine("IsUnderlined: {0}", fontAttrs.IsUnderlined); | ||
Console.WriteLine("IsSmallCaps: {0}", fontAttrs.IsSmallCaps); | ||
Console.WriteLine("Point size: {0}", fontAttrs.PointSize); | ||
} | ||
|
||
#region Tests | ||
[Test] | ||
public void GetWordFontAttributesWorks() | ||
{ | ||
using (var page = Engine.Process(TestImage)) | ||
using (var iter = page.GetIterator()) { | ||
// font attributes come in this order in the test image: | ||
// bold, italic, monospace, serif, smallcaps | ||
// | ||
// there is no test for underline because in 3.04 IsUnderlined is | ||
// hard-coded to "false". See: https://github.com/tesseract-ocr/tesseract/blob/3.04/ccmain/ltrresultiterator.cpp#182 | ||
|
||
var fontAttrs = iter.GetWordFontAttributes(); | ||
Assert.That(fontAttrs.FontInfo.IsBold, Is.True); | ||
Assert.That(iter.GetWordRecognitionLanguage(), Is.EqualTo("eng")); | ||
Assert.That(iter.GetWordIsFromDictionary(), Is.True); | ||
iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word); | ||
|
||
fontAttrs = iter.GetWordFontAttributes(); | ||
Assert.That(fontAttrs.FontInfo.IsItalic, Is.True); | ||
iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word); | ||
|
||
fontAttrs = iter.GetWordFontAttributes(); | ||
Assert.That(fontAttrs.FontInfo.IsFixedPitch, Is.True); | ||
iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word); | ||
|
||
fontAttrs = iter.GetWordFontAttributes(); | ||
Assert.That(fontAttrs.FontInfo.IsSerif, Is.True); | ||
iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word); | ||
|
||
fontAttrs = iter.GetWordFontAttributes(); | ||
Assert.That(fontAttrs.IsSmallCaps, Is.True); | ||
iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word); | ||
|
||
Assert.That(iter.GetWordIsNumeric(), Is.True); | ||
|
||
iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word); | ||
iter.Next(PageIteratorLevel.Word, PageIteratorLevel.Symbol); | ||
|
||
Assert.That(iter.GetSymbolIsSuperscript(), Is.True); | ||
|
||
iter.Next(PageIteratorLevel.TextLine, PageIteratorLevel.Word); | ||
iter.Next(PageIteratorLevel.Word, PageIteratorLevel.Symbol); | ||
|
||
Assert.That(iter.GetSymbolIsSubscript(), Is.True); | ||
} | ||
} | ||
#endregion Tests | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters