Skip to content

Commit

Permalink
Enabled text, underline annotations, fixed content editing for underl…
Browse files Browse the repository at this point in the history
…ine annotation
  • Loading branch information
michalrentka committed Aug 9, 2024
1 parent db9774d commit 3a4ec90
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 32 deletions.
18 changes: 9 additions & 9 deletions Zotero.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@
B39649182869B0D0000BCB6C /* ISBNParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = B39649172869B0D0000BCB6C /* ISBNParser.swift */; };
B3972689247D403200A8B469 /* UrlDetector.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3972688247D403200A8B469 /* UrlDetector.swift */; };
B3981427257A5A16002C755C /* AnnotationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3981426257A5A16002C755C /* AnnotationView.swift */; };
B398142E257A649D002C755C /* HighlightEditCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398142C257A649D002C755C /* HighlightEditCell.swift */; };
B398143F257A8EB2002C755C /* HighlightEditCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B398143E257A8EB2002C755C /* HighlightEditCell.xib */; };
B398142E257A649D002C755C /* TextContentEditCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398142C257A649D002C755C /* TextContentEditCell.swift */; };
B398143F257A8EB2002C755C /* TextContentEditCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B398143E257A8EB2002C755C /* TextContentEditCell.xib */; };
B3981B76258399AA00F8D15A /* NoteAnnotation.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3981B75258399AA00F8D15A /* NoteAnnotation.swift */; };
B398A915270C6A4300968EE8 /* WebDavController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398A914270C6A4300968EE8 /* WebDavController.swift */; };
B398A917270C6A5B00968EE8 /* WebDavSessionStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = B398A916270C6A5B00968EE8 /* WebDavSessionStorage.swift */; };
Expand Down Expand Up @@ -1853,8 +1853,8 @@
B39649172869B0D0000BCB6C /* ISBNParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ISBNParser.swift; sourceTree = "<group>"; };
B3972688247D403200A8B469 /* UrlDetector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UrlDetector.swift; sourceTree = "<group>"; };
B3981426257A5A16002C755C /* AnnotationView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnnotationView.swift; sourceTree = "<group>"; };
B398142C257A649D002C755C /* HighlightEditCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HighlightEditCell.swift; sourceTree = "<group>"; };
B398143E257A8EB2002C755C /* HighlightEditCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = HighlightEditCell.xib; sourceTree = "<group>"; };
B398142C257A649D002C755C /* TextContentEditCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextContentEditCell.swift; sourceTree = "<group>"; };
B398143E257A8EB2002C755C /* TextContentEditCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TextContentEditCell.xib; sourceTree = "<group>"; };
B3981B75258399AA00F8D15A /* NoteAnnotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NoteAnnotation.swift; sourceTree = "<group>"; };
B398A914270C6A4300968EE8 /* WebDavController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WebDavController.swift; sourceTree = "<group>"; };
B398A916270C6A5B00968EE8 /* WebDavSessionStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebDavSessionStorage.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3078,18 +3078,18 @@
B32CDD3C2AEA9BB100EF5054 /* AnnotationPopoverViewController.xib */,
B34C40FD25711C990057D5F5 /* ColorPickerCell.swift */,
B3764D9C2574F2DE0024274F /* ColorPickerCircleView.swift */,
61FA14CF2B08E24A00E7D423 /* ColorPickerStackView.swift */,
B36FD9B22A7929C8002D77E8 /* FontSizeCell.swift */,
B36FD9B02A7924CB002D77E8 /* FontSizePickerViewController.swift */,
B398D6BF2A77F9C60049A296 /* FontSizeView.swift */,
B398142C257A649D002C755C /* HighlightEditCell.swift */,
B398143E257A8EB2002C755C /* HighlightEditCell.xib */,
B34A4B7126E65FC200B3E993 /* LineWidthCell.swift */,
B34A4B6F26E63C9900B3E993 /* LineWidthView.swift */,
B34DF1BB2576956F0019CCD1 /* SwitchCell.swift */,
B34DF1BC2576956F0019CCD1 /* SwitchCell.xib */,
B398142C257A649D002C755C /* TextContentEditCell.swift */,
B398143E257A8EB2002C755C /* TextContentEditCell.xib */,
B34DF1B325768BB70019CCD1 /* TextFieldCell.swift */,
B34DF1B425768BB70019CCD1 /* TextFieldCell.xib */,
61FA14CF2B08E24A00E7D423 /* ColorPickerStackView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -4419,7 +4419,7 @@
buildActionMask = 2147483647;
files = (
B3593F33241A61C700760E20 /* ItemDetailNoteContentView.xib in Resources */,
B398143F257A8EB2002C755C /* HighlightEditCell.xib in Resources */,
B398143F257A8EB2002C755C /* TextContentEditCell.xib in Resources */,
618D83E72BAAC88C00E7966B /* PrivacyInfo.xcprivacy in Resources */,
B32A273D254841B80081E061 /* CreatorEditViewController.xib in Resources */,
B3830CE9255451DC00910FE0 /* TagPickerViewController.xib in Resources */,
Expand Down Expand Up @@ -5316,7 +5316,7 @@
B3F3D62C255EBE3500F310C2 /* AnnotationViewHeader.swift in Sources */,
B3E8FE34271429C300F51458 /* ExportLocalePickerView.swift in Sources */,
B39D42D929C0B82F0035CDA9 /* TagFilterCell.swift in Sources */,
B398142E257A649D002C755C /* HighlightEditCell.swift in Sources */,
B398142E257A649D002C755C /* TextContentEditCell.swift in Sources */,
B32F0BDA298BFCEE00C04557 /* LogsViewController.swift in Sources */,
B3BC1F60254322D200BA3388 /* ItemDetailAbstractEditCell.swift in Sources */,
B3422F44289A9F2400C53DD2 /* ItemDetailAttachmentContentView.swift in Sources */,
Expand Down
3 changes: 1 addition & 2 deletions Zotero/Models/AnnotationsConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ struct AnnotationsConfig {
// Size of note annotation in PDF document.
static let noteAnnotationSize: CGSize = CGSize(width: 22, height: 22)
static let positionSizeLimit = 65000
// TODO: Enable when text/underline annotations are fully available
static let supported: PSPDFKit.Annotation.Kind = [.note, .highlight, .square, .ink]//, .underline, .freeText]
static let supported: PSPDFKit.Annotation.Kind = [.note, .highlight, .square, .ink, .underline, .freeText]

static func colors(for type: AnnotationType) -> [String] {
switch type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ typealias AnnotationEditDeleteAction = () -> Void

final class AnnotationEditViewController: UIViewController {
private enum Section {
case properties, pageLabel, actions, highlight, fontSize
case properties, pageLabel, actions, textContent, fontSize

func cellId(index: Int) -> String {
switch self {
case .properties: return index == 0 ? "ColorPickerCell" : "LineWidthCell"
case .actions: return "ActionCell"
case .pageLabel: return "PageLabelCell"
case .highlight: return "HighlightCell"
case .textContent: return "TextContentCell"
case .fontSize: return "FontSizeCell"
}
}
Expand All @@ -48,8 +48,8 @@ final class AnnotationEditViewController: UIViewController {
if includeFontPicker {
sections.insert(.fontSize, at: 0)
}
if viewModel.state.type == .highlight {
sections.insert(.highlight, at: 0)
if viewModel.state.type == .highlight || viewModel.state.type == .underline {
sections.insert(.textContent, at: 0)
}
}

Expand Down Expand Up @@ -90,7 +90,7 @@ final class AnnotationEditViewController: UIViewController {

private func update(to state: AnnotationEditState) {
if state.changes.contains(.color) {
self.reload(sections: [.properties, .highlight])
self.reload(sections: [.properties, .textContent])
}
if state.changes.contains(.pageLabel) {
self.reload(sections: [.pageLabel])
Expand All @@ -112,7 +112,7 @@ final class AnnotationEditViewController: UIViewController {
private func scrollToHighlightCursor() {
let indexPath = IndexPath(row: 0, section: 0)

guard let cell = self.tableView.cellForRow(at: indexPath) as? HighlightEditCell, let cellCaretRect = cell.caretRect else { return }
guard let cell = self.tableView.cellForRow(at: indexPath) as? TextContentEditCell, let cellCaretRect = cell.caretRect else { return }

let rowRect = self.tableView.rectForRow(at: indexPath)
let caretRect = CGRect(x: (rowRect.minX + cellCaretRect.minX), y: (rowRect.minY + cellCaretRect.minY) + 10, width: cellCaretRect.width, height: cellCaretRect.height)
Expand All @@ -123,10 +123,10 @@ final class AnnotationEditViewController: UIViewController {
}

private func updatePreferredContentSize() {
let sectionCount = self.sections.count - (self.sections.contains(.highlight) ? 1 : 0)
let sectionCount = self.sections.count - (self.sections.contains(.textContent) ? 1 : 0)
var height: CGFloat = (CGFloat(sectionCount) * 80) + 36 // 80 for 36 spacer and 44 cell height

if self.viewModel.state.type == .highlight {
if sections.contains(.textContent) {
let width = AnnotationPopoverLayout.width - ((AnnotationPopoverLayout.annotationLayout.horizontalInset * 2) +
AnnotationPopoverLayout.annotationLayout.highlightContentLeadingOffset +
AnnotationPopoverLayout.annotationLayout.highlightLineWidth)
Expand Down Expand Up @@ -188,7 +188,7 @@ final class AnnotationEditViewController: UIViewController {
self.tableView.dataSource = self
self.tableView.register(ColorPickerCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 0))
self.tableView.register(LineWidthCell.self, forCellReuseIdentifier: Section.properties.cellId(index: 1))
self.tableView.register(UINib(nibName: "HighlightEditCell", bundle: nil), forCellReuseIdentifier: Section.highlight.cellId(index: 0))
self.tableView.register(UINib(nibName: "TextContentEditCell", bundle: nil), forCellReuseIdentifier: Section.textContent.cellId(index: 0))
self.tableView.register(FontSizeCell.self, forCellReuseIdentifier: Section.fontSize.cellId(index: 0))
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: Section.actions.cellId(index: 0))
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: Section.pageLabel.cellId(index: 0))
Expand Down Expand Up @@ -225,8 +225,8 @@ extension AnnotationEditViewController: UITableViewDataSource {
cell.valueObservable.subscribe(onNext: { value in self.viewModel.process(action: .setLineWidth(CGFloat(value))) }).disposed(by: cell.disposeBag)
}

case .highlight:
if let cell = cell as? HighlightEditCell {
case .textContent:
if let cell = cell as? TextContentEditCell {
cell.setup(with: self.viewModel.state.highlightText, color: self.viewModel.state.color)
cell.textObservable
.subscribe(onNext: { [weak self] text, needsHeightReload in
Expand Down Expand Up @@ -270,7 +270,7 @@ extension AnnotationEditViewController: UITableViewDelegate {
tableView.deselectRow(at: indexPath, animated: true)

switch self.sections[indexPath.section] {
case .properties, .highlight: break
case .properties, .textContent: break

case .actions:
self.deleteAction()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// HighlightEditCell.swift
// TextContentEditCell.swift
// Zotero
//
// Created by Michal Rentka on 04.12.2020.
Expand All @@ -10,7 +10,7 @@ import UIKit

import RxSwift

final class HighlightEditCell: UITableViewCell {
final class TextContentEditCell: UITableViewCell {
@IBOutlet private weak var lineView: UIView!
@IBOutlet private weak var textView: UITextView!

Expand Down Expand Up @@ -49,7 +49,7 @@ final class HighlightEditCell: UITableViewCell {
}
}

extension HighlightEditCell: UITextViewDelegate {
extension TextContentEditCell: UITextViewDelegate {
func textViewDidChange(_ textView: UITextView) {
let height = textView.contentSize.height
textView.sizeToFit()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="23077.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="23068.1"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="221" id="KGk-i7-Jjw" customClass="HighlightEditCell" customModule="Zotero" customModuleProvider="target">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="221" id="KGk-i7-Jjw" customClass="TextContentEditCell" customModule="Zotero" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="221"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
Expand Down Expand Up @@ -53,7 +53,7 @@
</objects>
<resources>
<systemColor name="labelColor">
<color red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
3 changes: 1 addition & 2 deletions Zotero/Scenes/Detail/PDF/Views/PDFReaderViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ class PDFReaderViewController: UIViewController {
separator.translatesAutoresizingMaskIntoConstraints = false
separator.backgroundColor = Asset.Colors.annotationSidebarBorderColor.color

// TODO: Add .underline and .freeText tools when those annotations are fully available
let annotationToolbar = AnnotationToolbarViewController(tools: [.highlight, .note, .image, .ink, .eraser], undoRedoEnabled: true, size: navigationBarHeight)
let annotationToolbar = AnnotationToolbarViewController(tools: [.highlight, .underline, .note, .freeText, .image, .ink, .eraser], undoRedoEnabled: true, size: navigationBarHeight)
annotationToolbar.delegate = self

add(controller: documentController)
Expand Down

0 comments on commit 3a4ec90

Please sign in to comment.