123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665 |
- //
- // KMRectangleController.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/11/26.
- //
- import Cocoa
- import KMComponentLibrary
- class KMRectangleController: NSViewController {
-
- //Color
- @IBOutlet var colorBGView: NSView!
- @IBOutlet var colorLabel: NSTextField!
- @IBOutlet var colorGroup: ComponentCColorGroup!
- @IBOutlet var colorSlider: ComponentSlider!
- @IBOutlet var colorOpacitySelect: ComponentSelect!
- @IBOutlet var fillColorGroup: ComponentCColorGroup!
-
- //Line
- @IBOutlet var lineBGView: NSView!
- @IBOutlet var lineLabel: NSTextField!
- @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] = [] //CPDFCircleAnnotation, CPDFSquareAnnotation
-
- private var circleAnnotations: [CPDFCircleAnnotation] {
- get {
- var validAnnotations: [CPDFCircleAnnotation] = []
- for annotation in annotations {
- if annotation is CPDFCircleAnnotation {
- validAnnotations.append((annotation as! CPDFCircleAnnotation))
- }
- }
- return validAnnotations
- }
- }
-
- private var squareAnnotations: [CPDFSquareAnnotation] {
- get {
- var validAnnotations: [CPDFSquareAnnotation] = []
- for annotation in annotations {
- if annotation is CPDFSquareAnnotation {
- validAnnotations.append((annotation as! CPDFSquareAnnotation))
- }
- }
- return validAnnotations
- }
- }
-
- var pdfView: CPDFListView?
- var viewManager: KMPDFViewManager?
-
- //MARK: - func
- override func viewDidAppear() {
- super.viewDidAppear()
-
-
- colorSlider.reloadData()
-
- lineWidthSlider.reloadData()
-
- lineDashSlider.reloadData()
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- setupProperty()
- }
-
- func setupProperty() {
-
- //Color
- colorLabel.stringValue = KMLocalizedString("Color")
- colorLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
- colorLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
-
- colorGroup.delegate = self
-
- fillColorGroup.delegate = self
-
- colorSlider.properties = ComponentSliderProperty(size: .m, percent: 1)
- colorSlider.delegate = self
-
- colorOpacitySelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- creatable: true,
- text: "100%",
- textUnit: "%",
- regexString: "0123456789%")
- if true {
- var opacityItems: [ComponentMenuitemProperty] = []
- for string in ["25%", "50%", "75%", "100%"] {
- let item = ComponentMenuitemProperty(type: .normal, text: string)
- opacityItems.append(item)
- }
- colorOpacitySelect.updateMenuItemsArr(opacityItems)
- }
- colorOpacitySelect.delegate = self
-
- //Line
- lineLabel.stringValue = KMLocalizedString("Line")
- 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")
- 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)
- }
- lineWidthSelect.updateMenuItemsArr(opacityItems)
- }
- 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() {
- guard let pdfView = self.pdfView else {
- return
- }
-
- var firstAnnotation: CPDFAnnotation?
-
- self.annotations.removeAll()
- let allAnnotations: [CPDFAnnotation] = pdfView.activeAnnotations as? [CPDFAnnotation] ?? []
- for annotation in allAnnotations {
- if annotation is CPDFCircleAnnotation {
- annotations.append((annotation as! CPDFCircleAnnotation))
- } else if annotation is CPDFSquareAnnotation {
- annotations.append((annotation as! CPDFSquareAnnotation))
- }
- }
- if annotations.count > 0 {
- firstAnnotation = annotations.first
- }
-
- if true {
- var colors: [NSColor] = []
- var fillColors: [NSColor] = []
-
- if let annotation = firstAnnotation {
- if annotation is CPDFSquareAnnotation {
- colors = KMAnnotationPropertiesColorManager.manager.rectangle_Colors
- fillColors = KMAnnotationPropertiesColorManager.manager.rectangle_Fill_Colors
- } else if annotation is CPDFCircleAnnotation {
- colors = KMAnnotationPropertiesColorManager.manager.circle_Colors
- fillColors = KMAnnotationPropertiesColorManager.manager.circle_Fill_Colors
- }
- } else if viewManager?.subToolMode == .Rectangle {
- colors = KMAnnotationPropertiesColorManager.manager.rectangle_Colors
- fillColors = KMAnnotationPropertiesColorManager.manager.rectangle_Fill_Colors
- } else if viewManager?.subToolMode == .Circle {
- colors = KMAnnotationPropertiesColorManager.manager.circle_Colors
- fillColors = KMAnnotationPropertiesColorManager.manager.circle_Fill_Colors
- }
-
- if colors.count > 4 {
- let colorAProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[0])
- let colorBProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[1])
- let colorCProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[2])
- let colorDProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[3])
- let colorEProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: true, color: colors[4])
-
- colorGroup.setUpWithColorPropertys([colorAProperty, colorBProperty, colorCProperty, colorDProperty], customItemProperty: colorEProperty)
- }
-
- if fillColors.count > 4 {
- let colorAProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: fillColors[0])
- let colorBProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: fillColors[1])
- let colorCProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: fillColors[2])
- let colorDProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: fillColors[3])
- let colorEProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: true, color: fillColors[4])
-
- fillColorGroup.setUpWithColorPropertys([colorAProperty, colorBProperty, colorCProperty, colorDProperty], customItemProperty: colorEProperty)
- }
- }
-
-
- if annotations.count == 0 {
- if viewManager?.subToolMode == .Rectangle {
- colorGroup.currentColor = CPDFSquareAnnotation.defaultColor()
-
- fillColorGroup.currentColor = CPDFSquareAnnotation.defaultInteriorColor()
-
- let opacity = CPDFSquareAnnotation.defaultOpacity()
- colorSlider.properties.percent = opacity
- colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
-
- let border: CPDFBorder = CPDFSquareAnnotation.defaultBorder()
-
- dashProperty.state = .normal
- solidProperty.state = .normal
- if border.style == .dashed {
- dashProperty.state = .pressed
- } else if border.style == .solid {
- solidProperty.state = .pressed
- }
-
- 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 if viewManager?.subToolMode == .Circle {
- colorGroup.currentColor = CPDFCircleAnnotation.defaultColor()
-
- fillColorGroup.currentColor = CPDFCircleAnnotation.defaultInteriorColor()
-
- let opacity = CPDFCircleAnnotation.defaultOpacity()
- colorSlider.properties.percent = opacity
- colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
-
- let border: CPDFBorder = CPDFCircleAnnotation.defaultBorder()
-
- dashProperty.state = .normal
- solidProperty.state = .normal
- if border.style == .dashed {
- dashProperty.state = .pressed
- } else if border.style == .solid {
- solidProperty.state = .pressed
- }
-
- 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 if annotations.count == 1, let annotation = firstAnnotation {
- colorGroup.currentColor = annotation.color
-
- if firstAnnotation is CPDFCircleAnnotation {
- fillColorGroup.currentColor = (firstAnnotation as! CPDFCircleAnnotation).interiorColor
- } else if firstAnnotation is CPDFSquareAnnotation {
- fillColorGroup.currentColor = (firstAnnotation as! CPDFSquareAnnotation).interiorColor
- }
-
- let opacity = annotation.opacity
- colorSlider.properties.percent = opacity
-
- colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
-
- let border: CPDFBorder = annotation.border
- dashProperty.state = .normal
- solidProperty.state = .normal
- if border.style == .dashed {
- dashProperty.state = .pressed
- } else if border.style == .solid {
- solidProperty.state = .pressed
- }
-
- let percent = (border.lineWidth - 1)/17
- lineWidthSlider.properties.percent = percent
-
- lineWidthSelect.properties.text = String(format: "%.0f%@", border.lineWidth, " pt")
-
- 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
-
- lineDashSelect.properties.text = String(format: "%.0f%@", CGFloat(dash), " pt")
-
- }
- } else {
- guard let annotation = firstAnnotation else {
- return
- }
-
- if true {
- let multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .color)
- if multiColor == true {
- colorGroup.currentColor = NSColor.clear
- } else {
- colorGroup.currentColor = annotation.color
- }
- }
-
- if true {
- let multiColor: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .interiorColor)
- if multiColor == true {
- fillColorGroup.currentColor = NSColor.clear
- } else {
- if firstAnnotation is CPDFSquareAnnotation {
- fillColorGroup.currentColor = (firstAnnotation as! CPDFSquareAnnotation).interiorColor
- } else if firstAnnotation is CPDFCircleAnnotation {
- fillColorGroup.currentColor = (firstAnnotation as! CPDFCircleAnnotation).interiorColor
- }
- }
- }
-
- if true {
- let multiOpacity: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .opacity)
- if multiOpacity {
- colorSlider.properties.percent = 0
-
- colorOpacitySelect.resetText("-")
- } else {
- let opacity = annotation.opacity
-
- colorSlider.properties.percent = opacity
- colorSlider.reloadData()
-
- colorOpacitySelect.properties.text = String(format: "%.0f%@", opacity*100, "%")
- colorOpacitySelect.reloadData()
- }
- }
-
- if true {
- let multiStyle: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .border_Style)
-
- linedashInfoView.isHidden = true
- if multiStyle {
- dashProperty.state = .normal
- solidProperty.state = .normal
-
- lineTypeSelector.reloadData()
- } else {
- let style = annotation.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 true {
- let multiLineWidth: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .line_Width)
-
- if multiLineWidth {
- lineWidthSlider.properties.percent = 0
- lineWidthSlider.reloadData()
-
- lineWidthSelect.resetText("-")
- } else {
- let border: CPDFBorder = annotation.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 {
- let multiLineDash: Bool = CPDFListView.isAnnotationsContainMultiType(annotations, withType: .dash_Pattern)
- if multiLineDash {
- lineDashSlider.properties.percent = 0
- lineDashSlider.reloadData()
-
- lineDashSelect.resetText("-")
- } else {
- var dashA = 1.0
- for dashPattern in annotation.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()
- }
- }
- }
-
- colorGroup.refreshUI()
- fillColorGroup.refreshUI()
- colorSlider.reloadData()
- colorOpacitySelect.reloadData()
- lineTypeSelector.reloadData()
- lineWidthSlider.reloadData()
- lineWidthSelect.reloadData()
- lineDashSlider.reloadData()
- lineDashSelect.reloadData()
-
- }
-
- //MARK: - Mouse
- override func mouseDown(with event: NSEvent) {
- super.mouseDown(with: event)
-
- view.window?.makeFirstResponder(nil)
- }
-
- }
- //MARK: - ComponentCColorDelegate
- extension KMRectangleController: ComponentCColorDelegate {
- func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
- if view == colorGroup {
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateColor(circleAnnotations, color, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateColor(squareAnnotations, color, withPDFView: pdfView)
- }
- } else if view == fillColorGroup {
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateInteriorColor(circleAnnotations, color, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateInteriorColor(squareAnnotations, color, withPDFView: pdfView)
- }
- }
- reloadData()
- }
- }
- //MARK: - ComponentSliderDelegate
- extension KMRectangleController: ComponentSliderDelegate {
- func componentSliderDidUpdate(_ view: ComponentSlider) {
- if view == colorSlider {
- let percent = view.properties.percent
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateOpacity(circleAnnotations, percent, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateOpacity(squareAnnotations, percent, withPDFView: pdfView)
- }
-
- } else if view == lineWidthSlider {
- let percent = view.properties.percent * 17 + 1
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateLineWidth(circleAnnotations, percent, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateLineWidth(squareAnnotations, percent, withPDFView: pdfView)
- }
-
- } else if view == lineDashSlider {
- let percent = view.properties.percent * 17 + 1
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle{
- CPDFCircleAnnotation.updateDashPattern(circleAnnotations, percent, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateDashPattern(squareAnnotations, percent, withPDFView: pdfView)
- }
- }
- reloadData()
- }
- }
- //MARK: - ComponentSelectDelegate
- extension KMRectangleController: ComponentSelectDelegate {
- func componentSelectTextDidEndEditing(_ view: ComponentSelect, removeUnit text: String?) {
- if let result = text {
- if view == colorOpacitySelect {
- let opacity = max(0, min(1, result.stringToCGFloat()/100))
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateOpacity(circleAnnotations, opacity, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateOpacity(squareAnnotations, opacity, withPDFView: pdfView)
- }
- } else if view == lineWidthSelect {
- var value = result.stringToCGFloat()
- if value > 18 {
- value = 18
- } else if value < 1 {
- value = 1
- }
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle{
- CPDFCircleAnnotation.updateLineWidth(circleAnnotations, value, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateLineWidth(squareAnnotations, value, withPDFView: pdfView)
- }
-
- } else if view == lineDashSelect {
- var value = result.stringToCGFloat()
- if value > 18 {
- value = 18
- } else if value < 1 {
- value = 1
- }
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateDashPattern(circleAnnotations, value, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateDashPattern(squareAnnotations, value, withPDFView: pdfView)
- }
- }
- reloadData()
- }
- }
-
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- if var result = menuItemProperty?.text {
- if let textUnit = view?.properties.textUnit {
- result = result.stringByDeleteCharString(textUnit)
- }
- if view == colorOpacitySelect {
- let opacity = max(0, min(1, result.stringToCGFloat()/100))
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateOpacity(circleAnnotations, opacity, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateOpacity(squareAnnotations, opacity, withPDFView: pdfView)
- }
-
- } else if view == lineWidthSelect {
- var value = result.stringToCGFloat()
- if value > 18 {
- value = 18
- } else if value < 1 {
- value = 1
- }
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateLineWidth(circleAnnotations, value, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateLineWidth(squareAnnotations, value, withPDFView: pdfView)
- }
-
- } else if view == lineDashSelect {
- var value = result.stringToCGFloat()
- if value > 18 {
- value = 18
- } else if value < 1 {
- value = 1
- }
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateDashPattern(circleAnnotations, value, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateDashPattern(squareAnnotations, value, withPDFView: pdfView)
- }
-
- }
- reloadData()
- }
- }
- }
- //MARK: - ComponentCSelectorGroupDelegate
- extension KMRectangleController: ComponentCSelectorGroupDelegate {
- func componentCSelectorGroupDidChoose(_ view: ComponentCSelectorGroup, _ item: ComponentCSelectorItem) {
- if item.properties == solidProperty {
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateStyle(circleAnnotations, .solid, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateStyle(squareAnnotations, .solid, withPDFView: pdfView)
- }
- } else if item.properties == dashProperty {
- if circleAnnotations.count > 0 || viewManager?.subToolMode == .Circle {
- CPDFCircleAnnotation.updateStyle(circleAnnotations, .dashed, withPDFView: pdfView)
- }
- if squareAnnotations.count > 0 || viewManager?.subToolMode == .Rectangle {
- CPDFSquareAnnotation.updateStyle(squareAnnotations, .dashed, withPDFView: pdfView)
- }
- }
- reloadData()
- }
- }
|