Browse Source

其他 - 替换文字搜索控件,替换缩放控件

liyuxuan 1 year ago
parent
commit
fb14423017

+ 63 - 30
Demo/Examples/Compdfkit_Tools/PDFView/PDFScaling/PDFScalingControl/CPDFScalingControl.xaml.cs

@@ -1,5 +1,4 @@
 using ComPDFKitViewer;
-using ComPDFKitViewer.PdfViewer;
 using System;
 using System.Windows;
 using System.Windows.Controls;
@@ -8,16 +7,16 @@ namespace Compdfkit_Tools.PDFControl
 {
     public partial class CPDFScalingControl : UserControl
     {
-        public CPDFViewer pdfViewer;
+        public PDFViewControl ViewControl;
 
         public CPDFScalingControl()
         {
             InitializeComponent();
         }
 
-        public void InitWithPDFViewer(CPDFViewer pdfViewer)
+        public void InitWithPDFViewer(PDFViewControl viewControl)
         {
-            this.pdfViewer = pdfViewer;
+            ViewControl = viewControl;
         }
 
         private void PDFScalingControl_Loaded(object sender, RoutedEventArgs e)
@@ -38,82 +37,106 @@ namespace Compdfkit_Tools.PDFControl
 
         private void PDFScalingControl_ScaleDecreaseEvent(object sender, EventArgs e)
         {
-            if (pdfViewer == null || pdfViewer.Document == null)
+            if (ViewControl == null || ViewControl.PDFViewTool == null)
             {
                 return;
             }
-            if (pdfViewer.ZoomFactor < 3)
+            CPDFViewer pdfViewer = ViewControl.PDFViewTool.GetCPDFViewer();
+            if (pdfViewer == null)
             {
-                pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.1);
+                return;
+            }
+         
+            if (pdfViewer.GetZoom() < 3)
+            {
+                pdfViewer.SetZoom(pdfViewer.GetZoom() - 0.1);
             }
-            else if (pdfViewer.ZoomFactor < 6)
+            else if (pdfViewer.GetZoom() < 6)
             {
-                pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.2);
+                pdfViewer.SetZoom(pdfViewer.GetZoom() - 0.2);
             }
-            else if (pdfViewer.ZoomFactor <= 10)
+            else if (pdfViewer.GetZoom() <= 10)
             {
-                pdfViewer.Zoom(pdfViewer.ZoomFactor - 0.3);
+                pdfViewer.SetZoom(pdfViewer.GetZoom() - 0.3);
             }
-            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
+            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.GetZoom() * 100)));
         }
 
         private void PDFScalingControl_ScaleIncreaseEvent(object sender, EventArgs e)
         {
-            if (pdfViewer == null || pdfViewer.Document == null)
+            if (ViewControl == null || ViewControl.PDFViewTool == null)
             {
                 return;
             }
-            if (pdfViewer.ZoomFactor < 3)
+            CPDFViewer pdfViewer = ViewControl.PDFViewTool.GetCPDFViewer();
+            if (pdfViewer == null)
             {
-                pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.1);
+                return;
             }
-            else if (pdfViewer.ZoomFactor < 6)
+
+            if (pdfViewer.GetZoom() < 3)
             {
-                pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.2);
+                pdfViewer.SetZoom(pdfViewer.GetZoom() + 0.1);
             }
-            else if (pdfViewer.ZoomFactor <= 10)
+            else if (pdfViewer.GetZoom() < 6)
             {
-                pdfViewer.Zoom(pdfViewer.ZoomFactor + 0.3);
+                pdfViewer.SetZoom(pdfViewer.GetZoom() + 0.2);
             }
-            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
+            else if (pdfViewer.GetZoom() <= 10)
+            {
+                pdfViewer.SetZoom(pdfViewer.GetZoom() + 0.3);
+            }
+            SetZoomTextBoxText(string.Format("{0}", (int)pdfViewer.GetZoom() * 100)));
         }
 
         private void PDFScalingControl_SetScaleEvent(object sender, string e)
         {
-            if (pdfViewer == null || pdfViewer.Document == null)
+            if (ViewControl == null || ViewControl.PDFViewTool == null)
+            {
+                return;
+            }
+            CPDFViewer pdfViewer = ViewControl.PDFViewTool.GetCPDFViewer();
+            if (pdfViewer == null)
             {
                 return;
             }
+
             if (!string.IsNullOrEmpty(e))
             {
-                pdfViewer.Zoom(double.Parse(e) / 100);
-                SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
+                pdfViewer.SetZoom(double.Parse(e) / 100);
+                SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.GetZoom() * 100)));
             }
         }
 
         private void CPDFScalingUI_SetPresetScaleEvent(object sender, string e)
         {
-            if (pdfViewer == null || pdfViewer.Document == null)
+            if (ViewControl == null || ViewControl.PDFViewTool == null)
+            {
+                return;
+            }
+            CPDFViewer pdfViewer = ViewControl.PDFViewTool.GetCPDFViewer();
+            if (pdfViewer == null)
             {
                 return;
             }
+          
             if (e == "Actual size")
             {
-                pdfViewer.ChangeFitMode(FitMode.FitSize);
+                pdfViewer.SetFitMode(FitModes.FitOriginal);
             }
             else if (e == "Suitable width")
             {
-                pdfViewer.ChangeFitMode(FitMode.FitWidth);
+                pdfViewer.SetFitMode(FitModes.FitWidth);
             }
             else if (e == "Single page size")
             {
-                pdfViewer.ChangeFitMode(FitMode.FitHeight);
+                pdfViewer.SetFitMode(FitModes.FitHeight);
             }
             else
             {
-                pdfViewer.Zoom(double.Parse(e) / 100);
+                pdfViewer.SetZoom(double.Parse(e) / 100);
             }
-            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
+            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.GetZoom() * 100)));
         }
 
         public void SetZoomTextBoxText(string value)
@@ -123,7 +146,17 @@ namespace Compdfkit_Tools.PDFControl
          
         private void CPDFPageScalingControl_LostFocus(object sender, RoutedEventArgs e)
         {
-            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.ZoomFactor * 100)));
+            if (ViewControl == null || ViewControl.PDFViewTool == null)
+            {
+                return;
+            }
+            CPDFViewer pdfViewer = ViewControl.PDFViewTool.GetCPDFViewer();
+            if (pdfViewer == null)
+            {
+                return;
+            }
+
+            SetZoomTextBoxText(string.Format("{0}", (int)(pdfViewer.GetZoom() * 100)));
         }
     }
 }

+ 1 - 4
Demo/Examples/Compdfkit_Tools/PDFView/PDFScaling/PDFScalingUI/CPDFScalingUI.xaml.cs

@@ -1,5 +1,4 @@
-using ComPDFKitViewer.PdfViewer;
-using System;
+using System;
 using System.ComponentModel;
 using System.Text.RegularExpressions;
 using System.Windows;
@@ -10,8 +9,6 @@ namespace Compdfkit_Tools.PDFControlUI
 {
     public partial class CPDFScalingUI : UserControl, INotifyPropertyChanged
     {
-        public CPDFViewer PDFView { get; set; }
-
         private string regixString = "[^0-9]+";
 
 

+ 36 - 17
Demo/Examples/Compdfkit_Tools/PDFView/PDFSearch/PDFSearchControl/CPDFSearchControl.xaml.cs

@@ -1,6 +1,7 @@
 using ComPDFKit.PDFPage;
+using ComPDFKit.Tool;
 using Compdfkit_Tools.PDFControlUI;
-using ComPDFKitViewer.PdfViewer;
+using ComPDFKitViewer;
 using System;
 using System.Collections.Generic;
 using System.Windows;
@@ -24,19 +25,36 @@ namespace Compdfkit_Tools.PDFControl
         private SolidColorBrush highLightBrush = new SolidColorBrush(Color.FromArgb(0x99, 0xFF, 0xF7, 0x00));
 
         private int ResultCount = 0;
+
+        private PDFViewControl ViewControl;
         public CPDFSearchControl()
         {
             InitializeComponent();
             Loaded += PDFSearch_Loaded;
         }
 
-        public void InitWithPDFViewer(CPDFViewer newPDFView)
+        public void InitWithPDFViewer(PDFViewControl newViewControl)
         {
-            if(pdfView!=newPDFView)
+            ViewControl = newViewControl;
+            if (ViewControl != null)
+            {
+                CPDFViewerTool viewTool = ViewControl.PDFViewTool;
+                if (viewTool != null)
+                {
+                    CPDFViewer newPDFView = viewTool.GetCPDFViewer();
+                    if (pdfView != newPDFView)
+                    {
+                        ClearSearchResult();
+                        pdfView = newPDFView;
+
+                    }
+                }
+            }
+            else
             {
                 ClearSearchResult();
-                pdfView = newPDFView;
             }
+
         }
 
         private void PDFSearch_Loaded(object sender, RoutedEventArgs e)
@@ -86,7 +104,7 @@ namespace Compdfkit_Tools.PDFControl
             Dispatcher.Invoke(() =>
             {
                 List<BindSearchResult> resultList = new List<BindSearchResult>();
-
+                List<TextSearchItem> totalItems = new List<TextSearchItem>();
                 foreach (int pageIndex in e.Items.Keys)
                 {
                     List<TextSearchItem> textSearchItems = e.Items[pageIndex];
@@ -99,12 +117,15 @@ namespace Compdfkit_Tools.PDFControl
                             TextRect = item.TextRect,
                             SearchWord = keyWord,
                             HighLightColor = Color.FromArgb(0x99, 0xFF, 0xF7, 0x00),
-                            PageRotate = item.PageRotate
+                            PageRotate = item.PageRotate,
+                            RefData=item
                         });
+                        totalItems.Add(item);
                     }
                 }
                 SearchResult.SetSearchResult(resultList);
                 ResultCount=resultList.Count;
+                ViewControl.PDFViewTool?.SetPageSelectText(totalItems);
 
                 if (resultList==null ||  resultList.Count==0)
                 {
@@ -124,7 +145,7 @@ namespace Compdfkit_Tools.PDFControl
                 return;
             }
 
-            if (pdfView == null || pdfView.Document == null)
+            if (pdfView == null || pdfView.GetDocument() == null)
             {
                 return;
             }
@@ -132,28 +153,26 @@ namespace Compdfkit_Tools.PDFControl
             if (textSearch != null && textSearch.CanDoSearch)
             {
                 keyWord = e;
-                textSearch.TextSearchDocument = pdfView.Document;
+                textSearch.TextSearchDocument = pdfView.GetDocument();
                 textSearch.SearchText(e, C_Search_Options.Search_Case_Insensitive);
             }
         }
 
         private void HighLightSelectResult(BindSearchResult result)
         {
-            if (result == null)
+            if (result == null || result.RefData==null)
             {
                 return;
             }
 
             List<TextSearchItem> selectList = new List<TextSearchItem>();
-            selectList.Add(new TextSearchItem()
+            TextSearchItem highlightItem=result.RefData as TextSearchItem;
+            if(highlightItem != null)
             {
-                PageIndex = result.PageIndex,
-                TextRect = result.TextRect,
-                TextContent = result.TextContent,
-                PageRotate = result.PageRotate,
-
-            });
-            pdfView.SetPageSelectText(selectList, highLightBrush);
+                highlightItem.CreatePaintBrush(highLightBrush.Color);
+                selectList.Add(highlightItem);
+                ViewControl.PDFViewTool?.HighLightSearchText(selectList);
+            }
         }
 
         private void ClearSearchResult()

+ 1 - 9
Demo/Examples/Compdfkit_Tools/PDFView/PDFSearch/PDFSearchUI/CPDFSearchResultUI.xaml.cs

@@ -1,22 +1,13 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.ComponentModel;
-using System.Globalization;
-using System.Linq;
-using System.Text;
 using System.Text.RegularExpressions;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;
 using System.Windows.Documents;
-using System.Windows.Input;
 using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
 
 
 namespace Compdfkit_Tools.PDFControlUI
@@ -148,6 +139,7 @@ namespace Compdfkit_Tools.PDFControlUI
         /// 页面旋转角度
         /// </summary>
         public int PageRotate { get; set; }
+        public object RefData {  get; set; }
     }
 
     internal class TextBindData