Kaynağa Gözat

ComPDFKit.Tool(pdftech) - 页面裁剪后添加注释保存位置调整

liyuxuan 6 ay önce
ebeveyn
işleme
513d8ee624

+ 14 - 4
Demo/Examples/ComPDFKit.Tool/CPDFToolManager.cs

@@ -1238,12 +1238,22 @@ namespace ComPDFKit.Tool
                                     CPDFDocument cPDFDocument = viewerTool.GetCPDFViewer().GetDocument();
                                     CPDFPage cPDFPage = cPDFDocument.PageAtIndex(pageindex);
                                     Point cropPoint = new Point();
-                                    if (viewerTool.GetCPDFViewer().GetIsCrop())
+                                    if (viewerTool.GetRotateAnnot())
                                     {
-                                        CRect cropRect = cPDFPage.GetCropBounds();
-                                        cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
-                                        cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
+                                        PageViewData viewData = viewerTool.PDFViewer.GetPageNodeByPageIndex(annotation.Page.PageIndex);
+                                        cropPoint.X = viewData.CropLeft;
+                                        cropPoint.Y = viewData.CropTop;
+                                    }
+                                    else
+                                    {
+                                        if (viewerTool.GetCPDFViewer().GetIsCrop())
+                                        {
+                                            CRect cropRect = cPDFPage.GetCropBounds();
+                                            cropPoint.X = DpiHelper.PDFNumToStandardNum(cropRect.left);
+                                            cropPoint.Y = DpiHelper.PDFNumToStandardNum(cropRect.top);
+                                        }
                                     }
+                                  
                                     Rect PDFRect = DpiHelper.StandardRectToPDFRect(new Rect(
                                         (mousePoint.X - pageBound.X + (cropPoint.X * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),
                                         (mousePoint.Y - pageBound.Y + (cropPoint.Y * viewerTool.GetCPDFViewer().GetZoom())) / viewerTool.GetCPDFViewer().GetZoom(),

+ 16 - 4
Demo/Examples/ComPDFKit.Tool/CPDFViewerTool.Annot.cs

@@ -277,12 +277,24 @@ namespace ComPDFKit.Tool
                 defaultSettingParam.SetAnnotParam(stampParam);
             }
             Point cropPoint = new Point();
-            if (PDFViewer.GetIsCrop())
+           
+
+            if(canRotateAnnot)
+            {
+                PageViewData viewData = PDFViewer.GetPageNodeByPageIndex(index);
+                cropPoint.X = viewData.CropLeft;
+                cropPoint.Y = viewData.CropTop;
+            }
+            else
             {
-                CRect cRect = cPDFPage.GetCropBounds();
-                cropPoint.X = DpiHelper.PDFNumToStandardNum(cRect.left);
-                cropPoint.Y = DpiHelper.PDFNumToStandardNum(cRect.top);
+                if (PDFViewer.GetIsCrop())
+                {
+                    CRect cRect = cPDFPage.GetCropBounds();
+                    cropPoint.X = DpiHelper.PDFNumToStandardNum(cRect.left);
+                    cropPoint.Y = DpiHelper.PDFNumToStandardNum(cRect.top);
+                }
             }
+
             SetScrollAndZoomTypeForAnnot(annotType);
             switch (annotType)
             {

+ 22 - 5
Demo/Examples/ComPDFKit.Tool/DrawTool/CreateAnnotTool.cs

@@ -303,7 +303,7 @@ namespace ComPDFKit.Tool.DrawTool
                         (DPIRect.Left - pageBound.X + (cropPoint.X * zoomFactor)) / zoomFactor, (DPIRect.Top - pageBound.Y + (cropPoint.Y * zoomFactor)) / zoomFactor,
                         DPIRect.Width / zoomFactor, DPIRect.Height / zoomFactor);
                 isDrawAnnot = false;
-                freeTextPoint = new Point((mouseStartPoint.X - pageBound.X) / zoomFactor, (mouseStartPoint.Y - pageBound.Y) / zoomFactor);
+                freeTextPoint = new Point((mouseStartPoint.X - pageBound.X ) / zoomFactor, (mouseStartPoint.Y - pageBound.Y) / zoomFactor);
                 mouseStartPoint = new Point();
                 mouseEndPoint = new Point();
                 moveOffset = new Point();
@@ -1481,8 +1481,25 @@ namespace ComPDFKit.Tool.DrawTool
                     textui.Foreground = new SolidColorBrush(textColor);
                     textui.Background = new SolidColorBrush(backgroundColor);
 
-                    textBorder.MaxWidth =(pageBound.Width - MousePoint.X - cropPoint.X);
-                    textBorder.MaxHeight =(pageBound.Height - MousePoint.Y - cropPoint.Y);
+                    double maxWidth = (pageBound.Left+pageBound.Width - MousePoint.X - cropPoint.X * zoomFactor);
+                    if (maxWidth > 0)
+                    {
+                        textBorder.MaxWidth = maxWidth;
+                    }
+                    else
+                    {
+                        textBorder.MaxWidth = pageBound.Left + pageBound.Width - MousePoint.X;
+                    }
+                    double maxHeight = (pageBound.Top+pageBound.Height - MousePoint.Y - cropPoint.Y * zoomFactor);
+                    if (maxHeight > 0)
+                    {
+                        textBorder.MaxHeight = maxHeight;
+                    }
+                    else
+                    {
+                        textBorder.MaxHeight = pageBound.Top + pageBound.Height - MousePoint.Y;
+                    }
+
                     textui.MinHeight = 40;
                     textui.MinWidth = 200;
 
@@ -1551,8 +1568,8 @@ namespace ComPDFKit.Tool.DrawTool
                             {
                                 updateFreeText.SetContent(textui.Text);
                                 Rect changeRect = new Rect(
-                                DpiHelper.StandardNumToPDFNum(freeTextPoint.X),
-                                 DpiHelper.StandardNumToPDFNum(freeTextPoint.Y),
+                                DpiHelper.StandardNumToPDFNum(freeTextPoint.X + cropPoint.X),
+                                 DpiHelper.StandardNumToPDFNum(freeTextPoint.Y + cropPoint.Y),
                                     DpiHelper.StandardNumToPDFNum(textBorder.ActualWidth / zoomFactor),
                                       DpiHelper.StandardNumToPDFNum(textBorder.ActualHeight / zoomFactor));