CPDFHighlightViewController.swift 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //
  2. // CPDFHighlightViewController.swift
  3. // ComPDFKit_Tools
  4. //
  5. // Copyright © 2014-2024 PDF Technologies, Inc. All Rights Reserved.
  6. //
  7. // THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
  8. // AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
  9. // UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
  10. // This notice may not be removed from this file.
  11. //
  12. import UIKit
  13. @objc protocol CPDFHighlightViewControllerDelegate: AnyObject {
  14. @objc optional func highlightViewController(_ highlightViewController: CPDFHighlightViewController, annotStyle: CAnnotStyle)
  15. }
  16. class CPDFHighlightViewController: CPDFAnnotationBaseViewController {
  17. weak var delegate: CPDFHighlightViewControllerDelegate?
  18. // MARK: - ViewController Methods
  19. override func viewDidLoad() {
  20. super.viewDidLoad()
  21. }
  22. override func commomInitTitle() {
  23. titleLabel?.text = NSLocalizedString("Highlight", comment: "")
  24. sampleView?.selecIndex = .highlight
  25. colorView?.selectedColor = annotStyle?.color
  26. }
  27. // MARK: - CPDFColorSelectViewDelegate
  28. override func selectColorView(_ select: CPDFColorSelectView, color: UIColor) {
  29. sampleView?.color = color
  30. annotStyle?.setColor(color)
  31. if annotStyle != nil {
  32. delegate?.highlightViewController?(self, annotStyle: annotStyle!)
  33. }
  34. sampleView?.setNeedsDisplay()
  35. }
  36. // MARK: - CPDFColorPickerViewDelegate
  37. override func pickerView(_ colorPickerView: CPDFColorPickerView, color: UIColor) {
  38. sampleView?.color = color
  39. annotStyle?.setColor(color)
  40. delegate?.highlightViewController?(self, annotStyle: annotStyle!)
  41. var red: CGFloat = 0
  42. var green: CGFloat = 0
  43. var blue: CGFloat = 0
  44. var alpha: CGFloat = 0
  45. color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
  46. self.opacitySliderView?.opacitySlider?.value = Float(alpha)
  47. self.opacitySliderView?.startLabel?.text = "\(Int(((self.opacitySliderView?.opacitySlider?.value ?? 0) / 1) * 100))%"
  48. updatePreferredContentSizeWithTraitCollection(traitCollection: traitCollection)
  49. }
  50. // MARK: - CPDFOpacitySliderViewDelegate
  51. override func opacitySliderView(_ opacitySliderView: CPDFOpacitySliderView, opacity: CGFloat) {
  52. sampleView?.opcity = opacity
  53. annotStyle?.setOpacity(opacity)
  54. if annotStyle != nil {
  55. delegate?.highlightViewController?(self, annotStyle: annotStyle!)
  56. }
  57. sampleView?.setNeedsDisplay()
  58. }
  59. // MARK: - UIColorPickerViewControllerDelegate
  60. @available(iOS 14.0, *)
  61. func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
  62. sampleView?.color = viewController.selectedColor
  63. annotStyle?.setColor(viewController.selectedColor)
  64. if annotStyle != nil {
  65. delegate?.highlightViewController?(self, annotStyle: annotStyle!)
  66. }
  67. var red: CGFloat = 0
  68. var green: CGFloat = 0
  69. var blue: CGFloat = 0
  70. var alpha: CGFloat = 0
  71. viewController.selectedColor.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
  72. self.opacitySliderView?.opacitySlider?.value = Float(alpha)
  73. self.opacitySliderView?.startLabel?.text = "\(Int(((self.opacitySliderView?.opacitySlider?.value ?? 0) / 1) * 100))%"
  74. updatePreferredContentSizeWithTraitCollection(traitCollection: traitCollection)
  75. }
  76. }