校对模式 TextLine 有 pos 和选框记录
Browse files- src/WpfEditor/MainWindow.xaml.cs +2 -2
- src/WpfEditor/TextEditorControl.cs +26 -3
- src/WpfEditor/ViewModel.cs +2 -1
- src/WpfEditor/global.cs +5 -1
- src/WpfEditor/readme.txt +14 -1
src/WpfEditor/MainWindow.xaml.cs
CHANGED
|
@@ -307,7 +307,7 @@ namespace WpfEditor
|
|
| 307 |
if (ViewModel.RectangleWidth > 5 && ViewModel.RectangleHeight > 5)
|
| 308 |
{
|
| 309 |
// 添加新的矩形框到集合
|
| 310 |
-
ViewModel.AddRectangle(
|
| 311 |
ViewModel.RectangleLeft,
|
| 312 |
ViewModel.RectangleTop,
|
| 313 |
ViewModel.RectangleWidth,
|
|
@@ -334,7 +334,7 @@ namespace WpfEditor
|
|
| 334 |
|
| 335 |
// 找出框选的文字
|
| 336 |
JObject jsn = (JObject)Editor._jsn_OpenImg.DeepClone();
|
| 337 |
-
jsn = Global.find_rectange_text(jsn, rect.X, rect.Y, rect.Width, rect.Height);
|
| 338 |
Editor.InsertText(jsn, Editor._md5_OpenImg);
|
| 339 |
|
| 340 |
|
|
|
|
| 307 |
if (ViewModel.RectangleWidth > 5 && ViewModel.RectangleHeight > 5)
|
| 308 |
{
|
| 309 |
// 添加新的矩形框到集合
|
| 310 |
+
int Id = ViewModel.AddRectangle(
|
| 311 |
ViewModel.RectangleLeft,
|
| 312 |
ViewModel.RectangleTop,
|
| 313 |
ViewModel.RectangleWidth,
|
|
|
|
| 334 |
|
| 335 |
// 找出框选的文字
|
| 336 |
JObject jsn = (JObject)Editor._jsn_OpenImg.DeepClone();
|
| 337 |
+
jsn = Global.find_rectange_text(jsn, rect.X, rect.Y, rect.Width, rect.Height, Id);
|
| 338 |
Editor.InsertText(jsn, Editor._md5_OpenImg);
|
| 339 |
|
| 340 |
|
src/WpfEditor/TextEditorControl.cs
CHANGED
|
@@ -1258,11 +1258,20 @@ namespace WpfEditor
|
|
| 1258 |
|
| 1259 |
var prism_wordsInfo = jsn["prism_wordsInfo"].Value<JArray>();
|
| 1260 |
foreach (var item in prism_wordsInfo)
|
| 1261 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1262 |
JArray charInfo = item["charInfo"].Value<JArray>();
|
|
|
|
|
|
|
| 1263 |
string line_word = item["word"].Value<string>();
|
| 1264 |
|
| 1265 |
-
var textLine = new TextLine();
|
| 1266 |
foreach (var item2 in charInfo)
|
| 1267 |
{
|
| 1268 |
string oneChar = item2["word"].Value<string>();
|
|
@@ -2467,7 +2476,21 @@ namespace WpfEditor
|
|
| 2467 |
}
|
| 2468 |
|
| 2469 |
public class TextLine
|
| 2470 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2471 |
public List<TextCharacter> Characters { get; set; } = new List<TextCharacter>();
|
| 2472 |
}
|
| 2473 |
|
|
|
|
| 1258 |
|
| 1259 |
var prism_wordsInfo = jsn["prism_wordsInfo"].Value<JArray>();
|
| 1260 |
foreach (var item in prism_wordsInfo)
|
| 1261 |
+
{
|
| 1262 |
+
JObject selected_rectange = new JObject();
|
| 1263 |
+
if (_mode == EditorMode.ReviseEdit) // 校对模式才有选框
|
| 1264 |
+
{
|
| 1265 |
+
selected_rectange = item["selected_rectange"].Value<JObject>();
|
| 1266 |
+
}
|
| 1267 |
+
|
| 1268 |
+
JArray pos = item["pos"].Value<JArray>();
|
| 1269 |
JArray charInfo = item["charInfo"].Value<JArray>();
|
| 1270 |
+
|
| 1271 |
+
|
| 1272 |
string line_word = item["word"].Value<string>();
|
| 1273 |
|
| 1274 |
+
var textLine = new TextLine(pos, selected_rectange);
|
| 1275 |
foreach (var item2 in charInfo)
|
| 1276 |
{
|
| 1277 |
string oneChar = item2["word"].Value<string>();
|
|
|
|
| 2476 |
}
|
| 2477 |
|
| 2478 |
public class TextLine
|
| 2479 |
+
{
|
| 2480 |
+
public TextLine()
|
| 2481 |
+
{
|
| 2482 |
+
|
| 2483 |
+
}
|
| 2484 |
+
|
| 2485 |
+
public TextLine(JArray po, JObject rectange)
|
| 2486 |
+
{
|
| 2487 |
+
this.pos = po;
|
| 2488 |
+
this.selected_rectange = rectange;
|
| 2489 |
+
}
|
| 2490 |
+
|
| 2491 |
+
public JArray pos { get; set; } = new JArray();
|
| 2492 |
+
public JObject selected_rectange { get; set; } = new JObject();
|
| 2493 |
+
|
| 2494 |
public List<TextCharacter> Characters { get; set; } = new List<TextCharacter>();
|
| 2495 |
}
|
| 2496 |
|
src/WpfEditor/ViewModel.cs
CHANGED
|
@@ -93,11 +93,12 @@ namespace WpfEditor
|
|
| 93 |
}
|
| 94 |
|
| 95 |
// 添加新的矩形框
|
| 96 |
-
public
|
| 97 |
{
|
| 98 |
RectangleCounter++;
|
| 99 |
var newRectangle = new RectangleItem(RectangleCounter, left, top, width, height);
|
| 100 |
Rectangles.Add(newRectangle);
|
|
|
|
| 101 |
}
|
| 102 |
|
| 103 |
// 清除单个临时矩形(绘制过程中使用)
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
// 添加新的矩形框
|
| 96 |
+
public int AddRectangle(double left, double top, double width, double height)
|
| 97 |
{
|
| 98 |
RectangleCounter++;
|
| 99 |
var newRectangle = new RectangleItem(RectangleCounter, left, top, width, height);
|
| 100 |
Rectangles.Add(newRectangle);
|
| 101 |
+
return RectangleCounter;
|
| 102 |
}
|
| 103 |
|
| 104 |
// 清除单个临时矩形(绘制过程中使用)
|
src/WpfEditor/global.cs
CHANGED
|
@@ -107,7 +107,7 @@ namespace WpfEditor
|
|
| 107 |
|
| 108 |
|
| 109 |
// 删掉 jsn 里不在选区的文字
|
| 110 |
-
public static JObject find_rectange_text(JObject jsn, int lft, int tp, int wdth, int hght )
|
| 111 |
{
|
| 112 |
//_lines.Add(new TextLine());
|
| 113 |
|
|
@@ -153,6 +153,10 @@ namespace WpfEditor
|
|
| 153 |
line_new["word"] = "";
|
| 154 |
line_new["pos"] = pos_new;
|
| 155 |
line_new["charInfo"] = charInfo_new;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
prism_wordsInfo_new.Add(line_new);
|
| 157 |
|
| 158 |
// 再看列文字左右是否在选区内
|
|
|
|
| 107 |
|
| 108 |
|
| 109 |
// 删掉 jsn 里不在选区的文字
|
| 110 |
+
public static JObject find_rectange_text(JObject jsn, int lft, int tp, int wdth, int hght, int Id ) // 矩形框 ID,从 1 开始递增
|
| 111 |
{
|
| 112 |
//_lines.Add(new TextLine());
|
| 113 |
|
|
|
|
| 153 |
line_new["word"] = "";
|
| 154 |
line_new["pos"] = pos_new;
|
| 155 |
line_new["charInfo"] = charInfo_new;
|
| 156 |
+
|
| 157 |
+
JObject selected_rectange = new JObject { { "Id", Id }, { "lft", lft }, { "tp", tp }, { "wdth", wdth }, { "hght", hght } }; // 框选矩形
|
| 158 |
+
line_new["selected_rectange"] = selected_rectange;
|
| 159 |
+
|
| 160 |
prism_wordsInfo_new.Add(line_new);
|
| 161 |
|
| 162 |
// 再看列文字左右是否在选区内
|
src/WpfEditor/readme.txt
CHANGED
|
@@ -39,6 +39,13 @@ WpfEditor\MainWindow.xaml.cs
|
|
| 39 |
|
| 40 |
单个字的修改逻辑 先选中一个字符,再打一个字
|
| 41 |
WpfEditor\TextEditorControl.cs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
private void InsertText(string text)
|
| 43 |
// 如果有选中的文本,先删除或修改它
|
| 44 |
if (HasSelection())
|
|
@@ -50,4 +57,10 @@ WpfEditor\TextEditorControl.cs
|
|
| 50 |
// 此处是修改单个字符的情况
|
| 51 |
var line = _lines[_cursorLine];
|
| 52 |
TextCharacter c = line.Characters[_cursorColumn-1];
|
| 53 |
-
c.Character = System.Text.Rune.GetRuneAt(text, 0); // 修改字符
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
单个字的修改逻辑 先选中一个字符,再打一个字
|
| 41 |
WpfEditor\TextEditorControl.cs
|
| 42 |
+
|
| 43 |
+
protected override void OnTextInput(TextCompositionEventArgs e)
|
| 44 |
+
// 应该是改到这里了
|
| 45 |
+
//InsertText(e.Text);
|
| 46 |
+
InsertTextCharacters(e.Text);
|
| 47 |
+
|
| 48 |
+
|
| 49 |
private void InsertText(string text)
|
| 50 |
// 如果有选中的文本,先删除或修改它
|
| 51 |
if (HasSelection())
|
|
|
|
| 57 |
// 此处是修改单个字符的情况
|
| 58 |
var line = _lines[_cursorLine];
|
| 59 |
TextCharacter c = line.Characters[_cursorColumn-1];
|
| 60 |
+
c.Character = System.Text.Rune.GetRuneAt(text, 0); // 修改字符
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
保存
|
| 64 |
+
public bool saveJson(string pth_img_)
|
| 65 |
+
|
| 66 |
+
|