Browse Source

注释列表-手绘缩略图大小更改问题

OYXH\oyxh 2 years ago
parent
commit
6358a01609

+ 25 - 0
PDF Office/ViewModels/BOTA/AnnotationContentViewModel.cs

@@ -781,6 +781,23 @@ namespace PDF_Office.ViewModels.BOTA
             }
         }
 
+        public async void ScrollToAnnot(int pageindex, int annotindex, ListBox AnnotationList)
+        {
+            //var list = PdfViewer.GetAnnotCommentList(pageindex, PdfViewer.Document);
+            for (int i = 0; i < AnnotationList.Items.Count; i++)
+            {
+                if ((AnnotationList.Items[i] as AnnotationHandlerEventArgs).AnnotIndex == annotindex && (AnnotationList.Items[i] as AnnotationHandlerEventArgs).PageIndex == pageindex)
+                {
+                    var item = AnnotationList.Items[i] as AnnotationHandlerEventArgs;
+                    //需要手动搜寻在哪一个分组 展开分组头
+                    ExpandGroupHeader(item, AnnotationList);
+                    AnnotationList.SelectedItem = item;
+                    await Task.Delay(1);
+                    AnnotationList.ScrollIntoView(item);
+                }
+            }
+        }
+
         /// <summary>
         /// listboxitem鼠标左键点击,显示分组的数据
         /// </summary>
@@ -1115,16 +1132,24 @@ namespace PDF_Office.ViewModels.BOTA
             {
                 if (docAnnots.IndexOf(annot) == annotIndex)
                 {
+                    CPDFInkAnnotation cPDFInk = (CPDFInkAnnotation)docAnnots[annotIndex];
                     CRect rawRect = annot.GetRect();
+
+                    rawRect = cPDFInk.Rect;
                     double scaleDpi = 96.0 / 72.0;
+
                     Rect paintRect = new Rect(rawRect.left * scaleDpi, rawRect.top * scaleDpi, rawRect.width() * scaleDpi, rawRect.height() * scaleDpi);
+
                     int drawWidth = (int)paintRect.Width;
                     int drawHeight = (int)paintRect.Height;
                     byte[] bitmapArray = new byte[drawWidth * drawHeight * 4];
                     annot.UpdateAp();
                     annot.RenderAnnot(drawWidth, drawHeight, bitmapArray);
+
                     WriteableBitmap wirteBitmap = new WriteableBitmap(drawWidth, drawHeight, 96, 96, PixelFormats.Bgra32, null);
                     wirteBitmap.WritePixels(new Int32Rect(0, 0, drawWidth, drawHeight), bitmapArray, wirteBitmap.BackBufferStride, 0);
+
+                    cPDFInk.SetRect(rawRect);
                     return wirteBitmap;
                 }
             }

+ 33 - 9
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.Command.cs

@@ -219,11 +219,35 @@ namespace PDF_Office.ViewModels.Tools
                     }
 
                 }
+
+                //注释列表同步选中
+                var list = e.GetPageAnnotsIndex();
+                bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
+
+                if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true && bOTAContent.TabItemAnnotation.IsSelected == true && list != null && list.Count > 0)
+                {
+                    if (list.Keys.Count == 0)
+                    {
+                        return;
+                    }
+                    var pageindex = new List<int>(list.Keys);
+                    List<int> annotes = new List<int>();
+                    list.TryGetValue(pageindex[0], out annotes);
+                    int annoteindex = annotes[0];
+                    AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
+
+                    if (viewModel != null)
+                    {
+                        viewModel.ScrollToAnnot(pageindex[0], annoteindex, annotation.AnnotationList);
+                    }
+                }
             }
             else
             {
+
                 viewContentViewModel.SelectedPrpoertyPanel("PropertyPanelContent", null);
             }
+
         }
 
         private bool isShapAnnot(AnnotHandlerEventArgs annot)
@@ -348,10 +372,10 @@ namespace PDF_Office.ViewModels.Tools
                         }
                         else
                         {
-                            if(e.AnnotEventArgsList.Count == 1)
+                            if (e.AnnotEventArgsList.Count == 1)
                             {
                                 var selectedAnnot = e.AnnotEventArgsList[0];
-                                switch(selectedAnnot.EventType)
+                                switch (selectedAnnot.EventType)
                                 {
                                     case AnnotArgsType.AnnotHighlight:
                                     case AnnotArgsType.AnnotUnderline:
@@ -384,9 +408,9 @@ namespace PDF_Office.ViewModels.Tools
                             else
                             {
                                 bool isHigh = true;//是否为高亮
-                               foreach(var item in e.AnnotEventArgsList)
+                                foreach (var item in e.AnnotEventArgsList)
                                 {
-                                    if(isHightAnnot(item) == false)
+                                    if (isHightAnnot(item) == false)
                                     {
                                         isHigh = false;
                                         break;
@@ -395,7 +419,7 @@ namespace PDF_Office.ViewModels.Tools
 
                                 e.PopupMenu = SelectMultiAnnotMenu(sender, isHigh);
                             }
-                           
+
                         }
                         if (e.PopupMenu != null)
                         {
@@ -544,12 +568,12 @@ namespace PDF_Office.ViewModels.Tools
                     switch (editEvent.EditAction)
                     {
                         case ActionType.Add:
-                            
+
                             bool isTabItemAnnotation = IsBOTATabItemShow(out BOTAContentViewModel bOTAContentViewModel, out BOTAContent bOTAContent, "TabItemAnnotation");
 
                             if (viewContentViewModel.OpenBOTA == true && isTabItemAnnotation == true)
                             {
-                                AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
+                                AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
 
                                 if (viewModel != null)
                                 {
@@ -564,7 +588,7 @@ namespace PDF_Office.ViewModels.Tools
                             isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
                             if (isTabItemAnnotation)
                             {
-                                AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
+                                AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
 
                                 if (viewModel != null)
                                 {
@@ -579,7 +603,7 @@ namespace PDF_Office.ViewModels.Tools
                             isTabItemAnnotation = IsBOTATabItemShow(out bOTAContentViewModel, out bOTAContent, "TabItemAnnotation");
                             if (bOTAContent.TabItemAnnotation.IsSelected)
                             {
-                                AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel);
+                                AnnotationContentViewModel viewModel = GetAnnotationContentViewModel(bOTAContentViewModel, out AnnotationContent annotation);
 
                                 if (viewModel != null)
                                 {

+ 5 - 3
PDF Office/ViewModels/Tools/AnnotToolContentViewModel.cs

@@ -181,9 +181,10 @@ namespace PDF_Office.ViewModels.Tools
 
         #region BOTA
 
-        private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel)
+        private AnnotationContentViewModel GetAnnotationContentViewModel(BOTAContentViewModel bOTAContentViewModel, out AnnotationContent annotation)
         {
             AnnotationContentViewModel viewModel = null;
+            annotation = null;
             if (bOTAContentViewModel != null)
             {
                 if (region.Regions.ContainsRegionWithName(bOTAContentViewModel.BOTAContentRegionName))
@@ -191,9 +192,10 @@ namespace PDF_Office.ViewModels.Tools
                     var views = region.Regions[bOTAContentViewModel.BOTAContentRegionName].Views;
                     foreach (var item in views)
                     {
-                        if (item is AnnotationContent annotation)
+                        if (item is AnnotationContent annotation1)
                         {
-                            viewModel = annotation.DataContext as AnnotationContentViewModel;
+                            annotation = annotation1;
+                            viewModel = annotation1.DataContext as AnnotationContentViewModel;
                             break;
                         }
                     }