KMNEditContentPopMode.swift 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // KMNEditContentPopMode.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/12/2.
  6. //
  7. import Cocoa
  8. @objc public enum EditContentPopType: Int, CaseIterable{
  9. case signTextEdit = 0
  10. case signImageEdit
  11. case multpleTextEdit
  12. case multpleImageEdit
  13. case multpleImageAndText
  14. case cropImage
  15. case editNone
  16. }
  17. class KMNEditContentPopMode: NSObject {
  18. private(set) var editArea: CPDFEditArea?
  19. private(set) var editAreas: [CPDFEditArea] = []
  20. private(set) var popType: EditContentPopType = .editNone
  21. init(currentEditAreas: [CPDFEditArea]) {
  22. super.init()
  23. if let firstAnnotation = editAreas.first {
  24. editArea = firstAnnotation
  25. }
  26. editAreas = currentEditAreas
  27. popType = self.contentEditType()
  28. }
  29. private func contentEditType()->EditContentPopType {
  30. let editArea:CPDFEditArea = editAreas.first ?? CPDFEditArea.init()
  31. let editType = contentSingeEditType(editArea: editArea)
  32. if editAreas.count == 0 {
  33. return .editNone
  34. } else if editAreas.count == 1 {
  35. return editType
  36. } else {
  37. var isSampleAnnotation = true
  38. for i in 1 ..< editAreas.count {
  39. let editArea:CPDFEditArea = editAreas[i]
  40. if editType != contentSingeEditType(editArea: editArea) {
  41. isSampleAnnotation = false
  42. break
  43. }
  44. }
  45. if(isSampleAnnotation) {
  46. return editType
  47. } else {
  48. return .multpleImageAndText
  49. }
  50. }
  51. }
  52. private func contentSingeEditType(editArea:CPDFEditArea)->EditContentPopType {
  53. if editArea.isTextArea() {
  54. return .signTextEdit
  55. } else if editArea.isImageArea() {
  56. if let imageEditArea = editArea as? CPDFEditImageArea {
  57. if imageEditArea.isCropMode == true {
  58. return .cropImage
  59. }
  60. }
  61. return .signImageEdit
  62. }
  63. return .editNone
  64. }
  65. }