Skip to content

Commit

Permalink
Changed FontAttributes to FontProperties and moved it to a higher level
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees van Spelde committed Dec 16, 2022
1 parent bec532e commit 72b77a8
Show file tree
Hide file tree
Showing 10 changed files with 317 additions and 205 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using System;
using System.IO;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TesseractOCR;
using TesseractOCR.Enums;
using TesseractOCR.Helpers;

namespace Tesseract.Tests.Leptonica.PixTests
{
Expand Down Expand Up @@ -32,7 +30,6 @@ public void OtsuBinarizationTest()
using var sourcePix = TesseractOCR.Pix.Image.LoadFromFile(sourcePixFilename);
using var binarizedImage = sourcePix.BinarizeOtsuAdaptiveThreshold(200, 200, 10, 10, 0.1F);
Assert.IsNotNull(binarizedImage);
Assert.AreNotEqual(binarizedImage.Handle, IntPtr.Zero);
SaveResult(binarizedImage, "binarizedOtsuImage.png");
}

Expand All @@ -44,7 +41,6 @@ public void SauvolaBinarizationTest()
using var grayscalePix = sourcePix.ConvertRGBToGray(1, 1, 1);
using var binarizedImage = grayscalePix.BinarizeSauvola(10, 0.35f, false);
Assert.IsNotNull(binarizedImage);
Assert.AreNotEqual(binarizedImage.Handle, IntPtr.Zero);
SaveResult(binarizedImage, "binarizedSauvolaImage.png");
}

Expand All @@ -56,7 +52,6 @@ public void SauvolaTiledBinarizationTest()
using var grayscalePix = sourcePix.ConvertRGBToGray(1, 1, 1);
using var binarizedImage = grayscalePix.BinarizeSauvolaTiled(10, 0.35f, 2, 2);
Assert.IsNotNull(binarizedImage);
Assert.AreNotEqual(binarizedImage.Handle, IntPtr.Zero);
SaveResult(binarizedImage, "binarizedSauvolaTiledImage.png");
}

Expand Down
65 changes: 65 additions & 0 deletions TesseractOCR/Font/Attributes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// FontAttributes.cs
//
// Author: Kees van Spelde <[email protected]>
//
// Copyright 2012-2019 Charles Weld
// Copyright 2021-2022 Kees van Spelde
//
// Licensed under the Apache License, Version 2.0 (the "License");
//
// - You may not use this file except in compliance with the License.
// - You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace TesseractOCR.Font
{
/// <summary>
/// This struct is the return type of ResultIterator.GetWordFontAttributes().
/// We can't use FontInfo directly because there are properties here that are not
/// accounted for in FontInfo (smallcaps, underline, etc.) Because of the caching
/// scheme we're using for FontInfo objects, we can't simply augment that class since
/// these extra properties are not accounted for by the FontInfo's unique ID.
/// </summary>
public sealed class Attributes
{
#region Properties
/// <summary>
/// Returns the font information
/// </summary>
public Info FontInfo { get; }

/// <summary>
/// Returns <c>true</c> when the text is underlined
/// </summary>
public bool IsUnderlined { get; }

/// <summary>
/// Returns <c>true</c> when the font is small caps
/// </summary>
public bool IsSmallCaps { get; }
#endregion

#region Constructor
/// <summary>
/// Creates this object and sets all it's needed properties
/// </summary>
/// <param name="fontInfo"></param>
/// <param name="isUnderlined"></param>
/// <param name="isSmallCaps"></param>
internal Attributes(Info fontInfo, bool isUnderlined, bool isSmallCaps)
{
FontInfo = fontInfo;
IsUnderlined = isUnderlined;
IsSmallCaps = isSmallCaps;
}
#endregion
}
}
83 changes: 83 additions & 0 deletions TesseractOCR/Font/Info.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Info.cs
//
// Author: Kees van Spelde <[email protected]>
//
// Copyright 2012-2019 Charles Weld
// Copyright 2021-2022 Kees van Spelde
//
// Licensed under the Apache License, Version 2.0 (the "License");
//
// - You may not use this file except in compliance with the License.
// - You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace TesseractOCR.Font
{
/// <summary>
/// The .NET equivalent of the ccstruct/fontinfo.h
/// FontInfo struct. It's missing spacing info
/// since we don't have any way of getting it (and
/// it's probably not all that useful anyway)
/// </summary>
public readonly struct Info
{
#region Properties
/// <summary>
/// Returns the name of the font
/// </summary>
public string Name { get; }

/// <summary>
/// Returns the id of the font
/// </summary>
public int Id { get; }

/// <summary>
/// Returns <c>true</c> when the font is in italic
/// </summary>
public bool IsItalic { get; }

/// <summary>
/// Returns <c>true</c> when the font is bold
/// </summary>
public bool IsBold { get; }

/// <summary>
/// Returns <c>true</c> when the font has a fixed pitch
/// </summary>
public bool IsFixedPitch { get; }

/// <summary>
/// Returns <c>true</c> when the font is serif
/// </summary>
public bool IsSerif { get; }

/// <summary>
/// Returns <c>true</c> when the font is fraktur
/// </summary>
public bool IsFraktur { get; }
#endregion

#region Constructor
internal Info(string name, int id, bool isItalic, bool isBold, bool isFixedPitch, bool isSerif,
bool isFraktur = false)
{
Name = name;
Id = id;
IsItalic = isItalic;
IsBold = isBold;
IsFixedPitch = isFixedPitch;
IsSerif = isSerif;
IsFraktur = isFraktur;
}
#endregion
}
}
53 changes: 53 additions & 0 deletions TesseractOCR/Font/Properties.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Properties.cs
//
// Author: Kees van Spelde <[email protected]>
//
// Copyright 2021-2022 Kees van Spelde
//
// Licensed under the Apache License, Version 2.0 (the "License");
//
// - You may not use this file except in compliance with the License.
// - You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using TesseractOCR.Enums;

namespace TesseractOCR.Font
{
/// <summary>
/// Returns font properties
/// </summary>
public class Properties
{
/// <summary>
/// Returns the point size of the font
/// </summary>
/// <remarks>
/// Point size is returned in printers points (1/72 inch)
/// </remarks>
public int PointSize { get; }

/// <summary>
/// Returns other font attributes
/// </summary>
/// <remarks>
/// This information is only available when using older engine modes like
/// <see cref="EngineMode.TesseractOnly "/> and <see cref="EngineMode.TesseractAndLstm "/>
/// </remarks>
public Attributes Attributes { get; }

internal Properties(int pointSize, Attributes attributes = null)
{
PointSize = pointSize;
Attributes = attributes;
}
}
}
65 changes: 0 additions & 65 deletions TesseractOCR/FontAttributes.cs

This file was deleted.

84 changes: 0 additions & 84 deletions TesseractOCR/FontInfo.cs

This file was deleted.

Loading

0 comments on commit 72b77a8

Please sign in to comment.