|
@@ -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 =
|
|
|
// }
|