dsh-native-uia 0.0.0-stage → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +663 -2
- package/client/client.js +269 -0
- package/cordis.patch.yml +10 -0
- package/icon.svg +11 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +75 -4
- package/scripts/bench-live.mjs +157 -0
- package/scripts/check-lease.mjs +308 -0
- package/scripts/install.mjs +154 -0
- package/scripts/lib/dsh-tools-stub.mjs +14 -0
- package/scripts/lib/load-tools-source.mjs +25 -0
- package/scripts/lib/sources.mjs +62 -0
- package/scripts/load-tools.mjs +74 -0
- package/scripts/measure-parse.mjs +77 -0
- package/scripts/regression-halt-latch.mjs +100 -0
- package/scripts/regression-quality.mjs +207 -0
- package/scripts/regression-tools.mjs +192 -0
- package/scripts/regression-worker.ps1 +1071 -0
- package/scripts/smoke.mjs +158 -0
- package/scripts/verify-capture-scale.mjs +37 -0
- package/scripts/verify-live-clipboard.mjs +108 -0
- package/scripts/verify-live-style.mjs +46 -0
- package/scripts/verify-live.mjs +104 -0
- package/scripts/verify-locator.mjs +52 -0
- package/scripts/verify.mjs +2110 -0
- package/src/activity-window.js +276 -0
- package/src/dashboard.js +103 -0
- package/src/guard.js +201 -0
- package/src/index.js +525 -0
- package/src/native-uia-remote.js +80 -0
- package/src/notes.js +83 -0
- package/src/state.js +267 -0
- package/src/themes.js +74 -0
- package/src/tools/defs/act.js +533 -0
- package/src/tools/defs/lifecycle.js +205 -0
- package/src/tools/defs/observe.js +309 -0
- package/src/tools/defs/pointer.js +298 -0
- package/src/tools/format.js +301 -0
- package/src/tools/index.js +128 -0
- package/src/tools/ocr.js +91 -0
- package/src/tools/recipes.js +44 -0
- package/src/tools/runtime.js +42 -0
- package/src/worker-client.js +268 -0
- package/worker/assets/dsh-whale.path +1 -0
- package/worker/bin/build-ocr.ps1 +41 -0
- package/worker/bin/ocr.cs +69 -0
- package/worker/bin/ocr.exe +0 -0
- package/worker/indicator-server.ps1 +2963 -0
- package/worker/lib/01-core.ps1 +64 -0
- package/worker/lib/02-uia.ps1 +221 -0
- package/worker/lib/03-window.ps1 +194 -0
- package/worker/lib/04-match.ps1 +435 -0
- package/worker/lib/05-value.ps1 +149 -0
- package/worker/lib/06-snapshot.ps1 +345 -0
- package/worker/lib/07-action.ps1 +291 -0
- package/worker/lib/08-command.ps1 +1485 -0
- package/worker/lib/09-pointer.ps1 +840 -0
- package/worker/lib/10-dispatch.ps1 +134 -0
- package/worker/ps-stdio.ps1 +173 -0
- package/worker/uia-worker.ps1 +599 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.IO;
|
|
3
|
+
using System.Text;
|
|
4
|
+
using System.Collections.Generic;
|
|
5
|
+
using Windows.Storage.Streams;
|
|
6
|
+
using Windows.Graphics.Imaging;
|
|
7
|
+
using Windows.Media.Ocr;
|
|
8
|
+
using Windows.Globalization;
|
|
9
|
+
|
|
10
|
+
class OcrTool {
|
|
11
|
+
static string J(string s) {
|
|
12
|
+
var sb = new StringBuilder();
|
|
13
|
+
foreach (char c in s) {
|
|
14
|
+
if (c == '"') sb.Append("\\\"");
|
|
15
|
+
else if (c == '\\') sb.Append("\\\\");
|
|
16
|
+
else if (c == '\n') sb.Append("\\n");
|
|
17
|
+
else if (c == '\r') sb.Append("\\r");
|
|
18
|
+
else if (c == '\t') sb.Append("\\t");
|
|
19
|
+
else if (c < ' ') sb.Append("\\u" + ((int)c).ToString("x4"));
|
|
20
|
+
else sb.Append(c);
|
|
21
|
+
}
|
|
22
|
+
return sb.ToString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static T Wait<T>(Windows.Foundation.IAsyncOperation<T> op) {
|
|
26
|
+
return op.AsTask().GetAwaiter().GetResult();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static int Main(string[] args) {
|
|
30
|
+
Console.OutputEncoding = new UTF8Encoding(false);
|
|
31
|
+
try {
|
|
32
|
+
if (args.Length < 1) { Console.WriteLine("{\"ok\":false,\"error\":\"no path\"}"); return 2; }
|
|
33
|
+
byte[] data = File.ReadAllBytes(args[0]);
|
|
34
|
+
var stream = new InMemoryRandomAccessStream();
|
|
35
|
+
var dw = new DataWriter(stream.GetOutputStreamAt(0));
|
|
36
|
+
dw.WriteBytes(data);
|
|
37
|
+
dw.StoreAsync().AsTask().GetAwaiter().GetResult();
|
|
38
|
+
dw.DetachStream();
|
|
39
|
+
stream.Seek(0);
|
|
40
|
+
var dec = Wait(BitmapDecoder.CreateAsync(stream));
|
|
41
|
+
var bmp = Wait(dec.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied));
|
|
42
|
+
|
|
43
|
+
OcrEngine eng = null;
|
|
44
|
+
try {
|
|
45
|
+
var lang = new Language("zh-Hans-CN");
|
|
46
|
+
if (OcrEngine.IsLanguageSupported(lang)) eng = OcrEngine.TryCreateFromLanguage(lang);
|
|
47
|
+
} catch { }
|
|
48
|
+
if (eng == null) eng = OcrEngine.TryCreateFromUserProfileLanguages();
|
|
49
|
+
if (eng == null) { Console.WriteLine("{\"ok\":false,\"error\":\"no engine\"}"); return 3; }
|
|
50
|
+
|
|
51
|
+
var res = Wait(eng.RecognizeAsync(bmp));
|
|
52
|
+
var words = new List<string>();
|
|
53
|
+
foreach (var line in res.Lines) {
|
|
54
|
+
foreach (var w in line.Words) {
|
|
55
|
+
var r = w.BoundingRect;
|
|
56
|
+
words.Add("{\"t\":\"" + J(w.Text) + "\",\"x\":" + ((int)Math.Round(r.X)) +
|
|
57
|
+
",\"y\":" + ((int)Math.Round(r.Y)) + ",\"w\":" + ((int)Math.Round(r.Width)) +
|
|
58
|
+
",\"h\":" + ((int)Math.Round(r.Height)) + "}");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
Console.WriteLine("{\"ok\":true,\"text\":\"" + J(res.Text) + "\",\"words\":[" +
|
|
62
|
+
string.Join(",", words.ToArray()) + "]}");
|
|
63
|
+
return 0;
|
|
64
|
+
} catch (Exception e) {
|
|
65
|
+
Console.WriteLine("{\"ok\":false,\"error\":\"" + J(e.GetType().Name + ": " + e.Message) + "\"}");
|
|
66
|
+
return 1;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
Binary file
|