Browse Source

ComPDFKit.Tool(Win)-2025注释多选初步逻辑

liyijie 1 week ago
parent
commit
6dee7a8351

+ 20 - 2
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.AnnotSelector.cs

@@ -77,7 +77,7 @@ namespace ComPDFKit.Tool
             }
         }
 
-        public void SetAnnotAllowMultiSelect(bool isAllow) 
+        public void SetAnnotAllowMultiSelect(bool isAllow)
         {
             AllowMultiSelect = isAllow;
             AllowAreaSelect = isAllow;
@@ -127,7 +127,7 @@ namespace ComPDFKit.Tool
             if (clean)
             {
                 Selector?.ClearItem();
-                Selector?.AddItem(annotData);
+                //Selector?.AddItem(annotData);
             }
         }
 
@@ -257,6 +257,24 @@ namespace ComPDFKit.Tool
             return null;
         }
 
+        public List<AnnotData> GetAnnotSelectsData()
+        {
+            if (PDFViewer != null && Selector != null && Selector.SelectAnnots != null && Selector.SelectAnnots.Count >= 1)
+            {
+                return Selector.SelectAnnots;
+            }
+            return null;
+        }
+
+        public AnnotSelector GetAnnotSelectsRect()
+        {
+            if (PDFViewer != null && Selector != null && Selector.SelectAnnots != null && Selector.SelectAnnots.Count >= 1)
+            {
+                return Selector;
+            }
+            return null;
+        }
+
         private int AnnotSelectGetCount()
         {
             if (Selector != null)

+ 18 - 0
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.SelectText.cs

@@ -185,6 +185,24 @@ namespace ComPDFKit.Tool
             (baseLayer as SelectText).CleanSearchInfo();
         }
 
+        public bool IsSelectText() {
+
+            bool select = false;
+            var selecttextinfo = GetTextSelectInfo();
+            if (selecttextinfo == null)
+            {
+                select = true;
+            }
+            else
+            {
+                if (selecttextinfo.PageSelectText.Count == 0)
+                {
+                    select = true;
+                }
+            }
+            return select;
+        }
+
         public void HighLightSearchText(List<TextSearchItem> selectTexts)
         {
             BaseLayer baseLayer = PDFViewer.GetViewForTag(selectTextTag);

+ 31 - 8
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.SelectedRect.cs

@@ -33,7 +33,7 @@ namespace ComPDFKit.Tool
             selectedRect.DataChanged += SelectedRect_DataChanged;
             selectedRect.DataChanging += SelectedRect_DataChanging;
             PDFViewer.InsertView(selectedRectViewIndex, customizeLayer);
-            selectedRectViewTag= customizeLayer.GetResTag();
+            selectedRectViewTag = customizeLayer.GetResTag();
         }
 
         /// <summary>
@@ -71,6 +71,18 @@ namespace ComPDFKit.Tool
                 isDrawSelectRect = true;
             }
         }
+        public SelectedRect GetSelectedRect()
+        {
+            Point point = Mouse.GetPosition(this);
+            BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
+
+            SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
+            if (selectedRect != null && isDrawSelectRect == true)
+            {
+                return selectedRect;
+            }
+            return null;
+        }
 
         public Cursor GetMoveSelectedRectCursor()
         {
@@ -98,7 +110,7 @@ namespace ComPDFKit.Tool
             if (selectedRect != null)
             {
                 selectedRect.SetOutSideScaling(isOutSideScaling);
-                selectedRect.OnMouseMove(point, out DrawTag,PDFViewer.ActualWidth,PDFViewer.ActualHeight);
+                selectedRect.OnMouseMove(point, out DrawTag, PDFViewer.ActualWidth, PDFViewer.ActualHeight);
                 selectedRect.Draw();
             }
             return DrawTag;
@@ -138,13 +150,13 @@ namespace ComPDFKit.Tool
 
         internal void SelectedAnnot()
         {
-            if (!isHitTestLink&& cacheHitTestAnnot?.CurrentType== C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
+            if (!isHitTestLink && cacheHitTestAnnot?.CurrentType == C_ANNOTATION_TYPE.C_ANNOTATION_LINK)
             {
-                return ;
+                return;
             }
-            if (isHitTestRedact && cacheHitTestAnnot?.CurrentType!= C_ANNOTATION_TYPE.C_ANNOTATION_REDACT)
+            if (isHitTestRedact && cacheHitTestAnnot?.CurrentType != C_ANNOTATION_TYPE.C_ANNOTATION_REDACT)
             {
-                return ;
+                return;
             }
             SelectAnnot(cacheHitTestAnnot.GetAnnotData());
         }
@@ -165,7 +177,7 @@ namespace ComPDFKit.Tool
             SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
             if (selectedRect != null)
             {
-                if (annotData==null)
+                if (annotData == null)
                 {
                     selectedRect.ClearDraw();
                 }
@@ -188,7 +200,7 @@ namespace ComPDFKit.Tool
                 selectedRect.Draw();
             }
         }
-        
+
         /// <summary>
         /// Identify whether the mouse is on the rectangle
         /// </summary>
@@ -207,5 +219,16 @@ namespace ComPDFKit.Tool
             }
             return false;
         }
+
+        internal AnnotData GetSelectAnnotData()
+        {
+            BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
+            SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
+            if (selectedRect != null && isDrawSelectRect == true)
+            {
+                return selectedRect.GetAnnotData();
+            }
+            return null;
+        }
     }
 }

+ 89 - 5
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.xaml.cs

@@ -352,7 +352,7 @@ namespace ComPDFKit.Tool
             {
                 return;
             }
-            
+
             if (!HitTestBorder())
             {
                 RemovePopTextUI();
@@ -378,6 +378,7 @@ namespace ComPDFKit.Tool
                 MouseLeftButtonDownHandler?.Invoke(this, mouseEventObject);
                 return;
             }
+            AnnotData beforeSelectAnnotData = GetSelectAnnotData();
             if (isDrawSelectRect)
             {
                 if (e.ClickCount == 2)
@@ -457,8 +458,39 @@ namespace ComPDFKit.Tool
                         }
                         else
                         {
-                            SelectedAnnot();
-                            CleanDrawSelectImage();
+                            if (AllowMultiSelect &&
+            (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
+                            {
+                                if (!AnnotSelectAreaHitTest())
+                                {
+                                    if (AnnotMoveHitTest())
+                                    {
+                                        BaseAnnot hitAnnot = PDFViewer?.AnnotHitTest() as BaseAnnot;
+
+
+                                        if (beforeSelectAnnotData != null)
+                                        {
+                                            AnnotSelectAddItem(beforeSelectAnnotData);
+                                        }
+                                        if (AnnotSelectGetCount() == 0 && hitAnnot != null)
+                                        {
+                                            AnnotSelectAddItem(hitAnnot.GetAnnotData());
+                                        }
+
+                                        mouseEventObject.hitTestType = MouseHitTestType.Annot;
+                                        mouseEventObject.annotType = cacheHitTestAnnot.GetAnnotData().AnnotType;
+                                    }
+                                    else
+                                    {
+                                        AnnotSelectAreaHit();
+                                    }
+                                }
+                                AnnotSelectMoveHit();
+                            }
+                            else
+                            {
+                                SelectedAnnot();
+                            }
                         }
                         isDrawSelectRect = true;
                     }
@@ -489,6 +521,10 @@ namespace ComPDFKit.Tool
                 }
                 else
                 {
+                    if (!AnnotSelectAreaHitTest())
+                    {
+                        AnnotSelectAreaHit();
+                    }
                     ReDrawSelectImage();
                 }
             }
@@ -626,6 +662,45 @@ namespace ComPDFKit.Tool
             {
                 return;
             }
+            if (currentModel == ToolType.Pan || currentModel == ToolType.CreateAnnot)
+            {
+                bool areaSelectAdd = AnnotSelectAreaSelect(false, true);
+                if (AnnotMoveHitTest())
+                {
+                    BaseAnnot checkItem = PDFViewer?.AnnotHitTest();
+                    AnnotSelectAddItem(checkItem?.GetAnnotData(), !AnnotSelectAreaHitTest());
+                }
+                if (AnnotSelectGetCount() > 0)
+                {
+                    CleanSelectedRect();
+                }
+                if (IsMoved == false && AnnotSelectAreaHitTest() == false && AnnotMoveHitTest() == false)
+                {
+                    AnnotSelectClean();
+                }
+                if (AnnotSelectGetCount() == 1)
+                {
+                    cacheHitTestAnnot = AnnotSelectGetAnnot();
+                    if (cacheHitTestAnnot != null)
+                    {
+                        BaseLayer baseLayer = PDFViewer.GetViewForTag(selectedRectViewTag);
+                        SelectedRect selectedRect = CommonHelper.FindVisualChild<SelectedRect>(baseLayer as CustomizeLayer);
+                        if (selectedRect != null)
+                        {
+                            if (IsMoved && areaSelectAdd == false)
+                            {
+                                selectedRect.UpdateAnnotData(cacheHitTestAnnot.GetAnnotData());
+                            }
+                            else
+                            {
+                                selectedRect.SetAnnotData(cacheHitTestAnnot.GetAnnotData());
+                            }
+                            selectedRect.Draw();
+                        }
+                        isDrawSelectRect = true;
+                    }
+                }
+            }
 
             if (currentModel == ToolType.WidgetEdit)
             {
@@ -689,7 +764,7 @@ namespace ComPDFKit.Tool
             }
             MouseLeftButtonUpHandler?.Invoke(this, mouseEventObject);
             ReleaseMouseCapture();
-            if (currentModel == ToolType.WidgetEdit)
+            if (currentModel == ToolType.WidgetEdit || currentModel == ToolType.Pan || currentModel == ToolType.CreateAnnot)
             {
                 AnnotSelectUpdate();
                 AnnotSelectDraw();
@@ -708,7 +783,7 @@ namespace ComPDFKit.Tool
                 return;
             }
 
-            if(FillManager?.MouseMoveHandle(e)==true)
+            if (FillManager?.MouseMoveHandle(e) == true)
             {
                 return;
             }
@@ -832,6 +907,15 @@ namespace ComPDFKit.Tool
                     AnnotSelectAreaHover();
                 }
             }
+            if (currentModel == ToolType.Pan && !IsText() && IsSelectText())
+            {
+
+                AnnotSelectAreaDraw();
+                if (!AnnotSelectMoveDraw())
+                {
+                    AnnotSelectAreaHover();
+                }
+            }
 
             MouseMoveHandler?.Invoke(this, mouseEventObject);
             PDFViewer.SetCustomMousePoint(Mouse.GetPosition(this).Y, Mouse.GetPosition(this).X);

+ 9 - 11
Demo/Examples/ComPDFKit.Tool/ComPDFKit.Tool.csproj

@@ -9,7 +9,7 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>ComPDFKit.Tool</RootNamespace>
     <AssemblyName>ComPDFKit.Tool</AssemblyName>
-    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <Deterministic>true</Deterministic>
     <TargetFrameworkProfile />
@@ -81,6 +81,14 @@
     <LangVersion>7.3</LangVersion>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="ComPDFKit.NET, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\PDF_Reader_Pro_Windows_git\pdfreaderpro_windows_exe\PDFReader_WPF\PDFReader_WPF\ComPDFKit.NET.dll</HintPath>
+    </Reference>
+    <Reference Include="ComPDFKit.Viewer, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\PDF_Reader_Pro_Windows_git\pdfreaderpro_windows_exe\PDFReader_WPF\PDFReader_WPF\ComPDFKit.Viewer.dll</HintPath>
+    </Reference>
     <Reference Include="PresentationCore" />
     <Reference Include="PresentationFramework" />
     <Reference Include="System" />
@@ -226,15 +234,5 @@
       <Name>ComPDFKit.Viewer</Name>
     </ProjectReference>
   </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\..\..\..\compdfkit_windows\ComPDFKit\ComPDFKitCSharp\ComPDFKit.NET.csproj">
-      <Project>{56e518ad-c126-4b48-9a09-0a64c87020e4}</Project>
-      <Name>ComPDFKit.NET</Name>
-    </ProjectReference>
-    <ProjectReference Include="..\..\..\..\compdfkit_windows_rebuild\ComPDFKit.Viewer\ComPDFKit.Viewer.csproj">
-      <Project>{783263cf-0da3-4095-9df8-2c4a6b3ff908}</Project>
-      <Name>ComPDFKit.Viewer</Name>
-    </ProjectReference>
-  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

+ 1 - 1
Demo/Examples/ComPDFKit.Tool/DrawTool/AnnotSelector.cs

@@ -11,7 +11,7 @@ using System.Windows.Media;
 
 namespace ComPDFKit.Tool.DrawTool
 {
-    internal class AnnotSelector:BaseLayer
+    public class AnnotSelector:BaseLayer
     {
         public CPDFViewer PDFViewer { get; set; }
         public List<AnnotData> SelectAnnots { get; set; } = new List<AnnotData>();

+ 9 - 0
Demo/Examples/ComPDFKit.Tool/DrawTool/SelectedRect.cs

@@ -574,6 +574,15 @@ namespace ComPDFKit.Tool.DrawTool
             return maxRect;
         }
 
+        public AnnotData GetAnnotData()
+        {
+            if (selectedRectData != null)
+            {
+               return selectedRectData.annotData;
+            }
+            return null;
+        }
+
         public void UpdateAnnotData(AnnotData annotData)
         {
             if(selectedRectData!=null)

+ 2 - 1
Demo/Examples/ComPDFKit.Tool/SettingParam/AnnotParam/FreeTextParam.cs

@@ -11,7 +11,8 @@ namespace ComPDFKit.Tool
             CurrentType = C_ANNOTATION_TYPE.C_ANNOTATION_FREETEXT;
         }
 
-        public byte[] LineColor { get; set; }
+        public byte[] LineColor { get; 
+            set; }
         public byte[] BgColor { get; set; }
         public bool HasBgColor {  get; set; }
         public byte[] FontColor { get; set; }