KMPrintPaperModel.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // KMPrintPaperModel.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2022/12/21.
  6. //
  7. import Cocoa
  8. enum KMPrintPaperDirectionType: String, CaseIterable {
  9. case vertical = "Vertical" //纵向
  10. case horizontal = "Horizontal" //横向
  11. static func allValues() -> [String] {
  12. var array: [String] = []
  13. for key in KMPrintPaperDirectionType.allCases {
  14. array.append(key.rawValue)
  15. }
  16. return array
  17. }
  18. static func typeOfRawValue(_ rawValue: String) -> KMPrintPaperDirectionType {
  19. var type: KMPrintPaperDirectionType = .vertical
  20. switch rawValue {
  21. case KMPrintPaperDirectionType.vertical.rawValue, NSLocalizedString(KMPrintPaperDirectionType.vertical.rawValue, comment: ""):
  22. type = .vertical
  23. case KMPrintPaperDirectionType.horizontal.rawValue, NSLocalizedString(KMPrintPaperDirectionType.horizontal.rawValue, comment: ""):
  24. type = .horizontal
  25. default:
  26. type = .vertical
  27. }
  28. return type
  29. }
  30. }
  31. //打印纸张设置
  32. struct KMPrintPaperInfo {
  33. var type: KMPaperType = .A4
  34. var inset: NSEdgeInsets = NSEdgeInsetsMake(20, 20, 20, 20)
  35. var size: CGSize {
  36. return KMPaperType.paperSize(type: type, px: true)
  37. }
  38. enum KMPaperType: String, CaseIterable {
  39. case A3 = "A3"
  40. case A4 = "A4"
  41. case A5 = "A5"
  42. case B5 = "B5"
  43. case Envelope_10 = "Envelope #10"
  44. case Envelope_Choukei_3 = "Envelope Choukei 3"
  45. case Envelope_DL = "DL信封"
  46. case JIS_B5 = "JIS B5"
  47. case ROC_16K = "ROC 16K"
  48. case SuperB_A3 = "Super B/A3"
  49. case Tabloid = "Tabloid"
  50. case Tabloid_Oversize = "Tabloid Oversize"
  51. case US_Legal = "US Legal"
  52. case US_Letter = "US Letter"
  53. case custom = "custom"
  54. static func allValues() -> [String] {
  55. var array: [String] = []
  56. for key in KMPaperType.allCases {
  57. array.append(key.rawValue)
  58. }
  59. return array
  60. }
  61. static func paperSize(type: KMPaperType, px: Bool) -> CGSize {
  62. var size = NSZeroSize
  63. switch type {
  64. //28.3
  65. case KMPaperType.A3:
  66. size = CGSize(width: 297, height: 420)
  67. case KMPaperType.A4:
  68. size = CGSize(width: 210, height: 297)
  69. case KMPaperType.A5:
  70. size = CGSize(width: 148, height: 210)
  71. case KMPaperType.B5:
  72. size = CGSize(width: 176, height: 250)
  73. case KMPaperType.Envelope_10:
  74. size = CGSize(width: 105, height: 241)
  75. case KMPaperType.Envelope_Choukei_3:
  76. size = CGSize(width: 120, height: 235)
  77. case KMPaperType.Envelope_DL:
  78. size = CGSize(width: 110, height: 220)
  79. case KMPaperType.JIS_B5:
  80. size = CGSize(width: 182, height: 257)
  81. case KMPaperType.ROC_16K:
  82. size = CGSize(width: 197, height: 273)
  83. case KMPaperType.SuperB_A3:
  84. size = CGSize(width: 330, height: 483)
  85. case KMPaperType.Tabloid:
  86. size = CGSize(width: 279, height: 432)
  87. case KMPaperType.Tabloid_Oversize:
  88. size = CGSize(width: 305, height: 457)
  89. case KMPaperType.US_Legal:
  90. size = CGSize(width: 216, height: 356)
  91. case KMPaperType.US_Letter:
  92. size = CGSize(width: 216, height: 279)
  93. default:
  94. size = CGSize(width: 210, height: 297)
  95. }
  96. if px {
  97. return CGSize(width: floor(size.width * (595.0 / 210.0)),
  98. height: floor(size.height * (842.0 / 297.0)))
  99. } else {
  100. return size
  101. }
  102. }
  103. }
  104. }
  105. class KMPrintPaperModel: NSObject {
  106. var info: KMPrintPaperInfo = KMPrintPaperInfo()
  107. var direction: KMPrintPaperDirectionType = .vertical
  108. }