diff --git a/Zotero/Controllers/AnnotationConverter.swift b/Zotero/Controllers/AnnotationConverter.swift index dcccf279b..de069709a 100644 --- a/Zotero/Controllers/AnnotationConverter.swift +++ b/Zotero/Controllers/AnnotationConverter.swift @@ -255,7 +255,7 @@ struct AnnotationConverter { annotation = self.inkAnnotation(from: zoteroAnnotation, type: type, color: color, boundingBoxConverter: boundingBoxConverter) case .underline: - annotation = self.underlineAnnotation(from: zoteroAnnotation, type: type, boundingBoxConverter: boundingBoxConverter) + annotation = self.underlineAnnotation(from: zoteroAnnotation, type: type, color: color, alpha: alpha, boundingBoxConverter: boundingBoxConverter) case .freeText: annotation = self.freeTextAnnotation(from: zoteroAnnotation, color: color, boundingBoxConverter: boundingBoxConverter) @@ -360,7 +360,13 @@ struct AnnotationConverter { return ink } - private static func underlineAnnotation(from annotation: PDFAnnotation, type: Kind, boundingBoxConverter: AnnotationBoundingBoxConverter) -> PSPDFKit.UnderlineAnnotation { + private static func underlineAnnotation( + from annotation: PDFAnnotation, + type: Kind, + color: UIColor, + alpha: CGFloat, + boundingBoxConverter: AnnotationBoundingBoxConverter + ) -> PSPDFKit.UnderlineAnnotation { let underline: PSPDFKit.UnderlineAnnotation switch type { case .export: @@ -372,6 +378,8 @@ struct AnnotationConverter { underline.boundingBox = annotation.boundingBox(boundingBoxConverter: boundingBoxConverter).rounded(to: 3) underline.rects = annotation.rects(boundingBoxConverter: boundingBoxConverter).map({ $0.rounded(to: 3) }) + underline.color = color + underline.alpha = alpha return underline } diff --git a/Zotero/Scenes/Detail/PDF/Models/UnderlineAnnotation.swift b/Zotero/Scenes/Detail/PDF/Models/UnderlineAnnotation.swift index 2f09212a2..6e3faee12 100644 --- a/Zotero/Scenes/Detail/PDF/Models/UnderlineAnnotation.swift +++ b/Zotero/Scenes/Detail/PDF/Models/UnderlineAnnotation.swift @@ -18,17 +18,15 @@ final class UnderlineAnnotation: PSPDFKit.UnderlineAnnotation { override func lockAndRender(in context: CGContext, options: RenderOptions?) { super.lockAndRender(in: context, options: options) - guard let comment = self.contents, !comment.isEmpty else { return } - - CommentIconDrawingController.draw(context: context, boundingBox: (self.rects?.first ?? self.boundingBox), color: (self.color ?? .black)) + guard let comment = contents, !comment.isEmpty, !flags.contains(.hidden) else { return } + CommentIconDrawingController.drawAnnotationComment(context: context, boundingBox: (rects?.first ?? boundingBox), color: (color ?? .black)) } override func draw(context: CGContext, options: RenderOptions?) { super.draw(context: context, options: options) - guard let comment = self.contents, !comment.isEmpty else { return } - - CommentIconDrawingController.draw(context: context, boundingBox: (self.rects?.first ?? self.boundingBox), color: (self.color ?? .black)) + guard let comment = contents, !comment.isEmpty, !flags.contains(.hidden) else { return } + CommentIconDrawingController.drawAnnotationComment(context: context, boundingBox: (rects?.first ?? boundingBox), color: (color ?? .black)) } override class var supportsSecureCoding: Bool { diff --git a/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift b/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift index bf9ac0b88..3af2dab5a 100644 --- a/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/AnnotationToolbarViewController.swift @@ -381,11 +381,16 @@ class AnnotationToolbarViewController: UIViewController { private func createHiddenToolsMenu() -> UIMenu { let children = self.toolButtons.filter({ $0.isHidden }).map({ tool in let isActive = self.delegate?.activeAnnotationTool == tool.type - return UIAction(title: tool.title, image: tool.image.withRenderingMode(.alwaysTemplate), discoverabilityTitle: tool.accessibilityLabel, state: (isActive ? .on : .off), - handler: { [weak self] _ in - guard let self = self else { return } - self.delegate?.toggle(tool: tool.type, options: self.currentAnnotationOptions) - }) + return UIAction( + title: tool.title, + image: tool.image.withRenderingMode(.alwaysTemplate), + discoverabilityTitle: tool.accessibilityLabel, + state: (isActive ? .on : .off), + handler: { [weak self] _ in + guard let self else { return } + delegate?.toggle(tool: tool.type, options: currentAnnotationOptions) + } + ) }) return UIMenu(children: children) } @@ -424,7 +429,10 @@ class AnnotationToolbarViewController: UIViewController { let recognizer = UITapGestureRecognizer() recognizer.delegate = self - recognizer.rx.event.subscribe(with: self, onNext: { `self`, _ in self.delegate?.toggle(tool: tool.type, options: self.currentAnnotationOptions) }).disposed(by: self.disposeBag) + recognizer.rx.event.subscribe(onNext: { [weak self] _ in + guard let self else { return } + delegate?.toggle(tool: tool.type, options: currentAnnotationOptions) + }).disposed(by: disposeBag) button.addGestureRecognizer(recognizer) return button diff --git a/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift b/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift index efa1bbdf6..889b8b240 100644 --- a/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift +++ b/Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift @@ -220,7 +220,7 @@ class PDFReaderViewController: UIViewController { separator.translatesAutoresizingMaskIntoConstraints = false separator.backgroundColor = Asset.Colors.annotationSidebarBorderColor.color - let annotationToolbar = AnnotationToolbarViewController(tools: [.highlight, .note, .image, .ink, .eraser], undoRedoEnabled: true, size: navigationBarHeight) + let annotationToolbar = AnnotationToolbarViewController(tools: [.highlight, .note, .image, .ink, .underline, .freeText, .eraser], undoRedoEnabled: true, size: navigationBarHeight) annotationToolbar.delegate = self add(controller: documentController) @@ -929,6 +929,12 @@ extension PSPDFKit.Annotation.Tool { case .note: return .note + case .freeText: + return .freeText + + case .underline: + return .underline + default: return nil }