|
@@ -22,10 +22,14 @@ class KMPenController: NSViewController {
|
|
|
@IBOutlet var lineTypeSelector: ComponentCSelectorGroup!
|
|
|
@IBOutlet var lineWidthSlider: ComponentSlider!
|
|
|
@IBOutlet var lineWidthSelect: ComponentSelect!
|
|
|
+ @IBOutlet var linedashInfoView: NSView!
|
|
|
+ @IBOutlet var lineDashSlider: ComponentSlider!
|
|
|
+ @IBOutlet var lineDashSelect: ComponentSelect!
|
|
|
|
|
|
+ private let solidProperty = ComponentCSelectorProperty.init(size: .s, state: .normal, text: "", iconImage: NSImage(named: "lineStyle_solid"))
|
|
|
+ private let dashProperty = ComponentCSelectorProperty.init(size: .s, state: .normal, text: "", iconImage: NSImage(named: "lineStyle_dash"))
|
|
|
|
|
|
-
|
|
|
- private var annotations: [CPDFAnnotation] = []
|
|
|
+ private var annotations: [CPDFInkAnnotation] = []
|
|
|
|
|
|
var pdfView: CPDFListView?
|
|
|
|
|
@@ -35,6 +39,10 @@ class KMPenController: NSViewController {
|
|
|
|
|
|
|
|
|
colorSlider.reloadData()
|
|
|
+
|
|
|
+ lineWidthSlider.reloadData()
|
|
|
+
|
|
|
+ lineDashSlider.reloadData()
|
|
|
}
|
|
|
|
|
|
override func viewDidLoad() {
|
|
@@ -83,15 +91,18 @@ class KMPenController: NSViewController {
|
|
|
lineLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
|
|
|
lineLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
|
|
|
|
|
|
+ lineTypeSelector.updateItemProperty([solidProperty, dashProperty])
|
|
|
+ lineTypeSelector.delegate = self
|
|
|
+
|
|
|
lineWidthSlider.properties = ComponentSliderProperty(size: .m, percent: 1)
|
|
|
lineWidthSlider.delegate = self
|
|
|
|
|
|
lineWidthSelect.properties = ComponentSelectProperties(size: .s,
|
|
|
- state: .normal,
|
|
|
- creatable: true,
|
|
|
- text: "2",
|
|
|
- textUnit: " pt",
|
|
|
- regexString: "0123456789 pt")
|
|
|
+ state: .normal,
|
|
|
+ creatable: true,
|
|
|
+ text: "2",
|
|
|
+ textUnit: " pt",
|
|
|
+ regexString: "0123456789 pt")
|
|
|
if true {
|
|
|
var opacityItems: [ComponentMenuitemProperty] = []
|
|
|
for string in ["1 pt", "3 pt", "6 pt", "9 pt", "12 pt", "15 pt", "18 pt"] {
|
|
@@ -102,6 +113,25 @@ class KMPenController: NSViewController {
|
|
|
}
|
|
|
lineWidthSelect.delegate = self
|
|
|
|
|
|
+ lineDashSlider.properties = ComponentSliderProperty(size: .m, percent: 1)
|
|
|
+ lineDashSlider.delegate = self
|
|
|
+
|
|
|
+ lineDashSelect.properties = ComponentSelectProperties(size: .s,
|
|
|
+ state: .normal,
|
|
|
+ creatable: true,
|
|
|
+ text: "2",
|
|
|
+ textUnit: " pt",
|
|
|
+ regexString: "0123456789 pt")
|
|
|
+ if true {
|
|
|
+ var opacityItems: [ComponentMenuitemProperty] = []
|
|
|
+ for string in ["1 pt", "3 pt", "6 pt", "9 pt", "12 pt", "15 pt", "18 pt"] {
|
|
|
+ let item = ComponentMenuitemProperty(type: .normal, text: string)
|
|
|
+ opacityItems.append(item)
|
|
|
+ }
|
|
|
+ lineDashSelect.updateMenuItemsArr(opacityItems)
|
|
|
+ }
|
|
|
+ lineDashSelect.delegate = self
|
|
|
+
|
|
|
}
|
|
|
|
|
|
func reloadData() {
|
|
@@ -113,77 +143,241 @@ class KMPenController: NSViewController {
|
|
|
self.annotations.removeAll()
|
|
|
let allAnnotations: [CPDFAnnotation] = pdfView.activeAnnotations as? [CPDFAnnotation] ?? []
|
|
|
for annotation in allAnnotations {
|
|
|
- if annotation is CPDFMarkupAnnotation {
|
|
|
- annotations.append((annotation as! CPDFMarkupAnnotation))
|
|
|
+ if annotation is CPDFInkAnnotation {
|
|
|
+ annotations.append((annotation as! CPDFInkAnnotation))
|
|
|
}
|
|
|
}
|
|
|
if annotations.count == 0 {
|
|
|
return
|
|
|
}
|
|
|
- let firstAnnotation = annotations.first
|
|
|
+ guard let firstAnnotation = annotations.first else {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
if annotations.count == 1 {
|
|
|
- colorGroup.currentColor = firstAnnotation?.color
|
|
|
+ colorGroup.currentColor = firstAnnotation.color
|
|
|
colorGroup.refreshUI()
|
|
|
|
|
|
- let opacity = firstAnnotation?.opacity ?? 0
|
|
|
+ let opacity = firstAnnotation.opacity
|
|
|
colorSlider.properties.percent = opacity
|
|
|
colorSlider.reloadData()
|
|
|
|
|
|
colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
|
|
|
colorOpacitySelect.reloadData()
|
|
|
|
|
|
+ let border: CPDFBorder = firstAnnotation.border
|
|
|
+
|
|
|
+ dashProperty.state = .normal
|
|
|
+ solidProperty.state = .normal
|
|
|
+ if border.style == .dashed {
|
|
|
+ dashProperty.state = .pressed
|
|
|
+ } else if border.style == .solid {
|
|
|
+ solidProperty.state = .pressed
|
|
|
+ }
|
|
|
+ lineTypeSelector.reloadData()
|
|
|
+
|
|
|
+ let percent = (border.lineWidth - 1)/17
|
|
|
+ lineWidthSlider.properties.percent = percent
|
|
|
+ lineWidthSlider.reloadData()
|
|
|
+
|
|
|
+ lineWidthSelect.properties.text = String(format: "%.0f%@", border.lineWidth, " pt")
|
|
|
+ lineWidthSelect.reloadData()
|
|
|
|
|
|
+ linedashInfoView.isHidden = true
|
|
|
+ if border.style == .dashed {
|
|
|
+ linedashInfoView.isHidden = false
|
|
|
+
|
|
|
+ var dash = 1.0
|
|
|
+ for dashPattern in border.dashPattern {
|
|
|
+ if let value = dashPattern as? CGFloat {
|
|
|
+ dash = value
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ let percent: CGFloat = (CGFloat(dash) - 1)/17
|
|
|
+ lineDashSlider.properties.percent = percent
|
|
|
+ lineDashSlider.reloadData()
|
|
|
+
|
|
|
+ lineDashSelect.properties.text = String(format: "%.0f%@", CGFloat(dash), " pt")
|
|
|
+ lineDashSelect.reloadData()
|
|
|
+ }
|
|
|
} else {
|
|
|
- var multiColor: Bool = false
|
|
|
- for annotationA in annotations {
|
|
|
- for annotationB in annotations {
|
|
|
- if annotationA != annotationB {
|
|
|
- if annotationA.color != annotationB.color {
|
|
|
- multiColor = true
|
|
|
- break
|
|
|
+ if true {
|
|
|
+ var multiColor: Bool = false
|
|
|
+ for annotationA in annotations {
|
|
|
+ for annotationB in annotations {
|
|
|
+ if annotationA != annotationB {
|
|
|
+ if annotationA.color != annotationB.color {
|
|
|
+ multiColor = true
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if multiColor == true {
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
if multiColor == true {
|
|
|
- break
|
|
|
+ colorGroup.currentColor = NSColor.clear
|
|
|
+ } else {
|
|
|
+ colorGroup.currentColor = firstAnnotation.color
|
|
|
}
|
|
|
+ colorGroup.refreshUI()
|
|
|
}
|
|
|
- if multiColor == true {
|
|
|
- colorGroup.currentColor = NSColor.clear
|
|
|
- } else {
|
|
|
- colorGroup.currentColor = firstAnnotation?.color
|
|
|
+
|
|
|
+ if true {
|
|
|
+ var multiOpacity: Bool = false
|
|
|
+ for annotationA in annotations {
|
|
|
+ for annotationB in annotations {
|
|
|
+ if annotationA != annotationB {
|
|
|
+ if annotationA.opacity != annotationB.opacity {
|
|
|
+ multiOpacity = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if multiOpacity == true {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if multiOpacity {
|
|
|
+ colorSlider.properties.percent = 0
|
|
|
+ colorSlider.reloadData()
|
|
|
+
|
|
|
+ colorOpacitySelect.resetText("-")
|
|
|
+ } else {
|
|
|
+ let opacity = firstAnnotation.opacity
|
|
|
+
|
|
|
+ colorSlider.properties.percent = opacity
|
|
|
+ colorSlider.reloadData()
|
|
|
+
|
|
|
+ colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
|
|
|
+ colorOpacitySelect.reloadData()
|
|
|
+ }
|
|
|
}
|
|
|
- colorGroup.refreshUI()
|
|
|
|
|
|
- var multiOpacity: Bool = false
|
|
|
- for annotationA in annotations {
|
|
|
- for annotationB in annotations {
|
|
|
- if annotationA != annotationB {
|
|
|
- if annotationA.opacity != annotationB.opacity {
|
|
|
- multiOpacity = true
|
|
|
- break
|
|
|
+ if true {
|
|
|
+ var multiStyle: Bool = false
|
|
|
+ for annotationA in annotations {
|
|
|
+ for annotationB in annotations {
|
|
|
+ if annotationA != annotationB {
|
|
|
+ if annotationA.borderStyle() != annotationB.borderStyle() {
|
|
|
+ multiStyle = true
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ if multiStyle == true {
|
|
|
+ break
|
|
|
+ }
|
|
|
}
|
|
|
- if multiOpacity == true {
|
|
|
- break
|
|
|
+
|
|
|
+ linedashInfoView.isHidden = true
|
|
|
+ if multiStyle {
|
|
|
+ dashProperty.state = .normal
|
|
|
+ solidProperty.state = .normal
|
|
|
+
|
|
|
+ lineTypeSelector.reloadData()
|
|
|
+ } else {
|
|
|
+ let style = firstAnnotation.border.style
|
|
|
+ dashProperty.state = .normal
|
|
|
+ solidProperty.state = .normal
|
|
|
+ if style == .dashed {
|
|
|
+ dashProperty.state = .pressed
|
|
|
+ } else if style == .solid {
|
|
|
+ solidProperty.state = .pressed
|
|
|
+ }
|
|
|
+ lineTypeSelector.reloadData()
|
|
|
+
|
|
|
+ if style == .dashed {
|
|
|
+ linedashInfoView.isHidden = false
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if multiOpacity {
|
|
|
- colorSlider.properties.percent = 0
|
|
|
- colorSlider.reloadData()
|
|
|
-
|
|
|
- colorOpacitySelect.resetText("-")
|
|
|
- } else {
|
|
|
- let opacity = firstAnnotation?.opacity ?? 0
|
|
|
-
|
|
|
- colorSlider.properties.percent = opacity
|
|
|
- colorSlider.reloadData()
|
|
|
-
|
|
|
- colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
|
|
|
- colorOpacitySelect.reloadData()
|
|
|
+ if true {
|
|
|
+ var multiLineWidth: Bool = false
|
|
|
+ for annotationA in annotations {
|
|
|
+ for annotationB in annotations {
|
|
|
+ if annotationA != annotationB {
|
|
|
+ if annotationA.borderStyle() != annotationB.borderStyle() {
|
|
|
+ multiLineWidth = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if multiLineWidth == true {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if multiLineWidth {
|
|
|
+ lineWidthSlider.properties.percent = 0
|
|
|
+ lineWidthSlider.reloadData()
|
|
|
+
|
|
|
+ lineWidthSelect.resetText("-")
|
|
|
+ } else {
|
|
|
+ let border: CPDFBorder = firstAnnotation.border
|
|
|
+
|
|
|
+ let percent = (border.lineWidth - 1)/17
|
|
|
+ lineWidthSlider.properties.percent = percent
|
|
|
+ lineWidthSlider.reloadData()
|
|
|
+
|
|
|
+ lineWidthSelect.properties.text = String(format: "%.0f%@", border.lineWidth, " pt")
|
|
|
+ lineWidthSelect.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if true {
|
|
|
+ var multiLineDash: Bool = false
|
|
|
+ for annotationA in annotations {
|
|
|
+ var dashA = 1.0
|
|
|
+ for dashPattern in annotationA.border.dashPattern {
|
|
|
+ if let value = dashPattern as? CGFloat {
|
|
|
+ dashA = value
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for annotationB in annotations {
|
|
|
+ if annotationA != annotationB {
|
|
|
+ var dashB = 1.0
|
|
|
+ for dashPattern in annotationB.border.dashPattern {
|
|
|
+ if let value = dashPattern as? CGFloat {
|
|
|
+ dashB = value
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if dashA != dashB {
|
|
|
+ multiLineDash = true
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if multiLineDash == true {
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if multiLineDash {
|
|
|
+ lineDashSlider.properties.percent = 0
|
|
|
+ lineDashSlider.reloadData()
|
|
|
+
|
|
|
+ lineDashSelect.resetText("-")
|
|
|
+ } else {
|
|
|
+ var dashA = 1.0
|
|
|
+ for dashPattern in firstAnnotation.border.dashPattern {
|
|
|
+ if let value = dashPattern as? CGFloat {
|
|
|
+ dashA = value
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let percent = (dashA - 1)/17
|
|
|
+ lineDashSlider.properties.percent = percent
|
|
|
+ lineDashSlider.reloadData()
|
|
|
+
|
|
|
+ lineDashSelect.properties.text = String(format: "%.0f%@", dashA, " pt")
|
|
|
+ lineDashSelect.reloadData()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -203,8 +397,9 @@ class KMPenController: NSViewController {
|
|
|
//MARK: - ComponentCColorDelegate
|
|
|
extension KMPenController: ComponentCColorDelegate {
|
|
|
func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
|
|
|
-
|
|
|
-
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateColor(color, withPDFView: pdfView)
|
|
|
+ }
|
|
|
reloadData()
|
|
|
}
|
|
|
}
|
|
@@ -212,8 +407,22 @@ extension KMPenController: ComponentCColorDelegate {
|
|
|
//MARK: - ComponentSliderDelegate
|
|
|
extension KMPenController: ComponentSliderDelegate {
|
|
|
func componentSliderDidUpdate(_ view: ComponentSlider) {
|
|
|
- let percent = view.properties.percent
|
|
|
-
|
|
|
+ if view == colorSlider {
|
|
|
+ let percent = view.properties.percent
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateOpacity(percent, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ } else if view == lineWidthSlider {
|
|
|
+ let percent = view.properties.percent * 17 + 1
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateLineWidth(percent, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ } else if view == lineDashSlider {
|
|
|
+ let percent = view.properties.percent * 17 + 1
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateDashPattern(percent, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ }
|
|
|
reloadData()
|
|
|
}
|
|
|
}
|
|
@@ -222,9 +431,50 @@ extension KMPenController: ComponentSliderDelegate {
|
|
|
extension KMPenController: ComponentSelectDelegate {
|
|
|
func componentSelectTextDidEndEditing(_ view: ComponentSelect, removeUnit text: String?) {
|
|
|
if let result = text {
|
|
|
- let opacity = max(0, min(1, result.stringToCGFloat()/100))
|
|
|
-
|
|
|
+ if view == colorOpacitySelect {
|
|
|
+ let opacity = max(0, min(1, result.stringToCGFloat()/100))
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateOpacity(opacity, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ } else if view == lineWidthSelect {
|
|
|
+ var value = result.stringToCGFloat()
|
|
|
+ if value > 18 {
|
|
|
+ value = 18
|
|
|
+ } else if value < 1 {
|
|
|
+ value = 1
|
|
|
+ }
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateLineWidth(value, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ } else if view == lineDashSelect {
|
|
|
+ var value = result.stringToCGFloat()
|
|
|
+ if value > 18 {
|
|
|
+ value = 18
|
|
|
+ } else if value < 1 {
|
|
|
+ value = 1
|
|
|
+ }
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateDashPattern(value, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ }
|
|
|
reloadData()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+//MARK: - ComponentCSelectorGroupDelegate
|
|
|
+extension KMPenController: ComponentCSelectorGroupDelegate {
|
|
|
+ func componentCSelectorGroupDidChoose(_ view: ComponentCSelectorGroup, _ item: ComponentCSelectorItem) {
|
|
|
+ if item.properties == solidProperty {
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateStyle(.solid, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ } else if item.properties == dashProperty {
|
|
|
+ for annotation in self.annotations {
|
|
|
+ annotation.updateStyle(.dashed, withPDFView: pdfView)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ reloadData()
|
|
|
+ }
|
|
|
+}
|