KMPrintPageModel.swift 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. //
  2. // KMPrintPageModel.swift
  3. // PDF Reader Pro
  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 Pages Only" //奇数页
  17. case evenPage = "Even Pages Only" //偶数页
  18. case custom = "e.g. 1,3-5,10" //自定义页面
  19. static func allValues() -> [String] {
  20. var array: [String] = []
  21. for key in PageRangeType.allCases {
  22. array.append(NSLocalizedString(key.rawValue, comment: ""))
  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 = "Document and Markups" //文档和标签
  47. case documentAndForm = "Comments & Forms:" //文档和表单
  48. case documentAndStamp = "Document and Stamps" //文档和贴图
  49. static func allValues() -> [String] {
  50. var array: [String] = []
  51. for key in KMPrintContentType.allCases {
  52. array.append(NSLocalizedString(key.rawValue, comment: ""))
  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 KMPrintModelType {
  75. case size //大小
  76. case poster //海报
  77. case multipage //多页
  78. case pamphlet //小册子
  79. }
  80. struct KMPrintPageOperation {
  81. var type: KMPrintModelType = .size
  82. var size: Size = Size()
  83. var isAutoRotate: Bool = false //自动旋转
  84. var poster: Poster = Poster()
  85. var multipage: Multipage = Multipage()
  86. var pamphlet: Pamphlet = Pamphlet()
  87. var pageOfPaper: PageOfPaper = PageOfPaper()
  88. struct PageOfPaper {
  89. var type: PageType = .page {
  90. didSet {
  91. if type != .custom {
  92. self.point = PageType.pointWithType(type)
  93. }
  94. }
  95. }
  96. var point: CGPoint = CGPoint(x: 1, y: 1)
  97. enum PageType: String, CaseIterable {
  98. case page = "1"
  99. case page2 = "2"
  100. case page4 = "4"
  101. case page6 = "6"
  102. case page9 = "9"
  103. case page16 = "16"
  104. case custom = "Custom"
  105. static func allValues() -> [String] {
  106. var array: [String] = []
  107. for key in PageType.allCases {
  108. array.append(key.rawValue)
  109. }
  110. return array
  111. }
  112. static func pointWithType(_ type: PageType) -> CGPoint {
  113. var point: CGPoint = CGPoint(x: 1, y: 1)
  114. switch type {
  115. case .page:
  116. point = CGPoint(x: 1, y: 1)
  117. case .page2:
  118. point = CGPoint(x: 1, y: 2)
  119. case .page4:
  120. point = CGPoint(x: 2, y: 2)
  121. case .page6:
  122. point = CGPoint(x: 2, y: 3)
  123. case .page9:
  124. point = CGPoint(x: 3, y: 3)
  125. case .page16:
  126. point = CGPoint(x: 4, y: 4)
  127. default:
  128. point = CGPoint(x: 1, y: 1)
  129. }
  130. return point
  131. }
  132. }
  133. }
  134. //大小模式参数内容
  135. struct Size {
  136. var model: Model = .auto
  137. var scale: CGFloat = 1.0
  138. var duplexPrintModel: KMPrintPrinterModel? //双面打印
  139. enum Model: String {
  140. case auto = "auto"
  141. case full = "full"
  142. case custom = "custom"
  143. }
  144. }
  145. //海报模式参数内容
  146. struct Poster {
  147. var type: PosterType = .tile
  148. var scale: CGFloat = 1.0
  149. var tilePoint: CGPoint = CGPoint(x: 1, y: 1)
  150. var overlap: Float = 0.0
  151. var isCutMark: Bool = false
  152. var isTags: Bool = false
  153. var tags: String = "(column,row)1.pdf 2023-01-09 05:49:54"
  154. enum PosterType {
  155. case tile //平铺
  156. case breakUp //拆分
  157. }
  158. }
  159. //多页模式参数内容
  160. struct Multipage {
  161. var orderType: Order = .horizontal
  162. var lineSpacing: CGFloat = 30
  163. var columnsSpacing: CGFloat = 30
  164. var isBorder: Bool = false
  165. //排序类型
  166. enum Order: String, CaseIterable {
  167. case horizontal = "Horizontal" //横向
  168. case horizontalReverseSequence = "Horizontal Reversed" //横向倒序
  169. case vertical = "Vertical" //纵向
  170. case verticalReverseSequence = "Vertical Reversed" //纵向倒序
  171. static func allValues() -> [String] {
  172. var array: [String] = []
  173. for key in Order.allCases {
  174. array.append(NSLocalizedString(key.rawValue, comment: ""))
  175. }
  176. return array
  177. }
  178. }
  179. }
  180. //小册子模式参数内容
  181. struct Pamphlet {
  182. var type: PamphletType = .doubleSided
  183. var pageIndex: Int = 1
  184. var toPageIndex: Int = 1
  185. var bookbindingType: BookbindingType = .leftHigh
  186. var margin: CGFloat = 0.0
  187. enum PamphletType: String, CaseIterable {
  188. case doubleSided = "Both sides" //双面
  189. case onlyPositive = "Front side only" //正面
  190. case onlyBack = "Back side only" //背面
  191. // case verticalReverseSequence = "Vertical Reverse Sequence" //纵向倒序
  192. static func allValues() -> [String] {
  193. var array: [String] = []
  194. for key in PamphletType.allCases {
  195. array.append(NSLocalizedString(key.rawValue, comment: ""))
  196. }
  197. return array
  198. }
  199. }
  200. enum BookbindingType: String, CaseIterable {
  201. case left = "Left" //左
  202. case right = "Right" //右
  203. case leftHigh = "Left (Tall)" //左高
  204. case rightHigh = "Right (Tall)" //右高
  205. static func allValues() -> [String] {
  206. var array: [String] = []
  207. for key in BookbindingType.allCases {
  208. array.append(NSLocalizedString(key.rawValue, comment: ""))
  209. }
  210. return array
  211. }
  212. }
  213. }
  214. }
  215. class KMPrintPageModel: NSObject {
  216. var range: KMPrintPageRange = KMPrintPageRange() //页面范围
  217. var contentType: KMPrintContentType = .document //页面内容
  218. var operation: KMPrintPageOperation = KMPrintPageOperation() //页面操作类型
  219. }