123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- //
- // 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
- }
|