Sfoglia il codice sorgente

【2025】【Edit】裁剪优化,串接完善

niehaoyu 20 ore fa
parent
commit
5c21a118b5

+ 9 - 3
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/Crop/KMCropController.swift

@@ -26,6 +26,7 @@ class KMCropController: NSViewController {
     private var coverController: KMCropCoverController?
     
     var pdfDocument: CPDFDocument?
+    var selectionRect: CGRect = .zero
 
     weak open var delegate: KMCropControllerDelegate?
     
@@ -74,9 +75,14 @@ class KMCropController: NSViewController {
         let bounds = page?.bounds ?? CGRectZero
         
         documentPreview.pdfView.toolMode = .selectToolMode
-        documentPreview.pdfView.displayBox = .mediaBox
-        documentPreview.pdfView.selectionRect = bounds
-        documentPreview.pdfView.setNeedsDisplayForVisiblePages()
+        documentPreview.pdfView.selectionPageIndex = 0
+        
+        if CGRectEqualToRect(selectionRect, CGRectZero) {
+            selectionRect = bounds
+        } else {
+            documentPreview.pdfView.selectionRect = selectionRect
+            documentPreview.pdfView.setNeedsDisplayForVisiblePages()
+        }
      
         propertyController.pdfView = documentPreview.pdfView
         propertyController.reloadData()

+ 12 - 4
PDF Office/PDF Master/KMClass/KMPDFViewController/KMMainViewController.swift

@@ -908,9 +908,14 @@ import KMComponentLibrary
         let editDocument = CPDFDocument.init()
         
         let page = listView.document.page(at: UInt(listView.currentPageIndex))
-        editDocument?.insertPageObject(page, at: 0)
         
+        editDocument?.insertPageObject(page, at: 0)
+        if let editPage = editDocument?.page(at: 0) {
+            editPage.setBounds(CGRectMake(0, 0, editPage.bounds(for: .mediaBox).size.width, editPage.bounds(for: .mediaBox).size.height), for: .cropBox)
+            controller.selectionRect = page?.bounds(for: .cropBox) ?? .zero
+         } 
         controller.pdfDocument = editDocument
+        
         controller.reloadData()
         
     }
@@ -923,9 +928,12 @@ import KMComponentLibrary
             cropController = nil
         }
         
-        toolbarManager.edit_crop_Property.state = .normal
-        pdfToolbarController?.refreshSecondToolbarItemsState()
-        
+        if viewManager.subToolMode == .Edit_Crop {
+            viewManager.subToolMode = .None
+            toolbarManager.edit_crop_Property.state = .normal
+            pdfToolbarController?.refreshSecondToolbarItemsState()
+        }
+
     }
     
     //MARK: - Watermark水印