|
@@ -8,6 +8,8 @@
|
|
|
import Cocoa
|
|
|
import KMComponentLibrary
|
|
|
|
|
|
+typealias KMOCRPageViewValueChangeAction = (_ view: KMOCRPageView, _ model: KMOCRModel) -> (Void)
|
|
|
+
|
|
|
class KMOCRPageView: BaseXibView {
|
|
|
@IBOutlet weak var ocrPlanLabel: NSTextField!
|
|
|
@IBOutlet weak var OCRPlan1Button: ComponentRadio!
|
|
@@ -30,6 +32,16 @@ class KMOCRPageView: BaseXibView {
|
|
|
|
|
|
@IBOutlet weak var saveAsPDFButton: ComponentCheckBox!
|
|
|
|
|
|
+ var selectIndex: Int = 0
|
|
|
+
|
|
|
+ var changeAction: KMOCRPageViewValueChangeAction?
|
|
|
+
|
|
|
+ var model: KMOCRModel = KMOCRModel() {
|
|
|
+ didSet {
|
|
|
+ self.updateLanguages()
|
|
|
+ self.reloadData()
|
|
|
+ }
|
|
|
+ }
|
|
|
override func draw(_ dirtyRect: NSRect) {
|
|
|
super.draw(dirtyRect)
|
|
|
|
|
@@ -63,6 +75,7 @@ class KMOCRPageView: BaseXibView {
|
|
|
|
|
|
override func setup() {
|
|
|
self.updateUI()
|
|
|
+ self.reloadData()
|
|
|
}
|
|
|
|
|
|
func updateUI() {
|
|
@@ -76,6 +89,41 @@ class KMOCRPageView: BaseXibView {
|
|
|
OCRPlan2ButtonWidthConstraint.constant = OCRPlan2Button.properties.propertyInfo.viewWidth
|
|
|
OCRPlan2Button.reloadData()
|
|
|
|
|
|
+ self.updateLanguages()
|
|
|
+ languageSelectButton.delegate = self
|
|
|
+
|
|
|
+ enhancementSwitch.properties = ComponentSwitchProperty(size: .s, open: false, isDisabled: false)
|
|
|
+ enhancementSwitch.setTarget(self, action: #selector(switchAction(_:)))
|
|
|
+
|
|
|
+ correctionSwitch.properties = ComponentSwitchProperty(size: .s, open: false, isDisabled: false)
|
|
|
+ correctionSwitch.setTarget(self, action: #selector(switchAction(_:)))
|
|
|
+
|
|
|
+ saveAsPDFButton.setTarget(self, action: #selector(saveAsPDFAction(_:)))
|
|
|
+ }
|
|
|
+
|
|
|
+ func reloadData() {
|
|
|
+
|
|
|
+ languageSelectButton.selectItemAtIndex(self.selectIndex)
|
|
|
+
|
|
|
+ self.OCRPlan1Button.properties.checkboxType = .normal
|
|
|
+ self.OCRPlan2Button.properties.checkboxType = .normal
|
|
|
+ if model.ocrType == .google {
|
|
|
+ self.OCRPlan1Button.properties.checkboxType = .selected
|
|
|
+ } else {
|
|
|
+ self.OCRPlan2Button.properties.checkboxType = .selected
|
|
|
+ }
|
|
|
+ self.OCRPlan1Button.reloadData()
|
|
|
+ self.OCRPlan2Button.reloadData()
|
|
|
+
|
|
|
+
|
|
|
+ self.saveAsPDFButton.properties.state = model.saveAsPDF ? .pressed : .normal
|
|
|
+ self.enhancementSwitch.properties.open = model.imageEnhancement
|
|
|
+ self.correctionSwitch.properties.open = model.imageCorrection
|
|
|
+
|
|
|
+ self.pageSelectButton.pageSelectView.selectItemAtIndex(0)
|
|
|
+ }
|
|
|
+
|
|
|
+ func updateLanguages() {
|
|
|
languageSelectButton.properties = ComponentSelectProperties(size: .s,
|
|
|
state: .normal,
|
|
|
isDisabled: false,
|
|
@@ -86,51 +134,64 @@ class KMOCRPageView: BaseXibView {
|
|
|
creatable: false,
|
|
|
text: NSLocalizedString("", comment: ""))
|
|
|
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)
|
|
|
-// }
|
|
|
+ var languages: [String] = KMOCRManager.manager.languages
|
|
|
|
|
|
- languageSelectButton.updateMenuItemsArr(menuItemArr)
|
|
|
- languageSelectButton.delegate = self
|
|
|
+ languages.insert(KMLocalizedString("Auto Detection"), at: 0)
|
|
|
+ for language in languages {
|
|
|
+ let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
|
|
|
+ itemSelected: false,
|
|
|
+ isDisabled: false,
|
|
|
+ keyEquivalent: nil,
|
|
|
+ text: language, identifier: "1")
|
|
|
+ menuItemArr.append(itemProperty)
|
|
|
+ }
|
|
|
|
|
|
- enhancementSwitch.properties = ComponentSwitchProperty(size: .s, open: false, isDisabled: false)
|
|
|
- enhancementSwitch.setTarget(self, action: #selector(switchAction(_:)))
|
|
|
+ languageSelectButton.updateMenuItemsArr(menuItemArr)
|
|
|
|
|
|
- correctionSwitch.properties = ComponentSwitchProperty(size: .s, open: false, isDisabled: false)
|
|
|
- correctionSwitch.setTarget(self, action: #selector(switchAction(_:)))
|
|
|
+ let position = languages.firstIndex(of: model.language) ?? 0
|
|
|
+ self.selectIndex = position
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//MARK: Action
|
|
|
extension KMOCRPageView {
|
|
|
func OCRPlan1ButtonAction(_ sender: ComponentCheckBox) {
|
|
|
+ model.ocrType = .google
|
|
|
+ self.reloadData()
|
|
|
|
|
|
+ guard let callBack = changeAction else { return }
|
|
|
+
|
|
|
+ callBack(self, model)
|
|
|
}
|
|
|
|
|
|
func OCRPlan2ButtonAction(_ sender: ComponentCheckBox) {
|
|
|
+ model.ocrType = .apple
|
|
|
+ self.reloadData()
|
|
|
+
|
|
|
+ guard let callBack = changeAction else { return }
|
|
|
|
|
|
+ callBack(self, model)
|
|
|
}
|
|
|
|
|
|
func switchAction(_ sender: ComponentSwitch) {
|
|
|
+ if sender == enhancementSwitch {
|
|
|
+ model.imageEnhancement = sender.properties.open
|
|
|
+ } else if sender == correctionSwitch {
|
|
|
+ model.imageCorrection = sender.properties.open
|
|
|
+ }
|
|
|
+// self.reloadData()
|
|
|
+ guard let callBack = changeAction else { return }
|
|
|
+
|
|
|
+ callBack(self, model)
|
|
|
+ }
|
|
|
+
|
|
|
+ func saveAsPDFAction(_ sender: ComponentCheckBox) {
|
|
|
+ model.saveAsPDF = (sender.properties.checkboxType == .normal) ? false : true
|
|
|
+// self.reloadData()
|
|
|
+
|
|
|
+ guard let callBack = changeAction else { return }
|
|
|
|
|
|
+ callBack(self, model)
|
|
|
}
|
|
|
}
|
|
|
|