// // KMNEditContentPopMode.swift // PDF Reader Pro // // Created by 丁林圭 on 2024/12/2. // import Cocoa @objc public enum EditContentPopType: Int, CaseIterable{ case signTextEdit = 0 case signImageEdit case multpleTextEdit case multpleImageEdit case multpleImageAndText case cropImage case editNone } class KMNEditContentPopMode: NSObject { private(set) var editArea: CPDFEditArea? private(set) var editAreas: [CPDFEditArea] = [] private(set) var popType: EditContentPopType = .editNone init(currentEditAreas: [CPDFEditArea]) { super.init() if let firstAnnotation = editAreas.first { editArea = firstAnnotation } editAreas = currentEditAreas popType = self.contentEditType() } private func contentEditType()->EditContentPopType { let editArea:CPDFEditArea = editAreas.first ?? CPDFEditArea.init() let editType = contentSingeEditType(editArea: editArea) if editAreas.count == 0 { return .editNone } else if editAreas.count == 1 { return editType } else { var isSampleAnnotation = true for i in 1 ..< editAreas.count { let editArea:CPDFEditArea = editAreas[i] if editType != contentSingeEditType(editArea: editArea) { isSampleAnnotation = false break } } if(isSampleAnnotation) { return editType } else { return .multpleImageAndText } } } private func contentSingeEditType(editArea:CPDFEditArea)->EditContentPopType { if editArea.isTextArea() { return .signTextEdit } else if editArea.isImageArea() { if let imageEditArea = editArea as? CPDFEditImageArea { if imageEditArea.isCropMode == true { return .cropImage } } return .signImageEdit } return .editNone } }