Skip to content

Commit 584272c

Browse files
authored
Merge branch 'main' into testing-centers
2 parents 1001ab0 + 6321022 commit 584272c

33 files changed

+2156
-1154
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ dotnet_style_require_accessibility_modifiers = for_non_interface_members
4343

4444
# Expression-level preferences
4545
dotnet_style_coalesce_expression = true
46-
dotnet_style_collection_initializer = true
46+
dotnet_style_collection_initializer = false
4747
dotnet_style_explicit_tuple_names = true
4848
dotnet_style_namespace_match_folder = true
4949
dotnet_style_null_propagation = true

.github/workflows/buildDev.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- name: Setup .NET
16-
uses: actions/setup-dotnet@v3
16+
uses: actions/setup-dotnet@v4
1717
with:
1818
dotnet-version: "8.0.x"
1919
- name: Install dependencies
@@ -27,7 +27,7 @@ jobs:
2727
run: dotnet publish ${{ env.PROJECT_PATH }} -c Release --self-contained -r win-x64 -p:PublishSingleFile=true -o publish
2828

2929
- name: Upload artifact
30-
uses: actions/upload-artifact@v3
30+
uses: actions/upload-artifact@v4
3131
with:
3232
name: Text-Grab
3333
path: .\publish

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ I am the author of the [PowerToy Text Extractor](https://learn.microsoft.com/en-
1717
### Community
1818

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

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

116117

117118
### Pssst, on a Mac?
118-
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!
119+
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!

Tests/LanguageTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Globalization;
2+
using Text_Grab.Models;
3+
4+
namespace Tests;
5+
public class LanguageTests
6+
{
7+
[Theory]
8+
[InlineData("zh-Hant")]
9+
[InlineData("zh-Hans")]
10+
public void CanParseEveryLanguageTag(string langTag)
11+
{
12+
CultureInfo culture = new(langTag);
13+
Assert.NotNull(culture);
14+
}
15+
16+
[Theory]
17+
[InlineData("chi_sim", "Chinese (Simplified)")]
18+
[InlineData("chi_tra", "Chinese (Traditional)")]
19+
[InlineData("chi_sim_vert", "Chinese (Simplified) Vertical")]
20+
[InlineData("chi_tra_vert", "Chinese (Traditional) Vertical")]
21+
public void CanParseChineseLanguageTag(string langTag, string expectedDisplayName)
22+
{
23+
TessLang tessLang = new(langTag);
24+
Assert.Equal(expectedDisplayName, tessLang.CultureDisplayName);
25+
}
26+
}

Tests/OcrTests.cs

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ namespace Tests;
1414

1515
public class OcrTests
1616
{
17-
private const string fontSamplePath = @".\Images\font_sample.png";
18-
private const string fontSampleResult = @"Times-Roman
17+
private const string fontSamplePath = @".\Images\font_sample.png";
18+
private const string fontSampleResult = @"Times-Roman
1919
Helvetica
2020
Courier
2121
Palatino-Roman
2222
Helvetica-Narrow
2323
Bookman-Demi";
2424

25-
private const string fontSampleResultForTesseract = @"Times-Roman
25+
private const string fontSampleResultForTesseract = @"Times-Roman
2626
Helvetica
2727
Courier
2828
Palatino-Roman
@@ -74,7 +74,7 @@ public async Task OcrFontTestImage()
7474
string testImagePath = fontTestPath;
7575
string expectedResult = fontTestResult;
7676

77-
Uri uri = new Uri(testImagePath, UriKind.Relative);
77+
Uri uri = new(testImagePath, UriKind.Relative);
7878
// When
7979
string ocrTextResult = await OcrUtilities.OcrAbsoluteFilePathAsync(FileUtilities.GetPathToLocalFile(testImagePath));
8080

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

9191

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

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

126126
string testImagePath = @".\Images\QrCodeTestImage.png";
127-
Uri uri = new Uri(testImagePath, UriKind.Relative);
127+
Uri uri = new(testImagePath, UriKind.Relative);
128128
// When
129129
string ocrTextResult = await OcrUtilities.OcrAbsoluteFilePathAsync(FileUtilities.GetPathToLocalFile(testImagePath));
130130

@@ -146,11 +146,11 @@ 300 Brown
146146
400 Dog";
147147

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

155155
DpiScale dpi = new(1, 1);
156156
Rectangle rectCanvasSize = new()
@@ -174,8 +174,8 @@ 300 Brown
174174
Assert.Equal(expectedResult, stringBuilder.ToString());
175175
}
176176

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

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

252-
Assert.Equal(expected, joinedString);
253-
}
251+
if (actualStrings.Count == 0)
252+
return;
254253

255-
[WpfFact]
254+
foreach (string tag in expected)
255+
{
256+
Assert.Contains(tag, actualStrings);
257+
}
258+
}
259+
260+
[WpfFact(Skip ="fails GitHub actions")]
256261
public async Task GetTesseractStrongLanguages()
257262
{
258263
List<ILanguage> expectedList = new()
259264
{
260265
new TessLang("eng"),
261266
new TessLang("spa"),
262-
// new TessLang("equ")
263267
};
264268

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

267-
string expectedAbbreviatedName = string.Join(',', expectedList.Select(l => l.AbbreviatedName).ToArray());
268-
string actualAbbreviatedName = string.Join(',', actualList.Select(l => l.AbbreviatedName).ToArray());
271+
if (actualList.Count == 0)
272+
return;
273+
274+
foreach (ILanguage tag in expectedList)
275+
{
276+
Assert.Contains(tag.AbbreviatedName, actualList.Select(x => x.AbbreviatedName).ToList());
277+
}
278+
}
279+
280+
[WpfFact]
281+
public async Task GetTesseractGitHubLanguage()
282+
{
283+
TesseractGitHubFileDownloader fileDownloader = new();
284+
285+
int length = TesseractGitHubFileDownloader.tesseractTrainedDataFileNames.Length;
286+
string languageFileDataName = TesseractGitHubFileDownloader.tesseractTrainedDataFileNames[new Random().Next(length)];
287+
string tempFilePath = Path.Combine(Path.GetTempPath(), languageFileDataName);
288+
289+
await fileDownloader.DownloadFileAsync(languageFileDataName, tempFilePath);
290+
291+
Assert.True(File.Exists(tempFilePath));
292+
Assert.True(new FileInfo(tempFilePath).Length > 0);
269293

270-
Assert.Equal(expectedAbbreviatedName, actualAbbreviatedName);
294+
File.Delete(tempFilePath);
271295
}
272296
}

Tests/Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0-preview-23577-04" />
13-
<PackageReference Include="xunit" Version="2.6.5" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0-preview-24080-01" />
13+
<PackageReference Include="xunit" Version="2.7.0" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7">
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
<PrivateAssets>all</PrivateAssets>
1717
</PackageReference>

Text-Grab-Package/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Identity
1212
Name="40087JoeFinApps.TextGrab"
1313
Publisher="CN=153F3B0F-BA3D-4964-8098-71AC78A1DF6A"
14-
Version="4.3.1.0" />
14+
Version="4.4.0.0" />
1515

1616
<Properties>
1717
<DisplayName>Text Grab</DisplayName>

Text-Grab/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@
133133
<setting name="ShortcutKeySets" serializeAs="String">
134134
<value />
135135
</setting>
136+
<setting name="RestoreEtwPositions" serializeAs="String">
137+
<value>True</value>
138+
</setting>
139+
<setting name="EtwUseMargins" serializeAs="String">
140+
<value>False</value>
141+
</setting>
136142
</Text_Grab.Properties.Settings>
137143
</userSettings>
138144
</configuration>

Text-Grab/Controls/CollapsibleButton.xaml.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77

88
namespace Text_Grab.Controls;
99

10-
/// <summary>
11-
/// Interaction logic for CollapsibleButton.xaml
12-
/// </summary>
1310
public partial class CollapsibleButton : System.Windows.Controls.Button, INotifyPropertyChanged
1411
{
1512
#region Fields
1613

1714
public string ButtonText
1815
{
19-
get { return (string)GetValue(ButtonTextProperty); }
20-
set { SetValue(ButtonTextProperty, value); }
16+
get => (string)GetValue(ButtonTextProperty);
17+
set => SetValue(ButtonTextProperty, value);
2118
}
2219

2320
public static readonly DependencyProperty ButtonTextProperty =
@@ -52,7 +49,7 @@ public CollapsibleButton()
5249

5350
public bool IsSymbol
5451
{
55-
get { return isSymbol; }
52+
get => isSymbol;
5653
set
5754
{
5855
isSymbol = value;
@@ -62,8 +59,8 @@ public bool IsSymbol
6259

6360
public SymbolRegular ButtonSymbol
6461
{
65-
get { return (SymbolRegular)GetValue(ButtonSymbolProperty); }
66-
set { SetValue(ButtonSymbolProperty, value); }
62+
get => (SymbolRegular)GetValue(ButtonSymbolProperty);
63+
set => SetValue(ButtonSymbolProperty, value);
6764
}
6865

6966
public static readonly DependencyProperty ButtonSymbolProperty =
@@ -81,17 +78,15 @@ private void ChangeButtonLayout_Click(object? sender = null, System.Windows.Rout
8178
if (!isSymbol)
8279
{
8380
// change to a normal button
84-
Style? tealButtonStyle = this.FindResource("TealColor") as Style;
85-
if (tealButtonStyle != null)
86-
this.Style = tealButtonStyle;
81+
if (FindResource("TealColor") is Style tealButtonStyle)
82+
Style = tealButtonStyle;
8783
ButtonTextBlock.Visibility = Visibility.Visible; ;
8884
}
8985
else
9086
{
9187
// change to a symbol button
92-
Style? SymbolButtonStyle = this.FindResource("SymbolButton") as Style;
93-
if (SymbolButtonStyle != null)
94-
this.Style = SymbolButtonStyle;
88+
if (FindResource("SymbolButton") is Style SymbolButtonStyle)
89+
Style = SymbolButtonStyle;
9590
ButtonTextBlock.Visibility = Visibility.Collapsed;
9691
}
9792
}
@@ -101,9 +96,8 @@ private void CollapsibleButton_Loaded(object sender, RoutedEventArgs e)
10196
if (isSymbol)
10297
{
10398
// change to a symbol button
104-
Style? SymbolButtonStyle = this.FindResource("SymbolButton") as Style;
105-
if (SymbolButtonStyle != null)
106-
this.Style = SymbolButtonStyle;
99+
if (FindResource("SymbolButton") is Style SymbolButtonStyle)
100+
Style = SymbolButtonStyle;
107101
ButtonTextBlock.Visibility = Visibility.Collapsed;
108102
}
109103
}

0 commit comments

Comments
 (0)