KMPrintPageModel.swift 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. //
  2. // KMPrintPageModel.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2022/12/21.
  6. //
  7. import Cocoa
  8. struct KMPrintPageRange {
  9. var type: PageRangeType = .allPage
  10. var pageString = ""
  11. var selectPages: [Int] = [] //选中页面
  12. var reversePrintOrder: Bool = false //逆页面打印
  13. enum PageRangeType: String, CaseIterable {
  14. case allPage = "All Pages" //全部页面
  15. case currentPage = "Current Page" //当前页面
  16. case oddPage = "Odd Page" //奇数页
  17. case evenPage = "Even Page" //偶数页
  18. case custom = "Custom" //自定义页面
  19. static func allValues() -> [String] {
  20. var array: [String] = []
  21. for key in PageRangeType.allCases {
  22. array.append(key.rawValue)
  23. }
  24. return array
  25. }
  26. static func typeOfRawValue(_ rawValue: String) -> PageRangeType {
  27. var type: PageRangeType = .allPage
  28. switch rawValue {
  29. case PageRangeType.allPage.rawValue, NSLocalizedString(PageRangeType.allPage.rawValue, comment: ""):
  30. type = .allPage
  31. case PageRangeType.currentPage.rawValue, NSLocalizedString(PageRangeType.currentPage.rawValue, comment: ""):
  32. type = .currentPage
  33. case PageRangeType.oddPage.rawValue, NSLocalizedString(PageRangeType.oddPage.rawValue, comment: ""):
  34. type = .oddPage
  35. case PageRangeType.custom.rawValue, NSLocalizedString(PageRangeType.custom.rawValue, comment: ""):
  36. type = .custom
  37. default:
  38. type = .allPage
  39. }
  40. return type
  41. }
  42. }
  43. }
  44. enum KMPrintContentType: String, CaseIterable {
  45. case document = "document" //文档
  46. case documentAndMarkup = "documentAndMarkup" //文档和标签
  47. case documentAndForm = "documentAndForm" //文档和表单
  48. case documentAndStamp = "documentAndStamp" //文档和贴图
  49. static func allValues() -> [String] {
  50. var array: [String] = []
  51. for key in KMPrintContentType.allCases {
  52. array.append(key.rawValue)
  53. }
  54. return array
  55. }
  56. static func typeOfRawValue(_ rawValue: String) -> KMPrintContentType {
  57. var type: KMPrintContentType = .document
  58. switch rawValue {
  59. case KMPrintContentType.document.rawValue, NSLocalizedString(KMPrintContentType.document.rawValue, comment: ""):
  60. type = .document
  61. case KMPrintContentType.documentAndMarkup.rawValue, NSLocalizedString(KMPrintContentType.documentAndMarkup.rawValue, comment: ""):
  62. type = .documentAndMarkup
  63. case KMPrintContentType.documentAndForm.rawValue, NSLocalizedString(KMPrintContentType.documentAndForm.rawValue, comment: ""):
  64. type = .documentAndForm
  65. case KMPrintContentType.documentAndStamp.rawValue, NSLocalizedString(KMPrintContentType.documentAndStamp.rawValue, comment: ""):
  66. type = .documentAndStamp
  67. default:
  68. type = .document
  69. }
  70. return type
  71. }
  72. }
  73. //类型
  74. enum PrintModelType {
  75. case size //大小
  76. case poster //海报
  77. case multipage //多页
  78. case pamphlet //小册子
  79. }
  80. struct KMPrintPageOperation {
  81. var type: PrintModelType = .size
  82. var size: Size = Size()
  83. var poster: Poster = Poster()
  84. var multipage: Multipage = Multipage()
  85. var pamphlet: Pamphlet = Pamphlet()
  86. struct PageOfPaper {
  87. var type: PageType = .page
  88. var point: CGPoint = CGPoint(x: 1, y: 1)
  89. enum PageType: String, CaseIterable {
  90. case page = "1"
  91. case page2 = "2"
  92. case page4 = "4"
  93. case page6 = "6"
  94. case page9 = "9"
  95. case page16 = "16"
  96. case custom = "custom"
  97. static func allValues() -> [String] {
  98. var array: [String] = []
  99. for key in PageType.allCases {
  100. array.append(key.rawValue)
  101. }
  102. array.removeObject("1")
  103. return array
  104. }
  105. static func pointWithType(_ type: PageType) -> CGPoint {
  106. var point: CGPoint = CGPoint(x: 1, y: 1)
  107. switch type {
  108. case .page:
  109. point = CGPoint(x: 1, y: 1)
  110. case .page2:
  111. point = CGPoint(x: 1, y: 2)
  112. case .page4:
  113. point = CGPoint(x: 2, y: 2)
  114. case .page6:
  115. point = CGPoint(x: 2, y: 3)
  116. case .page9:
  117. point = CGPoint(x: 3, y: 3)
  118. case .page16:
  119. point = CGPoint(x: 4, y: 4)
  120. default:
  121. point = CGPoint(x: 1, y: 1)
  122. }
  123. return point
  124. }
  125. }
  126. }
  127. //大小模式参数内容
  128. struct Size {
  129. var model: Model = .auto
  130. var scale: CGFloat = 1.0
  131. var duplexPrintModel: KMPrintPrinterModel? //双面打印
  132. enum Model: String {
  133. case auto = "auto"
  134. case full = "full"
  135. case custom = "custom"
  136. }
  137. }
  138. //海报模式参数内容
  139. struct Poster {
  140. var type: PosterType = .tile
  141. var scale: CGFloat = 1.0
  142. var tilePoint: CGPoint = CGPoint(x: 1, y: 1)
  143. var pageOfPaper: PageOfPaper = PageOfPaper()
  144. var overlap: Float = 0.0
  145. var isCutMark: Bool = false
  146. var isTags: Bool = false
  147. var tags: [String] = ["(column,row)1.pdf 2023-01-09 05:49:54"]
  148. enum PosterType {
  149. case tile //平铺
  150. case breakUp //拆分
  151. }
  152. }
  153. //多页模式参数内容
  154. struct Multipage {
  155. var orderType: Order = .horizontal
  156. var pageOfPaper: PageOfPaper = PageOfPaper()
  157. var isAutoRotate: Bool = false //自动旋转
  158. //排序类型
  159. enum Order: String, CaseIterable {
  160. case horizontal = "Horizontal" //横向
  161. case horizontalReverseSequence = "Horizontal Reverse Sequence" //横向倒序
  162. case vertical = "Vertical" //纵向
  163. case verticalReverseSequence = "Vertical Reverse Sequence" //纵向倒序
  164. static func allValues() -> [String] {
  165. var array: [String] = []
  166. for key in Order.allCases {
  167. array.append(key.rawValue)
  168. }
  169. return array
  170. }
  171. }
  172. }
  173. //小册子模式参数内容
  174. struct Pamphlet {
  175. var type: PamphletType = .doubleSided
  176. var pageIndex: Int = 1
  177. var toPageIndex: Int = 1
  178. var bookbindingType: BookbindingType = .left
  179. var isAutoRotate: Bool = false //自动旋转
  180. enum PamphletType: String, CaseIterable {
  181. case doubleSided = "Double Sided" //双面
  182. case onlyPositive = "Only Positive" //正面
  183. case onlyBack = "Only Back" //背面
  184. case verticalReverseSequence = "Vertical Reverse Sequence" //纵向倒序
  185. static func allValues() -> [String] {
  186. var array: [String] = []
  187. for key in PamphletType.allCases {
  188. array.append(key.rawValue)
  189. }
  190. return array
  191. }
  192. }
  193. enum BookbindingType: String, CaseIterable {
  194. case left = "Left" //左
  195. case right = "Right" //右
  196. case leftHigh = "Left(High)" //左高
  197. case rightHigh = "Right(High)" //右高
  198. static func allValues() -> [String] {
  199. var array: [String] = []
  200. for key in BookbindingType.allCases {
  201. array.append(key.rawValue)
  202. }
  203. return array
  204. }
  205. }
  206. }
  207. }
  208. class KMPrintPageModel: NSObject {
  209. var range: KMPrintPageRange = KMPrintPageRange() //页面范围
  210. var contentType: KMPrintContentType = .document //页面内容
  211. var operation: KMPrintPageOperation = KMPrintPageOperation() //页面操作类型
  212. }