Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add free text annotation font size update when resizing #998

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Zotero/Scenes/Detail/PDF/ViewModels/PDFReaderActionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1685,21 +1685,25 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi
let request = EditItemFieldsDbRequest(key: key, libraryId: viewModel.state.library.identifier, fieldValues: values, dateParser: dateParser)
requests.append(request)
}
} else if hasChanges([.boundingBox, .rects]), let rects = AnnotationConverter.rects(from: annotation) {
requests.append(EditAnnotationRectsDbRequest(key: key, libraryId: viewModel.state.library.identifier, rects: rects, boundingBoxConverter: boundingBoxConverter))
} else if hasChanges([.boundingBox]), let rects = AnnotationConverter.rects(from: annotation) {
} else if let textAnnotation = annotation as? PSPDFKit.FreeTextAnnotation {
var editFontSize = hasChanges([.fontSize])
// FreeTextAnnotation has only `boundingBox` change, not paired with paths or rects.
requests.append(EditAnnotationRectsDbRequest(key: key, libraryId: viewModel.state.library.identifier, rects: rects, boundingBoxConverter: boundingBoxConverter))
}
if hasChanges([.boundingBox]), let rects = AnnotationConverter.rects(from: annotation) {
requests.append(EditAnnotationRectsDbRequest(key: key, libraryId: viewModel.state.library.identifier, rects: rects, boundingBoxConverter: boundingBoxConverter))
// Font size may change due to the user resizing the bounding box, but it is not communicated properly in the PSPDFKit notification.
// Therefore, we always edit font size in this case, even if it didn't change.
editFontSize = true
}

if let textAnnotation = annotation as? PSPDFKit.FreeTextAnnotation {
if hasChanges([.rotation]) {
requests.append(EditAnnotationRotationDbRequest(key: key, libraryId: viewModel.state.library.identifier, rotation: textAnnotation.rotation))
}

if hasChanges([.fontSize]) {
if editFontSize {
requests.append(EditAnnotationFontSizeDbRequest(key: key, libraryId: viewModel.state.library.identifier, size: UInt(textAnnotation.fontSize)))
}
} else if hasChanges([.boundingBox, .rects]), let rects = AnnotationConverter.rects(from: annotation) {
requests.append(EditAnnotationRectsDbRequest(key: key, libraryId: viewModel.state.library.identifier, rects: rects, boundingBoxConverter: boundingBoxConverter))
}

if hasChanges(.color) {
Expand Down