Improve ocr files list and UI.

This commit is contained in:
Damiano Galassi committed 2019-05-31 12:58:52 +02:00
1 parent 3a4329fc50
commit 9269f31d37
3 files changed
+156 -29

No files matched your search

+127 -14
View File
@@ -21,7 +21,7 @@ final class OCRLanguage {
let langCode: String
let name: String
init(langCode: String, name: String) {
fileprivate init(langCode: String, name: String) {
self.status = .available
self.langCode = langCode
self.name = name
@@ -43,7 +43,7 @@ final class OCRLanguage {
private var task: URLSessionDownloadTask?
fileprivate func startDownload(from remoteURL: URL, to localURL: URL, completionHandler: @escaping (Bool) -> Void) -> URLSessionTask? {
fileprivate func startDownload(from remoteURL: URL, to localURL: URL, completionHandler: @escaping (Result<URL, Error>) -> Void) -> URLSessionTask? {
let sessionConfig = URLSessionConfiguration.default
let session = URLSession(configuration: sessionConfig)
let request = URLRequest(url: remoteURL.appendingPathComponent(name))
@@ -51,27 +51,22 @@ final class OCRLanguage {
let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
if let tempLocalUrl = tempLocalUrl, error == nil {
// Success
// if let statusCode = (response as? HTTPURLResponse)?.statusCode {
// print("Success: \(statusCode)")
// }
do {
try FileManager.default.copyItem(at: tempLocalUrl, to: localURL.appendingPathComponent(self.name, isDirectory: false))
let localCompleteURL = localURL.appendingPathComponent(self.name, isDirectory: false)
try FileManager.default.copyItem(at: tempLocalUrl, to: localCompleteURL)
self.status = .downloaded
self.task = nil
completionHandler(true)
completionHandler(.success(localCompleteURL))
} catch {
self.status = . available
self.task = nil
completionHandler(false)
// print("error writing file \(localURL) : \(writeError)")
completionHandler(.failure(error))
}
} else {
} else if let error = error {
self.status = .available
self.task = nil
completionHandler(false)
// print("Failure: \(String(describing: error?.localizedDescription))")
completionHandler(.failure(error))
}
}
@@ -104,7 +99,125 @@ final class OCRManager {
OCRLanguage(langCode: "am", name: "amh.traineddata"),
OCRLanguage(langCode: "ar", name: "ara.traineddata"),
OCRLanguage(langCode: "as", name: "asm.traineddata"),
OCRLanguage(langCode: "it", name: "ita.traineddata")]
OCRLanguage(langCode: "az", name: "aze.traineddata"),
OCRLanguage(langCode: "az-Cyrl", name: "aze_cyrl.traineddata"),
OCRLanguage(langCode: "be", name: "bel.traineddata"),
OCRLanguage(langCode: "bn", name: "ben.traineddata"),
OCRLanguage(langCode: "bo", name: "bod.traineddata"),
OCRLanguage(langCode: "bs", name: "bos.traineddata"),
OCRLanguage(langCode: "br", name: "bre.traineddata"),
OCRLanguage(langCode: "bg", name: "bul.traineddata"),
OCRLanguage(langCode: "ca", name: "cat.traineddata"),
OCRLanguage(langCode: "ceb", name: "ceb.traineddata"),
OCRLanguage(langCode: "cs", name: "ces.traineddata"),
OCRLanguage(langCode: "zh-Hans", name: "chi_sim.traineddata"),
// OCRLanguage(langCode: "chi_sim_vert", name: "chi_sim_vert.traineddata"),
OCRLanguage(langCode: "zh-Hant", name: "chi_tra.traineddata"),
// OCRLanguage(langCode: "chi_tra_vert", name: "chi_tra_vert.traineddata"),
OCRLanguage(langCode: "chr", name: "chr.traineddata"),
OCRLanguage(langCode: "co", name: "cos.traineddata"),
OCRLanguage(langCode: "cy", name: "cym.traineddata"),
OCRLanguage(langCode: "da", name: "dan.traineddata"),
OCRLanguage(langCode: "de", name: "deu.traineddata"),
OCRLanguage(langCode: "dv", name: "div.traineddata"),
OCRLanguage(langCode: "dz", name: "dzo.traineddata"),
OCRLanguage(langCode: "el", name: "ell.traineddata"),
OCRLanguage(langCode: "en", name: "eng.traineddata"),
OCRLanguage(langCode: "enm", name: "enm.traineddata"),
OCRLanguage(langCode: "eo", name: "epo.traineddata"),
OCRLanguage(langCode: "et", name: "est.traineddata"),
OCRLanguage(langCode: "eu", name: "eus.traineddata"),
OCRLanguage(langCode: "fo", name: "fao.traineddata"),
OCRLanguage(langCode: "fa", name: "fas.traineddata"),
OCRLanguage(langCode: "fil", name: "fil.traineddata"),
OCRLanguage(langCode: "fi", name: "fin.traineddata"),
OCRLanguage(langCode: "fr", name: "fra.traineddata"),
// OCRLanguage(langCode: "frk", name: "frk.traineddata"),
OCRLanguage(langCode: "frm", name: "frm.traineddata"),
OCRLanguage(langCode: "fy", name: "fry.traineddata"),
OCRLanguage(langCode: "gd", name: "gla.traineddata"),
OCRLanguage(langCode: "ga", name: "gle.traineddata"),
OCRLanguage(langCode: "gl", name: "glg.traineddata"),
OCRLanguage(langCode: "grc", name: "grc.traineddata"),
OCRLanguage(langCode: "gu", name: "guj.traineddata"),
OCRLanguage(langCode: "ht", name: "hat.traineddata"),
OCRLanguage(langCode: "he", name: "heb.traineddata"),
OCRLanguage(langCode: "hi", name: "hin.traineddata"),
OCRLanguage(langCode: "hr", name: "hrv.traineddata"),
OCRLanguage(langCode: "hu", name: "hun.traineddata"),
OCRLanguage(langCode: "hy", name: "hye.traineddata"),
OCRLanguage(langCode: "iu", name: "iku.traineddata"),
OCRLanguage(langCode: "id", name: "ind.traineddata"),
OCRLanguage(langCode: "is", name: "isl.traineddata"),
OCRLanguage(langCode: "it", name: "ita.traineddata"),
OCRLanguage(langCode: "jv", name: "jav.traineddata"),
OCRLanguage(langCode: "ja", name: "jpn.traineddata"),
// OCRLanguage(langCode: "jpn_vert", name: "jpn_vert.traineddata"),
OCRLanguage(langCode: "kn", name: "kan.traineddata"),
OCRLanguage(langCode: "ka", name: "kat.traineddata"),
// OCRLanguage(langCode: "kat_old", name: "kat_old.traineddata"),
OCRLanguage(langCode: "kk", name: "kaz.traineddata"),
OCRLanguage(langCode: "km", name: "khm.traineddata"),
OCRLanguage(langCode: "ky", name: "kir.traineddata"),
// OCRLanguage(langCode: "kmr", name: "kmr.traineddata"),
OCRLanguage(langCode: "ko", name: "kor.traineddata"),
// OCRLanguage(langCode: "kor_vert", name: "kor_vert.traineddata"),
OCRLanguage(langCode: "lo", name: "lao.traineddata"),
OCRLanguage(langCode: "la", name: "lat.traineddata"),
OCRLanguage(langCode: "lv", name: "lav.traineddata"),
OCRLanguage(langCode: "lt", name: "lit.traineddata"),
OCRLanguage(langCode: "lb", name: "ltz.traineddata"),
OCRLanguage(langCode: "ml", name: "mal.traineddata"),
OCRLanguage(langCode: "mr", name: "mar.traineddata"),
OCRLanguage(langCode: "mk", name: "mkd.traineddata"),
OCRLanguage(langCode: "mt", name: "mlt.traineddata"),
OCRLanguage(langCode: "mn", name: "mon.traineddata"),
OCRLanguage(langCode: "mi", name: "mri.traineddata"),
OCRLanguage(langCode: "ms", name: "msa.traineddata"),
OCRLanguage(langCode: "my", name: "mya.traineddata"),
OCRLanguage(langCode: "ne", name: "nep.traineddata"),
OCRLanguage(langCode: "nl", name: "nld.traineddata"),
OCRLanguage(langCode: "no", name: "nor.traineddata"),
OCRLanguage(langCode: "oc", name: "oci.traineddata"),
OCRLanguage(langCode: "or", name: "ori.traineddata"),
OCRLanguage(langCode: "osd", name: "osd.traineddata"),
OCRLanguage(langCode: "pa", name: "pan.traineddata"),
OCRLanguage(langCode: "pl", name: "pol.traineddata"),
OCRLanguage(langCode: "pt", name: "por.traineddata"),
OCRLanguage(langCode: "ps", name: "pus.traineddata"),
OCRLanguage(langCode: "qu", name: "que.traineddata"),
OCRLanguage(langCode: "ro", name: "ron.traineddata"),
OCRLanguage(langCode: "ru", name: "rus.traineddata"),
OCRLanguage(langCode: "sa", name: "san.traineddata"),
OCRLanguage(langCode: "si", name: "sin.traineddata"),
OCRLanguage(langCode: "sk", name: "slk.traineddata"),
OCRLanguage(langCode: "sl", name: "slv.traineddata"),
OCRLanguage(langCode: "sd", name: "snd.traineddata"),
OCRLanguage(langCode: "es", name: "spa.traineddata"),
// OCRLanguage(langCode: "spa_old", name: "spa_old.traineddata"),
OCRLanguage(langCode: "sq", name: "sqi.traineddata"),
OCRLanguage(langCode: "sr", name: "srp.traineddata"),
OCRLanguage(langCode: "sr-Latn", name: "srp_latn.traineddata"),
OCRLanguage(langCode: "su", name: "sun.traineddata"),
OCRLanguage(langCode: "sw", name: "swa.traineddata"),
OCRLanguage(langCode: "sv", name: "swe.traineddata"),
OCRLanguage(langCode: "syr", name: "syr.traineddata"),
OCRLanguage(langCode: "ta", name: "tam.traineddata"),
OCRLanguage(langCode: "tt", name: "tat.traineddata"),
OCRLanguage(langCode: "te", name: "tel.traineddata"),
OCRLanguage(langCode: "tg", name: "tgk.traineddata"),
OCRLanguage(langCode: "th", name: "tha.traineddata"),
OCRLanguage(langCode: "ti", name: "tir.traineddata"),
OCRLanguage(langCode: "to", name: "ton.traineddata"),
OCRLanguage(langCode: "tr", name: "tur.traineddata"),
OCRLanguage(langCode: "ug", name: "uig.traineddata"),
OCRLanguage(langCode: "uk", name: "ukr.traineddata"),
OCRLanguage(langCode: "ur", name: "urd.traineddata"),
OCRLanguage(langCode: "uz", name: "uzb.traineddata"),
OCRLanguage(langCode: "uz-Cyrl", name: "uzb_cyrl.traineddata"),
OCRLanguage(langCode: "vi", name: "vie.traineddata"),
OCRLanguage(langCode: "yi", name: "yid.traineddata"),
OCRLanguage(langCode: "yo", name: "yor.traineddata")]
private init() {
try? load()
+2 -2
View File
@@ -17,9 +17,9 @@ class OCRTableCellView : NSTableCellView {
switch item.status {
case .available:
actionButton.title = NSLocalizedString("Download", comment: "")
actionButton.title = NSLocalizedString("Get", comment: "")
case .downloading:
actionButton.title = NSLocalizedString("Cancel Download", comment: "")
actionButton.title = NSLocalizedString("Cancel", comment: "")
case .downloaded:
actionButton.title = NSLocalizedString("Remove", comment: "")
}
+27 -13
View File
@@ -15,11 +15,11 @@
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="Hz6-mo-xeY">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<rect key="frame" x="0.0" y="0.0" width="480" height="314"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<scrollView autohidesScrollers="YES" horizontalLineScroll="20" horizontalPageScroll="10" verticalLineScroll="20" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="QYE-NI-76o">
<rect key="frame" x="20" y="20" width="440" height="232"/>
<rect key="frame" x="20" y="62" width="440" height="232"/>
<clipView key="contentView" id="OFf-eT-AOX">
<rect key="frame" x="1" y="1" width="438" height="230"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
@@ -49,7 +49,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textField horizontalHuggingPriority="249" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="Fec-S0-J1M">
<rect key="frame" x="0.0" y="1" width="361" height="17"/>
<rect key="frame" x="87" y="1" width="348" height="17"/>
<textFieldCell key="cell" lineBreakMode="truncatingTail" sendsActionOnEndEditing="YES" title="Table View Cell" id="Zhz-YB-L6R">
<font key="font" metaFont="system"/>
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
@@ -57,8 +57,11 @@
</textFieldCell>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Lhm-Hc-3on">
<rect key="frame" x="362" y="-6" width="78" height="27"/>
<buttonCell key="cell" type="push" title="Download" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="DIS-cU-NvL">
<rect key="frame" x="-2" y="-6" width="90" height="27"/>
<constraints>
<constraint firstAttribute="width" relation="greaterThanOrEqual" constant="80" id="WJc-b5-b3e"/>
</constraints>
<buttonCell key="cell" type="push" title="Get" bezelStyle="rounded" alignment="center" controlSize="small" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="DIS-cU-NvL">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="smallSystem"/>
</buttonCell>
@@ -68,12 +71,12 @@
</button>
</subviews>
<constraints>
<constraint firstItem="Lhm-Hc-3on" firstAttribute="top" secondItem="lSD-av-rXp" secondAttribute="top" id="HFY-Dv-gax"/>
<constraint firstItem="Fec-S0-J1M" firstAttribute="leading" secondItem="lSD-av-rXp" secondAttribute="leading" constant="2" id="TFm-Og-N3R"/>
<constraint firstAttribute="trailing" secondItem="Lhm-Hc-3on" secondAttribute="trailing" id="fj8-Gq-9Mz"/>
<constraint firstItem="Fec-S0-J1M" firstAttribute="top" secondItem="lSD-av-rXp" secondAttribute="top" id="gVf-Vu-uuK"/>
<constraint firstItem="Lhm-Hc-3on" firstAttribute="leading" secondItem="Fec-S0-J1M" secondAttribute="trailing" constant="8" id="sBh-Qb-yBo"/>
<constraint firstAttribute="bottom" secondItem="Fec-S0-J1M" secondAttribute="bottom" constant="1" id="uWd-3R-MSq"/>
<constraint firstItem="Fec-S0-J1M" firstAttribute="top" secondItem="lSD-av-rXp" secondAttribute="top" id="9uf-fA-xpv"/>
<constraint firstAttribute="bottom" secondItem="Fec-S0-J1M" secondAttribute="bottom" constant="1" id="QLG-Ww-AZo"/>
<constraint firstItem="Fec-S0-J1M" firstAttribute="leading" secondItem="Lhm-Hc-3on" secondAttribute="trailing" constant="6" id="UsK-RG-vQJ"/>
<constraint firstItem="Lhm-Hc-3on" firstAttribute="leading" secondItem="lSD-av-rXp" secondAttribute="leading" constant="3" id="cOX-ia-Azj"/>
<constraint firstAttribute="trailing" secondItem="Fec-S0-J1M" secondAttribute="trailing" constant="2" id="duf-r8-sa5"/>
<constraint firstItem="Lhm-Hc-3on" firstAttribute="top" secondItem="lSD-av-rXp" secondAttribute="top" id="hh0-fq-9ol"/>
</constraints>
<connections>
<outlet property="actionButton" destination="Lhm-Hc-3on" id="2kv-5U-ZWH"/>
@@ -102,14 +105,25 @@
<autoresizingMask key="autoresizingMask"/>
</scroller>
</scrollView>
<textField verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" translatesAutoresizingMaskIntoConstraints="NO" id="86L-qx-fhB">
<rect key="frame" x="18" y="20" width="444" height="34"/>
<textFieldCell key="cell" selectable="YES" title="Language specific OCR data files can improve the optical character recognition results." id="LFI-zD-ohi">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="QYE-NI-76o" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="20" id="9Fy-vA-llH"/>
<constraint firstAttribute="trailing" secondItem="QYE-NI-76o" secondAttribute="trailing" constant="20" id="Vwb-4Y-WhU"/>
<constraint firstItem="QYE-NI-76o" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="20" id="em8-39-Ga2"/>
<constraint firstAttribute="bottom" secondItem="QYE-NI-76o" secondAttribute="bottom" constant="20" id="fRG-bD-lu1"/>
<constraint firstItem="86L-qx-fhB" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="20" id="fI4-AG-LoY"/>
<constraint firstItem="86L-qx-fhB" firstAttribute="top" secondItem="QYE-NI-76o" secondAttribute="bottom" constant="8" id="iWy-iw-A2N"/>
<constraint firstAttribute="trailing" secondItem="86L-qx-fhB" secondAttribute="trailing" constant="20" id="qeS-OH-SXd"/>
<constraint firstAttribute="bottom" secondItem="86L-qx-fhB" secondAttribute="bottom" constant="20" id="ulR-tl-1NW"/>
</constraints>
<point key="canvasLocation" x="-366" y="98"/>
<point key="canvasLocation" x="-478" y="-95"/>
</customView>
</objects>
</document>