-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathAdvRichTextBox.Designer.cs
More file actions
1722 lines (1548 loc) · 78 KB
/
AdvRichTextBox.Designer.cs
File metadata and controls
1722 lines (1548 loc) · 78 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
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using TrOCR.Helper;
namespace TrOCR
{
public class TempTranslateEventArgs : EventArgs
{
public string SourceLanguage { get; }
public string TargetLanguage { get; }
public TempTranslateEventArgs(string source, string target)
{
SourceLanguage = source;
TargetLanguage = target;
}
}
[Description("Provides a user control that allows the user to edit HTML page.")]
[ClassInterface(ClassInterfaceType.AutoDispatch)]
public class AdvRichTextBox : UserControl
{
// 【新增】定义一个携带语言数据的公共事件
public event EventHandler<TempTranslateEventArgs> TemporaryTranslateRequested;
// 【新增】定义状态变量:是否正在程序内部修改字体/格式
// public 属性,以便 FmMain 也能读取到
public bool IsFontChanging { get; private set; } = false;
// 【新增】通用字体切换辅助方法
// 作用:统一管理状态锁、颜色切换、配置文件保存
private void ChangeFontInternal(string fontName, ToolStripItem activeIcon)
{
// 1. 上锁:告诉外界(FmMain)现在正在改字体,别触发翻译
this.IsFontChanging = true;
try
{
// 2. 切换图标颜色 UI
this.font_宋体.ForeColor = Color.Black;
this.font_黑体.ForeColor = Color.Black;
this.font_楷体.ForeColor = Color.Black;
this.font_微软雅黑.ForeColor = Color.Black;
this.font_新罗马.ForeColor = Color.Black;
if (activeIcon != null)
{
activeIcon.ForeColor = Color.Red;
}
// 3. 核心字体切换逻辑
// ------------------------------------------------------------
// 先暂停重绘,防止闪烁
this.richTextBox1.SuspendLayout();
string text = this.richTextBox1.Text;
this.richTextBox1.Text = ""; // 这步会触发 TextChanged,但因为锁住了,所以安全
// 特殊处理:这里未来可以添加切换字体时的emojie渲染问题的修复代码
Font font = new Font(fontName, 16f * Program.Factor, GraphicsUnit.Pixel);
this.richTextBox1.Font = font;
this.richTextBox1.Text = text; // 这步也会触发 TextChanged
// 恢复重绘
this.richTextBox1.ResumeLayout();
// 4. 保存配置
// 映射一下显示名和保存名
string saveName = fontName;
if (fontName == "STKaiti") saveName = "楷体";
if (fontName == "Times New Roman") saveName = "新罗马";
IniHelper.SetValue("工具栏", "字体", saveName);
}
catch (Exception ex)
{
// 简单的错误捕获,防止字体不存在导致崩溃
System.Diagnostics.Debug.WriteLine("切换字体失败: " + ex.Message);
}
finally
{
// 5. 解锁:无论如何都要恢复,防止死锁
this.IsFontChanging = false;
}
}
protected override void Dispose(bool disposing)
{
if (disposing && this.components != null)
{
this.components.Dispose();
}
base.Dispose(disposing);
}
public void InitializeComponent()
{
CheckForIllegalCrossThreadCalls = false;
ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof(AdvRichTextBox));
this.font_宋体 = new ToolStripMenuItem();
this.font_楷体 = new ToolStripMenuItem();
this.font_黑体 = new ToolStripMenuItem();
this.font_微软雅黑 = new ToolStripMenuItem();
this.font_新罗马 = new ToolStripMenuItem();
this.zh_jp = new ToolStripMenuItem();
this.zh_ko = new ToolStripMenuItem();
this.zh_en = new ToolStripMenuItem();
this.mode_顶置 = new ToolStripMenuItem();
this.mode_正常 = new ToolStripMenuItem();
this.mode_合并 = new ToolStripMenuItem();
this.topmost = new ToolStripButton();
this.languagle = new ToolStripDropDownButton();
this.mode = new ToolStripDropDownButton();
this.Fontstyle = new ToolStripDropDownButton();
this.toolStripToolBar = new HelpRepaint.ToolStripEx();
this.toolStripButtonclose = new ToolStripButton();
this.toolStripButtonBold = new ToolStripButton();
this.toolStripButtonParagraph = new ToolStripButton();
this.toolStripButtonFind = new ToolStripButton();
this.toolStripButtonColor = new HelpRepaint.ColorPicker();
this.toolStripSeparatorFont = new ToolStripSeparator();
this.toolStripButtonFence = new ToolStripButton();
this.toolStripButtonSplit = new ToolStripButton();
this.toolStripButtoncheck = new ToolStripButton();
this.toolStripButtonIndent = new ToolStripButton();
this.toolStripSeparatorFormat = new ToolStripSeparator();
this.toolStripButtonLeft = new ToolStripButton();
this.toolStripButtonMerge = new ToolStripButton();
this.toolStripButtonVoice = new ToolStripButton();
this.toolStripButtonFull = new ToolStripButton();
this.toolStripSeparatorAlign = new ToolStripSeparator();
this.toolStripButtonspace = new ToolStripButton();
this.toolStripButtonR_arow = new ToolStripButton();
this.toolStripButtonSend = new ToolStripButton();
this.toolStripButtonTrans = new ToolStripButton();
this.toolStripButtonNote = new ToolStripButton();
this.richTextBox1 = new RichTextBoxEx();
this.toolStripToolBar.SuspendLayout();
base.SuspendLayout();
this.toolStripSeparatorFont.ForeColor = Color.White;
this.toolStripToolBar.GripStyle = ToolStripGripStyle.Hidden;
this.toolStripToolBar.Location = new Point(0, 0);
this.toolStripToolBar.Name = "toolStripToolBar";
//修复工具栏图标dpi缩放的代码目前放在构造函数了,放到InitializeComponent这里也行,
// 不过放到这里有个缺陷是vs设计器修改界面后会自动重写代码,可能覆盖掉自己添加的代码,构造函数里的不会被覆盖,
// 不过对于本项目来说,这个设计文件本来就不适合使用vs设计器设计,所以无所谓了
//修复工具栏图标dpi缩放的代码和构造函数里的一样:if判断加不加都行,这里就不加if判断了,毕竟注释掉了,只是告诉你也可以在这里修复
//this.toolStripToolBar.ImageScalingSize = new Size((int)(16 * Program.Factor), (int)(16 * Program.Factor));
//根据设置放大图标
if(StaticValue.ToolbarIconScaleFactor>0){
this.toolStripToolBar.ImageScalingSize = new Size((int)(16 * StaticValue.ToolbarIconScaleFactor), (int)(16 * StaticValue.ToolbarIconScaleFactor));
}
this.toolStripToolBar.RenderMode = ToolStripRenderMode.System;
this.toolStripToolBar.Size = new Size(600, 25);
this.toolStripToolBar.TabIndex = 1;
this.toolStripToolBar.Click += this.toolStripToolBar_Click;
this.toolStripToolBar.Text = "Tool Bar";
this.toolStripToolBar.BackColor = Color.White;
this.toolStripToolBar.Renderer = new HelpRepaint.MenuItemRenderer();
this.toolStripButtonBold.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonBold.Image = (Image)componentResourceManager.GetObject("toolStripButtonBold.Image");
this.toolStripButtonBold.ImageTransparentColor = Color.Magenta;
this.toolStripButtonBold.Name = "toolStripButtonBold";
this.toolStripButtonBold.Size = new Size(23, 22);
this.toolStripButtonBold.Text = "加粗";
this.toolStripButtonBold.Click += this.toolStripButtonBold_Click;
this.toolStripButtonParagraph.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonParagraph.Image = (Image)componentResourceManager.GetObject("toolStripButtonParagraph.Image");
this.toolStripButtonParagraph.ImageTransparentColor = Color.Magenta;
this.toolStripButtonParagraph.Name = "toolStripButtonParagraph";
this.toolStripButtonParagraph.Size = new Size(23, 22);
this.toolStripButtonParagraph.Text = "依据位置自动分段\r\n仅支持搜狗接口\r\n适合段落识别\r\n图片越清晰越准确\r\n准确度98%以上";
this.toolStripButtonParagraph.Click += this.toolStripButtonParagraph_Click;
this.toolStripButtonParagraph.MouseDown += this.toolStripButtonParagraph_keydown;
this.toolStripButtonFind.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonFind.Image = (Image)componentResourceManager.GetObject("toolStripButtonFind.Image");
this.toolStripButtonFind.ImageTransparentColor = Color.Magenta;
this.toolStripButtonFind.Name = "toolStripButtonFind";
this.toolStripButtonFind.Size = new Size(23, 22);
this.toolStripButtonFind.Text = "查找\\替换";
this.toolStripButtonFind.Click += this.toolStripButtonFind_Click;
this.toolStripButtonColor.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonColor.Image = (Image)componentResourceManager.GetObject("toolStripButtonColor.Image");
this.toolStripButtonColor.ImageTransparentColor = Color.Magenta;
this.toolStripButtonColor.Name = "toolStripButtonColor";
this.toolStripButtonColor.Size = new Size(23, 22);
this.toolStripButtonColor.Text = "字体颜色";
this.toolStripButtonColor.Click += this.toolStripButtonColor_Click;
this.toolStripButtonLeft.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonLeft.Image = (Image)componentResourceManager.GetObject("toolStripButtonLeft.Image");
this.toolStripButtonLeft.ImageTransparentColor = Color.Magenta;
this.toolStripButtonLeft.Name = "toolStripButtonLeft";
this.toolStripButtonLeft.Size = new Size(23, 22);
this.toolStripButtonLeft.Text = "左对齐";
this.toolStripButtonLeft.Click += this.toolStripButtonLeft_Click;
this.toolStripButtonMerge.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonMerge.Image = (Image)componentResourceManager.GetObject("toolStripButtonMerge.Image");
this.toolStripButtonMerge.ImageTransparentColor = Color.Magenta;
this.toolStripButtonMerge.Name = "toolStripButtonMerge";
this.toolStripButtonMerge.Size = new Size(23, 22);
this.toolStripButtonMerge.Text = "将文本合并成一段";
this.toolStripButtonMerge.Click += this.toolStripButtonMerge_Click;
this.toolStripButtonMerge.MouseDown += this.toolStripButtonMerge_keydown;
this.toolStripButtonVoice.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonVoice.Image = (Image)componentResourceManager.GetObject("toolStripButtonVoice.Image");
this.toolStripButtonVoice.ImageTransparentColor = Color.Magenta;
this.toolStripButtonVoice.Name = "toolStripButtonVoice";
this.toolStripButtonVoice.Size = new Size(23, 22);
this.toolStripButtonVoice.Text = "朗读";
this.toolStripButtonVoice.Click += this.toolStripButtonVoice_Click;
this.toolStripButtonFull.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonFull.Image = (Image)componentResourceManager.GetObject("toolStripButtonFull.Image");
this.toolStripButtonFull.ImageTransparentColor = Color.Magenta;
this.toolStripButtonFull.Name = "toolStripButtonFull";
this.toolStripButtonFull.Size = new Size(23, 22);
this.toolStripButtonFull.Text = "两端对齐";
this.toolStripButtonFull.Click += this.toolStripButtonFull_Click;
this.toolStripButtonspace.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonspace.Image = (Image)componentResourceManager.GetObject("toolStripButtonspace.Image");
this.toolStripButtonspace.ImageTransparentColor = Color.Magenta;
this.toolStripButtonspace.Name = "toolStripButtonLine";
this.toolStripButtonspace.Size = new Size(23, 22);
this.toolStripButtonspace.Text = "首行缩进";
this.toolStripButtonspace.Click += this.toolStripButtonspace_Click;
this.toolStripButtonFence.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonFence.Image = (Image)componentResourceManager.GetObject("toolStripButtonFence.Image");
this.toolStripButtonFence.ImageTransparentColor = Color.Magenta;
this.toolStripButtonFence.Name = "toolStripButtonformat";
this.toolStripButtonFence.Size = new Size(23, 22);
this.toolStripButtonFence.Text = "截图时自动分栏\r\n多选区时无效\r\n单击显示分栏示意图";
this.toolStripButtonFence.Click += this.toolStripButtonFence_Click;
this.toolStripButtonFence.MouseDown += this.toolStripButtonFence_keydown;
this.toolStripButtonSend.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonSend.Image = (Image)componentResourceManager.GetObject("toolStripButtonSend.Image");
this.toolStripButtonSend.ImageTransparentColor = Color.Magenta;
this.toolStripButtonSend.Name = "toolStripButtonSend";
this.toolStripButtonSend.Size = new Size(23, 22);
this.toolStripButtonSend.Text = "复制/发送";
this.toolStripButtonSend.Click += this.toolStripButtonSend_Click;
this.toolStripButtonSplit.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonSplit.Image = (Image)componentResourceManager.GetObject("toolStripButtonSplit.Image");
this.toolStripButtonSplit.ImageTransparentColor = Color.Magenta;
this.toolStripButtonSplit.Name = "toolStripButtonSplit";
this.toolStripButtonSplit.Size = new Size(23, 22);
this.toolStripButtonSplit.Text = "按图片中的行进行拆分";
this.toolStripButtonSplit.Click += this.toolStripButtonSplit_Click;
this.toolStripButtonSplit.MouseDown += this.toolStripButtonSplit_keydown;
this.toolStripButtoncheck.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtoncheck.Image = (Image)componentResourceManager.GetObject("toolStripButtoncheck.Image");
this.toolStripButtoncheck.ImageTransparentColor = Color.Magenta;
this.toolStripButtoncheck.Name = "toolStripButtoncheck";
this.toolStripButtoncheck.Size = new Size(23, 22);
this.toolStripButtoncheck.Text = "检查文本是否有错别字";
this.toolStripButtoncheck.Click += this.toolStripButtoncheck_Click;
this.toolStripButtoncheck.MouseDown += this.toolStripButtoncheck_keydown;
this.toolStripButtonTrans.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonTrans.Image = (Image)componentResourceManager.GetObject("toolStripButtonTrans.Image");
this.toolStripButtonTrans.ImageTransparentColor = Color.Magenta;
this.toolStripButtonTrans.Name = "toolStripButtonTrans";
this.toolStripButtonTrans.Size = new Size(23, 22);
this.toolStripButtonTrans.Text = "翻译";
this.toolStripButtonTrans.Click += this.toolStripButtonTrans_Click;
this.toolStripButtonTrans.MouseDown += this.toolStripButtontrans_keydown;
this.toolStripButtonNote.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonNote.Image = (Image)componentResourceManager.GetObject("toolStripButtonNote.Image");
this.toolStripButtonNote.ImageTransparentColor = Color.Magenta;
this.toolStripButtonNote.Name = "toolStripButtonTrans";
this.toolStripButtonNote.Size = new Size(23, 22);
this.toolStripButtonNote.Text = "记录窗体";
this.toolStripButtonNote.Click += this.toolStripButtonNote_Click;
this.toolStripButtonclose.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.toolStripButtonclose.Image = (Image)componentResourceManager.GetObject("toolStripButtonclose.Image");
this.toolStripButtonclose.ImageTransparentColor = Color.Magenta;
this.toolStripButtonclose.Name = "toolStripButtonclose";
this.toolStripButtonclose.Size = new Size(23, 22);
this.toolStripButtonclose.Text = "关闭";
this.toolStripButtonclose.Click += this.toolStripButtonclose_Click;
this.languagle.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.languagle.Image = (Image)componentResourceManager.GetObject("languagle.Image");
this.languagle.ImageTransparentColor = Color.Magenta;
this.languagle.Name = "toolStripButtonclose";
this.languagle.Size = new Size(23, 22);
this.languagle.Text = "选择翻译语言\r\n支持自动检测\r\n可以双向翻译";
this.zh_en.Text = "中⇆英";
this.zh_en.ForeColor = Color.Red;
this.zh_en.Click += this.zh_en_Click;
this.zh_jp.Text = "中⇆日";
this.zh_jp.ForeColor = Color.Black;
this.zh_jp.Click += this.zh_jp_Click;
this.zh_ko.Text = "中⇆韩";
this.zh_ko.ForeColor = Color.Black;
this.zh_ko.Click += this.zh_ko_Click;
this.languagle.DropDownItems.Add(this.zh_en);
this.languagle.DropDownItems.Add(this.zh_jp);
this.languagle.DropDownItems.Add(this.zh_ko);
//注释掉或改为true,这样此图标就跟随设置放大了
// this.languagle.AutoSize = false;
((ToolStripDropDownMenu)this.languagle.DropDown).ShowImageMargin = false;
this.languagle.DropDown.BackColor = Color.White;
this.languagle.DropDown.AutoSize = false;
if (Program.Factor == 1f)
{
this.languagle.DropDown.AutoSize = false;
}
else
{
this.languagle.DropDown.AutoSize = true;
}
this.languagle.DropDown.Width = Convert.ToInt32(55f);
this.languagle.DropDown.Height = Convert.ToInt32(70f);
this.languagle.ShowDropDownArrow = false;
// 【新增】绑定 MouseDown 事件
this.languagle.MouseDown += new System.Windows.Forms.MouseEventHandler(this.languagle_MouseDown);
this.topmost.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.topmost.Image = (Image)componentResourceManager.GetObject("mode.Image");
this.topmost.ImageTransparentColor = Color.Magenta;
this.topmost.Name = "toolStripButtonclose";
this.topmost.Size = new Size(23, 22);
this.topmost.Text = "顶置";
this.topmost.MouseDown += this.topmost_keydown;
this.Fontstyle.DisplayStyle = ToolStripItemDisplayStyle.Image;
this.Fontstyle.Image = (Image)componentResourceManager.GetObject("Fontstyle.Image");
this.Fontstyle.ImageTransparentColor = Color.Magenta;
this.Fontstyle.Name = "toolStripButtonclose";
this.Fontstyle.Size = new Size(23, 22);
this.Fontstyle.Text = "字体";
//注释掉或改为true,这样此图标就跟随设置放大了
// this.Fontstyle.AutoSize = false;
((ToolStripDropDownMenu)this.Fontstyle.DropDown).ShowImageMargin = false;
this.Fontstyle.DropDown.BackColor = Color.White;
this.Fontstyle.DropDown.AutoSize = false;
if (Program.Factor == 1f)
{
this.Fontstyle.DropDown.AutoSize = false;
}
else
{
this.Fontstyle.DropDown.AutoSize = true;
}
this.Fontstyle.DropDown.Width = Convert.ToInt32(123f);
this.Fontstyle.DropDown.Height = Convert.ToInt32(115f);
this.Fontstyle.ShowDropDownArrow = false;
this.font_宋体.Text = "宋体";
this.font_宋体.ForeColor = Color.Black;
this.font_宋体.Click += this.font_宋体c;
this.font_黑体.Text = "黑体";
this.font_黑体.ForeColor = Color.Black;
this.font_黑体.Click += this.font_黑体c;
this.font_楷体.Text = "楷体";
this.font_楷体.ForeColor = Color.Black;
this.font_楷体.Click += this.font_楷体c;
this.font_微软雅黑.Text = "微软雅黑";
this.font_微软雅黑.ForeColor = Color.Black;
this.font_微软雅黑.Click += this.font_微软雅黑c;
this.font_新罗马.Text = "Time New Roman";
this.font_新罗马.ForeColor = Color.Red;
this.font_新罗马.Click += this.font_新罗马c;
this.Fontstyle.DropDownItems.Add(this.font_宋体);
this.Fontstyle.DropDownItems.Add(this.font_黑体);
this.Fontstyle.DropDownItems.Add(this.font_楷体);
this.Fontstyle.DropDownItems.Add(this.font_微软雅黑);
this.Fontstyle.DropDownItems.Add(this.font_新罗马);
this.richTextBox1.Location = new Point(32, 13);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new Size(603, 457);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.DetectUrls = true;
this.richTextBox1.HideSelection = false;
this.richTextBox1.Text = "";
this.richTextBox1.BorderStyle = BorderStyle.None;
this.richTextBox1.Dock = DockStyle.Fill;
this.richTextBox1.Multiline = true;
this.richTextBox1.ScrollBars = RichTextBoxScrollBars.Vertical;
this.richTextBox1.KeyDown += this.richTextBox1_KeyDown;
this.richTextBox1.LinkClicked += this.richTextBox1_LinkClicked;
this.richTextBox1.MouseDown += this.richtextbox1_MouseDown;
this.richTextBox1.AllowDrop = true;
this.richTextBox1.MouseEnter += this.Form1_MouseEnter;
this.richTextBox1.DragEnter += this.Form1_DragEnter;
this.richTextBox1.DragDrop += this.Form1_DragDrop;
this.richTextBox1.SelectionAlignment = HelpRepaint.TextAlign.Left;
this.richTextBox1.SetLine = "行高";
this.richTextBox1.Font = new Font("Times New Roman", 16f * Program.Factor, GraphicsUnit.Pixel);
this.richTextBox1.LanguageOption = RichTextBoxLanguageOptions.UIFonts;
this.richTextBox1.TextChanged += this.richeditbox_TextChanged;
this.richTextBox1.Cursor = Cursors.IBeam;
this.indent_two(1);
this.mode.Font = new Font("微软雅黑", 9f * Program.Factor, FontStyle.Regular);
this.languagle.Font = new Font("微软雅黑", 9f * Program.Factor, FontStyle.Regular);
this.Fontstyle.Font = new Font("微软雅黑", 9f * Program.Factor, FontStyle.Regular);
base.AutoScaleMode = AutoScaleMode.None;
base.Controls.Add(this.richTextBox1);
base.Controls.Add(this.toolStripToolBar);
base.Name = "richTextBox";
base.Text = "richTextBox";
base.Size = new Size(600, 300);
this.toolStripToolBar.ResumeLayout(false);
this.toolStripToolBar.PerformLayout();
base.ResumeLayout(false);
base.PerformLayout();
}
public AdvRichTextBox()
{
this.toolspace = true;
this.toolFull = true;
this.c = new AdvRichTextBox.cmd(50);
this.Font = new Font(this.Font.Name, 9f / StaticValue.DpiFactor, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
this.InitializeComponent();
this.readIniFile();
// [新增] 根据 dpi 强制缩放工具栏的 *目标* 图标尺寸
//这样工具栏图标也强制放大了,而不只是图标所占格子放大,但是原始图标是16x16的,强制放大后会糊,
// 需要提供更高像素的图标,比如32x32,64x64的,这样放大后才清晰不糊
// 低像素图标一般放大会糊,但是高像素图标缩小一般不会糊
//ps:省事的话只需要一套高像素尺寸图标即可,更专业的是提供不同套像素尺寸的图标,然后根据dpi自动选择或缩放哪一套,
// 这里及未来会直接采用省事的方案: 只需要一套高像素图标
// if (Program.Factor > 1.0f)//这个if判断去掉也行,dpi对应1.0f的时候,计算一下也没啥性能影响
// {
// // 1. 计算新的目标图标大小 (例如 16 * 2.0 = 32)
// int newIconSize = (int)(16 * Program.Factor);
// // 2. 将这个新尺寸应用到 *整个工具栏*
// this.toolStripToolBar.ImageScalingSize = new System.Drawing.Size(newIconSize, newIconSize);
// //或者直接
// // this.toolStripToolBar.ImageScalingSize = new Size((int)(16 * Program.Factor), (int)(16 * Program.Factor));
// }
//字体图标(非图片图标)的思路看上个提交吧
this.richTextBox1.LanguageOption = RichTextBoxLanguageOptions.UIFonts;
}
/// <summary>
/// 设置工具栏的可用状态(用于流式输出时禁用,防止误触)
/// </summary>
public void SetToolbarEnabled(bool enabled)
{
if (this.toolStripToolBar != null)
{
this.toolStripToolBar.Enabled = enabled;
}
}
public override string Text
{
get
{
return this.richTextBox1.Text;
}
set
{
this.richTextBox1.Text = value;
}
}
public void toolStripButtonBold_Click(object sender, EventArgs e)
{
Font selectionFont = this.richTextBox1.SelectionFont;
if (selectionFont.Bold)
{
Font selectionFont2 = new Font(selectionFont, selectionFont.Style & ~FontStyle.Bold);
this.richTextBox1.SelectionFont = selectionFont2;
}
else
{
Font selectionFont3 = new Font(selectionFont, selectionFont.Style | FontStyle.Bold);
this.richTextBox1.SelectionFont = selectionFont3;
}
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonParagraph_Click(object sender, EventArgs e)
{
}
public void toolStripButtonFind_Click(object sender, EventArgs e)
{
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
ReplaceForm replaceForm = new ReplaceForm(this);
if (this.txt_flag == "天若幽心")
{
replaceForm.Text = "识别替换";
replaceForm.Location = base.PointToScreen(new Point((base.Width - replaceForm.Width) / 2, (base.Height - replaceForm.Height) / 2));
}
else
{
replaceForm.Text = "翻译替换";
replaceForm.Location = base.PointToScreen(new Point((base.Width - replaceForm.Width) / 2, (base.Height - replaceForm.Height) / 2));
}
replaceForm.Show(this);
}
public void toolStripButtonColor_Click(object sender, EventArgs e)
{
this.richTextBox1.SelectionColor = this.toolStripButtonColor.SelectedColor;
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonFence_Click(object sender, EventArgs e)
{
if (!File.Exists("cvextern.dll"))
{
MessageBox.Show("请从蓝奏网盘中下载cvextern.dll大小约25m,点击确定自动弹出网页。\r\n将下载后的文件与 天若OCR文字识别.exe 这个文件放在一起。");
Process.Start("https://www.lanzous.com/i1ab3vg");
return;
}
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
if (File.Exists("Data\\分栏预览图.jpg"))
{
Process process = new Process();
process.StartInfo.FileName = "Data\\分栏预览图.jpg";
process.StartInfo.Arguments = "rundl132.exe C://WINDOWS//system32//shimgvw.dll,ImageView";
process.Start();
process.Close();
}
}
public void toolStripButtonSplit_Click(object sender, EventArgs e)
{
// 1. 获取上次OCR识别后缓存的、按行拆分的文本
string splitText = StaticValue.v_Split;
// 如果没有缓存的拆分文本,则不执行任何操作
if (string.IsNullOrEmpty(splitText)) return;
// 2. 更新UI
this.richTextBox1.Text = splitText;
// 3. 根据设置,自动复制结果
if (StaticValue.IsSplitAutoCopy)
{
// 【核心修改】通过 FindForm() 获取主窗口实例并加锁
var mainForm = this.FindForm() as FmMain;
if (mainForm != null)
{
mainForm.SetClipboardWithLock(splitText);
}
}
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtoncheck_Click(object sender, EventArgs e)
{
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
new Thread(new ThreadStart(this.错别字检查API)).Start();
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonIndent_Click(object sender, EventArgs e)
{
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonLeft_Click(object sender, EventArgs e)
{
this.richTextBox1.SelectAll();
this.richTextBox1.SelectionAlignment = HelpRepaint.TextAlign.Left;
this.richTextBox1.Select(0, 0);
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonMerge_Click(object sender, EventArgs e)
{
string currentText = this.richTextBox1.Text;
if (string.IsNullOrEmpty(currentText)) return;
string finalText;
// 【新增】分支1:处理“去除所有空格”
if (StaticValue.IsMergeRemoveAllSpace)
{
// 使用正则表达式一次性移除所有空白字符(包括空格、换行、制表符等)
// finalText = Regex.Replace(currentText, @"\s+", "");
// 移除所有换行和空格(半角和全角)
finalText = Regex.Replace(currentText, @"[\r\n ]+", "");
}
else// 【保留】分支 2 和 3:执行原来的智能合并或默认合并
{
string[] lines = currentText.Split(new[] { "\r\n", "\n", "\r" }, StringSplitOptions.None);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < lines.Length; i++)
{
string processedLine;
// 【分支 2】智能模式
if (StaticValue.IsMergeRemoveSpace)
{
// --- 全新的、最终版的智能空格处理逻辑 ---
// 1. 规范化:将一行中连续的多个空格(半角/全角)替换为单个半角空格,并去除首尾空格
string normalizedLine = Regex.Replace(lines[i], @"[ \ ]+", " ").Trim();
if (normalizedLine.Length <= 1)
{
processedLine = normalizedLine;
}
else
{
StringBuilder lineSb = new StringBuilder();
lineSb.Append(normalizedLine[0]);
for (int j = 1; j < normalizedLine.Length; j++)
{
char lastChar = normalizedLine[j - 1];
char currentChar = normalizedLine[j];
// 【核心修改】细分字符类型
bool lastIsEnglish = (lastChar >= 'a' && lastChar <= 'z') || (lastChar >= 'A' && lastChar <= 'Z');
bool lastIsNumber = char.IsDigit(lastChar);
bool currentIsEnglish = (currentChar >= 'a' && currentChar <= 'z') || (currentChar >= 'A' && currentChar <= 'Z');
bool currentIsNumber = char.IsDigit(currentChar);
bool lastIsHanzi = lastChar >= 0x4E00 && lastChar <= 0x9FA5;
bool currentIsHanzi = currentChar >= 0x4E00 && currentChar <= 0x9FA5;
// 2. 修正:移除中文汉字之间的空格
if (lastIsHanzi && currentChar == ' ' && (j + 1 < normalizedLine.Length) && (normalizedLine[j + 1] >= 0x4E00 && normalizedLine[j + 1] <= 0x9FA5))
{
continue; // 跳过这个空格,不添加到结果中
}
// 3. 补充:在需要且当前没有空格的地方添加空格
bool spaceNeeded = (lastIsHanzi && (currentIsEnglish || currentIsNumber)) ||
((lastIsEnglish || lastIsNumber) && currentIsHanzi);
if (spaceNeeded && lastChar != ' ')
{
lineSb.Append(" ");
}
lineSb.Append(currentChar);
}
processedLine = lineSb.ToString();
}
}
else//// 【分支 3】默认模式(非智能,也非移除所有)
{
// 如果不启用智能模式,则只做简单的首尾修剪
processedLine = lines[i].Trim();
}
if (string.IsNullOrEmpty(processedLine)) continue;
sb.Append(processedLine);
// 4. 处理行与行之间的连接(这部分逻辑保持不变)
if (i < lines.Length - 1)
{
string nextLineRaw = lines[i + 1];
if (!string.IsNullOrWhiteSpace(nextLineRaw))
{
char lastChar = processedLine.LastOrDefault();
string nextLineProcessed = StaticValue.IsMergeRemoveSpace ? Regex.Replace(nextLineRaw, @"[ \ ]+", " ").Trim() : nextLineRaw.Trim();
if (!string.IsNullOrEmpty(nextLineProcessed))
{
char firstChar = nextLineProcessed.FirstOrDefault();
// 【核心修改】细分字符类型
bool lastIsEnglish = (lastChar >= 'a' && lastChar <= 'z') || (lastChar >= 'A' && lastChar <= 'Z');
bool lastIsNumber = char.IsDigit(lastChar);
bool firstIsEnglish = (firstChar >= 'a' && firstChar <= 'z') || (firstChar >= 'A' && firstChar <= 'Z');
bool firstIsNumber = char.IsDigit(firstChar);
bool lastIsHanzi = lastChar >= 0x4E00 && lastChar <= 0x9FA5;
bool firstIsHanzi = firstChar >= 0x4E00 && firstChar <= 0x9FA5;
// 【核心修改】更新添加空格的规则,排除英文与数字之间的情况
if ((lastIsEnglish && firstIsEnglish) || // 英文-英文
(lastIsHanzi && (firstIsEnglish || firstIsNumber)) || // 中文-英文/数字
((lastIsEnglish || lastIsNumber) && firstIsHanzi)) // 英文/数字-中文
{
sb.Append(" ");
}
}
}
}
}
finalText = sb.ToString();
}
// 更新UI并执行复制
this.richTextBox1.Text = finalText;
if (StaticValue.IsMergeAutoCopy && !string.IsNullOrEmpty(finalText))
{
// 【核心修改】通过 FindForm() 获取主窗口实例并加锁
var mainForm = this.FindForm() as FmMain;
if (mainForm != null)
{
mainForm.SetClipboardWithLock(finalText);
}
}
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonVoice_Click(object sender, EventArgs e)
{
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
HelpWin32.SendMessage(StaticValue.mainHandle, 786, 518);
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonFull_Click(object sender, EventArgs e)
{
this.richTextBox1.SelectAll();
this.richTextBox1.SelectionAlignment = HelpRepaint.TextAlign.Justify;
this.richTextBox1.Select(0, 0);
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonspace_Click(object sender, EventArgs e)
{
if (this.toolspace)
{
this.richTextBox1.SelectAll();
this.indent_two(0);
this.richTextBox1.Select(0, 0);
this.toolspace = false;
}
else
{
this.richTextBox1.SelectAll();
this.indent_two(1);
this.richTextBox1.Select(0, 0);
this.toolspace = true;
}
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripButtonSend_Click(object sender, EventArgs e)
{
// 判断是否有选中的文本
string textToCopy = string.IsNullOrEmpty(this.richTextBox1.SelectedText)
? this.richTextBox1.Text // 没有选中文本,复制全部
: this.richTextBox1.SelectedText; // 有选中文本,只复制选中部分
// 【核心修改】通过 FindForm() 获取主窗口实例并加锁
var mainForm = this.FindForm() as FmMain;
if (mainForm != null)
{
mainForm.SetClipboardWithLock(textToCopy);
}
HelpWin32.SendMessage(HelpWin32.GetForegroundWindow(), 786, 530);
HelpWin32.keybd_event(Keys.ControlKey, 0, 0u, 0u);
HelpWin32.keybd_event(Keys.V, 0, 0u, 0u);
HelpWin32.keybd_event(Keys.V, 0, 2u, 0u);
HelpWin32.keybd_event(Keys.ControlKey, 0, 2u, 0u);
CommonHelper.ShowHelpMsg("已复制");
}
public ContextMenuStrip ContextMenuStrip1
{
get
{
return this.richTextBox1.ContextMenuStrip;
}
set
{
this.richTextBox1.ContextMenuStrip = value;
}
}
public string Text_flag
{
set
{
this.txt_flag = value;
if (this.txt_flag == "天若幽心")
{
this.toolStripToolBar.Items.AddRange(new ToolStripItem[]
{
this.topmost,
this.Fontstyle,
this.toolStripButtonBold,
this.toolStripButtonColor,
this.toolStripButtonLeft,
this.toolStripButtonFull,
this.toolStripButtonspace,
this.toolStripButtonVoice,
this.toolStripButtonFind,
this.toolStripButtonSend,
this.toolStripButtonNote,
this.toolStripButtonParagraph,
this.toolStripButtonFence,
this.toolStripButtonSplit,
this.toolStripButtonMerge,
this.toolStripButtoncheck,
this.toolStripButtonTrans
});
return;
}
this.toolStripToolBar.Items.AddRange(new ToolStripItem[]
{
this.languagle,
this.Fontstyle,
this.toolStripButtonBold,
this.toolStripButtonColor,
this.toolStripButtonLeft,
this.toolStripButtonFull,
this.toolStripButtonspace,
this.toolStripButtonVoice,
this.toolStripButtonFind,
this.toolStripButtonSend,
this.toolStripButtonclose
});
}
}
public void toolStripButtonclose_Click(object sender, EventArgs e)
{
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
HelpWin32.SendMessage(HelpWin32.GetForegroundWindow(), 786, 511);
}
public void toolStripButtonTrans_Click(object sender, EventArgs e)
{
HelpWin32.SendMessage(StaticValue.mainHandle, 786, 512);
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
public void toolStripToolBar_Click(object sender, EventArgs e)
{
}
private void zh_en_Click(object sender, EventArgs e)
{
this.zh_en.ForeColor = Color.Red;
this.zh_jp.ForeColor = Color.Black;
this.zh_ko.ForeColor = Color.Black;
StaticValue.ZH2EN = true;
StaticValue.ZH2JP = false;
StaticValue.ZH2KO = false;
HelpWin32.SendMessage(StaticValue.mainHandle, 786, 512);
}
private void zh_jp_Click(object sender, EventArgs e)
{
this.zh_en.ForeColor = Color.Black;
this.zh_jp.ForeColor = Color.Red;
this.zh_ko.ForeColor = Color.Black;
StaticValue.ZH2EN = false;
StaticValue.ZH2JP = true;
StaticValue.ZH2KO = false;
HelpWin32.SendMessage(StaticValue.mainHandle, 786, 512);
}
private void zh_ko_Click(object sender, EventArgs e)
{
this.zh_en.ForeColor = Color.Black;
this.zh_jp.ForeColor = Color.Black;
this.zh_ko.ForeColor = Color.Red;
StaticValue.ZH2EN = false;
StaticValue.ZH2JP = false;
StaticValue.ZH2KO = true;
HelpWin32.SendMessage(StaticValue.mainHandle, 786, 512);
}
public void font_宋体c(object sender, EventArgs e)
{
ChangeFontInternal("宋体", this.font_宋体);
}
public void font_黑体c(object sender, EventArgs e)
{
ChangeFontInternal("黑体", this.font_黑体);
}
public void font_楷体c(object sender, EventArgs e)
{
ChangeFontInternal("STKaiti", this.font_楷体);
}
public void font_微软雅黑c(object sender, EventArgs e)
{
ChangeFontInternal("微软雅黑", this.font_微软雅黑);
}
public void font_新罗马c(object sender, EventArgs e)
{
ChangeFontInternal("Times New Roman", this.font_新罗马);
}
public void indent_two(int fla)
{
Font font = new Font(this.Font.Name, 9f * Program.Factor, this.Font.Style, this.Font.Unit, this.Font.GdiCharSet, this.Font.GdiVerticalFont);
Graphics graphics = base.CreateGraphics();
SizeF sizeF = graphics.MeasureString("中", font);
this.richTextBox1.SelectionIndent = (int)sizeF.Width * 2 * fla;
this.richTextBox1.SelectionHangingIndent = -(int)sizeF.Width * 2 * fla;
graphics.Dispose();
}
private void richeditbox_TextChanged(object sender, EventArgs e)
{
this.c.execute(this.richTextBox1.Text);
}
private void richTextBox1_LinkClicked(object sender, LinkClickedEventArgs e)
{
Process.Start(e.LinkText);
}
public string SelectText
{
get
{
return this.richTextBox1.SelectedText;
}
}
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
if (e.Control && e.KeyCode == Keys.V)
{
e.SuppressKeyPress = true;
this.richTextBox1.Paste(DataFormats.GetFormat(DataFormats.UnicodeText));
}
if (e.Control && e.KeyCode == Keys.Z)
{
this.c.undo();
// 简单方案:撤销后光标移到文本末尾
// 这是最安全和最可预测的行为
this.richTextBox1.Text = this.c.Record;
this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length;
this.richTextBox1.SelectionLength = 0;
this.richTextBox1.ScrollToCaret(); // 确保光标可见
}
if (e.Control && e.KeyCode == Keys.Y)
{
this.c.redo();
// 重做后光标也移到文本末尾
this.richTextBox1.Text = this.c.Record;
this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length;
this.richTextBox1.SelectionLength = 0;
this.richTextBox1.ScrollToCaret(); // 确保光标可见
}
if (e.Control && e.KeyCode == Keys.F)
{
ReplaceForm replaceForm = new ReplaceForm(this);
if (this.txt_flag == "天若幽心")
{
replaceForm.Text = "识别替换";
replaceForm.Location = base.PointToScreen(new Point((base.Width - replaceForm.Width) / 2, (base.Height - replaceForm.Height) / 2));
}
else
{
replaceForm.Text = "翻译替换";
replaceForm.Location = base.PointToScreen(new Point((base.Width - replaceForm.Width) / 2, (base.Height - replaceForm.Height) / 2));
}
replaceForm.Show(this);
}
}
public string Find
{
set
{
new Thread(new ThreadStart(this.错别字检查API)).Start();
HelpWin32.SetForegroundWindow(StaticValue.mainHandle);
}
}
public void 错别字检查API()
{
this.richTextBox1.SelectAll();
this.richTextBox1.SelectionColor = Color.Black;
this.richTextBox1.Select(0, 0);
try
{
JArray jarray = JArray.Parse(((JObject)JsonConvert.DeserializeObject(this.Post_Html("http://www.cuobiezi.net/api/v1/zh_spellcheck/client/pos/json", "{\"check_mode\": \"value2\",\"content\": \"" + this.richTextBox1.Text + "\", \"content2\": \"value1\", \"doc_type\": \"value2\",\"method\": \"value2\",\"return_format\": \"value2\",\"username\": \"tianruoyouxin\"}")))["Cases"].ToString());
for (int i = 0; i < jarray.Count; i++)
{
JObject jobject = JObject.Parse(jarray[i].ToString());