|
@@ -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 (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 {
|
|
|
- self.cropAllPage()
|
|
|
+ self.smart_cropAllPage()
|
|
|
} else if index == 4 {
|
|
|
self.cropAllPage()
|
|
|
} else if index == 5 {
|