Skip to content

Commit

Permalink
Merge branch 'main' into testing-centers
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJoeFin authored Mar 9, 2024
2 parents 1001ab0 + 6321022 commit 584272c
Show file tree
Hide file tree
Showing 33 changed files with 2,156 additions and 1,154 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members

# Expression-level preferences
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true
dotnet_style_collection_initializer = false
dotnet_style_explicit_tuple_names = true
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/buildDev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Install dependencies
Expand All @@ -27,7 +27,7 @@ jobs:
run: dotnet publish ${{ env.PROJECT_PATH }} -c Release --self-contained -r win-x64 -p:PublishSingleFile=true -o publish

- name: Upload artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: Text-Grab
path: .\publish
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ I am the author of the [PowerToy Text Extractor](https://learn.microsoft.com/en-
### Community

- [scoop](https://scoop.sh/)`scoop install text-grab`
- [choco](https://community.chocolatey.org) - `choco install text-grab`

## How to Build
Get the code:
Expand Down Expand Up @@ -115,4 +116,4 @@ If you have any questions or feedback reach out on Twitter [@TheJoeFin](http://w


### Pssst, on a Mac?
Check out the awesome app Text Sniper! It is very similar to Text Grab but for Mac! And if you use my [affiliate link here](https://gumroad.com/a/984365907/NYNNM) you will support Text Grab development as well!
Check out the awesome app Text Sniper! It is very similar to Text Grab but for Mac! And if you use my [affiliate link here](https://gumroad.com/a/984365907/NYNNM) you will support Text Grab development as well!
26 changes: 26 additions & 0 deletions Tests/LanguageTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Globalization;
using Text_Grab.Models;

namespace Tests;
public class LanguageTests
{
[Theory]
[InlineData("zh-Hant")]
[InlineData("zh-Hans")]
public void CanParseEveryLanguageTag(string langTag)
{
CultureInfo culture = new(langTag);
Assert.NotNull(culture);
}

[Theory]
[InlineData("chi_sim", "Chinese (Simplified)")]
[InlineData("chi_tra", "Chinese (Traditional)")]
[InlineData("chi_sim_vert", "Chinese (Simplified) Vertical")]
[InlineData("chi_tra_vert", "Chinese (Traditional) Vertical")]
public void CanParseChineseLanguageTag(string langTag, string expectedDisplayName)
{
TessLang tessLang = new(langTag);
Assert.Equal(expectedDisplayName, tessLang.CultureDisplayName);
}
}
72 changes: 48 additions & 24 deletions Tests/OcrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ namespace Tests;

public class OcrTests
{
private const string fontSamplePath = @".\Images\font_sample.png";
private const string fontSampleResult = @"Times-Roman
private const string fontSamplePath = @".\Images\font_sample.png";
private const string fontSampleResult = @"Times-Roman
Helvetica
Courier
Palatino-Roman
Helvetica-Narrow
Bookman-Demi";

private const string fontSampleResultForTesseract = @"Times-Roman
private const string fontSampleResultForTesseract = @"Times-Roman
Helvetica
Courier
Palatino-Roman
Expand Down Expand Up @@ -74,7 +74,7 @@ public async Task OcrFontTestImage()
string testImagePath = fontTestPath;
string expectedResult = fontTestResult;

Uri uri = new Uri(testImagePath, UriKind.Relative);
Uri uri = new(testImagePath, UriKind.Relative);
// When
string ocrTextResult = await OcrUtilities.OcrAbsoluteFilePathAsync(FileUtilities.GetPathToLocalFile(testImagePath));

Expand All @@ -89,11 +89,11 @@ public async Task AnalyzeTable()
string expectedResult = tableTestResult;


Uri uri = new Uri(testImagePath, UriKind.Relative);
Language englishLanguage = new("en-US");
Uri uri = new(testImagePath, UriKind.Relative);
Language EnglishLanguage = new("en-US");
Bitmap testBitmap = new(FileUtilities.GetPathToLocalFile(testImagePath));
// When
OcrResult ocrResult = await OcrUtilities.GetOcrResultFromImageAsync(testBitmap, englishLanguage);
OcrResult ocrResult = await OcrUtilities.GetOcrResultFromImageAsync(testBitmap, EnglishLanguage);

DpiScale dpi = new(1, 1);
Rectangle rectCanvasSize = new()
Expand Down Expand Up @@ -124,7 +124,7 @@ public async Task ReadQrCode()
string expectedResult = "This is a test of the QR Code system";

string testImagePath = @".\Images\QrCodeTestImage.png";
Uri uri = new Uri(testImagePath, UriKind.Relative);
Uri uri = new(testImagePath, UriKind.Relative);
// When
string ocrTextResult = await OcrUtilities.OcrAbsoluteFilePathAsync(FileUtilities.GetPathToLocalFile(testImagePath));

Expand All @@ -146,11 +146,11 @@ 300 Brown
400 Dog";

string testImagePath = @".\Images\Table-Test-2.png";
Uri uri = new Uri(testImagePath, UriKind.Relative);
Language englishLanguage = new("en-US");
Uri uri = new(testImagePath, UriKind.Relative);
Language EnglishLanguage = new("en-US");
Bitmap testBitmap = new(FileUtilities.GetPathToLocalFile(testImagePath));
// When
OcrResult ocrResult = await OcrUtilities.GetOcrResultFromImageAsync(testBitmap, englishLanguage);
OcrResult ocrResult = await OcrUtilities.GetOcrResultFromImageAsync(testBitmap, EnglishLanguage);

DpiScale dpi = new(1, 1);
Rectangle rectCanvasSize = new()
Expand All @@ -174,8 +174,8 @@ 300 Brown
Assert.Equal(expectedResult, stringBuilder.ToString());
}

[WpfFact(Skip ="since the hocr is not being used from Tesseract it will not be tested for now")]

[WpfFact(Skip = "since the hocr is not being used from Tesseract it will not be tested for now")]
public async Task TesseractHocr()
{
int intialLinesToSkip = 12;
Expand Down Expand Up @@ -242,31 +242,55 @@ public async Task TesseractFontSample()
Assert.Equal(fontSampleResultForTesseract, tessoutput.RawOutput);
}

[WpfFact]
[WpfFact(Skip = "fails GitHub actions")]
public async Task GetTessLanguages()
{
string expected = "eng,spa";
List<string> actualStrings = await TesseractHelper.TesseractLangsAsStrings();
string joinedString = string.Join(',', actualStrings.ToArray());
List<string> expected = new() { "eng", "spa" };
List<string> actualStrings = await TesseractHelper.TesseractLanguagesAsStrings();

Assert.Equal(expected, joinedString);
}
if (actualStrings.Count == 0)
return;

[WpfFact]
foreach (string tag in expected)
{
Assert.Contains(tag, actualStrings);
}
}

[WpfFact(Skip ="fails GitHub actions")]
public async Task GetTesseractStrongLanguages()
{
List<ILanguage> expectedList = new()
{
new TessLang("eng"),
new TessLang("spa"),
// new TessLang("equ")
};

List<ILanguage> actualList = await TesseractHelper.TesseractLanguages();

string expectedAbbreviatedName = string.Join(',', expectedList.Select(l => l.AbbreviatedName).ToArray());
string actualAbbreviatedName = string.Join(',', actualList.Select(l => l.AbbreviatedName).ToArray());
if (actualList.Count == 0)
return;

foreach (ILanguage tag in expectedList)
{
Assert.Contains(tag.AbbreviatedName, actualList.Select(x => x.AbbreviatedName).ToList());
}
}

[WpfFact]
public async Task GetTesseractGitHubLanguage()
{
TesseractGitHubFileDownloader fileDownloader = new();

int length = TesseractGitHubFileDownloader.tesseractTrainedDataFileNames.Length;
string languageFileDataName = TesseractGitHubFileDownloader.tesseractTrainedDataFileNames[new Random().Next(length)];
string tempFilePath = Path.Combine(Path.GetTempPath(), languageFileDataName);

await fileDownloader.DownloadFileAsync(languageFileDataName, tempFilePath);

Assert.True(File.Exists(tempFilePath));
Assert.True(new FileInfo(tempFilePath).Length > 0);

Assert.Equal(expectedAbbreviatedName, actualAbbreviatedName);
File.Delete(tempFilePath);
}
}
6 changes: 3 additions & 3 deletions Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23577-04" />
<PackageReference Include="xunit" Version="2.6.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-preview-24080-01" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion Text-Grab-Package/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Identity
Name="40087JoeFinApps.TextGrab"
Publisher="CN=153F3B0F-BA3D-4964-8098-71AC78A1DF6A"
Version="4.3.1.0" />
Version="4.4.0.0" />

<Properties>
<DisplayName>Text Grab</DisplayName>
Expand Down
6 changes: 6 additions & 0 deletions Text-Grab/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
<setting name="ShortcutKeySets" serializeAs="String">
<value />
</setting>
<setting name="RestoreEtwPositions" serializeAs="String">
<value>True</value>
</setting>
<setting name="EtwUseMargins" serializeAs="String">
<value>False</value>
</setting>
</Text_Grab.Properties.Settings>
</userSettings>
</configuration>
28 changes: 11 additions & 17 deletions Text-Grab/Controls/CollapsibleButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@

namespace Text_Grab.Controls;

/// <summary>
/// Interaction logic for CollapsibleButton.xaml
/// </summary>
public partial class CollapsibleButton : System.Windows.Controls.Button, INotifyPropertyChanged
{
#region Fields

public string ButtonText
{
get { return (string)GetValue(ButtonTextProperty); }
set { SetValue(ButtonTextProperty, value); }
get => (string)GetValue(ButtonTextProperty);
set => SetValue(ButtonTextProperty, value);
}

public static readonly DependencyProperty ButtonTextProperty =
Expand Down Expand Up @@ -52,7 +49,7 @@ public CollapsibleButton()

public bool IsSymbol
{
get { return isSymbol; }
get => isSymbol;
set
{
isSymbol = value;
Expand All @@ -62,8 +59,8 @@ public bool IsSymbol

public SymbolRegular ButtonSymbol
{
get { return (SymbolRegular)GetValue(ButtonSymbolProperty); }
set { SetValue(ButtonSymbolProperty, value); }
get => (SymbolRegular)GetValue(ButtonSymbolProperty);
set => SetValue(ButtonSymbolProperty, value);
}

public static readonly DependencyProperty ButtonSymbolProperty =
Expand All @@ -81,17 +78,15 @@ private void ChangeButtonLayout_Click(object? sender = null, System.Windows.Rout
if (!isSymbol)
{
// change to a normal button
Style? tealButtonStyle = this.FindResource("TealColor") as Style;
if (tealButtonStyle != null)
this.Style = tealButtonStyle;
if (FindResource("TealColor") is Style tealButtonStyle)
Style = tealButtonStyle;
ButtonTextBlock.Visibility = Visibility.Visible; ;
}
else
{
// change to a symbol button
Style? SymbolButtonStyle = this.FindResource("SymbolButton") as Style;
if (SymbolButtonStyle != null)
this.Style = SymbolButtonStyle;
if (FindResource("SymbolButton") is Style SymbolButtonStyle)
Style = SymbolButtonStyle;
ButtonTextBlock.Visibility = Visibility.Collapsed;
}
}
Expand All @@ -101,9 +96,8 @@ private void CollapsibleButton_Loaded(object sender, RoutedEventArgs e)
if (isSymbol)
{
// change to a symbol button
Style? SymbolButtonStyle = this.FindResource("SymbolButton") as Style;
if (SymbolButtonStyle != null)
this.Style = SymbolButtonStyle;
if (FindResource("SymbolButton") is Style SymbolButtonStyle)
Style = SymbolButtonStyle;
ButtonTextBlock.Visibility = Visibility.Collapsed;
}
}
Expand Down
Loading

0 comments on commit 584272c

Please sign in to comment.