Skip to content

Commit

Permalink
feat: adapt to silent ocr and fix some bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZGGSONG committed Jan 18, 2024
1 parent 514cf5c commit fe749a0
Show file tree
Hide file tree
Showing 20 changed files with 635 additions and 34 deletions.
52 changes: 49 additions & 3 deletions Attachments/iconfont/demo_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ <h1 class="logo"><a href="https://www.iconfont.cn/" title="iconfont 首页" targ
<div class="content unicode" style="display: block;">
<ul class="icon_lists dib-box">

<li class="dib">
<span class="icon iconfont">&#xe61a;</span>
<div class="name">OCR识别</div>
<div class="code-name">&amp;#xe61a;</div>
</li>

<li class="dib">
<span class="icon iconfont">&#xe695;</span>
<div class="name">OCR</div>
<div class="code-name">&amp;#xe695;</div>
</li>

<li class="dib">
<span class="icon iconfont">&#xe725;</span>
<div class="name">密码显示隐藏-02</div>
Expand Down Expand Up @@ -378,9 +390,9 @@ <h3 id="-font-face">第一步:拷贝项目下面生成的 <code>@font-face</co
<pre><code class="language-css"
>@font-face {
font-family: 'iconfont';
src: url('iconfont.woff2?t=1705480740490') format('woff2'),
url('iconfont.woff?t=1705480740490') format('woff'),
url('iconfont.ttf?t=1705480740490') format('truetype');
src: url('iconfont.woff2?t=1705574336968') format('woff2'),
url('iconfont.woff?t=1705574336968') format('woff'),
url('iconfont.ttf?t=1705574336968') format('truetype');
}
</code></pre>
<h3 id="-iconfont-">第二步:定义使用 iconfont 的样式</h3>
Expand All @@ -406,6 +418,24 @@ <h3 id="-">第三步:挑选相应图标并获取字体编码,应用于页面
<div class="content font-class">
<ul class="icon_lists dib-box">

<li class="dib">
<span class="icon iconfont icon-OCRshibie"></span>
<div class="name">
OCR识别
</div>
<div class="code-name">.icon-OCRshibie
</div>
</li>

<li class="dib">
<span class="icon iconfont icon-OCR"></span>
<div class="name">
OCR
</div>
<div class="code-name">.icon-OCR
</div>
</li>

<li class="dib">
<span class="icon iconfont icon-mimaxianshiyincang-"></span>
<div class="name">
Expand Down Expand Up @@ -892,6 +922,22 @@ <h3 id="-">第二步:挑选相应图标并获取类名,应用于页面:</h
<div class="content symbol">
<ul class="icon_lists dib-box">

<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#icon-OCRshibie"></use>
</svg>
<div class="name">OCR识别</div>
<div class="code-name">#icon-OCRshibie</div>
</li>

<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#icon-OCR"></use>
</svg>
<div class="name">OCR</div>
<div class="code-name">#icon-OCR</div>
</li>

<li class="dib">
<svg class="icon svg-icon" aria-hidden="true">
<use xlink:href="#icon-mimaxianshiyincang-"></use>
Expand Down
14 changes: 11 additions & 3 deletions Attachments/iconfont/iconfont.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@font-face {
font-family: "iconfont"; /* Project id 4294789 */
src: url('iconfont.woff2?t=1705480740490') format('woff2'),
url('iconfont.woff?t=1705480740490') format('woff'),
url('iconfont.ttf?t=1705480740490') format('truetype');
src: url('iconfont.woff2?t=1705574336968') format('woff2'),
url('iconfont.woff?t=1705574336968') format('woff'),
url('iconfont.ttf?t=1705574336968') format('truetype');
}

.iconfont {
Expand All @@ -13,6 +13,14 @@
-moz-osx-font-smoothing: grayscale;
}

.icon-OCRshibie:before {
content: "\e61a";
}

.icon-OCR:before {
content: "\e695";
}

.icon-mimaxianshiyincang-:before {
content: "\e725";
}
Expand Down
2 changes: 1 addition & 1 deletion Attachments/iconfont/iconfont.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Attachments/iconfont/iconfont.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
"css_prefix_text": "icon-",
"description": "基于.Net 6 开发的新款翻译工具",
"glyphs": [
{
"icon_id": "10048824",
"name": "OCR识别",
"font_class": "OCRshibie",
"unicode": "e61a",
"unicode_decimal": 58906
},
{
"icon_id": "15556290",
"name": "OCR",
"font_class": "OCR",
"unicode": "e695",
"unicode_decimal": 59029
},
{
"icon_id": "6250252",
"name": "密码显示隐藏-02",
Expand Down
Binary file modified Attachments/iconfont/iconfont.ttf
Binary file not shown.
Binary file modified Attachments/iconfont/iconfont.woff
Binary file not shown.
Binary file modified Attachments/iconfont/iconfont.woff2
Binary file not shown.
1 change: 1 addition & 0 deletions STranslate.Model/ConstStr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static class ConstStr
public const string DEFAULTOPENHOTKEY = "Alt + G";
public const string DEFAULTMOUSEHOOKHOTKEY = "Alt + Shift + D";
public const string DEFAULTOCRHOTKEY = "Alt + Shift + S";
public const string DEFAULTSILENTOCRHOTKEY = "Alt + Shift + F";

public const string USERDEFINEFONTKEY = "UserFont";
public const string DEFAULTFONTNAME = "LXGW WenKai";
Expand Down
6 changes: 5 additions & 1 deletion STranslate.Model/Hotkeys.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class Hotkeys
public MousehookTranslate MousehookTranslate { get; set; } = new MousehookTranslate();

public OCR OCR { get; set; } = new OCR();

public SilentOCR SilentOCR { get; set; } = new SilentOCR();
}

public class InputTranslate : HotkeyBase { }
Expand All @@ -27,6 +29,8 @@ public class MousehookTranslate : HotkeyBase { }

public class OCR : HotkeyBase { }

public class SilentOCR : HotkeyBase { }

public class HotkeyBase
{
public KeyModifiers Modifiers { get; set; }
Expand All @@ -43,8 +47,8 @@ public static class HotkeyExtensions
public static T Update<T>(this T t, KeyModifiers modifiers, KeyCodes key, string? text, bool conflict = false)
where T : HotkeyBase
{
t.Modifiers = modifiers;
t.Key = key;
t.Modifiers = modifiers;
t.Text = text;
t.Conflict = conflict;
return t;
Expand Down
Binary file modified STranslate.Style/Fonts/iconfont.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions STranslate/Helper/ConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private ConfigModel InitialConfig()
hk.OpenMainWindow.Update(KeyModifiers.MOD_ALT, KeyCodes.G, ConstStr.DEFAULTOPENHOTKEY);
hk.MousehookTranslate.Update(KeyModifiers.MOD_ALT | KeyModifiers.MOD_SHIFT, KeyCodes.D, ConstStr.DEFAULTMOUSEHOOKHOTKEY);
hk.OCR.Update(KeyModifiers.MOD_ALT | KeyModifiers.MOD_SHIFT, KeyCodes.S, ConstStr.DEFAULTOCRHOTKEY);
hk.SilentOCR.Update(KeyModifiers.MOD_ALT | KeyModifiers.MOD_SHIFT, KeyCodes.F, ConstStr.DEFAULTSILENTOCRHOTKEY);
return new ConfigModel
{
HistorySize = 100,
Expand Down
59 changes: 50 additions & 9 deletions STranslate/Helper/HotkeyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public class HotkeyHelper
public static KeyModifiers OCRModifiers;
public static KeyCodes OCRKey;

public static int SilentOCRId = 860;
public static KeyModifiers SilentOCRModifiers;
public static KeyCodes SilentOCRKey;

public delegate void HotKeyCallBackHanlder();

private static readonly Dictionary<int, HotKeyCallBackHanlder> keymap = new();
Expand Down Expand Up @@ -125,15 +129,8 @@ private static void RegisterHotKey(IntPtr handle)
OCRModifiers = Hotkeys!.OCR.Modifiers;
OCRKey = Hotkeys!.OCR.Key;

if (Hotkeys!.ScreenShotTranslate.Key != 0)
{
Hotkeys!.ScreenShotTranslate.Conflict = !CommonUtil.RegisterHotKey(
handle,
ScreenShotTranslateId,
(byte)Hotkeys!.ScreenShotTranslate.Modifiers,
(int)Hotkeys!.ScreenShotTranslate.Key
);
}
SilentOCRModifiers = Hotkeys!.SilentOCR.Modifiers;
SilentOCRKey = Hotkeys!.SilentOCR.Key;

if (Hotkeys!.InputTranslate.Key != 0)
{
Expand All @@ -144,6 +141,7 @@ private static void RegisterHotKey(IntPtr handle)
(int)Hotkeys!.InputTranslate.Key
);
}

if (Hotkeys!.CrosswordTranslate.Key != 0)
{
Hotkeys!.CrosswordTranslate.Conflict = !CommonUtil.RegisterHotKey(
Expand All @@ -153,6 +151,17 @@ private static void RegisterHotKey(IntPtr handle)
(int)Hotkeys!.CrosswordTranslate.Key
);
}

if (Hotkeys!.ScreenShotTranslate.Key != 0)
{
Hotkeys!.ScreenShotTranslate.Conflict = !CommonUtil.RegisterHotKey(
handle,
ScreenShotTranslateId,
(byte)Hotkeys!.ScreenShotTranslate.Modifiers,
(int)Hotkeys!.ScreenShotTranslate.Key
);
}

if (Hotkeys!.OpenMainWindow.Key != 0)
{
Hotkeys!.OpenMainWindow.Conflict = !CommonUtil.RegisterHotKey(
Expand All @@ -162,6 +171,7 @@ private static void RegisterHotKey(IntPtr handle)
(int)Hotkeys!.OpenMainWindow.Key
);
}

if (Hotkeys!.MousehookTranslate.Key != 0)
{
Hotkeys!.MousehookTranslate.Conflict = !CommonUtil.RegisterHotKey(
Expand All @@ -171,6 +181,7 @@ private static void RegisterHotKey(IntPtr handle)
(int)Hotkeys!.MousehookTranslate.Key
);
}

if (Hotkeys!.OCR.Key != 0)
{
Hotkeys!.OCR.Conflict = !CommonUtil.RegisterHotKey(
Expand All @@ -180,6 +191,15 @@ private static void RegisterHotKey(IntPtr handle)
(int)Hotkeys!.OCR.Key
);
}
if (Hotkeys!.SilentOCR.Key != 0)
{
Hotkeys!.SilentOCR.Conflict = !CommonUtil.RegisterHotKey(
handle,
SilentOCRId,
(byte)Hotkeys!.SilentOCR.Modifiers,
(int)Hotkeys!.SilentOCR.Key
);
}
}

/// <summary>
Expand Down Expand Up @@ -310,6 +330,26 @@ public static void ReRegisterHotKey()
}
OCRModifiers = Hotkeys!.OCR.Modifiers;
OCRKey = Hotkeys!.OCR.Key;

if (Hotkeys!.SilentOCR.Key == 0)
{
CommonUtil.UnregisterHotKey(MainIntPtr, SilentOCRId);
}
else if (
SilentOCRModifiers != Hotkeys!.SilentOCR.Modifiers
|| SilentOCRKey != Hotkeys!.SilentOCR.Key
)
{
CommonUtil.UnregisterHotKey(MainIntPtr, SilentOCRId);
Hotkeys!.SilentOCR.Conflict = !CommonUtil.RegisterHotKey(
MainIntPtr,
SilentOCRId,
(byte)Hotkeys!.SilentOCR.Modifiers,
(int)Hotkeys!.SilentOCR.Key
);
}
SilentOCRModifiers = Hotkeys!.SilentOCR.Modifiers;
SilentOCRKey = Hotkeys!.SilentOCR.Key;
}

/// <summary>
Expand All @@ -323,6 +363,7 @@ public static void UnRegisterHotKey(Window window)
CommonUtil.UnregisterHotKey(MainIntPtr, OpenMainWindowId);
CommonUtil.UnregisterHotKey(MainIntPtr, MousehookTranslateId);
CommonUtil.UnregisterHotKey(MainIntPtr, OCRId);
CommonUtil.UnregisterHotKey(MainIntPtr, SilentOCRId);
var hwnd = new WindowInteropHelper(window).Handle;
_hwndSource = HwndSource.FromHwnd(hwnd);
_hwndSource.RemoveHook(WndProc);
Expand Down
Loading

0 comments on commit fe749a0

Please sign in to comment.