123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- //
- // KMPrintPageModel.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2022/12/21.
- //
- import Cocoa
- struct KMPrintPageRange {
- var type: PageRangeType = .allPage
- var pageString = ""
- var selectPages: [Int] = [] //选中页面
- var reversePrintOrder: Bool = false //逆页面打印
-
- enum PageRangeType: String, CaseIterable {
- case allPage = "All Pages" //全部页面
- case currentPage = "Current Page" //当前页面
- case oddPage = "Odd Pages Only" //奇数页
- case evenPage = "Even Pages Only" //偶数页
- case custom = "e.g. 1,3-5,10" //自定义页面
-
- static func allValues() -> [String] {
- var array: [String] = []
- for key in PageRangeType.allCases {
- array.append(NSLocalizedString(key.rawValue, comment: ""))
- }
- return array
- }
-
- static func typeOfRawValue(_ rawValue: String) -> PageRangeType {
- var type: PageRangeType = .allPage
- switch rawValue {
- case PageRangeType.allPage.rawValue, NSLocalizedString(PageRangeType.allPage.rawValue, comment: ""):
- type = .allPage
- case PageRangeType.currentPage.rawValue, NSLocalizedString(PageRangeType.currentPage.rawValue, comment: ""):
- type = .currentPage
- case PageRangeType.oddPage.rawValue, NSLocalizedString(PageRangeType.oddPage.rawValue, comment: ""):
- type = .oddPage
- case PageRangeType.custom.rawValue, NSLocalizedString(PageRangeType.custom.rawValue, comment: ""):
- type = .custom
- default:
- type = .allPage
- }
- return type
- }
- }
- }
- enum KMPrintContentType: String, CaseIterable {
- case document = "Document" //文档
- case documentAndMarkup = "Document and Markups" //文档和标签
- case documentAndForm = "Comments & Forms:" //文档和表单
- case documentAndStamp = "Document and Stamps" //文档和贴图
-
- static func allValues() -> [String] {
- var array: [String] = []
- for key in KMPrintContentType.allCases {
- array.append(NSLocalizedString(key.rawValue, comment: ""))
- }
- return array
- }
-
- static func typeOfRawValue(_ rawValue: String) -> KMPrintContentType {
- var type: KMPrintContentType = .document
- switch rawValue {
- case KMPrintContentType.document.rawValue, NSLocalizedString(KMPrintContentType.document.rawValue, comment: ""):
- type = .document
- case KMPrintContentType.documentAndMarkup.rawValue, NSLocalizedString(KMPrintContentType.documentAndMarkup.rawValue, comment: ""):
- type = .documentAndMarkup
- case KMPrintContentType.documentAndForm.rawValue, NSLocalizedString(KMPrintContentType.documentAndForm.rawValue, comment: ""):
- type = .documentAndForm
- case KMPrintContentType.documentAndStamp.rawValue, NSLocalizedString(KMPrintContentType.documentAndStamp.rawValue, comment: ""):
- type = .documentAndStamp
- default:
- type = .document
- }
- return type
- }
- }
- //类型
- enum KMPrintModelType {
- case size //大小
- case poster //海报
- case multipage //多页
- case pamphlet //小册子
- }
- struct KMPrintPageOperation {
- var type: KMPrintModelType = .size
- var size: Size = Size()
- var isAutoRotate: Bool = false //自动旋转
-
- var poster: Poster = Poster()
- var multipage: Multipage = Multipage()
- var pamphlet: Pamphlet = Pamphlet()
-
- var pageOfPaper: PageOfPaper = PageOfPaper()
-
- struct PageOfPaper {
- var type: PageType = .page {
- didSet {
- if type != .custom {
- self.point = PageType.pointWithType(type)
- }
- }
- }
- var point: CGPoint = CGPoint(x: 1, y: 1)
-
- enum PageType: String, CaseIterable {
- case page = "1"
- case page2 = "2"
- case page4 = "4"
- case page6 = "6"
- case page9 = "9"
- case page16 = "16"
- case custom = "Custom"
-
- static func allValues() -> [String] {
- var array: [String] = []
- for key in PageType.allCases {
- array.append(key.rawValue)
- }
- return array
- }
-
- static func pointWithType(_ type: PageType) -> CGPoint {
- var point: CGPoint = CGPoint(x: 1, y: 1)
- switch type {
- case .page:
- point = CGPoint(x: 1, y: 1)
- case .page2:
- point = CGPoint(x: 1, y: 2)
- case .page4:
- point = CGPoint(x: 2, y: 2)
- case .page6:
- point = CGPoint(x: 2, y: 3)
- case .page9:
- point = CGPoint(x: 3, y: 3)
- case .page16:
- point = CGPoint(x: 4, y: 4)
- default:
- point = CGPoint(x: 1, y: 1)
- }
- return point
- }
- }
- }
-
- //大小模式参数内容
- struct Size {
- var model: Model = .auto
- var scale: CGFloat = 1.0
- var duplexPrintModel: KMPrintPrinterModel? //双面打印
-
- enum Model: String {
- case auto = "auto"
- case full = "full"
- case custom = "custom"
- }
- }
-
- //海报模式参数内容
- struct Poster {
- var type: PosterType = .tile
- var scale: CGFloat = 1.0
- var tilePoint: CGPoint = CGPoint(x: 1, y: 1)
- var overlap: Float = 0.0
- var isCutMark: Bool = false
- var isTags: Bool = false
- var tags: String = "(column,row)1.pdf 2023-01-09 05:49:54"
-
- enum PosterType {
- case tile //平铺
- case breakUp //拆分
- }
- }
- //多页模式参数内容
- struct Multipage {
- var orderType: Order = .horizontal
- var lineSpacing: CGFloat = 30
- var columnsSpacing: CGFloat = 30
- var isBorder: Bool = false
-
- //排序类型
- enum Order: String, CaseIterable {
- case horizontal = "Horizontal" //横向
- case horizontalReverseSequence = "Horizontal Reversed" //横向倒序
- case vertical = "Vertical" //纵向
- case verticalReverseSequence = "Vertical Reversed" //纵向倒序
-
- static func allValues() -> [String] {
- var array: [String] = []
- for key in Order.allCases {
- array.append(NSLocalizedString(key.rawValue, comment: ""))
- }
- return array
- }
- }
- }
- //小册子模式参数内容
- struct Pamphlet {
- var type: PamphletType = .doubleSided
- var pageIndex: Int = 1
- var toPageIndex: Int = 1
- var bookbindingType: BookbindingType = .leftHigh
- var margin: CGFloat = 0.0
-
- enum PamphletType: String, CaseIterable {
- case doubleSided = "Both sides" //双面
- case onlyPositive = "Front side only" //正面
- case onlyBack = "Back side only" //背面
- // case verticalReverseSequence = "Vertical Reverse Sequence" //纵向倒序
-
- static func allValues() -> [String] {
- var array: [String] = []
- for key in PamphletType.allCases {
- array.append(NSLocalizedString(key.rawValue, comment: ""))
- }
- return array
- }
- }
-
- enum BookbindingType: String, CaseIterable {
- case left = "Left" //左
- case right = "Right" //右
- case leftHigh = "Left (Tall)" //左高
- case rightHigh = "Right (Tall)" //右高
-
- static func allValues() -> [String] {
- var array: [String] = []
- for key in BookbindingType.allCases {
- array.append(NSLocalizedString(key.rawValue, comment: ""))
- }
- return array
- }
- }
-
- }
- }
- class KMPrintPageModel: NSObject {
- var range: KMPrintPageRange = KMPrintPageRange() //页面范围
- var contentType: KMPrintContentType = .document //页面内容
- var operation: KMPrintPageOperation = KMPrintPageOperation() //页面操作类型
- }
|