Skip to content

Commit

Permalink
Add free text annotation font size update when resizing (#998)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Aug 21, 2024
1 parent c55e6de commit bee68f0
Showing 1 changed file with 11 additions and 7 deletions.
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

0 comments on commit bee68f0

Please sign in to comment.