123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- //
- // KMEditPDFModel.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2024/6/25.
- //
- import Cocoa
- class KMEditPDFModel: NSObject {
- //
- // var cFont: CPDFFont?
- var editingAreas: [CPDFEditArea]?
-
- var textAreas: [CPDFEditTextArea]? {
- get {
- guard let areas = self.editingAreas else {
- return nil
- }
- var datas: [CPDFEditTextArea] = []
- for area in areas {
- if let data = area as? CPDFEditTextArea {
- datas.append(data)
- continue
- }
- }
- return datas
- }
- }
-
- var imageAreas: [CPDFEditImageArea]? {
- get {
- guard let areas = self.editingAreas else {
- return nil
- }
- var datas: [CPDFEditImageArea] = []
- for area in areas {
- if let data = area as? CPDFEditImageArea {
- datas.append(data)
- continue
- }
- }
- return datas
- }
- }
-
- var fontColors: [NSColor] = []
- var fontNames: [String] = []
- var fontSizes: [CGFloat] = []
- var fontBolds: [Bool] = []
- var fontItalics: [Bool] = []
- var textAlignments: [NSTextAlignment] = []
- var boundsArray: [NSRect] = []
- var rotates: [CGFloat] = []
- var opacitys: [CGFloat] = []
-
- func editAreasFontColorIsEqual() -> Bool {
- let datas = self.fontColors
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let color = datas.first
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if d != color {
- return false
- }
- }
- return true
- }
-
- func editAreasFontNameIsEqual() -> Bool {
- let datas = self.fontNames
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let data = datas.first
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if d != data {
- return false
- }
- }
- return true
- }
-
- func editAreasFontSizeIsEqual() -> Bool {
- let datas = self.fontSizes
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let data = datas.first
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if d != data {
- return false
- }
- }
- return true
- }
-
- func editAreasFontBoldIsEqual() -> Bool {
- let datas = self.fontBolds
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let data = datas.first
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if d != data {
- return false
- }
- }
- return true
- }
-
- func editAreasFontItalicIsEqual() -> Bool {
- let datas = self.fontItalics
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let data = datas.first
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if d != data {
- return false
- }
- }
- return true
- }
-
- func editAreasTextAlignmentIsEqual() -> Bool {
- let datas = self.textAlignments
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let data = datas.first?.rawValue ?? 0
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if d.rawValue != data {
- return false
- }
- }
- return true
- }
-
- func editAreasBoundsIsEqualForWidth() -> Bool {
- let datas = self.boundsArray
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let width = datas.first?.width ?? 0
- for (i, rect) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if width != rect.size.width {
- return false
- }
- }
- return true
- }
-
- func editAreasBoundsIsEqualForHeight() -> Bool {
- let datas = self.boundsArray
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let height = datas.first?.height ?? 0
- for (i, rect) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if height != rect.size.height {
- return false
- }
- }
- return true
- }
-
- func editAreasRotateIsEqual() -> Bool {
- let datas = self.rotates
- if datas.isEmpty {
- return false
- }
- // if self.editAreasHavTextArea() {
- // return false
- // }
- // let datas = self._editAreasRotates()
- if datas.count == 1 {
- return true
- }
- let data = datas.first ?? 0
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if data != d {
- return false
- }
- }
- return true
- }
-
- func editAreasOpacityIsEqual() -> Bool {
- let datas = self.opacitys
- if datas.isEmpty {
- return false
- }
- if datas.count == 1 {
- return true
- }
- let data = datas.first ?? 0
- for (i, d) in datas.enumerated() {
- if i == 0 {
- continue
- }
- if data != d {
- return false
- }
- }
- return true
- }
- }
|