123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858 |
- //
- // KMNPopContentEditWindowController.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/12/2.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNPopContentEditViewController: KMNBaseViewController {
- public var editType:EditContentPopType = .editNone {
- didSet {
- rightOffsetConstraint.constant = 49.0
- paneBox.isHidden = false
-
- switch editType {
- case .signTextEdit :
- textPopView.layoutSubtreeIfNeeded()
-
- operationWidthConstraint.constant = textPopView.bounds.width
- self.view.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = textPopView
- congfigFontPopUI()
-
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightLeft")
- fontAlightButton.reloadData()
- break
- case .signImageEdit:
- imagePopView.layoutSubtreeIfNeeded()
- congfigSignImageUI()
-
- operationWidthConstraint.constant = imagePopView.bounds.width
- self.view.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = imagePopView
- break
- case .multpleTextEdit:
- textPopView.layoutSubtreeIfNeeded()
- operationWidthConstraint.constant = textPopView.bounds.width
- self.view.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = textPopView
- congfigFontPopUI()
-
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightLeft")
- fontAlightButton.reloadData()
- break
- case .multpleImageEdit:
- imagePopView.layoutSubtreeIfNeeded()
- congfigMultpleImageUI()
-
- operationWidthConstraint.constant = imagePopView.bounds.width
- self.view.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = imagePopView
- break
- case .multpleImageAndText:
- alightView.layoutSubtreeIfNeeded()
- operationWidthConstraint.constant = alightView.bounds.width
- self.view.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = alightView
- break
- case .cropImage:
- cropPopView.layoutSubtreeIfNeeded()
- rightOffsetConstraint.constant = 0
- paneBox.isHidden = true
- operationWidthConstraint.constant = cropPopView.bounds.width
- self.view.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = cropPopView
- break
- case .editNone:
- break
- }
- }
- }
-
- public var isOpenPane = false {
- didSet {
- if isOpenPane == true {
- paneSelectorItem.properties.state = .pressed
- } else {
- paneSelectorItem.properties.state = .normal
- }
- paneSelectorItem.reloadData()
- }
- }
-
- public var editContentPopMode:KMNEditContentPopMode = KMNEditContentPopMode(currentEditAreas: []) {
- didSet {
- let editPopType = editContentPopMode.popType
- editType = editPopType
-
- if(editType == .signTextEdit || editType == .multpleTextEdit) {
- let textEditAreas = listView?.km_editingTextAreas()
- let oldColor:NSColor? = fontColor
- let firstTextEditArea = textEditAreas?.first
- let firstColor = listView?.editingSelectionFontColor(with: firstTextEditArea)
- var newColor:NSColor? = firstColor
-
- for textEditArea in textEditAreas ?? [] {
- if firstTextEditArea != textEditArea {
- let color = listView?.editingSelectionFontColor(with: firstTextEditArea)
-
- if CPDFListView.isTheSameColor(color, anotherColor: firstColor) == false{
- newColor = nil
- break
- }
- }
- }
-
- if !CPDFListView.isTheSameColor(newColor, anotherColor: oldColor) {
- fontColor = newColor
- }
-
- let oldBold:Bool = isBold
- let newBolds:[Bool] = listView?.km_editTextAreasFontBolds(textEditAreas ?? []) ?? []
- var newBold = true
- for i in 0 ..< newBolds.count {
- let boldV = newBolds[i]
- if boldV == false {
- newBold = false
- break
- }
- }
-
- if oldBold != newBold {
- isBold = newBold
- }
-
- let oldItalic:Bool = isItalic
- let newItalics:[Bool] = listView?.km_editTextAreasFontItalics(textEditAreas ?? []) ?? []
-
- var newItalic = true
- for i in 0 ..< newItalics.count {
- let boldV = newItalics[i]
- if boldV == false {
- newItalic = false
- break
- }
- }
-
- if oldItalic != newItalic {
- isItalic = newItalic
- }
-
- let oldStrikeoutLine:Bool = isStrikeoutLine
- let newStrikeoutLines:[Bool] = listView?.km_editTextAreasFontStrikeout(textEditAreas ?? []) ?? []
-
- var newStrikeoutLine = true
- for i in 0 ..< newStrikeoutLines.count {
- let boldV = newStrikeoutLines[i]
- if boldV == false {
- newStrikeoutLine = false
- break
- }
- }
-
- if oldStrikeoutLine != newStrikeoutLine {
- isStrikeoutLine = newStrikeoutLine
- }
-
- let oldUnderLine:Bool = isUnderLine
- let newUnderLines:[Bool] = listView?.km_editTextAreasFontUnder(textEditAreas ?? []) ?? []
-
- var newUnderLine = true
- for i in 0 ..< newStrikeoutLines.count {
- let boldV = newUnderLines[i]
- if boldV == false {
- newUnderLine = false
- break
- }
- }
-
- if oldUnderLine != newUnderLine {
- isUnderLine = newUnderLine
- }
-
- let alights = listView?.km_editTextAreasTextAlignments(textEditAreas ?? []) ?? []
- var newAlignment = alights.first ?? .left
- let oldAlignment :NSTextAlignment = fontAlight
- for i in 0 ..< alights.count {
- let alignmentV = alights[i]
- if oldAlignment != alignmentV {
- newAlignment = .left
- break
- }
- }
- if oldAlignment != newAlignment {
- fontAlight = newAlignment
- }
-
- let fonts = listView?.km_editTextAreasComPDFFonts(textEditAreas ?? []) ?? []
-
- var newFont:CPDFFont? = fonts.first
- for i in 0 ..< fonts.count {
- let fontV = fonts[i]
- if i != 0 && (fontV.familyName != compdfFont?.familyName || fontV.styleName != compdfFont?.styleName) {
- newFont = nil
- break
- }
- }
-
- compdfFont = newFont
- }
- }
- }
-
- private var fontColor:NSColor? {
- didSet {
- fontColorItem.properties?.color = fontColor
- fontColorItem.reloadData()
- }
- }
-
- private var compdfFont:CPDFFont?{
- didSet {
- if(compdfFont != nil) {
- let styleName = compdfFont!.styleName
- if(styleName?.isEmpty == true) {
- fontNameSelect.properties.text = compdfFont!.familyName
- } else {
- fontNameSelect.properties.text = compdfFont!.familyName + "-" + (compdfFont!.styleName ?? "")
- }
- } else {
- fontNameSelect.properties.text = "-"
- }
- fontNameSelect.reloadData()
- }
- }
-
- private var fontAlight:NSTextAlignment = .left {
- didSet {
- if fontAlight == .center {
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightCenter")
- } else if fontAlight == .right {
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightRight")
- } else if fontAlight == .justified {
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightJus")
- } else {
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightLeft")
- }
- fontAlightButton.reloadData()
- }
- }
-
- private var objectAlign:ObjectAlignType = .alightLeft {
- didSet {
- switch objectAlign {
- case .alightLeft :
- listView?.changeEditingAreas(.left)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightLeft")
- break
- case .alightRight:
- listView?.changeEditingAreas(.right)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightRight")
- break
- case .alightTop:
- listView?.changeEditingAreas(.top)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightTop")
- break
-
- case .alightVer:
- listView?.changeEditingAreas(.vertical)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightVer")
- break
- case .alightHor:
- listView?.changeEditingAreas(.horizontally)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightHor")
- break
- case .alightBottom:
- listView?.changeEditingAreas(.bottom)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightBottom")
- break
- case .averageVer:
- listView?.changeEditingAreas(.disVertical)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjecAlignAverageVer")
- break
- case .averageHor:
- listView?.changeEditingAreas(.disHorizontally)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjecAlignAverageHor")
- break
- }
- alightButton.reloadData()
- }
- }
-
- private var isBold:Bool = false {
- didSet {
- fontBoldSelectorItem.properties.state = isBold ? .pressed : .normal
- fontBoldSelectorItem.reloadData()
- }
- }
-
- private var isItalic:Bool = false {
- didSet {
- fontItalicSelectorItem.properties.state = isItalic ? .pressed : .normal
- fontItalicSelectorItem.reloadData()
- }
- }
-
- private var isStrikeoutLine:Bool = false {
- didSet {
- }
- }
-
- private var isUnderLine:Bool = false {
- didSet {
- }
- }
-
- static let shared: KMNPopContentEditViewController = {
- let windowC = KMNPopContentEditViewController(nibName: "KMNPopContentEditViewController", bundle: nil)
- return windowC
- }()
-
- var paneCallback: PaneCallback?
- var updatePDFViewCallback: UpdatePDFViewCallback?
-
- @IBOutlet weak var contentBox: NSBox!
- @IBOutlet weak var operationBox: NSBox!
- @IBOutlet weak var paneBox: NSBox!
- @IBOutlet weak var lineBox: NSBox!
- @IBOutlet var paneSelectorItem: ComponentCSelectorItem!
- @IBOutlet weak var operationWidthConstraint: NSLayoutConstraint!
- @IBOutlet weak var rightOffsetConstraint: NSLayoutConstraint!
-
- @IBOutlet var textPopView: NSView!
- @IBOutlet var fontColorItem: ComponentCColorItem!
- @IBOutlet var fontNameSelect: ComponentSelect!
- @IBOutlet var fontBoldSelectorItem: ComponentCSelector!
- @IBOutlet var fontItalicSelectorItem: ComponentCSelector!
- @IBOutlet var fontSizeZoomOutButton: ComponentButton!
- @IBOutlet var fontSizeZoomInButton: ComponentButton!
- @IBOutlet var fontAlightButton: ComponentButton!
-
- @IBOutlet var imagePopView: NSView!
- @IBOutlet var rotaLeftButton: ComponentButton!
- @IBOutlet var rotaRightButton: ComponentButton!
- @IBOutlet var horizontalMirrorButton: ComponentButton!
- @IBOutlet var verticalMirrorButton: ComponentButton!
- @IBOutlet var cropButton: ComponentButton!
- @IBOutlet var replaceButton: ComponentButton!
- @IBOutlet var extractButton: ComponentButton!
- @IBOutlet weak var rightConstraint: NSLayoutConstraint!
-
- @IBOutlet var alightView: NSView!
- @IBOutlet var alightButton: ComponentButton!
-
- @IBOutlet var cropPopView: NSView!
- @IBOutlet var cropSureButton: ComponentButton!
- @IBOutlet var cropRestButton: ComponentButton!
-
- private var extractGroupView: ComponentGroup?
-
- weak var listView: CPDFListView?
-
- private var fontPopover:NSPopover?
- private var ObjectPopover:NSPopover?
- override func viewDidLoad() {
- super.viewDidLoad()
- }
-
- override func initContentView() {
- super.initContentView()
-
- paneSelectorItem.properties = ComponentCSelectorProperty(iconImage:NSImage(named: "KMNImageNameListViewPopPane"))
- paneSelectorItem.setTarget(self, action: #selector(paneButtonClicked(_ :)))
-
- fontBoldSelectorItem.properties = ComponentCSelectorProperty(
- iconImage:NSImage(named: "KMNImageNameContentBold"))
- fontBoldSelectorItem.setTarget(self, action: #selector(fontBoldButtonClicked(_ :)))
-
- fontItalicSelectorItem.properties = ComponentCSelectorProperty(
- iconImage:NSImage(named: "KMNImageNameContentItalic"))
- fontItalicSelectorItem.setTarget(self, action: #selector(fontItalicButtonClicked(_ :)))
-
- fontSizeZoomOutButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopFontSizeZoomOut"),
- keepPressState: false)
- fontSizeZoomOutButton.setTarget(self, action: #selector(fontSizeZoomOutButtonClicked(_ :)))
-
- fontSizeZoomInButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopFontSizeZoomIn"),
- keepPressState: false)
- fontSizeZoomInButton.setTarget(self, action: #selector(fontSizeZoomInButtonClicked(_ :)))
-
- fontColorItem.properties = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: .clear)
- fontColorItem.delegate = self
-
- fontAlightButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopAlightLeft"),
- keepPressState: false)
- fontAlightButton.setTarget(self, action: #selector(fontAlightButtonClicked(_ :)))
-
- rotaLeftButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentRotateLeft"),
- keepPressState: false)
- rotaLeftButton.setTarget(self, action: #selector(rotateLeftButtonClicked(_ :)))
-
- rotaRightButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentRotateRight"),
- keepPressState: false)
- rotaRightButton.setTarget(self, action: #selector(rotateRightButtonClicked(_ :)))
-
- horizontalMirrorButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentHorMirr"),
- keepPressState: false)
- horizontalMirrorButton.setTarget(self, action: #selector(horizontalMirrorButtonClicked(_ :)))
-
- verticalMirrorButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentVerMirr"),
- keepPressState: false)
- verticalMirrorButton.setTarget(self, action: #selector(verticalMirrorButtonClicked(_ :)))
-
- alightButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightLeft"))
- alightButton.setTarget(self, action: #selector(alightButtonClicked(_ :)))
-
- cropRestButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentCropRest"),keepPressState: false)
- cropRestButton.setTarget(self, action: #selector(cropRestClicked(_ :)))
-
- cropSureButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentCropSure"),keepPressState: false)
- cropSureButton.setTarget(self, action: #selector(cropSureClicked(_ :)))
- }
-
- override func updateUIThemeColor() {
- super.updateUIThemeColor()
-
- lineBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider")
- contentBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup")
- contentBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/3-default")
- }
-
- override func updateUILanguage() {
- super.updateUILanguage()
-
- }
-
- //MARK: - Public
- public func closePopView() {
- if ObjectPopover?.isShown == true {
- ObjectPopover?.close()
- }
-
- if fontPopover?.isShown == true {
- fontPopover?.close()
- }
- }
-
- //MARK: - private
- private func congfigFontPopUI() {
- fontNameSelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: NSLocalizedString("", comment: ""))
- fontNameSelect.delegate = self
-
- var menuItemArr: [ComponentMenuitemProperty] = []
- for familyName in CPDFFont.familyNames {
- let fontNames = CPDFFont.fontNames(forFamilyName: familyName)
- let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: familyName,
- identifier: "1")
- var subMenuItemArr: [ComponentMenuitemProperty] = []
-
- for fontName in fontNames {
- let subItemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: fontName,identifier: "2")
- subMenuItemArr.append(subItemProperty)
- }
-
- itemProperty.subPropertys = subMenuItemArr
- menuItemArr.append(itemProperty)
- }
-
- fontNameSelect.updateMenuItemsArr(menuItemArr)
- }
-
- private func congfigSignImageUI() {
- rightConstraint.constant = 36
- imagePopView.display()
-
- cropButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentCrop"),
- keepPressState: false)
- cropButton.setTarget(self, action: #selector(cropImageButtonClicked(_ :)))
-
- replaceButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentReplace"),
- keepPressState: false)
- replaceButton.setTarget(self, action: #selector(replaceImageButtonClicked(_ :)))
-
- extractButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentExtract"),
- keepPressState: false)
- extractButton.setTarget(self, action: #selector(extractImageButtonClicked(_ :)))
-
- extractButton.isHidden = false
- }
-
- private func congfigMultpleImageUI() {
- rightConstraint.constant = 0
- imagePopView.display()
-
- cropButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentExtract"),
- keepPressState: false)
- cropButton.setTarget(self, action: #selector(extractImageButtonClicked(_ :)))
-
- replaceButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameContentReplace"),
- keepPressState: false)
- replaceButton.setTarget(self, action: #selector(alightButtonClicked(_ :)))
-
- extractButton.isHidden = true
- }
-
- func removeGroupView() {
- if extractGroupView != nil {
- extractGroupView?.removeFromSuperview()
- }
- extractButton.properties.state = .normal
- extractButton.reloadData()
- }
-
- //MARK: - Action
- @objc func paneButtonClicked(_ sender: NSView) {
- isOpenPane = !isOpenPane
- paneCallback?(isOpenPane)
- }
-
- @objc func fontBoldButtonClicked(_ sender: NSView) {
- listView?.setEditingTextarea_Bold()
- updatePDFViewCallback?()
- let textEditAreas = listView?.km_editingTextAreas()
- let newBolds:[Bool] = listView?.km_editTextAreasFontBolds(textEditAreas ?? []) ?? []
- if newBolds.first == false {
- fontBoldSelectorItem.properties.state = .normal
- fontBoldSelectorItem.reloadData()
- }
- }
-
- @objc func fontItalicButtonClicked(_ sender: NSView) {
- listView?.setEditingTextarea_Italic()
- updatePDFViewCallback?()
- let textEditAreas = listView?.km_editingTextAreas()
- let newItalics:[Bool] = listView?.km_editTextAreasFontItalics(textEditAreas ?? []) ?? []
- if newItalics.first == false {
- fontItalicSelectorItem.properties.state = .normal
- fontItalicSelectorItem.reloadData()
- }
- }
-
- @objc func fontUnderLineButtonClicked(_ sender: NSView) {
- listView?.setEditingTextarea_Under()
- updatePDFViewCallback?()
- let textEditAreas = listView?.km_editingTextAreas()
- let newUnders:[Bool] = listView?.km_editTextAreasFontUnder(textEditAreas ?? []) ?? []
-
- }
-
- @objc func fontStrikeoutLineButtonClicked(_ sender: NSView) {
- listView?.setEditingTextarea_Strikeout()
- updatePDFViewCallback?()
- let textEditAreas = listView?.km_editingTextAreas()
- let newStrikeouts:[Bool] = listView?.km_editTextAreasFontStrikeout(textEditAreas ?? []) ?? []
-
- }
-
- @objc func fontSizeZoomOutButtonClicked(_ sender: NSView) {
- listView?.zoomOutEditTextFontSize()
- updatePDFViewCallback?()
- }
-
- @objc func fontSizeZoomInButtonClicked(_ sender: NSView) {
- listView?.zoomInEditTextFontSize()
- updatePDFViewCallback?()
- }
-
- @objc func alightButtonClicked(_ sender: NSView) {
- if ObjectPopover?.isShown == true {
- ObjectPopover?.close()
- } else {
- let vc = KMNPopDetailsViewController(nibName: "KMNPopDetailsViewController", bundle: nil)
- let createFilePopover: NSPopover = NSPopover.init()
- createFilePopover.contentViewController = vc
- createFilePopover.delegate = self
- createFilePopover.animates = true
- createFilePopover.behavior = .semitransient
- createFilePopover.setValue(true, forKey: "shouldHideAnchor")
- createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 20, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
-
- if (editContentPopMode.editAreas.count == 2) {
- vc.detailPopType = .doubleObjectAlight
- } else if (editContentPopMode.editAreas.count > 2) {
- vc.detailPopType = .multpleObjectAlight
- }
- vc.objectChangeAlighCallback = { [weak self] alight in
- self?.objectAlign = alight
- self?.updatePDFViewCallback?()
- }
- ObjectPopover = createFilePopover
- vc.objectAlignType = objectAlign
- }
- }
-
- @objc func fontAlightButtonClicked(_ sender: NSView) {
- if fontPopover?.isShown == true {
- fontPopover?.close()
- } else {
- let vc = KMNPopDetailsViewController(nibName: "KMNPopDetailsViewController", bundle: nil)
- let createFilePopover: NSPopover = NSPopover.init()
- createFilePopover.contentViewController = vc
- createFilePopover.delegate = self
- createFilePopover.animates = true
- createFilePopover.behavior = .semitransient
- createFilePopover.setValue(true, forKey: "shouldHideAnchor")
- createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 20, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
-
- vc.detailPopType = .contentEditAlight
- vc.fontChangeAlighCallback = { [weak self] alight in
- self?.listView?.setEditingTextarea_Alignment(align: alight)
- self?.fontAlight = alight
- self?.updatePDFViewCallback?()
- }
- fontPopover = createFilePopover
- vc.fontAlight = fontAlight
-
- }
- }
-
- @objc func rotateLeftButtonClicked(_ sender: NSView) {
- listView?.leftRotateAction()
- updatePDFViewCallback?()
- }
-
- @objc func rotateRightButtonClicked(_ sender: NSView) {
- listView?.rightRotateAction()
- updatePDFViewCallback?()
- }
-
- @objc func horizontalMirrorButtonClicked(_ sender: NSView) {
- listView?.reverseYAction()
- updatePDFViewCallback?()
- }
-
- @objc func verticalMirrorButtonClicked(_ sender: NSView) {
- listView?.reverseXAction()
- updatePDFViewCallback?()
- }
-
- @objc func cropImageButtonClicked(_ sender: NSView) {
- listView?.cropAction()
- }
-
- @objc func replaceImageButtonClicked(_ sender: NSView) {
- listView?.replaceImageEdit()
- updatePDFViewCallback?()
- }
-
- @objc func extractImageButtonClicked(_ sender: NSView) {
- if extractGroupView?.superview != nil {
- removeGroupView()
- } else {
- var viewHeight: CGFloat = 8
- var menuItemArr: [ComponentMenuitemProperty] = []
- for i in ["jpg", "png", "pdf"] {
- let properties_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: KMLocalizedString(i))
- menuItemArr.append(properties_Menuitem)
- viewHeight += 36
- }
-
- if extractGroupView == nil {
- extractGroupView = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
- }
- extractGroupView?.groupDelegate = self
- extractGroupView?.frame = CGRectMake(310, 0, 72, viewHeight)
- extractGroupView?.updateGroupInfo(menuItemArr)
-
- var point = CGPoint(x: sender.frame.origin.x + sender.frame.size.width/2, y: CGRectGetMaxY(sender.frame))
- point = self.view.convert(point, to: nil)
- extractGroupView?.showWithPoint(point, relativeTo:sender)
-
- extractButton.properties.state = .pressed
- extractButton.reloadData()
- }
- }
-
- @objc func cropRestClicked(_ sender: NSView) {
- listView?.cropRestAction()
- }
-
- @objc func cropSureClicked(_ sender: NSView) {
- listView?.cropComfirmAction()
- }
-
- @objc func fontColorChange(_ sender: Any) {
- if let color = (sender as? NSColorPanel)?.color {
- listView?.changeEditingTextarea_Color(color: color)
- updatePDFViewCallback?()
- }
- }
-
- }
- //MARK: - ComponentCColorDelegate
- extension KMNPopContentEditViewController: ComponentCColorDelegate {
- func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
- if (view == fontColorItem) {
- fontColorItem.properties?.state = .normal
- fontColorItem.reloadData()
-
- let colorPanel = NSColorPanel.shared
-
- colorPanel.setTarget(self)
- colorPanel.showsAlpha = false
- colorPanel.setAction(#selector(self.fontColorChange(_:)))
- colorPanel.orderFront(nil)
- }
- }
-
- }
- //MARK: - ComponentSelectDelegate
- extension KMNPopContentEditViewController: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- if(view == fontNameSelect) {
- if menuItemProperty?.identifier == "1" {
- let familyName = fontNameSelect.properties.text ?? "Helvetica"
- let styles = CPDFFont.fontNames(forFamilyName: familyName)
-
- compdfFont = CPDFFont(familyName: familyName, fontStyle: styles.first ?? "")
- listView?.setEditingTextarea_font(font: compdfFont ?? CPDFFont(familyName: "Helvetica", fontStyle: ""))
- } else if menuItemProperty?.identifier == "2" { //字体样式
- compdfFont = CPDFFont(familyName: compdfFont?.familyName ?? "Helvetica", fontStyle: menuItemProperty?.text ?? "")
- listView?.setEditingTextarea_font(font: compdfFont ?? CPDFFont(familyName: "Helvetica", fontStyle: ""))
- }
- }
- }
- }
- //MARK: - ComponentSelectDelegate
- extension KMNPopContentEditViewController: NSPopoverDelegate {
- func popoverWillClose(_ notification: Notification) {
- if fontPopover == (notification.object as? NSPopover) {
- if(fontAlightButton.properties.state == .pressed) {
- fontAlightButton.properties.state = .normal
- fontAlightButton.reloadData()
- }
- } else if ObjectPopover == (notification.object as? NSPopover) {
- if(alightButton.properties.state == .pressed) {
- alightButton.properties.state = .normal
- alightButton.reloadData()
- }
- }
-
- }
- }
- extension KMNPopContentEditViewController: ComponentGroupDelegate {
- func componentGroupDidDismiss(group: ComponentGroup?) {
- removeGroupView()
-
- extractButton.properties.state = .normal
- extractButton.reloadData()
- }
-
- func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
- if group == extractGroupView {
- if let selItem = menuItemProperty {
- let index = group?.menuItemArr.firstIndex(of: selItem)
- if index == 0 {
- listView?.exportEditingImageAreasAction(format: "jpg")
- } else if index == 1 {
- listView?.exportEditingImageAreasAction(format: "png")
- } else if index == 2 {
- listView?.exportEditingImageAreasAction(format: "pdf")
- }
- }
- }
- }
- }
|