KMPrintPageModel.swift 8.1 KB

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