// // KMNoteReplyHanddler.swift // PDF Reader Pro // // Created by User-Tangchao on 2024/9/19. // import Cocoa // 注释回复处理类 class KMNoteReplyHanddler: NSObject { func markAnnotation(_ anno: CPDFAnnotation?) { guard let state = self.fetchAnnoState(anno) else { anno?.createReplyStateAnnotation(.marked) return } if state == .unMarked { anno?.setAnnotState(.marked) } } func unMarkAnnotation(_ anno: CPDFAnnotation?) { guard let state = self.fetchAnnoState(anno) else { return } if state == .marked { anno?.setAnnotState(.unMarked) } } func fetchAnnoState(_ anno: CPDFAnnotation?) -> CPDFAnnotationState? { guard let replyA = self.fetchMarkAnnotation(anno) else { return nil } return replyA.getAnnotState() } func fetchMarkAnnotation(_ anno: CPDFAnnotation?) -> CPDFAnnotation? { guard let theAnno = anno else { return nil } for replyA in theAnno.replyAnnotations ?? [] { if replyA.replyAnnotationType == .mark { return replyA } } return nil } }