marinofaggiana 4 years ago
parent
commit
d7bb17da99

+ 43 - 31
iOSClient/Main/Create cloud/NCCreateFormUploadScanDocument.swift

@@ -84,6 +84,9 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
         // Theming view
         NotificationCenter.default.addObserver(self, selector: #selector(changeTheming), name: NSNotification.Name(rawValue: k_notificationCenter_changeTheming), object: nil)
         changeTheming()
+        
+        let value = CCUtility.getTextRecognitionStatus()
+        SetTextRecognition(newValue: value)
     }
     
     @objc func changeTheming() {
@@ -218,36 +221,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
         
         if formRow.tag == "textRecognition" {
             
-            let rowCompressionQuality: XLFormRowDescriptor = self.form.formRow(withTag: "compressionQuality")!
-            let rowFileTape: XLFormRowDescriptor = self.form.formRow(withTag: "filetype")!
-            let rowFileName: XLFormRowDescriptor = self.form.formRow(withTag: "fileName")!
-            let rowPassword: XLFormRowDescriptor = self.form.formRow(withTag: "password")!
-           
-            self.form.delegate = nil
-            
-            if newValue as! Int == 1 {
-                rowFileTape.selectorOptions = ["PDF","TXT"]
-                rowFileTape.value = "PDF"
-                fileType = "PDF"
-                rowPassword.disabled = true
-                rowCompressionQuality.disabled = false
-            } else {
-                if arrayImages.count == 1 {
-                    rowFileTape.selectorOptions = ["PDF","JPG"]
-                } else {
-                    rowFileTape.selectorOptions = ["PDF"]
-                }
-                rowFileTape.value = "PDF"
-                fileType = "PDF"
-                rowPassword.disabled = false
-                rowCompressionQuality.disabled = false
-            }
-            
-            rowFileName.value = createFileName(rowFileName.value as? String)
-            self.updateFormRow(rowFileName)
-            self.tableView.reloadData()
-
-            self.form.delegate = self
+            self.SetTextRecognition(newValue: newValue as! Int)
         }
         
         if formRow.tag == "fileName" {
@@ -325,6 +299,44 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
         }
     }
     
+    func SetTextRecognition(newValue: Int) {
+        
+        let rowCompressionQuality: XLFormRowDescriptor = self.form.formRow(withTag: "compressionQuality")!
+        let rowFileTape: XLFormRowDescriptor = self.form.formRow(withTag: "filetype")!
+        let rowFileName: XLFormRowDescriptor = self.form.formRow(withTag: "fileName")!
+        let rowPassword: XLFormRowDescriptor = self.form.formRow(withTag: "password")!
+        let rowTextRecognition: XLFormRowDescriptor = self.form.formRow(withTag: "textRecognition")!
+
+        self.form.delegate = nil
+         
+        if newValue == 1 {
+            rowFileTape.selectorOptions = ["PDF","TXT"]
+            rowFileTape.value = "PDF"
+            fileType = "PDF"
+            rowPassword.disabled = true
+            rowCompressionQuality.disabled = false
+        } else {
+            if arrayImages.count == 1 {
+                rowFileTape.selectorOptions = ["PDF","JPG"]
+            } else {
+                rowFileTape.selectorOptions = ["PDF"]
+            }
+            rowFileTape.value = "PDF"
+            fileType = "PDF"
+            rowPassword.disabled = false
+            rowCompressionQuality.disabled = false
+        }
+         
+        rowFileName.value = createFileName(rowFileName.value as? String)
+        self.updateFormRow(rowFileName)
+        self.tableView.reloadData()
+        
+        CCUtility.setTextRecognitionStatus(newValue)
+        rowTextRecognition.value = newValue
+        
+        self.form.delegate = self
+    }
+    
     override func textFieldDidBeginEditing(_ textField: UITextField) {
         
         let cell = textField.formDescriptorCell()
@@ -708,7 +720,7 @@ class NCCreateFormUploadScanDocument: XLFormViewController, NCSelectDelegate, NC
         // Search kern (W)
         let font = UIFont(descriptor: fontDescriptor, size: bestFontSize)
         attributes = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: fontColor, NSAttributedString.Key.kern: 0] as [NSAttributedString.Key : Any]
-        for kern in 1...1000 {
+        for kern in stride(from: 0, through: 100, by: 0.1) {
             let attributesTmp = [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: fontColor, NSAttributedString.Key.kern: kern] as [NSAttributedString.Key : Any]
             let size = text.size(withAttributes: attributesTmp).width
             if size <= bounds.width {

+ 3 - 0
iOSClient/Utility/CCUtility.h

@@ -174,6 +174,9 @@
 + (NSString *)getMediaSortDate;
 + (void)setMediaSortDate:(NSString *)value;
 
++ (NSInteger)getTextRecognitionStatus;
++ (void)setTextRecognitionStatus:(NSInteger)value;
+
 // ===== Varius =====
 
 + (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL;

+ 19 - 0
iOSClient/Utility/CCUtility.m

@@ -712,6 +712,25 @@
 {
     [UICKeyChainStore setString:value forKey:@"mediaSortDate" service:k_serviceShareKeyChain];
 }
+
++ (NSInteger)getTextRecognitionStatus
+{
+    NSString *value = [UICKeyChainStore stringForKey:@"textRecognitionStatus" service:k_serviceShareKeyChain];
+    
+    if (value == nil) {
+        return 0;
+    } else {
+        return [value integerValue];
+    }
+}
+
++ (void)setTextRecognitionStatus:(NSInteger)value
+{
+    NSString *valueString = [@(value) stringValue];
+    [UICKeyChainStore setString:valueString forKey:@"textRecognitionStatus" service:k_serviceShareKeyChain];
+}
+
+
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Various =====
 #pragma --------------------------------------------------------------------------------------------