Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalrentka committed Mar 5, 2024
1 parent f4e91d2 commit 7e7a918
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 15 deletions.
12 changes: 10 additions & 2 deletions Zotero/Controllers/AnnotationConverter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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
}
Expand Down
10 changes: 4 additions & 6 deletions Zotero/Scenes/Detail/PDF/Models/UnderlineAnnotation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -929,6 +929,12 @@ extension PSPDFKit.Annotation.Tool {
case .note:
return .note

case .freeText:
return .freeText

case .underline:
return .underline

default:
return nil
}
Expand Down

0 comments on commit 7e7a918

Please sign in to comment.