-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
3970 lines (2777 loc) · 119 KB
/
MainWindow.xaml.cs
File metadata and controls
3970 lines (2777 loc) · 119 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Threading;
using System.Windows.Documents;
using System.Windows.Markup;
using Diff;
using System.Reflection;
using Interop.UIAutomationClient;
using Net;
using LibB;
namespace TypeB
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
///
public partial class MainWindow : Window
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left; //最左坐标
public int Top; //最上坐标
public int Right; //最右坐标
public int Bottom; //最下坐标
}
enum MouseEventFlag : uint
{
Move = 0x0001,
LeftDown = 0x0002,
LeftUp = 0x0004,
RightDown = 0x0008,
RightUp = 0x0010,
MiddleDown = 0x0020,
MiddleUp = 0x0040,
XDown = 0x0080,
XUp = 0x0100,
Wheel = 0x0800,
VirtualDesk = 0x4000,
Absolute = 0x8000
}
[DllImport("User32")]
public extern static bool GetCursorPos(ref System.Drawing.Point cPoint);
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr fGetForegroundWindow();
[DllImport("user32.dll")]
static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, IntPtr extraInfo);
[DllImport("User32")]
public extern static void SetCursorPos(int x, int y);
#region 热键
[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
[DllImport("user32.dll")]
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
#region dll
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(int hwnd, StringBuilder lpString, int cch);
[DllImport("user32.dll", CharSet = CharSet.Auto, EntryPoint = "GetClassName")]
public static extern int GetClassName(int hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "SwitchToThisWindow")]
private static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);
[DllImport("user32.dll", EntryPoint = "SendMessageA")]
private static extern int SendMessage(System.IntPtr ptr, int wMsg, int wParam, int lParam);
//输入法
[DllImport("imm32.dll")]
public static extern IntPtr ImmGetContext(IntPtr hWnd);
[DllImport("imm32.dll")]
public static extern bool ImmGetConversionStatus(IntPtr hIMC,
ref int conversion, ref int sentence);
[DllImport("imm32.dll")]
public static extern bool ImmSetConversionStatus(IntPtr hIMC, int conversion, int sentence);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern short GetKeyState(int vKey);
// public const int VK_BACK = 0x08; //BACKSPACE 密钥
#endregion
private const int HOTKEY_ID = 9000;
//Modifiers:
private const int MOD_NONE = 0x0000; //[NONE]
private const int MOD_ALT = 0x0001; //ALT
private const int MOD_CONTROL = 0x0002; //CTRL
private const int MOD_SHIFT = 0x0004; //SHIFT
private const int MOD_WIN = 0x0008; //WINDOWS
//CAPS LOCK:
private const int VK_A = 65;
private const int VK_B = 66;
private const int VK_C = 67;
private const int VK_D = 68;
private const int VK_E = 69;
private const int VK_F = 70;
private const int VK_G = 71;
private const int VK_H = 72;
private const int VK_I = 73;
private const int VK_J = 74;
private const int VK_K = 75;
private const int VK_L = 76;
private const int VK_M = 77;
private const int VK_N = 78;
private const int VK_O = 79;
private const int VK_P = 80;
private const int VK_Q = 81;
private const int VK_R = 82;
private const int VK_S = 83;
private const int VK_T = 84;
private const int VK_U = 85;
private const int VK_V = 86;
private const int VK_W = 87;
private const int VK_X = 88;
private const int VK_Y = 89;
private const int VK_Z = 90;
#region
const int VK_LBUTTON = 0x01; //鼠标左键
const int VK_RBUTTON = 0x02; //鼠标右键
const int VK_CANCEL = 0x03; //控制中断处理
const int VK_MBUTTON = 0x04; //中间鼠标按钮 (三键鼠标)
const int VK_XBUTTON1 = 0x05; //X1 鼠标按钮
const int VK_XBUTTON2 = 0x06; //X2 鼠标按钮
const int VK_BACK = 0x08; //BACKSPACE 密钥
const int VK_TAB = 0x09; //Tab 键
const int VK_CLEAR = 0x0C; //CLEAR 键
const int VK_RETURN = 0x0D; //Enter 键
const int VK_SHIFT = 0x10; //SHIFT 键
const int VK_CONTROL = 0x11; //Ctrl 键
const int VK_MENU = 0x12; //Alt 键
const int VK_PAUSE = 0x13; //PAUSE 键
const int VK_CAPITAL = 0x14; //CAPS LOCK 键
const int VK_KANA = 0x15; //IME Kana 模式
const int VK_HANGUEL = 0x15; //IME 朝鲜文库埃尔模式 (保持兼容性;使用 VK_HANGUL)
const int VK_HANGUL = 0x15; //IME Hanguel 模式
const int VK_IME_ON = 0x16; //IME On
const int VK_JUNJA = 0x17; //IME Junja 模式
const int VK_FINAL = 0x18; //IME 最终模式
const int VK_HANJA = 0x19; //IME Hanja 模式
const int VK_KANJI = 0x19; //IME Kanji 模式
const int VK_IME_OFF = 0x1A; //IME 关闭
const int VK_ESCAPE = 0x1B; //ESC 键
const int VK_CONVERT = 0x1C; //IME 转换
const int VK_NONCONVERT = 0x1D; //IME 不转换
const int VK_ACCEPT = 0x1E; //IME 接受
const int VK_MODECHANGE = 0x1F; //IME 模式更改请求
const int VK_SPACE = 0x20; //空格键
const int VK_PRIOR = 0x21; //PAGE UP 键
const int VK_NEXT = 0x22; //PAGE DOWN 键
const int VK_END = 0x23; //END 键
const int VK_HOME = 0x24; //HOME 键
const int VK_LEFT = 0x25; //向左键
const int VK_UP = 0x26; //向上键
const int VK_RIGHT = 0x27; //向右键
const int VK_DOWN = 0x28; //向下键
const int VK_SELECT = 0x29; //SELECT 键
const int VK_PRINT = 0x2A; //PRINT 键
const int VK_EXECUTE = 0x2B; //EXECUTE 键
const int VK_SNAPSHOT = 0x2C; //打印屏幕键
const int VK_INSERT = 0x2D; //INS 密钥
const int VK_DELETE = 0x2E; //DEL 键
const int VK_HELP = 0x2F; //帮助密钥
const int VK_LWIN = 0x5B; //左Windows键 (自然键盘)
const int VK_RWIN = 0x5C; //右Windows键 (自然键盘)
const int VK_APPS = 0x5D; //应用程序键 (自然键盘)
const int VK_SLEEP = 0x5F; //计算机休眠键
const int VK_NUMPAD0 = 0x60; //数字键盘 0 键
const int VK_NUMPAD1 = 0x61; //数字键盘 1 键
const int VK_NUMPAD2 = 0x62; //数字键盘 2 键
const int VK_NUMPAD3 = 0x63; //数字键盘 3 键
const int VK_NUMPAD4 = 0x64; //数字键盘 4 键
const int VK_NUMPAD5 = 0x65; //数字键盘 5 键
const int VK_NUMPAD6 = 0x66; //数字键盘 6 键
const int VK_NUMPAD7 = 0x67; //数字键盘 7 键
const int VK_NUMPAD8 = 0x68; //数字键盘 8 键
const int VK_NUMPAD9 = 0x69; //数字键盘 9 键
const int VK_MULTIPLY = 0x6A; //乘键
const int VK_ADD = 0x6B; //添加密钥
const int VK_SEPARATOR = 0x6C; //分隔符键
const int VK_SUBTRACT = 0x6D; //减去键
const int VK_DECIMAL = 0x6E; //十进制键
const int VK_DIVIDE = 0x6F; //除键
const int VK_F1 = 0x70; //F1 键
const int VK_F2 = 0x71; //F2 键
const int VK_F3 = 0x72; //F3 键
const int VK_F4 = 0x73; //F4 键
const int VK_F5 = 0x74; //F5 键
const int VK_F6 = 0x75; //F6 键
const int VK_F7 = 0x76; //F7 键
const int VK_F8 = 0x77; //F8 键
const int VK_F9 = 0x78; //F9 键
const int VK_F10 = 0x79; //F10 键
const int VK_F11 = 0x7A; //F11 键
const int VK_F12 = 0x7B; //F12 键
const int VK_F13 = 0x7C; //F13 键
const int VK_F14 = 0x7D; //F14 键
const int VK_F15 = 0x7E; //F15 键
const int VK_F16 = 0x7F; //F16 键
const int VK_F17 = 0x80; //F17 键
const int VK_F18 = 0x81; //F18 键
const int VK_F19 = 0x82; //F19 键
const int VK_F20 = 0x83; //F20 键
const int VK_F21 = 0x84; //F21 键
const int VK_F22 = 0x85; //F22 键
const int VK_F23 = 0x86; //F23 键
const int VK_F24 = 0x87; //F24 键
const int VK_NUMLOCK = 0x90; //NUM LOCK 密钥
const int VK_SCROLL = 0x91; //SCROLL LOCK 键
const int VK_LSHIFT = 0xA0; //左 SHIFT 键
const int VK_RSHIFT = 0xA1; //右 SHIFT 键
const int VK_LCONTROL = 0xA2; //左 Ctrl 键
const int VK_RCONTROL = 0xA3; //右 Ctrl 键
const int VK_LMENU = 0xA4; //左 Alt 键
const int VK_RMENU = 0xA5; //右 ALT 键
const int VK_BROWSER_BACK = 0xA6; //浏览器后退键
const int VK_BROWSER_FORWARD = 0xA7; //浏览器前进键
const int VK_BROWSER_REFRESH = 0xA8; //浏览器刷新键
const int VK_BROWSER_STOP = 0xA9; //浏览器停止键
const int VK_BROWSER_SEARCH = 0xAA; //浏览器搜索键
const int VK_BROWSER_FAVORITES = 0xAB; //浏览器收藏键
const int VK_BROWSER_HOME = 0xAC; //浏览器“开始”和“主页”键
const int VK_VOLUME_MUTE = 0xAD; //静音键
const int VK_VOLUME_DOWN = 0xAE; //音量减小键
const int VK_VOLUME_UP = 0xAF; //音量增加键
const int VK_MEDIA_NEXT_TRACK = 0xB0; //下一曲目键
const int VK_MEDIA_PREV_TRACK = 0xB1; //上一曲目键
const int VK_MEDIA_STOP = 0xB2; //停止媒体键
const int VK_MEDIA_PLAY_PAUSE = 0xB3; //播放/暂停媒体键
const int VK_LAUNCH_MAIL = 0xB4; //启动邮件键
const int VK_LAUNCH_MEDIA_SELECT = 0xB5; //选择媒体键
const int VK_LAUNCH_APP1 = 0xB6; //启动应用程序 1 键
const int VK_LAUNCH_APP2 = 0xB7; //启动应用程序 2 键
const int VK_OEM_1 = 0xBA; //用于其他字符;它可能因键盘而异。 对于美国标准键盘,“;:”键
const int VK_OEM_PLUS = 0xBB; //对于任何国家/地区,“+”键
const int VK_OEM_COMMA = 0xBC; //对于任何国家/地区,“,键
const int VK_OEM_MINUS = 0xBD; //对于任何国家/地区,“-”键
const int VK_OEM_PERIOD = 0xBE; //对于任何国家/地区,“.”键
const int VK_OEM_2 = 0xBF; //用于其他字符;它可能因键盘而异。 对于美国标准键盘,“/?” key
const int VK_OEM_3 = 0xC0; //用于其他字符;它可能因键盘而异。 对于美国标准键盘,“~”键
const int VK_OEM_4 = 0xDB; //用于其他字符;它可能因键盘而异。 对于美国标准键盘,“[{”键
const int VK_OEM_5 = 0xDC; //用于其他字符;它可能因键盘而异。 对于美国标准键盘,“\|”键
const int VK_OEM_6 = 0xDD; //用于其他字符;它可能因键盘而异。 对于美国标准键盘,“]}”键
const int VK_OEM_7 = 0xDE; //用于其他字符;它可能因键盘而异。 对于美国标准键盘,“单引号/双引号”键
const int VK_OEM_8 = 0xDF; //用于其他字符;它可能因键盘而异。
const int VK_OEM_102 = 0xE2; //<>美国标准键盘上的键,或\\|非美国 102 键键盘上的键
const int VK_PROCESSKEY = 0xE5; //IME PROCESS 密钥
const int VK_PACKET = 0xE7; //用于将 Unicode 字符当作键击传递。 该 VK_PACKET 键是用于非键盘输入方法的 32 位虚拟键值的低字。 有关详细信息,请参阅“备注”,以及KEYBDINPUTSendInputWM_KEYDOWNWM_KEYUP
const int VK_ATTN = 0xF6; //Attn 键
const int VK_CRSEL = 0xF7; //CrSel 键
const int VK_EXSEL = 0xF8; //ExSel 密钥
const int VK_EREOF = 0xF9; //擦除 EOF 密钥
const int VK_PLAY = 0xFA; //播放键
const int VK_ZOOM = 0xFB; //缩放键
const int VK_NONAME = 0xFC; //预留
const int VK_PA1 = 0xFD; //PA1 键
const int VK_OEM_CLEAR = 0xFE; //清除键
#endregion
private HwndSource source;
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
IntPtr handle = new WindowInteropHelper(this).Handle;
source = HwndSource.FromHwnd(handle);
source.AddHook(HwndHook);
// RegisterHotKey(handle, HOTKEY_ID, MOD_NONE, VK_F5); //
RegisterHotKey(handle, HOTKEY_ID, MOD_NONE, VK_F4); //
RegisterHotKey(handle, HOTKEY_ID, MOD_CONTROL, VK_E); //
RegisterHotKey(handle, HOTKEY_ID, MOD_NONE, VK_MBUTTON); //中键
}
public static MainWindow Current
{
get
{
foreach (var s in App.Current.Windows)
{
if (s is MainWindow)
{
return (MainWindow)s;
}
}
return null;
}
}
private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
const int WM_HOTKEY = 0x0312;
switch (msg)
{
case WM_HOTKEY:
switch (wParam.ToInt32())
{
case HOTKEY_ID:
int vkey = (((int)lParam >> 16) & 0xFFFF);
if (vkey == VK_E)
{
HotKeyCtrlE();
}
else if (vkey == VK_F4)
{
HotKeyF4();
}
// else if (vkey == VK_F5)
// {
// HotKeyF5();
// }
else if (vkey == VK_MBUTTON)
{
HotKeyMButton();
}
handled = true;
break;
}
break;
}
return IntPtr.Zero;
}
#endregion
Stopwatch sw = new Stopwatch();
private enum UpdateLevel
{
Progress = 1,
PageArrange = 2
};
// static Brush myBrush = new SolidColorBrush(Color.FromArgb(0xff, 0x95, 0xb0, 0xe3));
static string[] NoneHeadPuncts =
{
"=",
",",
"-",
"。",
"·",
"、",
"】",
"、",
";",
")",
"!",
"@",
"#",
"¥",
"%",
"…",
"&",
"*",
"”",
"’",
"'",
"+",
"—",
"》",
"~",
"|",
"",
"?",
":",
"=",
",",
"-",
".",
"`",
"\\",
"]",
"/",
";" ,
"\'",
")",
"!",
"@",
"#",
"$",
"%",
"^",
"&",
"*",
"(",
"+",
"_",
">",
"~",
"|",
"",
"?",
":" ,
"\"",
" "
};
static string[] NoneTailPuncts =
{
"【",
"(",
"《",
"{",
"[",
"<",
"{",
"“",
"‘",
};
static List<string> AZ = new List<string> { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "'" };
private void UpdateDisplay(UpdateLevel updateLevel)
{
if (IsLookingType && StateManager.LastType)
{
BlindDiff();
return;
}
if (updateLevel >= UpdateLevel.PageArrange)
PageReArrange();
if (updateLevel >= UpdateLevel.Progress)
PageProgressUpdate();
void PageReArrange()
{
double y = (this.ActualHeight - 95.74 - 0.5 - 15) * 0.75 - (expd.IsExpanded ? 145 : 0);
double x = (this.ActualWidth - 52);
Paginator.ArrangePage(x, y, Config.GetDouble("字体大小"), TextInfo.Words.Count);
TextInfo.PageNum = -1;
}
void PageProgressUpdate()
{
//计算页码
// int nextToType = TextInfo.wordStates.IndexOf(WordStates.NO_TYPE);
int nextToType = new StringInfo(TbxInput.Text).LengthInTextElements;
if (nextToType >= TextInfo.Words.Count)
nextToType = TextInfo.Words.Count - 1;
/*
if (nextToType == -1)
{
nextToType = TextInfo.Words.Count - 1;
}
*/
// int newPageNum = Paginator.GetPageNum(nextToType);
// if (newPageNum == -1)
// return;
// if (newPageNum != TextInfo.PageNum)
if (TextInfo.PageNum == -1 || nextToType > Paginator.Pages[TextInfo.PageNum].BodyEnd || nextToType < Paginator.Pages[TextInfo.PageNum].BodyStart)
{
//清空显示
TbDispay.Children.Clear();
ScDisplay.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
TextInfo.Blocks.Clear();
int pn = Paginator.GetPageNum(nextToType);
if (pn < 0)
return;
if (Paginator.Pages.Count < pn)
return;
Page p = Paginator.Pages[pn];
var fm = GetCurrentFontFamily();// new FontFamily(Config.GetString("字体"));
double fs = Config.GetDouble("字体大小");
double height = fs * (1.0 + Config.GetDouble("行距"));
double MinWidth = Config.GetDouble("字体大小") * 0.9;
ScDisplay.FontFamily = fm;
ScDisplay.Foreground = Colors.DisplayForeground;
ScDisplay.FontSize = fs; TbAcc.FontSize = fs / 2.3;
TbxInput.FontFamily = fm;
if (p.HeadEnd >= 0)
TextInfo.PageStartIndex = p.HeadStart;
else
TextInfo.PageStartIndex = p.BodyStart;
//添加头
if (p.HeadEnd >= 0)
{
for (int i = p.HeadStart; i <= p.HeadEnd; i++)
{
TextBlock tb = new TextBlock();
tb.Text = TextInfo.Words[i];
tb.Height = height;
if (tb.Text == "“" || tb.Text == "‘")
{
tb.MinWidth = MinWidth;
tb.TextAlignment = TextAlignment.Right;
}
else if (tb.Text == "”" || tb.Text == "’")
{
tb.MinWidth = MinWidth;
tb.TextAlignment = TextAlignment.Left;
}
TextInfo.Blocks.Add(tb);
}
}
if (p.BodyEnd >= 0)
{
for (int i = p.BodyStart; i <= p.BodyEnd; i++)
{
TextBlock tb = new TextBlock();
tb.Text = TextInfo.Words[i];
tb.Height = height;
if (tb.Text == "“" || tb.Text == "‘")
{
tb.MinWidth = MinWidth;
tb.TextAlignment = TextAlignment.Right;
}
else if (tb.Text == "”" || tb.Text == "’")
{
tb.MinWidth = MinWidth;
tb.TextAlignment = TextAlignment.Left;
}
TextInfo.Blocks.Add(tb);
}
}
if (p.FootEnd >= 0)
{
for (int i = p.FootStart; i <= p.FootEnd; i++)
{
TextBlock tb = new TextBlock();
tb.Text = TextInfo.Words[i];
tb.Height = height;
if (tb.Text == "“" || tb.Text == "‘")
{
tb.MinWidth = MinWidth;
tb.TextAlignment = TextAlignment.Right;
}
else if (tb.Text == "”" || tb.Text == "’")
{
tb.MinWidth = MinWidth;
tb.TextAlignment = TextAlignment.Left;
}
tb.TextDecorations = TextDecorations.Underline;
TextInfo.Blocks.Add(tb);
}
}
if (TextInfo.Blocks.Count >= 3) //标点打包,不在行首显示
{
int total = TextInfo.Blocks.Count;
//字符序列是否不允许出现在首尾
bool[] nohead = new bool[TextInfo.Blocks.Count];
bool[] notail = new bool[TextInfo.Blocks.Count];
for (int i = 0; i < TextInfo.Blocks.Count; i++)
{
nohead[i] = NoneHeadPuncts.Contains(TextInfo.Blocks[i].Text);
notail[i] = NoneTailPuncts.Contains(TextInfo.Blocks[i].Text);
}
for (int i = 1; i < TextInfo.Blocks.Count - 1; i++)
{
string c2 = TextInfo.Blocks[i].Text;
string c1 = TextInfo.Blocks[i-1].Text;
string c3 = TextInfo.Blocks[i + 1].Text;
if (AZ.Contains(c2))
{
if (AZ.Contains(c1))
nohead[i] = true;
if (AZ.Contains(c3))
notail[i] = true;
}
}
bool[] inpack = new bool[TextInfo.Blocks.Count]; //是否打包
bool[] isPackHead = new bool[TextInfo.Blocks.Count]; //是否是包头
bool[] isPackTail = new bool[TextInfo.Blocks.Count]; // 是否是包尾,
inpack[0] = notail[0] || nohead[1];
isPackHead[0] = inpack[0];
isPackTail[0] = false;
inpack[total - 1] = nohead[total - 1] || notail[total - 2];
isPackHead[total - 1] = false;
isPackTail[total - 1] = inpack[total - 1];
for (int i = 1; i < TextInfo.Blocks.Count - 1; i++)
{
inpack[i] = nohead[i] || notail[i] || notail[i - 1] || nohead[i + 1];
isPackHead[i] = !nohead[i] && inpack[i] && !notail[i - 1];
isPackTail[i] = !notail[i] && inpack[i] && !nohead[i + 1];
}
StackPanel lstk = new StackPanel();
for (int i = 0; i < TextInfo.Blocks.Count; i++)
{
if (isPackHead[i])
{
lstk = new StackPanel();
lstk.Orientation = Orientation.Horizontal;
lstk.Width = double.NaN;
lstk.Height = double.NaN;
lstk.Children.Add(TextInfo.Blocks[i]);
}
else if (isPackTail[i])
{
lstk.Children.Add(TextInfo.Blocks[i]);
TbDispay.Children.Add(lstk);
}
else if (inpack[i])
{
lstk.Children.Add(TextInfo.Blocks[i]);
}
else
{
TbDispay.Children.Add(TextInfo.Blocks[i]);
}
}
}
else
{
foreach (var tb in TextInfo.Blocks)
TbDispay.Children.Add(tb);
}
TextInfo.PageNum = pn;
TextInfo.BlocksStates.Clear();
TextInfo.Blocks.ForEach(t => TextInfo.BlocksStates.Add(WordStates.NO_TYPE));
}
//设置背景色
if (!IsLookingType || IsBlindType)
for (int i = 0; i < TextInfo.Blocks.Count; i++)
{
if (TextInfo.BlocksStates[i] != TextInfo.wordStates[TextInfo.PageStartIndex + i])
{
switch (TextInfo.wordStates[TextInfo.PageStartIndex + i])
{
case WordStates.WRONG:
TextInfo.Blocks[i].Background = IsBlindType ? Colors.CorrectBackground : Colors.IncorrectBackground;
break;
case WordStates.RIGHT:
TextInfo.Blocks[i].Background = Colors.CorrectBackground;
break;
case WordStates.NO_TYPE:
TextInfo.Blocks[i].Background = null;
break;
default:
break;
}
TextInfo.BlocksStates[i] = TextInfo.wordStates[TextInfo.PageStartIndex + i];
}
}
if (Config.GetBool("允许滚动") || nextToType == 0)
{
double fs = Config.GetDouble("字体大小");
double fh = fs * (1.0 + Config.GetDouble("行距"));
bool ScrollCondition = false;
int NextBlockIndex = (nextToType - TextInfo.PageStartIndex);
double pos = TextInfo.Blocks[NextBlockIndex].TranslatePoint(new Point(0, 0), TextInfo.Blocks[0]).Y + TextInfo.Blocks[NextBlockIndex].ActualHeight / 2;
double center = ScDisplay.ViewportHeight * 0.48;
double offset = pos - center;
if (offset < 0)
offset = 0;
if (offset > ScDisplay.ScrollableHeight)
offset = ScDisplay.ScrollableHeight;
if (NextBlockIndex > 0 && TextInfo.Blocks[NextBlockIndex].TranslatePoint(new Point(0, 0), TextInfo.Blocks[NextBlockIndex - 1]).X <= 0)
ScrollCondition = true;
if (Math.Abs(ScDisplay.VerticalOffset - offset) > fh * 0.8)
ScrollCondition = true;
if (nextToType == 0)
ScrollCondition = true;
if (ScrollCondition)
ScDisplay.ScrollToVerticalOffset(offset);
//跟随显示速度
bool showSpeed = Config.GetBool("速度跟随提示") && !double.IsNaN(Score.GetValidSpeed()) && Score.GetValidSpeed() > 0;
if (!showSpeed)
{
if (TbAcc.Visibility == Visibility.Visible)
TbAcc.Visibility = Visibility.Hidden;
}
else
{
if (TbAcc.Visibility == Visibility.Hidden)
TbAcc.Visibility = Visibility.Visible;
double AccLeft = TextInfo.Blocks[NextBlockIndex].TranslatePoint(new Point(0, 0), TextInfo.Blocks[0]).X + TextInfo.Blocks[NextBlockIndex].ActualWidth / 3;
double AccTop = TextInfo.Blocks[NextBlockIndex].TranslatePoint(new Point(0, 0), TextInfo.Blocks[0]).Y + TextInfo.Blocks[NextBlockIndex].ActualHeight - offset;
Canvas.SetTop(TbAcc, AccTop);
Canvas.SetLeft(TbAcc, AccLeft);
// 只显示速度
TbAcc.Text = Score.GetValidSpeed().ToString("F2");
TbAcc.Foreground = Colors.GetSpeedColor(Score.GetValidSpeed());
}
//跟随显示提示
/*
bool showAccuracy = Config.GetBool("增强键准提示") && !double.IsNaN(Score.GetAccuracy());
bool showSpeed = Config.GetBool("增强速度提示") && !double.IsNaN(Score.GetValidSpeed());
if (!showAccuracy && !showSpeed)
{
if (TbAcc.Visibility == Visibility.Visible)
TbAcc.Visibility = Visibility.Hidden;
}
else
{
if (TbAcc.Visibility == Visibility.Hidden)
TbAcc.Visibility = Visibility.Visible;
double AccLeft = TextInfo.Blocks[NextBlockIndex].TranslatePoint(new Point(0, 0), TextInfo.Blocks[0]).X + TextInfo.Blocks[NextBlockIndex].ActualWidth / 3;
double AccTop = TextInfo.Blocks[NextBlockIndex].TranslatePoint(new Point(0, 0), TextInfo.Blocks[0]).Y + TextInfo.Blocks[NextBlockIndex].ActualHeight - offset;
Canvas.SetTop(TbAcc, AccTop);
Canvas.SetLeft(TbAcc, AccLeft);
// 根据启用的功能显示不同内容
if (showAccuracy && showSpeed)
{
// 两个功能都启用,显示组合信息
TbAcc.Text = $"{Score.GetValidSpeed():F0},{(100 * Score.GetAccuracy()):F1}%";
// 使用速度颜色作为主色调
TbAcc.Foreground = Colors.GetSpeedColor(Score.GetValidSpeed());
}
else if (showSpeed)
{
// 只显示速度
TbAcc.Text = Score.GetValidSpeed().ToString("F2");
TbAcc.Foreground = Colors.GetSpeedColor(Score.GetValidSpeed());
}
else if (showAccuracy)
{
// 只显示准确率
TbAcc.Text = (100 * Score.GetAccuracy()).ToString("F2");
TbAcc.Foreground = Colors.GetAccColor(Score.GetAccuracy());
}
}
*/
}
}
void BlindDiff()
{
TbDispay.Children.Clear();
ScDisplay.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
TextBlock tb = new TextBlock();
tb.FontSize = Config.GetDouble("字体大小");
tb.FontFamily = GetCurrentFontFamily();// new FontFamily(Config.GetString("字体"));
tb.Background = BdDisplay.Background;
tb.TextWrapping = TextWrapping.Wrap;
tb.HorizontalAlignment = HorizontalAlignment.Stretch;
tb.VerticalAlignment = VerticalAlignment.Top;
tb.Foreground = Colors.DisplayForeground;
string currentMatchText = string.Concat(TextInfo.Words);
string t1 = currentMatchText.Replace('”', '\"').Replace('“', '\"').Replace('‘', '\'').Replace('’', '\'');
string t2 = TbxInput.Text.Replace('”', '\"').Replace('“', '\"').Replace('‘', '\'').Replace('’', '\'');
List<DiffRes> diffs = DiffTool.Diff(t1, t2);
int counter = 0;
foreach (var df in diffs)
{
Run r = new Run();
switch (df.Type)
{
case DiffType.None:
r.Text = currentMatchText.Substring(df.OrigIndex, 1);
r.Background = Colors.CorrectBackground;
break;
case DiffType.Delete:
r.Text = currentMatchText.Substring(df.OrigIndex - 1, 1);
counter--;
// r.Background = Colors.CorrectBackground;
break;
case DiffType.Add:
r.Text = TbxInput.Text.Substring(df.RevIndex + counter, 1);
counter++;
r.Background = Colors.IncorrectBackground;
break;
}
tb.Inlines.Add(r);
}
TbDispay.Children.Add(tb);
}