Browse Source

【海报】海报页面有较多问题,看截图,且点击保存无反应 -- tag功能补充

lizhe 10 months ago
parent
commit
00da6b1ae0

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Print/Model/KMPrintPageModel.swift

@@ -169,7 +169,7 @@ struct KMPrintPageOperation {
         var overlap: Float = 0.0
         var isCutMark: Bool = false
         var isTags: Bool = false
-        var tags: [String] = ["(column,row)1.pdf 2023-01-09 05:49:54"]
+        var tags: String = "(column,row)1.pdf 2023-01-09 05:49:54"
         
         enum PosterType {
             case tile //平铺

+ 73 - 22
PDF Office/PDF Master/Class/PDFTools/Print/Presenter/KMPrintPresenter.swift

@@ -519,36 +519,42 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
                         context.strokePath()
                     }
                     NSGraphicsContext.restoreGraphicsState()
+                    if data.page.operation.poster.isTags {
+                        self.drawLabelText(data: data, point: CGPointMake(CGFloat(i + 1), CGFloat(j + 1)))
+                    }
 //                        page.setBounds(NSRect(x: 0, y: 0, width: pageRect.size.width, height: pageRect.size.height), for: .cropBox)
                 }
             }
         }
     }
     
-    func drawLabelTextContextSize(context: CGContext) {
-        let pageSize = CGSize(width: 0, height: 0)
-        let KBlankA4W = pageSize.width
-        let KBlankA4H = pageSize.height
+    func drawLabelText(data: KMPrintModel, point: NSPoint) {
+        let paperSize: CGSize = self.fetchPaperSize(data.paper)//纸张大小
+        
+        let KBlankA4W = paperSize.width
+        let KBlankA4H = paperSize.height
         
         var contextString: String
-//        if let labelString = PDFPrint.labelString, !labelString.isEmpty {
-//            contextString = labelString
-//        } else {
+        let labelString = data.page.operation.poster.tags
+        
+        if labelString.count != 0 {
+            contextString = labelString
+        } else {
             let date = Date()
             let formatter = DateFormatter()
             formatter.dateFormat = "YYYY-MM-dd hh:mm:ss"
-        contextString = "(\("1"),\("1")) \("filePath.lastPathComponent") \(formatter.string(from: date))"
-//        }
+            contextString = "(\(point.x),\(point.y)) \(self.document?.documentURL.lastPathComponent) \(formatter.string(from: date))"
+        }
         
         let fontSize = 12.0 * (max(KBlankA4W, KBlankA4H) / 842)
         let font = NSFont.systemFont(ofSize: fontSize)
         let color = NSColor.black
         
-        var size = NSSize.zero
-        var style = NSMutableParagraphStyle()
+        var size = CGSize.zero
+        let style = NSMutableParagraphStyle()
         style.alignment = .center
         style.lineBreakMode = .byCharWrapping
-        var attributes = [NSAttributedString.Key: Any]()
+        var attributes: [NSAttributedString.Key: Any] = [:]
         attributes[.paragraphStyle] = style
         attributes[.foregroundColor] = color
         attributes[.font] = font
@@ -556,18 +562,63 @@ extension KMPrintPresenter: KMPrintPresenterDocument {
                                           options: [.usesLineFragmentOrigin, .usesFontLeading],
                                           attributes: attributes).size
         
-//        if PDFPrint.splitType == .pageNumber {
-            contextString.draw(in: CGRect(x: 10 + 10,
-                                          y: KBlankA4H - 10 + size.height,
-                                          width: size.width, height: size.height),
-                                withAttributes: attributes)
+        let drawRect: CGRect
+//        if data.page.operation.poster.type == .tile {
+//            drawRect = CGRect(x: 20 + 10,
+//                              y: 100 + size.height,
+//                              width: size.width, height: size.height)
 //        } else {
-//            contextString.draw(in: CGRect(x: PDFPrint.edgeInsets.left + 10,
-//                                          y: KBlankA4H - PDFPrint.edgeInsets.top + size.height,
-//                                          width: size.width, height: size.height),
-//                                withAttributes: attributes)
+            drawRect = CGRect(x: 20,
+                              y: paperSize.height - size.height - 40,
+                              width: size.width, height: size.height)
 //        }
+        
+        contextString.draw(in: drawRect, withAttributes: attributes)
     }
+    
+//    func drawLabelTextContextSize(context: CGContext) {
+//        let pageSize = CGSize(width: 0, height: 0)
+//        let KBlankA4W = pageSize.width
+//        let KBlankA4H = pageSize.height
+//        
+//        var contextString: String
+////        if let labelString = PDFPrint.labelString, !labelString.isEmpty {
+////            contextString = labelString
+////        } else {
+//            let date = Date()
+//            let formatter = DateFormatter()
+//            formatter.dateFormat = "YYYY-MM-dd hh:mm:ss"
+//        contextString = "(\("1"),\("1")) \("filePath.lastPathComponent") \(formatter.string(from: date))"
+////        }
+//        
+//        let fontSize = 12.0 * (max(KBlankA4W, KBlankA4H) / 842)
+//        let font = NSFont.systemFont(ofSize: fontSize)
+//        let color = NSColor.black
+//        
+//        var size = NSSize.zero
+//        var style = NSMutableParagraphStyle()
+//        style.alignment = .center
+//        style.lineBreakMode = .byCharWrapping
+//        var attributes = [NSAttributedString.Key: Any]()
+//        attributes[.paragraphStyle] = style
+//        attributes[.foregroundColor] = color
+//        attributes[.font] = font
+//        size = contextString.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: CGFloat.greatestFiniteMagnitude),
+//                                          options: [.usesLineFragmentOrigin, .usesFontLeading],
+//                                          attributes: attributes).size
+//        
+////        if PDFPrint.splitType == .pageNumber {
+//            contextString.draw(in: CGRect(x: 10 + 10,
+//                                          y: KBlankA4H - 10 + size.height,
+//                                          width: size.width, height: size.height),
+//                                withAttributes: attributes)
+////        } else {
+////            contextString.draw(in: CGRect(x: PDFPrint.edgeInsets.left + 10,
+////                                          y: KBlankA4H - PDFPrint.edgeInsets.top + size.height,
+////                                          width: size.width, height: size.height),
+////                                withAttributes: attributes)
+////        }
+//    }
 
 }
 
@@ -1064,7 +1115,7 @@ extension KMPrintPresenter: KMPrintPresenterDraw {
     //    }
     
     func drawString(_ pageModel: KMPrintPageModel, _ contextSize: CGSize) {
-        var string = pageModel.operation.poster.tags.first ?? ""
+        var string = pageModel.operation.poster.tags
 //        if string.isEmpty {
 //            string =
 //        }

+ 7 - 6
PDF Office/PDF Master/Class/PDFTools/Print/View/ChooseView/View/View/DealPaper/KMPrintChoosePageSizePosterView.swift

@@ -71,7 +71,8 @@ class KMPrintChoosePageSizePosterView: KMBaseXibView {
         self.tagsTextField.onlyNumber = false
         self.tagsTextField.placeholderString = "(column,row)1.pdf 2023-01-09 05:49:54"
         self.tagsTextField.textDidChange = { [unowned self] (string) in
-            self.outputData.tags = string.components(separatedBy: " ")
+            self.outputData.tags = string
+//            self.outputData.tags = string.components(separatedBy: " ")
             self.actionReloadData()
         }
         
@@ -106,12 +107,12 @@ class KMPrintChoosePageSizePosterView: KMBaseXibView {
         self.tagsButton.state = (self.outputData.isTags == true) ? .on : .off
         
         self.tileScaleTextField.stringValue = (self.outputData.scale * 100).description
-        var string: String = ""
-        for s in self.outputData.tags {
-            string += " " + s
-        }
+//        var string: String = ""
+//        for s in self.outputData.tags {
+//            string += " " + s
+//        }
         
-        self.tagsTextField.stringValue = string
+        self.tagsTextField.stringValue = self.outputData.tags
     }
 }
 

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Print/View/PrintSettingView/View/Poster/KMPrintPosterView.swift

@@ -272,7 +272,7 @@ extension KMPrintPosterView {
             labelTextField.isEditable = false
         }
     
-        self.viewModel.posterTagsAction(isSelect: labelButton.state == .on, tags:[labelTextField.stringValue]) { success, model in
+        self.viewModel.posterTagsAction(isSelect: labelButton.state == .on, tags:labelTextField.stringValue) { success, model in
             self.updatePDFView(isPageChange: false)
         }
     }

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/Print/View/PrintSettingView/ViewModel/KMPrintViewModel.swift

@@ -180,7 +180,7 @@ extension KMPrintViewModel {
         completion(true, model)
     }
     
-    func posterTagsAction(isSelect: Bool, tags: [String], completion: KMPrintViewModelCompletion) {
+    func posterTagsAction(isSelect: Bool, tags: String, completion: KMPrintViewModelCompletion) {
         if isSelect == self.model.page.operation.poster.isTags {
             completion(false, nil)
             return