Browse Source

ComPDFKit.Tool(win)-优化对齐逻辑减少误差

liyijie 4 months ago
parent
commit
007e172d9a
1 changed files with 76 additions and 12 deletions
  1. 76 12
      Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.TextEdit.cs

+ 76 - 12
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.TextEdit.cs

@@ -2404,12 +2404,28 @@ namespace ComPDFKit.Tool
             CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
             CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
             cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
-            foreach (SelectedRect item in MultiSelectEditList.Children)
+            foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
             {
+                SelectedRect item = checkItem;
+                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
+                    {
+                        editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
+                    }
+                }
+                if (item == null)
+                {
+                    continue;
+                }
                 PDFEditHistory pDFEditHistory = new PDFEditHistory();
                 pDFEditHistory.PageIndex = multiPage;
                 pDFEditHistory.EditPage = cPDFEditPage;
-                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    continue;
+                }
                 EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
                 Rect rect = item.GetRect();
                 if (currentZoom < 1)
@@ -2461,32 +2477,48 @@ namespace ComPDFKit.Tool
             CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
             CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
             cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
-            foreach (SelectedRect item in MultiSelectEditList.Children)
+            foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
             {
+                SelectedRect item = checkItem;
+                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
+                    {
+                        editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
+                    }
+                }
+                if (item == null)
+                {
+                    continue;
+                }
                 PDFEditHistory pDFEditHistory = new PDFEditHistory();
                 pDFEditHistory.PageIndex = multiPage;
                 pDFEditHistory.EditPage = cPDFEditPage;
-                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    continue;
+                }
                 EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
                 Rect rect = item.GetRect();
                 if (currentZoom < 1)
                 {
-                    rect.X = rect.X - editPadding * currentZoom;
+                    rect.X = rect.X - editPadding;
                 }
                 else
                 {
-                    rect.X = rect.X - editPadding / currentZoom;
+                    rect.X = rect.X - editPadding;
                 }
 
                 item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignRight(rect, drawRect), rect, drawRect), currentZoom);
                 Rect rect2 = item.GetRect();
                 if (currentZoom < 1)
                 {
-                    rect2.X = rect2.X - editPadding * currentZoom;
+                    rect2.X = rect2.X - editPadding ;
                 }
                 else
                 {
-                    rect2.X = rect2.X - editPadding / currentZoom;
+                    rect2.X = rect2.X - editPadding;
                 }
 
                 Rect pageBound = newEditAreaObject.PageBound;
@@ -2580,12 +2612,28 @@ namespace ComPDFKit.Tool
             CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
             CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
             cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
-            foreach (SelectedRect item in MultiSelectEditList.Children)
+            foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
             {
+                SelectedRect item = checkItem;
+                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
+                    {
+                        editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
+                    }
+                }
+                if (item == null)
+                {
+                    continue;
+                }
                 PDFEditHistory pDFEditHistory = new PDFEditHistory();
                 pDFEditHistory.PageIndex = multiPage;
                 pDFEditHistory.EditPage = cPDFEditPage;
-                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    continue;
+                }
                 EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
                 Rect rect = item.GetRect();
                 item.SetRect(GetDrawAlignRect(AlignmentsHelp.SetAlignHorizonCenter(rect, drawRect), rect, drawRect), currentZoom);
@@ -2621,12 +2669,28 @@ namespace ComPDFKit.Tool
             CPDFPage cPDFPage = cPDFDocument.PageAtIndex(multiPage);
             CPDFEditPage cPDFEditPage = cPDFPage.GetEditPage();
             cPDFEditPage.BeginEdit(CPDFEditType.EditText | CPDFEditType.EditImage);
-            foreach (SelectedRect item in MultiSelectEditList.Children)
+            foreach (SelectedRect checkItem in MultiSelectEditList.GetMulitSelectList())
             {
+                SelectedRect item = checkItem;
+                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    if (MultiSelectEditList.GetRelationKey(item, out int checkPage, out int checkEdit))
+                    {
+                        editAreaObject = GetEditAreaObjectListForIndex(checkPage, checkEdit);
+                    }
+                }
+                if (item == null)
+                {
+                    continue;
+                }
                 PDFEditHistory pDFEditHistory = new PDFEditHistory();
                 pDFEditHistory.PageIndex = multiPage;
                 pDFEditHistory.EditPage = cPDFEditPage;
-                EditAreaObject editAreaObject = GetEditAreaObjectListForRect(item);
+                if (editAreaObject == null)
+                {
+                    continue;
+                }
                 EditAreaObject newEditAreaObject = GetSelectedForIndex(multiPage, editAreaObject.EditAreaIndex);
                 Rect rect = item.GetRect();
                 rect.Y = rect.Y - editPadding;