KMPDFAnnotationTextWidgetSub.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //
  2. // KMPDFAnnotationTextWidgetSub.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by wanjun on 2024/1/31.
  6. //
  7. import Cocoa
  8. class KMPDFAnnotationTextWidgetSub: CPDFTextWidgetAnnotation {
  9. func transformContext(for page: PDFPage, displayBox box: PDFDisplayBox) {
  10. var transform = NSAffineTransform()
  11. // Identity.
  12. transform = NSAffineTransform()
  13. // Bounds for page.
  14. let boxRect = page.bounds(for: box)
  15. // Handle rotation.
  16. let rotation = page.rotation
  17. switch rotation {
  18. case 90:
  19. transform.rotate(byDegrees: -90)
  20. transform.translateX(by: -boxRect.size.width, yBy: 0.0)
  21. case 180:
  22. transform.rotate(byDegrees: 180)
  23. transform.translateX(by: -boxRect.size.width, yBy: -boxRect.size.height)
  24. case 270:
  25. transform.rotate(byDegrees: 90)
  26. transform.translateX(by: 0.0, yBy: -boxRect.size.height)
  27. default:
  28. break
  29. }
  30. // Origin.
  31. transform.translateX(by: -boxRect.origin.x, yBy: -boxRect.origin.y)
  32. // Concatenate.
  33. transform.concat()
  34. }
  35. func keysForValuesToObserveForUndo() -> Set<String> {
  36. return []
  37. }
  38. }