Pārlūkot izejas kodu

【综合】裁剪,白边距效果补充

tangchao 1 gadu atpakaļ
vecāks
revīzija
7a1e978c27

+ 74 - 26
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1899,7 +1899,6 @@ extension KMMainViewController {
         
         /// 刷新预览视图
         self.listView.layoutDocumentView()
-        
         self.listView.displayBox = .cropBox
     }
     
@@ -1928,7 +1927,7 @@ extension KMMainViewController {
     }
     
     
-   @objc func cropAllPage() {
+   @objc func smart_cropAllPage() {
         var size = NSZeroSize
         for i in 0 ..< self.listView.document.pageCount {
             let page = self.listView.document.page(at: i)
@@ -1944,31 +1943,31 @@ extension KMMainViewController {
             let page = self.listView.document.page(at: i)
             var rect = KMCropTools.getPageForegroundBox(page!)
             let bounds: NSRect = (page?.bounds(for: .mediaBox))!
-            if (rect.minX - bounds.minX > bounds.maxX-rect.maxX) {
-                rect.origin.x = rect.maxX-size.width
-            }
-            
-            rect.origin.y = rect.maxY-size.height
-            rect.size = size
-            
-            if (NSWidth(rect) > NSWidth(bounds)) {
-                rect.size.width = NSWidth(bounds)
-            }
-            if (NSHeight(rect) > NSHeight(bounds)) {
-                rect.size.height = NSHeight(bounds)
-            }
+//            if (rect.minX - bounds.minX > bounds.maxX-rect.maxX) {
+//                rect.origin.x = rect.maxX-size.width
+//            }
             
-            if (NSMinX(rect) < NSMinX(bounds)) {
-                rect.origin.x = NSMinX(bounds)
-            } else if (NSMaxX(rect) > NSMaxX(bounds)) {
-                rect.origin.x = NSMaxX(bounds) - NSWidth(rect)
-            }
+//            rect.origin.y = rect.maxY-size.height
+//            rect.size = size
             
-            if (NSMinY(rect) < NSMinY(bounds)) {
-                rect.origin.y = NSMinY(bounds)
-            } else if (NSMaxY(rect) > NSMaxY(bounds)) {
-                rect.origin.y = NSMaxY(bounds) - NSHeight(rect)
-            }
+//            if (NSWidth(rect) > NSWidth(bounds)) {
+//                rect.size.width = NSWidth(bounds)
+//            }
+//            if (NSHeight(rect) > NSHeight(bounds)) {
+//                rect.size.height = NSHeight(bounds)
+//            }
+//
+//            if (NSMinX(rect) < NSMinX(bounds)) {
+//                rect.origin.x = NSMinX(bounds)
+//            } else if (NSMaxX(rect) > NSMaxX(bounds)) {
+//                rect.origin.x = NSMaxX(bounds) - NSWidth(rect)
+//            }
+//
+//            if (NSMinY(rect) < NSMinY(bounds)) {
+//                rect.origin.y = NSMinY(bounds)
+//            } else if (NSMaxY(rect) > NSMaxY(bounds)) {
+//                rect.origin.y = NSMaxY(bounds) - NSHeight(rect)
+//            }
             
             rectArray.append(rect)
         }
@@ -1977,6 +1976,55 @@ extension KMMainViewController {
        self.handlePageBoundsDidChange(page: nil, action: CPDFPage.Action.crop)
     }
     
+    @objc func cropAllPage() {
+         var size = NSZeroSize
+         for i in 0 ..< self.listView.document.pageCount {
+             let page = self.listView.document.page(at: i)
+             let rect = KMCropTools.getPageForegroundBox(page!)
+             size.width = fmax(size.width, NSWidth(rect))
+             size.height = fmax(size.height, NSHeight(rect))
+         }
+        beginProgressSheet(with: KMLocalizedString("Cropping Pages", "Message for progress sheet"), maxValue: min(18, self.listView.document.pageCount))
+        var rectArray: Array<NSRect> = []
+         for i in 0 ..< self.listView.document.pageCount {
+             progressController?.increment(by: Double(i))
+             progressController?.doubleValue = Double(i)
+             let page = self.listView.document.page(at: i)
+             var rect = KMCropTools.getPageForegroundBox(page!)
+             let bounds: NSRect = (page?.bounds(for: .mediaBox))!
+             if (rect.minX - bounds.minX > bounds.maxX-rect.maxX) {
+                 rect.origin.x = rect.maxX-size.width
+             }
+             
+             rect.origin.y = rect.maxY-size.height
+             rect.size = size
+             
+             if (NSWidth(rect) > NSWidth(bounds)) {
+                 rect.size.width = NSWidth(bounds)
+             }
+             if (NSHeight(rect) > NSHeight(bounds)) {
+                 rect.size.height = NSHeight(bounds)
+             }
+             
+             if (NSMinX(rect) < NSMinX(bounds)) {
+                 rect.origin.x = NSMinX(bounds)
+             } else if (NSMaxX(rect) > NSMaxX(bounds)) {
+                 rect.origin.x = NSMaxX(bounds) - NSWidth(rect)
+             }
+             
+             if (NSMinY(rect) < NSMinY(bounds)) {
+                 rect.origin.y = NSMinY(bounds)
+             } else if (NSMaxY(rect) > NSMaxY(bounds)) {
+                 rect.origin.y = NSMaxY(bounds) - NSHeight(rect)
+             }
+             
+             rectArray.append(rect)
+         }
+         
+         cropPages(to: rectArray)
+        self.handlePageBoundsDidChange(page: nil, action: CPDFPage.Action.crop)
+     }
+    
     func cropPages(to rects: Array<NSRect>) {
         let currentPage = self.listView.currentPage()
         let visibleRect: NSRect = self.listView.convert(self.listView.convert(self.listView.documentView().visibleRect, from: self.listView.documentView()), to: self.listView.currentPage())
@@ -4541,7 +4589,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
             if index == 2 { // 裁剪当前页面
                 self.cropCurrentPage()
             } else if index == 3 { // Auto Crop – Separate
-                self.cropAllPage()
+                self.smart_cropAllPage()
             } else if index == 4 { // Auto Crop – Combined
                 self.cropAllPage()
             } else if index == 5 { // Select Area

+ 3 - 3
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+MenuAction.swift

@@ -942,13 +942,13 @@ extension KMMainViewController: KMSystemToolMenuProtocol {
         self.cropCurrentPage()
     }
     
+    // 白边距
     func autoCropAll(_ sender: Any?) {
-        #warning("暂时这么处理,后续调整")
-        self.cropAllPage()
+        self.smart_cropAllPage()
     }
     
+    // 自动
     func smartAutoCropAll(_ sender: Any?) {
-        #warning("暂时这么处理,后续调整")
         self.cropAllPage()
     }
     

+ 42 - 10
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -269,8 +269,8 @@
             filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "3851"
-            endingLineNumber = "3851"
+            startingLineNumber = "3899"
+            endingLineNumber = "3899"
             landmarkName = "clickChildTool(type:index:)"
             landmarkType = "7">
          </BreakpointContent>
@@ -285,13 +285,13 @@
             filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "3859"
-            endingLineNumber = "3859"
+            startingLineNumber = "3907"
+            endingLineNumber = "3907"
             landmarkName = "clickChildTool(type:index:)"
             landmarkType = "7">
             <Locations>
                <Location
-                  uuid = "704A9D07-43BC-4F2B-8466-823716A7A94F - 16183e7ec6398bda"
+                  uuid = "704A9D07-43BC-4F2B-8466-823716A7A94F - 16183e7ec6398daa"
                   shouldBeEnabled = "Yes"
                   ignoreCount = "0"
                   continueAfterRunningActions = "No"
@@ -301,12 +301,12 @@
                   urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift"
                   startingColumnNumber = "9223372036854775807"
                   endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "3859"
-                  endingLineNumber = "3859"
+                  startingLineNumber = "3907"
+                  endingLineNumber = "3907"
                   offsetFromSymbolStart = "219">
                </Location>
                <Location
-                  uuid = "704A9D07-43BC-4F2B-8466-823716A7A94F - 16183e7ec6398bda"
+                  uuid = "704A9D07-43BC-4F2B-8466-823716A7A94F - 16183e7ec6398daa"
                   shouldBeEnabled = "Yes"
                   ignoreCount = "0"
                   continueAfterRunningActions = "No"
@@ -316,12 +316,44 @@
                   urlString = "file:///Users/kdanmobile/work/tangchao/git/PDFOffice/PDF%20Office/PDF%20Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift"
                   startingColumnNumber = "9223372036854775807"
                   endingColumnNumber = "9223372036854775807"
-                  startingLineNumber = "3859"
-                  endingLineNumber = "3859"
+                  startingLineNumber = "3907"
+                  endingLineNumber = "3907"
                   offsetFromSymbolStart = "288">
                </Location>
             </Locations>
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "80B5B3FF-8C4D-4A21-ADEC-AD848598BDB2"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+MenuAction.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "947"
+            endingLineNumber = "947"
+            landmarkName = "autoCropAll(_:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "1080823F-C977-4741-9812-7C251C2DA0D9"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+MenuAction.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "952"
+            endingLineNumber = "952"
+            landmarkName = "smartAutoCropAll(_:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>