123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //
- // KMPrintPaperModel.swift
- // PDF Reader Pro
- //
- // 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
- }
- }
- enum KMPrintPaperInfoUnit: String, CaseIterable {
- case mm = "mm"
- case cm = "cm"
- case `in` = "in"
- case px = "px"
-
- static func allValues() -> [String] {
- var array: [String] = []
- for key in KMPrintPaperInfoUnit.allCases {
- array.append(key.rawValue)
- }
- array.removeLast()
- return array
- }
- }
- //打印纸张设置
- struct KMPrintPaperInfo {
- var type: KMPaperType = .A4
- var inset: NSEdgeInsets = NSEdgeInsetsMake(30, 30, 30, 30)
- var customSize: CGSize = CGSize(width: 210, height: 297)
- var unit: KMPrintPaperInfoUnit = .mm
- var size: CGSize {
- return KMPaperType.paperSize(type: type, unit: unit)
- }
-
- // var showSize: CGSize {
- // return KMPaperType.paperSize(type: type, px: false)
- // }
-
- enum KMPaperType: String, CaseIterable {
- case Actual = "Actual Size"
- 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(NSLocalizedString(key.rawValue, comment: ""))
- }
- return array
- }
-
- static func paperSize(type: KMPaperType, unit: KMPrintPaperInfoUnit) -> 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 unit == .mm {
- } else if unit == .cm {
- size = CGSize(width: floor(size.width * 0.1),
- height: floor(size.height * 0.1))
- } else if unit == .in {
- size = CGSize(width: floor(size.width * 0.254),
- height: floor(size.height * 0.254))
- } else {
- size = CGSize(width: floor(size.width * (595.0 / 210.0)),
- height: floor(size.height * (842.0 / 297.0)))
- }
- return CGSize(width: size.width * 100 / 100, height: size.height * 100 / 100)
- }
- }
-
- func unitScanel(unit: KMPrintPaperInfoUnit) -> CGFloat {
- if unit == .mm {
- return 1.0
- } else if unit == .cm {
- return 0.1
- } else if unit == .in {
- return 0.254
- } else {
- return 1.0
- }
- }
- }
- class KMPrintPaperModel: NSObject {
- var info: KMPrintPaperInfo = KMPrintPaperInfo()
- var direction: KMPrintPaperDirectionType = .vertical
- }
|