v0.1: Fixed replies icons
This commit is contained in:
@@ -206,8 +206,8 @@ public enum AnnotationFactory {
|
||||
?? UUID().uuidString
|
||||
_ = annotation.setValue(parentIdentifier, forAnnotationKey: AnnotationKeys.inReplyTo)
|
||||
_ = annotation.setValue("R", forAnnotationKey: AnnotationKeys.replyType)
|
||||
let popup = makePopupIfNeeded(for: annotation, on: page, open: false)
|
||||
return AnnotationInsertion(page: page, annotation: annotation, popup: popup)
|
||||
hideReplyMarker(annotation, on: page)
|
||||
return AnnotationInsertion(page: page, annotation: annotation, popup: nil)
|
||||
}
|
||||
|
||||
public static func updateComment(
|
||||
@@ -241,6 +241,11 @@ public enum AnnotationFactory {
|
||||
return nil
|
||||
}
|
||||
|
||||
if AnnotationKeys.isReply(annotation) {
|
||||
hideReplyMarker(annotation, on: page)
|
||||
return nil
|
||||
}
|
||||
|
||||
if let popup = annotation.popup {
|
||||
popup.contents = text
|
||||
popup.userName = author
|
||||
@@ -309,6 +314,25 @@ public enum AnnotationFactory {
|
||||
return popup
|
||||
}
|
||||
|
||||
public static func hideReplyMarker(_ annotation: PDFAnnotation, on page: PDFPage) {
|
||||
guard AnnotationKeys.isReply(annotation) else { return }
|
||||
|
||||
let pageBounds = page.bounds(for: .cropBox)
|
||||
annotation.bounds = CGRect(
|
||||
x: pageBounds.maxX + 32,
|
||||
y: pageBounds.maxY + 32,
|
||||
width: 1,
|
||||
height: 1
|
||||
)
|
||||
annotation.shouldDisplay = true
|
||||
annotation.shouldPrint = false
|
||||
|
||||
if let popup = annotation.popup {
|
||||
page.removeAnnotation(popup)
|
||||
annotation.popup = nil
|
||||
}
|
||||
}
|
||||
|
||||
public static func parentAnnotation(for annotation: PDFAnnotation) -> PDFAnnotation {
|
||||
if AnnotationKeys.annotation(annotation, hasSubtype: .popup),
|
||||
let parent = annotation.value(forAnnotationKey: .parent) as? PDFAnnotation {
|
||||
|
||||
@@ -180,7 +180,7 @@ public enum AnnotationKeys {
|
||||
) -> String? {
|
||||
if let parentID = annotation.value(forAnnotationKey: inReplyTo) as? String,
|
||||
!parentID.isEmpty {
|
||||
return parentID
|
||||
return stableIDForAnnotation(named: parentID, in: document) ?? parentID
|
||||
}
|
||||
|
||||
guard let parent = annotation.value(forAnnotationKey: inReplyTo) as? PDFAnnotation else {
|
||||
@@ -199,6 +199,20 @@ public enum AnnotationKeys {
|
||||
return stableID(for: parent, pageIndex: pageIndex, annotationIndex: annotationIndex)
|
||||
}
|
||||
|
||||
private static func stableIDForAnnotation(named name: String, in document: PDFDocument?) -> String? {
|
||||
guard let document else { return nil }
|
||||
|
||||
for pageIndex in 0..<document.pageCount {
|
||||
guard let page = document.page(at: pageIndex) else { continue }
|
||||
for (annotationIndex, candidate) in page.annotations.enumerated() {
|
||||
guard candidate.value(forAnnotationKey: .name) as? String == name else { continue }
|
||||
return stableID(for: candidate, pageIndex: pageIndex, annotationIndex: annotationIndex)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
public static func isReply(_ annotation: PDFAnnotation) -> Bool {
|
||||
annotation.value(forAnnotationKey: inReplyTo) is PDFAnnotation
|
||||
|| annotation.value(forAnnotationKey: inReplyTo) is String
|
||||
|
||||
Reference in New Issue
Block a user