init
Browse files- .gitattributes +12 -0
- .gitignore +29 -0
- App.xaml +9 -0
- App.xaml.cs +14 -0
- AssemblyInfo.cs +10 -0
- CustomRichTextBox.cs +59 -0
- MainWindow.xaml +9 -0
- MainWindow.xaml.cs +20 -0
- RichChar.cs +14 -0
- WpfRichTextBox.csproj +11 -0
- WpfRichTextBox.sln +25 -0
.gitattributes
CHANGED
|
@@ -1,4 +1,16 @@
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pdf filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
**/data/img/*.txt filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
src/WeChatOcrCpp/wco_data/**/* filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.aps filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ico filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.pgm filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.exe filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.dll filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lib filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.exp filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
data/img/*.txt filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.ttf filter=lfs diff=lfs merge=lfs -text
|
| 14 |
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 15 |
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 16 |
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Debug/
|
| 2 |
+
node_modules/
|
| 3 |
+
output/
|
| 4 |
+
package-lock.json
|
| 5 |
+
Release/
|
| 6 |
+
x64/
|
| 7 |
+
bin/
|
| 8 |
+
imrad.dir/
|
| 9 |
+
build/
|
| 10 |
+
.vs/
|
| 11 |
+
*.user
|
| 12 |
+
*.filters
|
| 13 |
+
*.exe
|
| 14 |
+
!src/WeChatOcrCpp/wco_data/WeChatOCR.exe
|
| 15 |
+
*.pdb
|
| 16 |
+
*obj
|
| 17 |
+
*.log
|
| 18 |
+
*.tlog
|
| 19 |
+
*.recipe
|
| 20 |
+
*.ilk
|
| 21 |
+
out.json
|
| 22 |
+
tmp.jpg
|
| 23 |
+
config.py
|
| 24 |
+
config.json
|
| 25 |
+
# *dll
|
| 26 |
+
imgui.ini
|
| 27 |
+
7e644cf859a5e100a21ff67a63486ae0.txt
|
| 28 |
+
7e644cf859a5e100a21ff67a63486ae0.json
|
| 29 |
+
__pycache__/
|
App.xaml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<Application x:Class="WpfRichTextBox.App"
|
| 2 |
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
| 3 |
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
| 4 |
+
xmlns:local="clr-namespace:WpfRichTextBox"
|
| 5 |
+
StartupUri="MainWindow.xaml">
|
| 6 |
+
<Application.Resources>
|
| 7 |
+
|
| 8 |
+
</Application.Resources>
|
| 9 |
+
</Application>
|
App.xaml.cs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Configuration;
|
| 2 |
+
using System.Data;
|
| 3 |
+
using System.Windows;
|
| 4 |
+
|
| 5 |
+
namespace WpfRichTextBox
|
| 6 |
+
{
|
| 7 |
+
/// <summary>
|
| 8 |
+
/// Interaction logic for App.xaml
|
| 9 |
+
/// </summary>
|
| 10 |
+
public partial class App : Application
|
| 11 |
+
{
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
}
|
AssemblyInfo.cs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Windows;
|
| 2 |
+
|
| 3 |
+
[assembly: ThemeInfo(
|
| 4 |
+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
| 5 |
+
//(used if a resource is not found in the page,
|
| 6 |
+
// or application resource dictionaries)
|
| 7 |
+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
| 8 |
+
//(used if a resource is not found in the page,
|
| 9 |
+
// app, or any theme specific resource dictionaries)
|
| 10 |
+
)]
|
CustomRichTextBox.cs
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Collections.Generic;
|
| 2 |
+
using System.Windows.Controls;
|
| 3 |
+
using System.Windows.Documents;
|
| 4 |
+
using System.Windows.Media;
|
| 5 |
+
using System.Windows;
|
| 6 |
+
|
| 7 |
+
namespace WpfRichTextBox
|
| 8 |
+
{
|
| 9 |
+
|
| 10 |
+
public class CustomRichTextBox : RichTextBox
|
| 11 |
+
{
|
| 12 |
+
public List<RichChar> RichChars { get; private set; } = new List<RichChar>();
|
| 13 |
+
|
| 14 |
+
public CustomRichTextBox()
|
| 15 |
+
{
|
| 16 |
+
TextChanged += CustomRichTextBox_TextChanged;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
private void CustomRichTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
| 20 |
+
{
|
| 21 |
+
SyncRichChars();
|
| 22 |
+
InvalidateVisual();
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
private void SyncRichChars()
|
| 26 |
+
{
|
| 27 |
+
RichChars.Clear();
|
| 28 |
+
var text = new TextRange(Document.ContentStart, Document.ContentEnd).Text;
|
| 29 |
+
for (int i = 0; i < text.Length; i++)
|
| 30 |
+
{
|
| 31 |
+
RichChars.Add(new RichChar
|
| 32 |
+
{
|
| 33 |
+
Character = text[i],
|
| 34 |
+
Position = new Point(i * 16, 10), // 横向排列,纵坐标可调整
|
| 35 |
+
Color = Colors.Black // 默认颜色
|
| 36 |
+
});
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
protected override void OnRender(DrawingContext drawingContext)
|
| 41 |
+
{
|
| 42 |
+
base.OnRender(drawingContext);
|
| 43 |
+
foreach (var richChar in RichChars)
|
| 44 |
+
{
|
| 45 |
+
var formattedText = new FormattedText(
|
| 46 |
+
richChar.Character.ToString(),
|
| 47 |
+
System.Globalization.CultureInfo.CurrentCulture,
|
| 48 |
+
FlowDirection.LeftToRight,
|
| 49 |
+
new Typeface("Segoe UI"),
|
| 50 |
+
16,
|
| 51 |
+
new SolidColorBrush(richChar.Color),
|
| 52 |
+
VisualTreeHelper.GetDpi(this).PixelsPerDip);
|
| 53 |
+
|
| 54 |
+
drawingContext.DrawText(formattedText, richChar.Position);
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
}
|
MainWindow.xaml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<Window x:Class="WpfRichTextBox.MainWindow"
|
| 2 |
+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
| 3 |
+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
| 4 |
+
xmlns:local="clr-namespace:WpfRichTextBox"
|
| 5 |
+
Title="MainWindow" Height="350" Width="525">
|
| 6 |
+
<Grid>
|
| 7 |
+
<local:CustomRichTextBox x:Name="customRichTextBox" Width="400" Height="200"/>
|
| 8 |
+
</Grid>
|
| 9 |
+
</Window>
|
MainWindow.xaml.cs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Windows;
|
| 2 |
+
|
| 3 |
+
namespace WpfRichTextBox
|
| 4 |
+
{
|
| 5 |
+
public partial class MainWindow : Window
|
| 6 |
+
{
|
| 7 |
+
public MainWindow()
|
| 8 |
+
{
|
| 9 |
+
InitializeComponent();
|
| 10 |
+
|
| 11 |
+
new System.Windows.Documents.TextRange(customRichTextBox.Document.ContentStart, customRichTextBox.Document.ContentEnd).Text = "Hello World!";
|
| 12 |
+
if (customRichTextBox.RichChars.Count > 0)
|
| 13 |
+
{
|
| 14 |
+
customRichTextBox.RichChars[0].Color = System.Windows.Media.Colors.Red;
|
| 15 |
+
customRichTextBox.RichChars[0].Position = new System.Windows.Point(50, 50);
|
| 16 |
+
customRichTextBox.InvalidateVisual();
|
| 17 |
+
}
|
| 18 |
+
}
|
| 19 |
+
}
|
| 20 |
+
}
|
RichChar.cs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
using System.Windows;
|
| 2 |
+
using System.Windows.Media;
|
| 3 |
+
|
| 4 |
+
namespace WpfRichTextBox
|
| 5 |
+
{
|
| 6 |
+
|
| 7 |
+
public class RichChar
|
| 8 |
+
{
|
| 9 |
+
public char Character { get; set; }
|
| 10 |
+
public Point Position { get; set; } // 图片上的坐标
|
| 11 |
+
public Color Color { get; set; }
|
| 12 |
+
// 可扩展其他属性,如字体、大小等
|
| 13 |
+
}
|
| 14 |
+
}
|
WpfRichTextBox.csproj
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<Project Sdk="Microsoft.NET.Sdk">
|
| 2 |
+
|
| 3 |
+
<PropertyGroup>
|
| 4 |
+
<OutputType>WinExe</OutputType>
|
| 5 |
+
<TargetFramework>net8.0-windows</TargetFramework>
|
| 6 |
+
<Nullable>enable</Nullable>
|
| 7 |
+
<ImplicitUsings>enable</ImplicitUsings>
|
| 8 |
+
<UseWPF>true</UseWPF>
|
| 9 |
+
</PropertyGroup>
|
| 10 |
+
|
| 11 |
+
</Project>
|
WpfRichTextBox.sln
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Microsoft Visual Studio Solution File, Format Version 12.00
|
| 3 |
+
# Visual Studio Version 17
|
| 4 |
+
VisualStudioVersion = 17.14.35806.103 d17.14
|
| 5 |
+
MinimumVisualStudioVersion = 10.0.40219.1
|
| 6 |
+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfRichTextBox", "WpfRichTextBox.csproj", "{D9FDC891-69E4-4747-86B2-25F554977569}"
|
| 7 |
+
EndProject
|
| 8 |
+
Global
|
| 9 |
+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
| 10 |
+
Debug|Any CPU = Debug|Any CPU
|
| 11 |
+
Release|Any CPU = Release|Any CPU
|
| 12 |
+
EndGlobalSection
|
| 13 |
+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
| 14 |
+
{D9FDC891-69E4-4747-86B2-25F554977569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
| 15 |
+
{D9FDC891-69E4-4747-86B2-25F554977569}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
| 16 |
+
{D9FDC891-69E4-4747-86B2-25F554977569}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
| 17 |
+
{D9FDC891-69E4-4747-86B2-25F554977569}.Release|Any CPU.Build.0 = Release|Any CPU
|
| 18 |
+
EndGlobalSection
|
| 19 |
+
GlobalSection(SolutionProperties) = preSolution
|
| 20 |
+
HideSolutionNode = FALSE
|
| 21 |
+
EndGlobalSection
|
| 22 |
+
GlobalSection(ExtensibilityGlobals) = postSolution
|
| 23 |
+
SolutionGuid = {58653FF6-BDB2-4CBF-BFA2-12FC1B6FB87C}
|
| 24 |
+
EndGlobalSection
|
| 25 |
+
EndGlobal
|