KMOCRModel.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //
  2. // KMOCRModel.swift
  3. // PDF Master
  4. //
  5. // Created by lizhe on 2022/12/7.
  6. //
  7. import Cocoa
  8. /**
  9. OCR导出类型
  10. */
  11. struct KMOCRExportOptions: OptionSet {
  12. let rawValue: Int
  13. static let pdf = KMOCRExportOptions(rawValue: 1 << 0)
  14. static let txt = KMOCRExportOptions(rawValue: 1 << 1)
  15. static let all: KMOCRExportOptions = [.pdf, .txt]
  16. }
  17. /**
  18. OCR语言类型
  19. */
  20. enum KMOCRLanguageType: String, CaseIterable {
  21. case auto
  22. case english = "en-US"
  23. case french = "fr-FR"
  24. case italian = "it-IT"
  25. case german = "de-DE"
  26. case spanish = "es-ES"
  27. case portuguese = "pt-BR"
  28. case chineseTraditional = "zh-Hant"
  29. case chineseSimplified = "zh-Hans"
  30. static func allValues() -> [String] {
  31. var array: [String] = []
  32. for key in KMOCRLanguageType.allCases {
  33. array.append(key.rawValue)
  34. }
  35. return array
  36. }
  37. static func typeOfRawValue(_ rawValue: String) -> KMOCRLanguageType {
  38. var type: KMOCRLanguageType = .english
  39. switch rawValue {
  40. case KMOCRLanguageType.english.rawValue:
  41. type = .english
  42. case KMOCRLanguageType.french.rawValue:
  43. type = .french
  44. case KMOCRLanguageType.italian.rawValue:
  45. type = .italian
  46. case KMOCRLanguageType.german.rawValue:
  47. type = .german
  48. case KMOCRLanguageType.spanish.rawValue:
  49. type = .spanish
  50. case KMOCRLanguageType.portuguese.rawValue:
  51. type = .portuguese
  52. case KMOCRLanguageType.chineseTraditional.rawValue:
  53. type = .chineseTraditional
  54. case KMOCRLanguageType.chineseSimplified.rawValue:
  55. type = .chineseSimplified
  56. default:
  57. type = .english
  58. }
  59. return type
  60. }
  61. }
  62. class KMOCRModel: NSObject {
  63. var filePaths: Array<String>?
  64. var exportOptions: KMOCRExportOptions! = .pdf
  65. var languageType: KMOCRLanguageType! = .english
  66. var exportFilePath: String = ""
  67. var languageDic: NSDictionary = [KMGOCRLanguageCodeKey:"en-US", KMGOCRLanguageStringKey:"English"]
  68. static func supportedTypes() -> [String] {
  69. return ["pdf"]
  70. }
  71. }