Prechádzať zdrojové kódy

【页面编辑】插入自定义页面,选择标准A4,方向为横向,添加的还是纵向的A4纸(已修复)

tangchao 1 rok pred
rodič
commit
787dd38a89

+ 7 - 2
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -536,7 +536,11 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
             }
             let windowController = KMPageEditInsertCustomPageWindowController()
             if (self.thumbnailView.selectionIndexPaths.count > 0) {
-                windowController.selectedPageSize = self.getSelectedPage().bounds.size
+                let page = self.getSelectedPage()
+                let width = page.bounds.size.width * 210 / 595
+                let height = page.bounds.size.height * 297 / 842
+                windowController.selectedPageSize = NSSize(width: width, height: height)
+//                windowController.selectedPageSize = self.getSelectedPage().bounds.size
             }
             
             self.km_beginSheet(windowC: windowController)
@@ -558,6 +562,7 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
                 
                 /// 样式
                 //            let type = windowC.typeIndex
+                // mm 单位的大小
                 let pageSize = windowC.pageSize
                 let direction = windowC.direction
                 let _pageSize = KMPageEditTools.sizeUnitToBoundSize(unit: .mm, pageSize: pageSize)
@@ -568,7 +573,7 @@ class KMPDFEditViewController: KMPDFThumbViewBaseController {
                 document?.insertPage(_pageSize, at: 0)
                 if let page: CPDFPage = (document?.page(at: 0)) {
                     if (direction == 0) { /// 纵向
-//                        page.rotation = 90
+                        page.rotation = 90
                     }
                     
                     self?.insertPages(pages: [page], at: IndexSet(integer: _insertIndex+1))

+ 15 - 0
PDF Office/PDF Master/Class/PDFTools/PageEdit/Tools/KMPageEditTools.swift

@@ -276,4 +276,19 @@ class KMPageEditTools: NSObject {
         let height = result.height
         return NSSize(width: width * 595 / 210, height: height * 842 / 297)
     }
+    
+    class func boundSizeToUnitSize(size boundSize: NSSize, to toUnit: KMPageSizeUint) -> NSSize {
+        let _fromUnit = toUnit
+        let _toUnit: KMPageSizeUint = .mm
+        var result: NSSize = boundSize
+        if (_fromUnit == .cm) {
+            result = NSSize(width: boundSize.width * 10, height: boundSize.height * 10)
+        } else if (_fromUnit == .km_in) {
+            result = NSSize(width: boundSize.width * 10 * 25.4,height: boundSize.height * 10 * 25.4)
+        }
+        
+        let width = result.width
+        let height = result.height
+        return NSSize(width: width * 210 / 595, height: height * 297 / 842)
+    }
 }

+ 8 - 8
PDF Office/PDF Master/Class/PDFTools/PageEdit/View/KMPageEditInsertPageSizeItemView.swift

@@ -44,16 +44,16 @@ class KMPageEditInsertPageSizeItemView: KMPageEditBaseItemView {
                 }
             } else {
                 self.currentPageVC?.enabled = true
-                let width = KMPageSizeTool.conversion(withUnit: "mm", value: newValue.width/595*210)
-                let height = KMPageSizeTool.conversion(withUnit: "mm", value: newValue.height/842*297)
+//                let width = KMPageSizeTool.conversion(withUnit: "mm", value: newValue.width/595*210)
+//                let height = KMPageSizeTool.conversion(withUnit: "mm", value: newValue.height/842*297)
                 var widthValue: String = "0"
                 var heightValue: String = "0"
-                if let _value = Float(width) {
-                    widthValue = String(format: "%.1f", _value)
-                }
-                if let _value = Float(height) {
-                    heightValue = String(format: "%.1f", _value)
-                }
+//                if let _value = Float(width) {
+                widthValue = String(format: "%.0f", newValue.width)
+//                }
+//                if let _value = Float(height) {
+                heightValue = String(format: "%.0f", newValue.height)
+//                }
                 
                 self.currentPageVC?.stringValue = "\(NSLocalizedString("Current page", comment: ""))(\(widthValue) x \(heightValue)mm)"
                 self.currentPageVC?.checkbox_radio()