// // KMPrintPaperModel.swift // PDF Master // // Created by lizhe on 2022/12/21. // import Cocoa enum KMPrintPaperDirectionType: String, CaseIterable { case vertical = "Vertical" //纵向 case horizontal = "Horizontal" //横向 static func allValues() -> [String] { var array: [String] = [] for key in KMPrintPaperDirectionType.allCases { array.append(key.rawValue) } return array } static func typeOfRawValue(_ rawValue: String) -> KMPrintPaperDirectionType { var type: KMPrintPaperDirectionType = .vertical switch rawValue { case KMPrintPaperDirectionType.vertical.rawValue, NSLocalizedString(KMPrintPaperDirectionType.vertical.rawValue, comment: ""): type = .vertical case KMPrintPaperDirectionType.horizontal.rawValue, NSLocalizedString(KMPrintPaperDirectionType.horizontal.rawValue, comment: ""): type = .horizontal default: type = .vertical } return type } } //打印纸张设置 struct KMPrintPaperInfo { var type: KMPaperType = .A4 var inset: NSEdgeInsets = NSEdgeInsetsMake(20, 20, 20, 20) var size: CGSize { return KMPaperType.paperSize(type: type, px: true) } enum KMPaperType: String, CaseIterable { case A3 = "A3" case A4 = "A4" case A5 = "A5" case B5 = "B5" case Envelope_10 = "Envelope #10" case Envelope_Choukei_3 = "Envelope Choukei 3" case Envelope_DL = "DL信封" case JIS_B5 = "JIS B5" case ROC_16K = "ROC 16K" case SuperB_A3 = "Super B/A3" case Tabloid = "Tabloid" case Tabloid_Oversize = "Tabloid Oversize" case US_Legal = "US Legal" case US_Letter = "US Letter" case custom = "custom" static func allValues() -> [String] { var array: [String] = [] for key in KMPaperType.allCases { array.append(key.rawValue) } return array } static func paperSize(type: KMPaperType, px: Bool) -> CGSize { var size = NSZeroSize switch type { //28.3 case KMPaperType.A3: size = CGSize(width: 297, height: 420) case KMPaperType.A4: size = CGSize(width: 210, height: 297) case KMPaperType.A5: size = CGSize(width: 148, height: 210) case KMPaperType.B5: size = CGSize(width: 176, height: 250) case KMPaperType.Envelope_10: size = CGSize(width: 105, height: 241) case KMPaperType.Envelope_Choukei_3: size = CGSize(width: 120, height: 235) case KMPaperType.Envelope_DL: size = CGSize(width: 110, height: 220) case KMPaperType.JIS_B5: size = CGSize(width: 182, height: 257) case KMPaperType.ROC_16K: size = CGSize(width: 197, height: 273) case KMPaperType.SuperB_A3: size = CGSize(width: 330, height: 483) case KMPaperType.Tabloid: size = CGSize(width: 279, height: 432) case KMPaperType.Tabloid_Oversize: size = CGSize(width: 305, height: 457) case KMPaperType.US_Legal: size = CGSize(width: 216, height: 356) case KMPaperType.US_Letter: size = CGSize(width: 216, height: 279) default: size = CGSize(width: 210, height: 297) } if px { return CGSize(width: floor(size.width * (595.0 / 210.0)), height: floor(size.height * (842.0 / 297.0))) } else { return size } } } } class KMPrintPaperModel: NSObject { var info: KMPrintPaperInfo = KMPrintPaperInfo() var direction: KMPrintPaperDirectionType = .vertical }