KMRightSideController.swift 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. //
  2. // KMRightSideController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/11/12.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. @objc protocol KMRightSideControllerDelegate: AnyObject {
  10. @objc optional func kmRightSideControllerDidContendVCUpdated(_ controller: KMRightSideController)
  11. //OCR
  12. @objc func kmRightSideControllerOCRShowTypeChange(_ controller: KMRightSideController, _ type: KMOCRShowType)
  13. @objc func kmRightSideControllerOCRDoneAction(_ controller: KMRightSideController, _ model: KMOCRModel)
  14. @objc func kmRightSideControllerRotateLeft(_ annotations: [CPDFStampAnnotation], withPDFView pdfView: CPDFListView?)
  15. @objc func kmRightSideControllerRotateRight(_ annotations: [CPDFStampAnnotation], withPDFView pdfView: CPDFListView?)
  16. @objc func kmRightSideControllerShowMeasureSetting(_ controller: KMRightSideController)
  17. }
  18. class KMRightSideController: NSViewController {
  19. @IBOutlet var contendView: NSView!
  20. @IBOutlet var contendLeftDivider: ComponentDivider!
  21. @IBOutlet var headerBGView: NSView!
  22. @IBOutlet var titleLabel: NSTextField!
  23. @IBOutlet var headerRightButton: ComponentButton!
  24. @IBOutlet var infoContendView: NSView!
  25. @IBOutlet var infoContendTopConst: NSLayoutConstraint!
  26. @IBOutlet var infoScrollView: KMScrollView!
  27. @IBOutlet var emptyView: ComponentEmpty!
  28. var pdfView: CPDFListView?
  29. var viewManager: KMPDFViewManager?
  30. //Controller
  31. //Markup
  32. var highlight_Controller: KMHighlightController?
  33. var note_Controller: KMNoteController?
  34. var pen_Controller: KMPenController?
  35. var eraser_Controller: KMEraserController?
  36. var rectangle_Controller: KMRectangleController?
  37. var line_Controller: KMLineController?
  38. var freeText_Controller: KMTextBoxController?
  39. var stamplist_Controller: KMStampListController?
  40. var stamp_Controller: KMStampController?
  41. var signature_Controller: KMSignatureController?
  42. var signatureList_Controller: KMSignatureListController?
  43. var measure_Controller: KMMeasureController?
  44. //Edit
  45. var edit_textController: KMEditPDFTextPropertyViewController?
  46. var edit_imageController: KMEditImageController?
  47. var edit_linkController: KMLinkViewController?
  48. var edit_cropController: KMCropPropertyController?
  49. var edit_alignmentController: KMNAlignmentController?
  50. //Form
  51. var form_fieldController: FormsTextFieldController?
  52. var form_checkBoxController: FormsCheckBoxController?
  53. var form_radioController: FormsRadioController?
  54. var form_listController: FormsListController?
  55. var form_buttonController: FormsButtonController?
  56. var form_digitalSignController: FormsDigitalSignController?
  57. //Fill
  58. var fill_tickController: FillTickController?
  59. var fill_dateController: FillDateController?
  60. //
  61. //OCR
  62. var tool_OCRController: KMOCRController?
  63. var contentViewController: NSViewController?
  64. weak open var delegate: KMRightSideControllerDelegate?
  65. //MARK: - func
  66. override func viewDidLoad() {
  67. super.viewDidLoad()
  68. // Do view setup here.
  69. setupUI()
  70. setupContentController()
  71. }
  72. //MARK: - Get
  73. func getValidAnnotations() -> [CPDFAnnotation] {
  74. return []
  75. }
  76. //MARK: - Set
  77. func setupUI() {
  78. contendView.wantsLayer = true
  79. contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
  80. contendLeftDivider.properties = ComponentDividerProperty(type: .vertical)
  81. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  82. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
  83. emptyView.properties = ComponentEmptyProperty(emptyType: .noWatermark, text: KMLocalizedString("No identical attributes"), subText: "")
  84. }
  85. func updateTitleLabel() {
  86. let subToolMode = viewManager?.subToolMode ?? .None
  87. let annotations: [CPDFAnnotation] = self.pdfView?.activeAnnotations as? [CPDFAnnotation] ?? []
  88. var firstAnnotation: CPDFAnnotation?
  89. if let firstObject = annotations.first {
  90. firstAnnotation = firstObject
  91. }
  92. titleLabel.stringValue = ""
  93. if contentViewController is KMHighlightController {
  94. titleLabel.stringValue = KMLocalizedString("Highlight")
  95. if let annotation = firstAnnotation, annotation is CPDFMarkupAnnotation {
  96. let markupAnnotation = firstAnnotation as! CPDFMarkupAnnotation
  97. if markupAnnotation.markupType() == .underline {
  98. titleLabel.stringValue = KMLocalizedString("Underline")
  99. } else if markupAnnotation.markupType() == .squiggly {
  100. titleLabel.stringValue = KMLocalizedString("Wavyline")
  101. } else if markupAnnotation.markupType() == .strikeOut {
  102. titleLabel.stringValue = KMLocalizedString("Strikethrough")
  103. }
  104. } else {
  105. if viewManager?.subToolMode == .Underline {
  106. titleLabel.stringValue = KMLocalizedString("Underline")
  107. } else if viewManager?.subToolMode == .Waveline {
  108. titleLabel.stringValue = KMLocalizedString("Wavyline")
  109. } else if viewManager?.subToolMode == .Strikethrough {
  110. titleLabel.stringValue = KMLocalizedString("Strikethrough")
  111. }
  112. }
  113. } else if (contentViewController is KMNoteController) {
  114. titleLabel.stringValue = KMLocalizedString("Note")
  115. } else if (contentViewController is KMPenController) {
  116. titleLabel.stringValue = KMLocalizedString("Pen")
  117. } else if (contentViewController is KMEraserController) {
  118. titleLabel.stringValue = KMLocalizedString("Eraser")
  119. } else if (contentViewController is KMLineController) {
  120. if let annotation = firstAnnotation, annotation is CPDFLineAnnotation {
  121. let lineAnnotation = firstAnnotation as! CPDFLineAnnotation
  122. if lineAnnotation.type == "Line" {
  123. titleLabel.stringValue = KMLocalizedString("Line")
  124. } else if lineAnnotation.type == "Arrow" {
  125. titleLabel.stringValue = KMLocalizedString("Arrow")
  126. }
  127. } else if subToolMode == .Arrow {
  128. titleLabel.stringValue = KMLocalizedString("Arrow")
  129. } else if subToolMode == .Line {
  130. titleLabel.stringValue = KMLocalizedString("Line")
  131. }
  132. } else if (contentViewController is KMRectangleController) {
  133. if let annotation = firstAnnotation, annotation is CPDFSquareAnnotation {
  134. titleLabel.stringValue = KMLocalizedString("Rectangle")
  135. } else if let annotation = firstAnnotation, annotation is CPDFCircleAnnotation {
  136. titleLabel.stringValue = KMLocalizedString("Circle")
  137. } else if subToolMode == .Rectangle {
  138. titleLabel.stringValue = KMLocalizedString("Rectangle")
  139. } else if subToolMode == .Circle {
  140. titleLabel.stringValue = KMLocalizedString("Circle")
  141. }
  142. } else if (contentViewController is KMTextBoxController) {
  143. titleLabel.stringValue = KMLocalizedString("Text Box")
  144. } else if (contentViewController is KMEditPDFTextPropertyViewController) {
  145. titleLabel.stringValue = KMLocalizedString("Text")
  146. } else if (contentViewController is KMEditImageController) {
  147. titleLabel.stringValue = KMLocalizedString("Image")
  148. } else if (contentViewController is KMLinkViewController) {
  149. titleLabel.stringValue = KMLocalizedString("Link")
  150. } else if (contentViewController is KMCropPropertyController) {
  151. titleLabel.stringValue = KMLocalizedString("Crop")
  152. } else if (contentViewController is KMStampListController) || (contentViewController is KMStampController) {
  153. titleLabel.stringValue = KMLocalizedString("Stamp")
  154. } else if (contentViewController is KMSignatureListController) || (contentViewController is KMSignatureController) {
  155. titleLabel.stringValue = KMLocalizedString("Sign")
  156. } else if (contentViewController is KMMeasureController) {
  157. titleLabel.stringValue = KMLocalizedString("Measure")
  158. } else if (contentViewController is FormsTextFieldController) {
  159. titleLabel.stringValue = KMLocalizedString("Text Field")
  160. } else if (contentViewController is FormsCheckBoxController) {
  161. titleLabel.stringValue = KMLocalizedString("Check Box")
  162. } else if (contentViewController is FormsRadioController) {
  163. titleLabel.stringValue = KMLocalizedString("Radio Button")
  164. } else if (contentViewController is FormsButtonController) {
  165. titleLabel.stringValue = KMLocalizedString("Button")
  166. } else if (contentViewController is FormsListController) {
  167. if let annotation = firstAnnotation, annotation is CPDFChoiceWidgetAnnotation {
  168. let lineAnnotation = firstAnnotation as! CPDFChoiceWidgetAnnotation
  169. if lineAnnotation.isListChoice == true {
  170. titleLabel.stringValue = KMLocalizedString("List")
  171. } else {
  172. titleLabel.stringValue = KMLocalizedString("Dropdown")
  173. }
  174. } else if subToolMode == .Form_list {
  175. titleLabel.stringValue = KMLocalizedString("List")
  176. } else if subToolMode == .Form_dropdown {
  177. titleLabel.stringValue = KMLocalizedString("Dropdown")
  178. }
  179. } else if (contentViewController is FillTickController) {
  180. titleLabel.stringValue = KMLocalizedString("Fill")
  181. } else if (contentViewController is FillDateController) {
  182. titleLabel.stringValue = KMLocalizedString("Date")
  183. } else if (contentViewController is KMOCRController) {
  184. titleLabel.stringValue = KMLocalizedString("OCR")
  185. } else if (contentViewController is FormsDigitalSignController) {
  186. titleLabel.stringValue = KMLocalizedString("Signature")
  187. }
  188. else {
  189. }
  190. }
  191. //MARK: - Setup
  192. func setupContentController() {
  193. /**
  194. Case1:选中指定模式:显示指定模式的属性设置界面,例如橡皮擦。
  195. Case2:未选中模式:根据选中的注释显示指定属性设置界面
  196. 1、筛选出指定模式下对应的右边界面,进行显示。
  197. 2、再判断是否有选中注释,多选不同类型注释时,判断为未选中注释。
  198. 3、判断选中指定类型的注释,或者选中的模式,都展示对应的界面。
  199. */
  200. /**
  201. 只在指定模式下可以选中特定注释:
  202. 编辑模式下:可以选中编辑块跟Link注释
  203. Form模式下:可以选中Form注释
  204. */
  205. contentViewController?.view.removeFromSuperview()
  206. contentViewController = nil
  207. let toolMode = viewManager?.toolMode ?? .None
  208. let subToolMode = viewManager?.subToolMode ?? .None
  209. let annotations: [CPDFAnnotation] = self.pdfView?.activeAnnotations as? [CPDFAnnotation] ?? []
  210. if toolMode == .Edit {
  211. //MARK: -Edit编辑
  212. if subToolMode == .Edit_Link {
  213. //链接
  214. if edit_linkController == nil {
  215. edit_linkController = KMLinkViewController.init()
  216. }
  217. edit_linkController?.delegate = self
  218. edit_linkController?.pdfView = self.pdfView
  219. contentViewController = edit_linkController
  220. } else if subToolMode == .Edit_Crop {
  221. if edit_cropController == nil {
  222. edit_cropController = KMCropPropertyController.init()
  223. }
  224. contentViewController = edit_cropController
  225. } else {
  226. if pdfView?.km_EditingAreas().isEmpty == true {
  227. //未选中文字跟图片
  228. if subToolMode == .Edit_text {
  229. if edit_textController == nil {
  230. edit_textController = KMEditPDFTextPropertyViewController.init()
  231. }
  232. edit_textController?.pdfView = self.pdfView
  233. contentViewController = edit_textController
  234. } else if subToolMode == .Edit_Image {
  235. if edit_imageController == nil {
  236. edit_imageController = KMEditImageController.init()
  237. }
  238. edit_imageController?.pdfView = self.pdfView
  239. contentViewController = edit_imageController
  240. }
  241. } else if pdfView?.km_editingImageAreas().isEmpty == true && pdfView?.km_editingTextAreas().isEmpty == false {
  242. //编辑文字
  243. if edit_textController == nil {
  244. edit_textController = KMEditPDFTextPropertyViewController.init()
  245. }
  246. edit_textController?.pdfView = self.pdfView
  247. contentViewController = edit_textController
  248. } else if pdfView?.km_editingImageAreas().isEmpty == false && pdfView?.km_editingTextAreas().isEmpty == true {
  249. //编辑图片
  250. if edit_imageController == nil {
  251. edit_imageController = KMEditImageController.init()
  252. }
  253. edit_imageController?.pdfView = self.pdfView
  254. contentViewController = edit_imageController
  255. } else if pdfView?.km_editingImageAreas().isEmpty == false && pdfView?.km_editingTextAreas().isEmpty == false {
  256. //混选
  257. if edit_alignmentController == nil {
  258. edit_alignmentController = KMNAlignmentController.init()
  259. }
  260. edit_alignmentController?.delegate = self
  261. contentViewController = edit_alignmentController
  262. }
  263. }
  264. } else if toolMode == .Form {
  265. var firstAnnotation: CPDFAnnotation?
  266. if annotations.count > 0 {
  267. firstAnnotation = annotations.first
  268. }
  269. var controlType: CPDFWidgetControlType = .unknownControl
  270. var isListChoice: Int = -1
  271. if let annotation = firstAnnotation as? CPDFButtonWidgetAnnotation {
  272. controlType = annotation.controlType()
  273. } else if let annotation = firstAnnotation as? CPDFChoiceWidgetAnnotation {
  274. isListChoice = 0
  275. if annotation.isListChoice {
  276. isListChoice = 1
  277. }
  278. }
  279. if firstAnnotation is CPDFTextWidgetAnnotation {
  280. if form_fieldController == nil {
  281. form_fieldController = FormsTextFieldController.init()
  282. }
  283. form_fieldController?.pdfView = self.pdfView
  284. contentViewController = form_fieldController
  285. } else if controlType == .checkBoxControl {
  286. if form_checkBoxController == nil {
  287. form_checkBoxController = FormsCheckBoxController.init()
  288. }
  289. form_checkBoxController?.pdfView = self.pdfView
  290. contentViewController = form_checkBoxController
  291. } else if controlType == .radioButtonControl {
  292. if form_radioController == nil {
  293. form_radioController = FormsRadioController.init()
  294. }
  295. form_radioController?.pdfView = self.pdfView
  296. contentViewController = form_radioController
  297. } else if isListChoice >= 0 {
  298. if form_listController == nil {
  299. form_listController = FormsListController.init()
  300. }
  301. form_listController?.pdfView = self.pdfView
  302. form_listController?.viewManager = self.viewManager
  303. contentViewController = form_listController
  304. form_listController?.clearData()
  305. } else if controlType == .pushButtonControl {
  306. if form_buttonController == nil {
  307. form_buttonController = FormsButtonController.init()
  308. }
  309. form_buttonController?.pdfView = self.pdfView
  310. contentViewController = form_buttonController
  311. } else if firstAnnotation is CPDFSignatureWidgetAnnotation {
  312. if form_digitalSignController == nil {
  313. form_digitalSignController = FormsDigitalSignController.init()
  314. }
  315. form_digitalSignController?.pdfView = self.pdfView
  316. contentViewController = form_digitalSignController
  317. }
  318. } else {
  319. let exitMulitAnnotation = pdfView?.isMultiAnnotation(annotations)
  320. if exitMulitAnnotation == true {
  321. return
  322. }
  323. var firstAnnotation: CPDFAnnotation?
  324. if annotations.count > 0 {
  325. firstAnnotation = annotations.first
  326. }
  327. if viewManager?.viewToolsType == .Content_Selection {
  328. if edit_cropController == nil {
  329. edit_cropController = KMCropPropertyController.init()
  330. }
  331. contentViewController = edit_cropController
  332. } else if firstAnnotation is CPDFMarkupAnnotation || subToolMode == .Highlight || subToolMode == .Underline || subToolMode == .Waveline || subToolMode == .Strikethrough {
  333. if highlight_Controller == nil {
  334. highlight_Controller = KMHighlightController.init()
  335. }
  336. highlight_Controller?.pdfView = self.pdfView
  337. contentViewController = highlight_Controller
  338. } else if firstAnnotation is CPDFFreeTextAnnotation ||
  339. subToolMode == .Text ||
  340. subToolMode == .fill_date {
  341. if firstAnnotation is CSelfSignAnnotationFreeText || subToolMode == .fill_date {
  342. if fill_dateController == nil {
  343. fill_dateController = FillDateController.init()
  344. }
  345. fill_dateController?.pdfView = self.pdfView
  346. contentViewController = fill_dateController
  347. } else {
  348. if freeText_Controller == nil {
  349. freeText_Controller = KMTextBoxController.init()
  350. }
  351. freeText_Controller?.pdfView = self.pdfView
  352. contentViewController = freeText_Controller
  353. }
  354. } else if firstAnnotation is CPDFTextAnnotation || subToolMode == .Note {
  355. if note_Controller == nil {
  356. note_Controller = KMNoteController.init()
  357. }
  358. note_Controller?.pdfView = self.pdfView
  359. contentViewController = note_Controller
  360. } else if firstAnnotation is CPDFInkAnnotation || subToolMode == .Pen {
  361. if pen_Controller == nil {
  362. pen_Controller = KMPenController.init()
  363. }
  364. pen_Controller?.pdfView = self.pdfView
  365. contentViewController = pen_Controller
  366. } else if subToolMode == .Eraser {
  367. if eraser_Controller == nil {
  368. eraser_Controller = KMEraserController.init()
  369. }
  370. contentViewController = eraser_Controller
  371. } else if firstAnnotation is CPDFCircleAnnotation || firstAnnotation is CPDFSquareAnnotation || subToolMode == .Rectangle || subToolMode == .Circle {
  372. if rectangle_Controller == nil {
  373. rectangle_Controller = KMRectangleController.init()
  374. }
  375. rectangle_Controller?.pdfView = self.pdfView
  376. contentViewController = rectangle_Controller
  377. } else if firstAnnotation is CPDFLineAnnotation || firstAnnotation is CPDFPolylineAnnotation || firstAnnotation is CPDFPolygonAnnotation || subToolMode == .Line || subToolMode == .Arrow || subToolMode == .Measure {
  378. var isMeasure = false
  379. if let annotation = firstAnnotation as? CPDFLineAnnotation, annotation.isMeasure == true {
  380. isMeasure = true
  381. } else if let _ = firstAnnotation as? CPDFPolylineAnnotation {
  382. isMeasure = true
  383. } else if let _ = firstAnnotation as? CPDFPolygonAnnotation {
  384. isMeasure = true
  385. } else if subToolMode == .Measure {
  386. isMeasure = true
  387. }
  388. if isMeasure {
  389. if measure_Controller == nil {
  390. measure_Controller = KMMeasureController.init()
  391. }
  392. measure_Controller?.pdfView = self.pdfView
  393. measure_Controller?.viewManager = self.viewManager
  394. contentViewController = measure_Controller
  395. } else {
  396. if line_Controller == nil {
  397. line_Controller = KMLineController.init()
  398. }
  399. line_Controller?.pdfView = self.pdfView
  400. contentViewController = line_Controller
  401. }
  402. } else if firstAnnotation is CPDFStampAnnotation {
  403. if firstAnnotation is CSelfSignAnnotation {
  404. if fill_tickController == nil {
  405. fill_tickController = FillTickController.init()
  406. }
  407. fill_tickController?.viewManager = self.viewManager
  408. fill_tickController?.pdfView = self.pdfView
  409. contentViewController = fill_tickController
  410. } else {
  411. if stamp_Controller == nil {
  412. stamp_Controller = KMStampController.init()
  413. }
  414. stamp_Controller?.pdfView = self.pdfView
  415. stamp_Controller?.delegate = self
  416. contentViewController = stamp_Controller
  417. }
  418. } else if subToolMode == .Stamp {
  419. if stamplist_Controller == nil {
  420. stamplist_Controller = KMStampListController.init()
  421. stamplist_Controller?.delegate = self
  422. }
  423. stamplist_Controller?.pdfView = self.pdfView
  424. contentViewController = stamplist_Controller
  425. } else if firstAnnotation is CPDFSignatureAnnotation {
  426. if signature_Controller == nil {
  427. signature_Controller = KMSignatureController.init()
  428. }
  429. signature_Controller?.pdfView = self.pdfView
  430. contentViewController = signature_Controller
  431. } else if subToolMode == .Sign || subToolMode == .fill_sign {
  432. if signatureList_Controller == nil {
  433. signatureList_Controller = KMSignatureListController.init()
  434. }
  435. signatureList_Controller?.pdfView = self.pdfView
  436. contentViewController = signatureList_Controller
  437. } else if subToolMode == .Fill_tick ||
  438. subToolMode == .fill_fork ||
  439. subToolMode == .fill_rectangle ||
  440. subToolMode == .fill_line ||
  441. subToolMode == .fill_dot {
  442. if fill_tickController == nil {
  443. fill_tickController = FillTickController.init()
  444. }
  445. fill_tickController?.viewManager = self.viewManager
  446. fill_tickController?.pdfView = self.pdfView
  447. contentViewController = fill_tickController
  448. } else if subToolMode == .Measure {
  449. if measure_Controller == nil {
  450. measure_Controller = KMMeasureController.init()
  451. }
  452. measure_Controller?.pdfView = self.pdfView
  453. measure_Controller?.viewManager = self.viewManager
  454. contentViewController = measure_Controller
  455. } else if subToolMode == .Tool_OCR {
  456. if tool_OCRController == nil {
  457. tool_OCRController = KMOCRController.init()
  458. tool_OCRController?.typeChange = { [unowned self] controller, type in
  459. delegate?.kmRightSideControllerOCRShowTypeChange(self, type)
  460. }
  461. tool_OCRController?.doneAction = { [unowned self] controller, model in
  462. delegate?.kmRightSideControllerOCRDoneAction(self, model)
  463. }
  464. }
  465. tool_OCRController?.pdfView = self.pdfView
  466. contentViewController = tool_OCRController
  467. } else {
  468. }
  469. }
  470. if let contendVC = contentViewController {
  471. contendVC.view.frame = infoContendView.bounds
  472. contendVC.view.autoresizingMask = [.width, .height]
  473. // infoContendView.addSubview(contendVC.view)
  474. // infoScrollView.contentViewSize = CGSizeMake(264, 600)
  475. infoScrollView.documentView = contendVC.view
  476. // infoScrollView.layout()
  477. delegate?.kmRightSideControllerDidContendVCUpdated?(self)
  478. }
  479. if let _ = contentViewController {
  480. infoContendView.isHidden = false
  481. headerBGView.isHidden = false
  482. emptyView.isHidden = true
  483. } else {
  484. infoContendView.isHidden = true
  485. headerBGView.isHidden = true
  486. emptyView.isHidden = false
  487. }
  488. updateTitleLabel()
  489. }
  490. //MARK: - reloadData
  491. func reloadContendTopConst() {
  492. infoContendTopConst.constant = 40
  493. headerBGView.isHidden = false
  494. if contentViewController is KMHighlightController {
  495. //高亮
  496. if CPDFMarkupAnnotation.isMarkupAnnotationsContainMultiType((contentViewController as! KMHighlightController).getValidAnnotations()) {
  497. infoContendTopConst.constant = 0
  498. headerBGView.isHidden = true
  499. }
  500. } else if contentViewController is KMLineController {
  501. //线段
  502. if CPDFLineAnnotation.isLineAnnotationsContainMultiType((contentViewController as! KMLineController).getValidAnnotations()) {
  503. infoContendTopConst.constant = 0
  504. headerBGView.isHidden = true
  505. }
  506. } else if contentViewController is KMRectangleController {
  507. //图形
  508. let annotations: [CPDFAnnotation] = self.pdfView?.activeAnnotations as? [CPDFAnnotation] ?? []
  509. if CPDFAnnotation.isShapeAnnotationsContainMultiType(annotations) {
  510. infoContendTopConst.constant = 0
  511. headerBGView.isHidden = true
  512. }
  513. } else if contentViewController is KMNAlignmentController {
  514. //对齐
  515. infoContendTopConst.constant = 0
  516. headerBGView.isHidden = true
  517. }
  518. }
  519. func reloadTopRightButtonInfo() {
  520. headerRightButton.isHidden = true
  521. if contentViewController is KMStampListController {
  522. let stampListVC = contentViewController as! KMStampListController
  523. if stampListVC.stampType == .dynamic {
  524. headerRightButton.isHidden = false
  525. headerRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "stampDynamic_Setting"), keepPressState: false)
  526. } else if stampListVC.stampType == .custom {
  527. headerRightButton.isHidden = false
  528. headerRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "watermark_template_add"), keepPressState: false)
  529. }
  530. } else if contentViewController is KMSignatureListController {
  531. headerRightButton.isHidden = false
  532. headerRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "watermark_template_add"), keepPressState: false)
  533. } else if contentViewController is KMOCRController {
  534. headerRightButton.isHidden = false
  535. headerRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "tools_report"), keepPressState: false)
  536. headerRightButton.toolTip = KMLocalizedString("If you have any feedback or suggestions for improvements to the OCR feature, please contact us.")
  537. } else if contentViewController is KMMeasureController {
  538. headerRightButton.isHidden = false
  539. headerRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "stampDynamic_Setting"), keepPressState: false)
  540. } else if contentViewController is KMCropPropertyController {
  541. headerRightButton.isHidden = false
  542. headerRightButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "icon_recover"), keepPressState: false)
  543. }
  544. headerRightButton.setTarget(self, action: #selector(headerRightButtonClicked(_:)))
  545. }
  546. func reloadData() {
  547. let toolMode = viewManager?.toolMode ?? .None
  548. let subToolMode = viewManager?.subToolMode ?? .None
  549. if (contentViewController is KMHighlightController) {
  550. (contentViewController as? KMHighlightController)?.viewManager = viewManager
  551. (contentViewController as? KMHighlightController)?.reloadData()
  552. } else if (contentViewController is KMNoteController) {
  553. (contentViewController as? KMNoteController)?.reloadData()
  554. } else if (contentViewController is KMPenController) {
  555. (contentViewController as? KMPenController)?.reloadData()
  556. } else if (contentViewController is KMEraserController) {
  557. (contentViewController as? KMEraserController)?.reloadData()
  558. } else if (contentViewController is KMLineController) {
  559. (contentViewController as? KMLineController)?.viewManager = viewManager
  560. (contentViewController as? KMLineController)?.reloadData()
  561. } else if (contentViewController is KMRectangleController) {
  562. (contentViewController as? KMRectangleController)?.viewManager = viewManager
  563. (contentViewController as? KMRectangleController)?.reloadData()
  564. } else if (contentViewController is KMTextBoxController) {
  565. (contentViewController as? KMTextBoxController)?.reloadData()
  566. } else if (contentViewController is KMStampController) {
  567. (contentViewController as? KMStampController)?.reloadData()
  568. } else if (contentViewController is KMSignatureListController) {
  569. (contentViewController as? KMSignatureListController)?.reloadData()
  570. } else if (contentViewController is FormsTextFieldController) {
  571. (contentViewController as? FormsTextFieldController)?.reloadData()
  572. } else if (contentViewController is FormsCheckBoxController) {
  573. (contentViewController as? FormsCheckBoxController)?.reloadData()
  574. } else if (contentViewController is FormsRadioController) {
  575. (contentViewController as? FormsRadioController)?.reloadData()
  576. } else if (contentViewController is FormsListController) {
  577. (contentViewController as? FormsListController)?.reloadData()
  578. } else if (contentViewController is FormsButtonController) {
  579. (contentViewController as? FormsButtonController)?.reloadData()
  580. } else if (contentViewController is FormsDigitalSignController) {
  581. (contentViewController as? FormsDigitalSignController)?.reloadData()
  582. } else if (contentViewController is FillTickController) {
  583. (contentViewController as? FillTickController)?.reloadData()
  584. } else if (contentViewController is FillDateController) {
  585. (contentViewController as? FillDateController)?.reloadData()
  586. } else if (contentViewController is KMMeasureController) {
  587. (contentViewController as? KMMeasureController)?.reloadData()
  588. } else if (contentViewController is KMSignatureController) {
  589. (contentViewController as? KMSignatureController)?.reloadData()
  590. } else if (contentViewController is KMEditPDFTextPropertyViewController) {
  591. (contentViewController as? KMEditPDFTextPropertyViewController)?.reloadData()
  592. } else if (contentViewController is KMEditImageController) {
  593. (contentViewController as? KMEditImageController)?.reloadData()
  594. } else if (contentViewController is KMLinkViewController) {
  595. (contentViewController as? KMLinkViewController)?.reloadData()
  596. } else if (contentViewController is KMCropPropertyController) {
  597. (contentViewController as? KMCropPropertyController)?.reloadData()
  598. } else if (contentViewController is KMNAlignmentController) {
  599. if let areas = pdfView?.km_EditingAreas(), areas.count > 2 {
  600. (contentViewController as? KMNAlignmentController)?.updateMulti(true)
  601. } else {
  602. (contentViewController as? KMNAlignmentController)?.updateMulti(false)
  603. }
  604. }
  605. if toolMode == .Markup {
  606. if (subToolMode == .Highlight ||
  607. subToolMode == .Underline ||
  608. subToolMode == .Waveline ||
  609. subToolMode == .Strikethrough) && (contentViewController is KMHighlightController) {
  610. (contentViewController as? KMHighlightController)?.reloadData()
  611. }
  612. }
  613. reloadContendTopConst()
  614. reloadTopRightButtonInfo()
  615. }
  616. public func reloadDataWithPDFView(pdfView: CPDFListView) {
  617. self.pdfView = pdfView
  618. setupContentController()
  619. reloadData()
  620. }
  621. //MARK: - Action
  622. @objc func headerRightButtonClicked(_ button: ComponentButton) {
  623. if contentViewController is KMStampListController {
  624. let stampListVC = contentViewController as! KMStampListController
  625. if stampListVC.stampType == .dynamic {
  626. stampListVC.showDynamicSetting()
  627. } else if stampListVC.stampType == .custom {
  628. stampListVC.createCustomStamp()
  629. }
  630. } else if contentViewController is KMSignatureListController {
  631. let vc = contentViewController as! KMSignatureListController
  632. vc.createCustomStamp()
  633. } else if contentViewController is KMMeasureController {
  634. delegate?.kmRightSideControllerShowMeasureSetting(self)
  635. } else if contentViewController is KMCropPropertyController {
  636. } else if contentViewController is KMOCRController {
  637. let help = KMUserFeekbackHanddler()
  638. help.showFeekbackWindow(with: KMLocalizedString("Propose a New Feature", comment: ""))
  639. }
  640. }
  641. //MARK: - 重新刷新编辑中内容
  642. public func reloadEditingAreas() {
  643. if contentViewController is KMEditPDFTextPropertyViewController {
  644. (contentViewController as! KMEditPDFTextPropertyViewController).reloadData()
  645. } else if contentViewController is KMEditImageController {
  646. (contentViewController as! KMEditImageController).reloadData()
  647. }
  648. }
  649. //MARK: - 裁剪模式下刷新文档
  650. public func reloadCropDocument(_ pdfview: CPDFListView?) {
  651. if viewManager?.subToolMode == .Edit_Crop && (contentViewController is KMCropPropertyController) {
  652. (contentViewController as! KMCropPropertyController).pdfView = pdfview
  653. (contentViewController as! KMCropPropertyController).reloadData()
  654. }
  655. }
  656. }
  657. //MARK: - KMStampListControllerDelegate
  658. extension KMRightSideController: KMStampListControllerDelegate {
  659. func kmStampListControllerDidStampTypeUpdated(_ controller: KMStampListController) {
  660. reloadTopRightButtonInfo()
  661. }
  662. }
  663. //MARK: - KMStampControllerDelegate
  664. extension KMRightSideController: KMStampControllerDelegate {
  665. func kmStampControllerRotateLeft(_ annotations: [CPDFStampAnnotation], withPDFView pdfView: CPDFListView?) {
  666. delegate?.kmRightSideControllerRotateLeft(annotations, withPDFView: pdfView)
  667. }
  668. func kmStampControllerRotateRight(_ annotations: [CPDFStampAnnotation], withPDFView pdfView: CPDFListView?) {
  669. delegate?.kmRightSideControllerRotateRight(annotations, withPDFView: pdfView)
  670. }
  671. }
  672. //MARK: - KMLinkViewControllerDelegate
  673. extension KMRightSideController: KMLinkViewControllerDelegate {
  674. func kmLinkViewControllerDidUpdateMode(_ controller: KMLinkViewController) {
  675. delegate?.kmRightSideControllerDidContendVCUpdated?(self)
  676. }
  677. }
  678. //MARK: - KMNAlignmentControllerDelegate
  679. extension KMRightSideController: KMNAlignmentControllerDelegate {
  680. func alignmentControllerDidClick(_ controller: KMNAlignmentController, _ alignmentType: KMPDFActiveFormsAlignType) {
  681. pdfView?.changeEditingAreas(alignmentType)
  682. }
  683. }