Ver Fonte

Merge branch 'develop_PDFReaderProNew' of git.kdan.cc:Mac_PDF/PDF_Office into develop_PDFReaderProNew

tangchao há 1 ano atrás
pai
commit
5194d505be

+ 1 - 1
PDF Office/PDF Master/Class/Common/Category/NSString+KMExtension.swift

@@ -114,7 +114,7 @@ let SKAnnotationTextWidgetPrintKey = "SKAnnotationTextWidgetPrintKey"
 let SKAnnotationTextWidgetFontColorKey = "SKAnnotationTextWidgetFontColorKey"
 let SKAnnotationTextWidgetBackgroundColorKey = "SKAnnotationTextWidgetBackgroundColorKey"
 let SKAnnotationTextWidgetFontSizeKey = "SKAnnotationTextWidgetFontSizeKey"
-let CAnnotationTextWidgetFontNameKey = "CAnnotationTextWidgetFontNameKey"
+let SKAnnotationTextWidgetFontNameKey = "SKAnnotationTextWidgetFontNameKey"
 let SKAnnotationTextWidgetAlignmenKey = "SKAnnotationTextWidgetAlignmenKey"
 let SKAnnotationTextMultilineKey = "SKAnnotationTextMultilineKey"
 let SKAnnotationTextStringValueKey = "SKAnnotationStringValueMultilineKey"

+ 3 - 3
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotationModel.m

@@ -1244,7 +1244,7 @@
                 color = [userDefaults PDFListViewColorForKey:CFreeTextNoteFontColorKey];
                 break;
             case CAnnotationTypeTextField:
-                color = [userDefaults PDFListViewColorForKey:CAnnotationTextWidgetFontColorKey];
+                color = [userDefaults PDFListViewColorForKey:CAnnotationTextWidgetFontColorKey] ? : NSColor.blackColor;
                 break;
             case CAnnotationTypeListMenu:
                 color = [userDefaults PDFListViewColorForKey:CAnnotationChoiceListWidgetFontColorKey];
@@ -1337,7 +1337,7 @@
                 fontSize = [userDefaults floatForKey:CFreeTextNoteFontSizeKey] < 0.001 ? 11 : [userDefaults floatForKey:CFreeTextNoteFontSizeKey];
                 break;
             case CAnnotationTypeTextField:
-                fontSize = [userDefaults floatForKey:CAnnotationTextWidgetFontSizeKey] < 0.001 ? 11 : [userDefaults floatForKey:CAnnotationTextWidgetFontSizeKey];
+                fontSize = [userDefaults floatForKey:SKAnnotationTextWidgetFontSizeKey] < 0.001 ? 11 : [userDefaults floatForKey:SKAnnotationTextWidgetFontSizeKey];
                 break;
             case CAnnotationTypeListMenu:
                 fontSize = [userDefaults floatForKey:CAnnotationChoiceListWidgetFontSizeKey] < 0.001 ? 11 : [userDefaults floatForKey:CAnnotationChoiceListWidgetFontSizeKey];
@@ -1380,7 +1380,7 @@
                 [userDefaults setFloat:fontSize forKey:CFreeTextNoteFontSizeKey];
                 break;
             case CAnnotationTypeTextField:
-                [userDefaults setFloat:fontSize forKey:CAnnotationTextWidgetFontSizeKey];
+                [userDefaults setFloat:fontSize forKey:SKAnnotationTextWidgetFontSizeKey];
                 break;
             case CAnnotationTypeListMenu:
                 [userDefaults setFloat:fontSize forKey:CAnnotationChoiceListWidgetFontSizeKey];

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -3188,7 +3188,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             if (backgroundColor) {
                 [(CPDFWidgetAnnotation *)textWidget setBackgroundColor:backgroundColor];
             } else {
-                [(CPDFWidgetAnnotation *)textWidget setBackgroundColor:[NSColor clearColor]];
+                [(CPDFWidgetAnnotation *)textWidget setBackgroundColor:[NSColor whiteColor]];
             }
             
             NSColor* fontColor = [sud colorForKey:@"SKAnnotationTextWidgetFontColorKey"];

+ 6 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Tool.m

@@ -300,6 +300,12 @@
 - (void)setNeedsDisplayAnnotation:(CPDFAnnotation *)annotation {
     if (annotation) {
         [self setNeedsDisplayAnnotationViewForPage:annotation.page];
+        if ([annotation isKindOfClass:[CPDFStampAnnotation class]] ||
+            [annotation isKindOfClass:[CPDFFreeTextAnnotation class]] ||
+            [annotation isKindOfClass:[CPDFSignatureAnnotation class]] ||
+            [annotation isKindOfClass:[CPDFWidgetAnnotation class]]) {
+            [annotation updateAppearanceStream];
+        }
     } else {
         [self setNeedsDisplayAnnotationViewForVisiblePages];
     }

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CStringConstants.h

@@ -125,8 +125,8 @@ extern NSString *CArrowNoteEndStyleKey;
 extern NSString *CAnnotationTextWidgetLineStyleKey;
 extern NSString *CAnnotationTextWidgetLineWidthKey;
 extern NSString *CAnnotationTextWidgetBorderColorKey;
-extern NSString *CAnnotationTextWidgetFontNameKey;
-extern NSString *CAnnotationTextWidgetFontSizeKey;
+extern NSString *SKAnnotationTextWidgetFontNameKey;
+extern NSString *SKAnnotationTextWidgetFontSizeKey;
 extern NSString *CAnnotationTextWidgetFontColorKey;
 extern NSString *CAnnotationTextWidgetAlignmenKey;
 extern NSString *CAnnotationTextWidgetBackgroundColorKey;

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CStringConstants.m

@@ -124,8 +124,8 @@ NSString *CArrowNoteEndStyleKey = @"CArrowNoteEndStyle";
 NSString *CAnnotationTextWidgetLineStyleKey = @"CAnnotationTextWidgetLineStyle";
 NSString *CAnnotationTextWidgetLineWidthKey = @"CAnnotationTextWidgetLineWidthKey";
 NSString *CAnnotationTextWidgetBorderColorKey = @"CAnnotationTextWidgetBorderColor";
-NSString *CAnnotationTextWidgetFontNameKey = @"CAnnotationTextWidgetFontNameKey";
-NSString *CAnnotationTextWidgetFontSizeKey = @"CAnnotationTextWidgetFontSize";
+NSString *SKAnnotationTextWidgetFontNameKey = @"SKAnnotationTextWidgetFontNameKey";
+NSString *SKAnnotationTextWidgetFontSizeKey = @"SKAnnotationTextWidgetFontSizeKey";
 NSString *CAnnotationTextWidgetFontColorKey = @"CAnnotationTextWidgetFontColor";
 NSString *CAnnotationTextWidgetAlignmenKey = @"CAnnotationTextWidgetAlignmen";
 NSString *CAnnotationTextWidgetBackgroundColorKey = @"CAnnotationTextWidgetBackgroundColor";

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMAnnotationPropertiesViewController.m

@@ -507,8 +507,8 @@
 //        self.contentViewController = vc;
         if (annotationMode == CAnnotationTypeTextField) {
             KMAnnotationFromViewController *vc = [[KMAnnotationFromViewController alloc] init];
-            vc.annotationModel = annotationModel;
             vc.pdfView = self.pdfView;
+            vc.annotationModel = annotationModel;
             self.propertiesBox.contentView = vc.view;
             self.contentViewController = vc;
         } else if (annotationMode == CAnnotationTypeListMenu ||

+ 94 - 74
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/ViewController/FormProperties/KMAnnotationFromViewController.swift

@@ -12,7 +12,7 @@ import Cocoa
     private var _annotations: [CPDFWidgetAnnotation] = []
     private var _formMode: CAnnotationType = .radioButton
     var pdfView: CPDFListView?
-    var annotationModel: CPDFAnnotationModel?
+    var _annotationModel: CPDFAnnotationModel?
     
     @IBOutlet private var colorLabel: NSTextField!
     @IBOutlet private var colorPickerView: KMColorPickerView!
@@ -108,49 +108,63 @@ import Cocoa
             _formMode = newValue
             isFromMode = true
             
-            let defaults = UserDefaults.standard
-            var annotation: CPDFWidgetAnnotation?
-            var backgroundColor: NSColor?
-            var fontColor: NSColor?
-            
-            if formMode == .textField {
-                annotation = CPDFTextWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!)
-                backgroundColor = defaults.color(forKey: SKAnnotationTextWidgetBackgroundColorKey) ?? NSColor.clear
-                annotation?.backgroundColor = backgroundColor
-                fontColor = defaults.color(forKey: SKAnnotationTextWidgetFontColorKey)
-                annotation?.fontColor = fontColor
-                (annotation as! CPDFTextWidgetAnnotation).alignment = NSTextAlignment(rawValue: defaults.integer(forKey: SKAnnotationTextWidgetAlignmenKey)) ?? .left
-                if let font = defaults.font(forNameKey: CAnnotationTextWidgetFontNameKey, sizeKey: CAnnotationTextWidgetFontSizeKey) {
-                    annotation?.font = font
-                }
-                if let tAnnotation = annotation as? CPDFTextWidgetAnnotation {
-                    (annotation as! CPDFTextWidgetAnnotation).isMultiline = defaults.bool(forKey: SKAnnotationTextMultilineKey)
-                }
-            } else if formMode == .listMenu {
-                annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: true)
-                backgroundColor = defaults.color(forKey: SKAnnotationChoiceListWidgetBackgroundColorKey) ?? NSColor.clear
-                annotation?.backgroundColor = backgroundColor
-                fontColor = defaults.color(forKey: SKAnnotationChoiceListWidgetFontColorKey)
-                annotation?.fontColor = fontColor
-                if let font = defaults.font(forNameKey: SKAnnotationChoiceListWidgetFontNameKey, sizeKey: SKAnnotationChoiceListWidgetFontSizeKey) {
-                    annotation?.font = font
-                }
-            } else if formMode == .comboBox {
-                annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: false)
-                backgroundColor = defaults.color(forKey: SKAnnotationChoiceWidgetBackgroundColorKey) ?? NSColor.clear
-                annotation?.backgroundColor = backgroundColor
-                fontColor = defaults.color(forKey: SKAnnotationChoiceWidgetFontColorKey)
-                annotation?.fontColor = fontColor
-                if let font = defaults.font(forNameKey: SKAnnotationChoiceWidgetFontNameKey, sizeKey: SKAnnotationChoiceWidgetFontSizeKey) {
-                    annotation?.font = font
+//            let defaults = UserDefaults.standard
+//            var annotation: CPDFWidgetAnnotation?
+//            var backgroundColor: NSColor?
+//            var fontColor: NSColor?
+//            
+//            if formMode == .textField {
+//                annotation = CPDFTextWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!)
+//                backgroundColor = defaults.color(forKey: SKAnnotationTextWidgetBackgroundColorKey) ?? NSColor.clear
+//                annotation?.backgroundColor = backgroundColor
+//                fontColor = defaults.color(forKey: SKAnnotationTextWidgetFontColorKey)
+//                annotation?.fontColor = fontColor
+//                (annotation as! CPDFTextWidgetAnnotation).alignment = NSTextAlignment(rawValue: defaults.integer(forKey: SKAnnotationTextWidgetAlignmenKey)) ?? .left
+//                if let font = defaults.font(forNameKey: SKAnnotationTextWidgetFontNameKey, sizeKey: SKAnnotationTextWidgetFontSizeKey) {
+//                    annotation?.font = font
+//                }
+//                if let tAnnotation = annotation as? CPDFTextWidgetAnnotation {
+//                    (annotation as! CPDFTextWidgetAnnotation).isMultiline = defaults.bool(forKey: SKAnnotationTextMultilineKey)
+//                }
+//            } else if formMode == .listMenu {
+//                annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: true)
+//                backgroundColor = defaults.color(forKey: SKAnnotationChoiceListWidgetBackgroundColorKey) ?? NSColor.clear
+//                annotation?.backgroundColor = backgroundColor
+//                fontColor = defaults.color(forKey: SKAnnotationChoiceListWidgetFontColorKey)
+//                annotation?.fontColor = fontColor
+//                if let font = defaults.font(forNameKey: SKAnnotationChoiceListWidgetFontNameKey, sizeKey: SKAnnotationChoiceListWidgetFontSizeKey) {
+//                    annotation?.font = font
+//                }
+//            } else if formMode == .comboBox {
+//                annotation = CPDFChoiceWidgetAnnotation(PDFListViewNoteWith: (pdfView?.document)!, listChoice: false)
+//                backgroundColor = defaults.color(forKey: SKAnnotationChoiceWidgetBackgroundColorKey) ?? NSColor.clear
+//                annotation?.backgroundColor = backgroundColor
+//                fontColor = defaults.color(forKey: SKAnnotationChoiceWidgetFontColorKey)
+//                annotation?.fontColor = fontColor
+//                if let font = defaults.font(forNameKey: SKAnnotationChoiceWidgetFontNameKey, sizeKey: SKAnnotationChoiceWidgetFontSizeKey) {
+//                    annotation?.font = font
+//                }
+//            } else {
+//                annotation = CPDFWidgetAnnotation(document: (pdfView?.document)!)
+//            }
+//            
+//            self.annotations = [annotation].compactMap { $0 }
+//            self.annotation = annotations.first
+        }
+    }
+    
+    var annotationModel: CPDFAnnotationModel {
+        get {
+            return _annotationModel!
+        }
+        set {
+            _annotationModel = newValue
+            formMode = _annotationModel?.annotationType ?? .textField
+            if _annotationModel?.annotations != nil {
+                if annotationModel.annotations.count > 0 {
+                    annotations = _annotationModel?.annotations as! [CPDFWidgetAnnotation]
                 }
-            } else {
-                annotation = CPDFWidgetAnnotation(document: (pdfView?.document)!)
             }
-            
-            self.annotations = [annotation].compactMap { $0 }
-            self.annotation = annotations.first
-
         }
     }
 
@@ -206,23 +220,23 @@ import Cocoa
                 annotationFont = (annotation as! CPDFTextWidgetAnnotation).font
             }
         } else {
-            if let presetValue = annotationModel?.stringValue() {
-                annotationModel?.setStringValue(presetValue)
+            if let presetValue = annotationModel.stringValue() {
+                annotationModel.setStringValue(presetValue)
             }
             var opacity: CGFloat = 1
-            let color = annotationModel?.backgroundColor()
+            let color = annotationModel.backgroundColor()
             if color != nil {
                 color!.usingColorSpaceName(.calibratedRGB)?.getRed(nil, green:nil, blue: nil, alpha: &opacity)
             }
 
-            let fontColor = annotationModel?.fontColor()
+            let fontColor = annotationModel.fontColor()
             fillColorPickerView!.color = color
             colorPickerView.color = fontColor
-            fontSizeComboBox.stringValue = "\(annotationModel?.fontSize() ?? 12.0) pt"
+            fontSizeComboBox.stringValue = "\(annotationModel.fontSize() ?? 12.0) pt"
             
-            var annotationFont = NSFont.systemFont(ofSize: (annotationModel?.fontSize())!)
-            if annotationModel?.fontName() != nil {
-                annotationFont = NSFont(name: (annotationModel?.fontName())!, size: (annotationModel?.fontSize())!)!
+            var annotationFont = NSFont.systemFont(ofSize: annotationModel.fontSize())
+            if annotationModel.fontName() != nil {
+                annotationFont = NSFont(name: (annotationModel.fontName())!, size: (annotationModel.fontSize()))!
             }
             DispatchQueue.global(qos: .default).async { [self] in
                 let fonts = NSFontManager.shared.availableFontFamilies
@@ -231,15 +245,15 @@ import Cocoa
                 let style = annotationFont.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String
                 let menu = NSMenu()
                 for (index, fontName) in fonts.enumerated() {
-                    if let font = NSFont(name: fontName, size: (annotationModel?.fontSize())!) {
+                    if let font = NSFont(name: fontName, size: annotationModel.fontSize()) {
                         let attributes: [NSAttributedString.Key: Any] = [.font: font]
                         let attributedString = NSAttributedString(string: fontName, attributes: attributes)
                         let item = NSMenuItem()
                         item.attributedTitle = attributedString
                         menu.addItem(item)
 
-                        if annotationModel?.fontName() != nil {
-                            if annotationModel?.fontName() == font.fontName {
+                        if annotationModel.fontName() != nil {
+                            if annotationModel.fontName() == font.fontName {
                                 selectedIndex = index
                             }
                         }
@@ -263,25 +277,23 @@ import Cocoa
     
     func updateAnnotationMode() {
         let userDefaults = UserDefaults.standard
-        guard let annotation = self.annotation else { return }
-        
         if formMode == .textField {
-            userDefaults.setColor(annotation.backgroundColor, forKey: SKAnnotationTextWidgetBackgroundColorKey)
-            userDefaults.setColor(annotation.fontColor, forKey: SKAnnotationTextWidgetFontColorKey)
-            userDefaults.set((annotation as! CPDFTextWidgetAnnotation).alignment.rawValue, forKey: SKAnnotationTextWidgetAlignmenKey)
-            userDefaults.set(annotation.font.fontName, forKey: CAnnotationTextWidgetFontNameKey)
-            userDefaults.set(annotation.font.pointSize, forKey: CAnnotationTextWidgetFontSizeKey)
-            userDefaults.set((annotation as! CPDFTextWidgetAnnotation).isMultiline, forKey: SKAnnotationTextMultilineKey)
-        } else if formMode == .comboBox {
-            userDefaults.setColor(annotation.backgroundColor, forKey: SKAnnotationChoiceWidgetBackgroundColorKey)
-            userDefaults.setColor(annotation.fontColor, forKey: SKAnnotationChoiceWidgetFontColorKey)
-            userDefaults.set(annotation.font.fontName, forKey: SKAnnotationChoiceWidgetFontNameKey)
-            userDefaults.set(annotation.font.pointSize, forKey: SKAnnotationChoiceWidgetFontSizeKey)
+            userDefaults.setColor(annotationModel.backgroundColor(), forKey: SKAnnotationTextWidgetBackgroundColorKey)
+            userDefaults.setColor(annotationModel.fontColor(), forKey: SKAnnotationTextWidgetFontColorKey)
+            userDefaults.set(annotationModel.alignment().rawValue, forKey: SKAnnotationTextWidgetAlignmenKey)
+            userDefaults.set(annotationModel.fontName(), forKey: SKAnnotationTextWidgetFontNameKey)
+            userDefaults.set(annotationModel.fontSize(), forKey: SKAnnotationTextWidgetFontSizeKey)
+            userDefaults.set(annotationModel.isMultiline(), forKey: SKAnnotationTextMultilineKey)
         } else if formMode == .comboBox {
-            userDefaults.setColor(annotation.backgroundColor, forKey: SKAnnotationChoiceListWidgetBackgroundColorKey)
-            userDefaults.setColor(annotation.fontColor, forKey: SKAnnotationChoiceListWidgetFontColorKey)
-            userDefaults.set(annotation.font.fontName, forKey: SKAnnotationChoiceListWidgetFontNameKey)
-            userDefaults.set(annotation.font.pointSize, forKey: SKAnnotationChoiceListWidgetFontSizeKey)
+            userDefaults.setColor(annotationModel.backgroundColor(), forKey: SKAnnotationChoiceWidgetBackgroundColorKey)
+            userDefaults.setColor(annotationModel.fontColor(), forKey: SKAnnotationChoiceWidgetFontColorKey)
+            userDefaults.set(annotationModel.fontName(), forKey: SKAnnotationChoiceWidgetFontNameKey)
+            userDefaults.set(annotationModel.fontSize(), forKey: SKAnnotationChoiceWidgetFontSizeKey)
+        } else if formMode == .listMenu {
+            userDefaults.setColor(annotationModel.backgroundColor(), forKey: SKAnnotationChoiceListWidgetBackgroundColorKey)
+            userDefaults.setColor(annotationModel.fontColor(), forKey: SKAnnotationChoiceListWidgetFontColorKey)
+            userDefaults.set(annotationModel.fontName(), forKey: SKAnnotationChoiceListWidgetFontNameKey)
+            userDefaults.set(annotationModel.fontSize(), forKey: SKAnnotationChoiceListWidgetFontSizeKey)
         }
     }
     
@@ -291,9 +303,10 @@ import Cocoa
     }
 
     private func updateAnnotation() {
-        if annotationModel?.annotation != nil {
+        if annotationModel.annotation != nil {
             for tAnnotation in annotations {
                 pdfView?.setNeedsDisplayAnnotationViewFor(tAnnotation.page)
+                tAnnotation.updateAppearanceStream()
             }
         }
     }
@@ -379,13 +392,20 @@ import Cocoa
             tAnnotation.fontColor = colorPickerView.color
             tAnnotation.setButtonWidgetStateString(annotationString)
         }
+        updateAnnotationMode()
         updateAnnotation()
     }
 
     @IBAction func fillColorPickerViewAction(_ sender: Any) {
-        for tAnnotation in annotations {
-//            tAnnotation.removeAllAppearanceStreams()
-            tAnnotation.backgroundColor = fillColorPickerView.color
+        if annotations.count > 0 {
+            for tAnnotation in annotations {
+    //            tAnnotation.removeAllAppearanceStreams()
+                tAnnotation.backgroundColor = fillColorPickerView.color
+            }
+        } else {
+            
+            annotationModel.setBackgroundColor(fillColorPickerView.color)
+            updateAnnotationMode()
         }
         updateAnnotation()
     }