123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- //
- // KMConvertSettingView.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/5/9.
- //
- let kKMConvertLanugageSelectedIndex: String = "KMConvertLanugageSelectedIndex"
- typealias KMConvertSettingViewPageRangeDidChangeCallback = (_ pageRange: KMPageRange) -> Void
- typealias KMConvertSettingViewPageRangeDidInputFinishCallback = (_ pageRangeString: String) -> ()
- // 转档 设置视图 基类
- class KMConvertSettingView: KMConvertBaseView {
- private var _currentLanguage: String?
- var currentLanguage: String? {
- get {
- return self._currentLanguage
- }
- set {
- self._currentLanguage = newValue
-
- if let indexString = UserDefaults.standard.string(forKey: kKMConvertLanugageSelectedIndex), let index = Int(indexString) {
- self.ocrLanuguageIndex = index
- return
- }
- // var language: COCRLanguage = .english
- // if let _language = KMPDFConvertManager.defaultManager.ocrLanguage(appleLanguage: self._currentLanguage) {
- // language = _language
- // }
- // if let index = KMPDFConvertManager.defaultManager.languages_asc.firstIndex(of: language) {
- // self.ocrLanuguageIndex = index
- // } else {
- // self.ocrLanuguageIndex = 2
- // }
- }
- }
-
- var ocrLanuguageIndex: Int = 3 {
- didSet {
- self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
- }
- }
-
- var pageRangeSelectedIndex: Int = 0
- var pageRangeDidChange: KMConvertSettingViewPageRangeDidChangeCallback?
- var pageRangeDidInputFinishCallback: KMConvertSettingViewPageRangeDidInputFinishCallback?
- var lanugageDidSelected: KMValueDidChangeBlock?
-
- private var _ocrItemView: KMConvertOCRSettingItemView?
- var ocrItemView: KMConvertOCRSettingItemView? {
- get {
- return self._ocrItemView
- }
- set {
- if (self._ocrItemView != newValue) {
- self._ocrItemView = newValue
-
- newValue?.lanugageDidSelected = { [unowned self] value, change in
- guard let callback = self.lanugageDidSelected else {
- return
- }
-
- callback(value, change)
- }
- }
- }
- }
- private var _pageRangeItemView: KMConvertPageRangeSettingItemView?
- var pageRangeItemView: KMConvertPageRangeSettingItemView? {
- get {
- return self._pageRangeItemView
- }
- set {
- if (self._pageRangeItemView != newValue) {
- self._pageRangeItemView = newValue
- newValue?.isTextDidEndCallback = true
- newValue?.itemClick = { [unowned self] index, _ in
- self.pageRangeSelectedIndex = index
-
- guard let callback = self.pageRangeDidChange else {
- return
- }
-
- callback(KMPageRange(rawValue: index)!)
- }
-
- newValue?.textDidEndEditingCallback = { [unowned self] textString in
- let pageRange = KMPageRange(rawValue: self.pageRangeSelectedIndex)
- if (pageRange != .custom) {
- return
- }
-
- guard let callback = self.pageRangeDidInputFinishCallback else {
- return
- }
-
- callback(textString)
- }
- }
- }
- }
- var tipView: KMConvertSettingLimitTipView?
-
- override func initSubViews() {
- super.initSubViews()
-
- let tipView = KMConvertSettingLimitTipView()
- self.addSubview(tipView)
- self.tipView = tipView
- }
-
- override func layout() {
- super.layout()
-
- // let width = NSWidth(self.bounds)
- // let height = NSHeight(self.bounds)
- // self.tipView?.frame = NSMakeRect(0, 10, width, 16+20+16)
- }
-
- var pageCount = 0 {
- didSet {
- self.pageRangeItemView?.pageCount = self.pageCount
- }
- }
-
- var ocrEnabled: Bool {
- get {
- guard let state = self.ocrItemView?.checkVC?.state else {
- return false
- }
- return state == .Checked
- }
- }
-
- func getPageRangeString() -> String {
- if let view = self.pageRangeItemView {
- return view.pageRangeValue
- }
- return ""
- }
- }
|