Преглед на файлове

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

tangchao преди 10 месеца
родител
ревизия
6f0831311a

+ 10 - 0
PDF Office/PDF Master/Class/KMAdvertisement/Manager/KMAdvertisementManager.swift

@@ -373,6 +373,16 @@ extension KMAdvertisementManager {
             return false
         }
         
+        let currentTime = Int(NSDate.init().timeIntervalSince1970 * 1000)
+        if info.show == "1" &&
+            currentTime > Int(info.startTime ?? "0") ?? currentTime &&
+            currentTime < Int(info.endTime ?? "0") ?? currentTime {
+           
+        } else {
+            return false
+        }
+        
+        
         if info.subscriptionType == "1" {
             if !IAPProductsManager.default().isAvailableAllFunction() {
                 return false

+ 56 - 0
PDF Office/PDF Master/Class/PDFTools/Compare/KMCompareWindowController.swift

@@ -15,6 +15,8 @@ class KMCompareWindowController: KMBaseWindowController {
     @IBOutlet weak var compareView: KMCompareView!
     
     var pdfCompareContent: CPDFCompareContent?
+    var maskView: KMBookletMaskView?
+    var progressController: SKProgressController?
     
     var filePath: String = "" {
         didSet {
@@ -60,12 +62,14 @@ class KMCompareWindowController: KMBaseWindowController {
     
     func compareAction(config: KMCompareFilesConfig) {
         compareView.doneButton.isEnabled = false
+        self.showWaitting()
 
         guard let pdfOldDocument = config.fileOldAttribute.pdfDocument, let pdfNewDocument = config.fileNewAttribute.pdfDocument else {
             let alert = NSAlert()
             alert.alertStyle = .critical
             alert.messageText = NSLocalizedString("Please select two files to compare", comment: "")
             alert.runModal()
+            self.hideWaitting()
             return
         }
 
@@ -78,6 +82,7 @@ class KMCompareWindowController: KMBaseWindowController {
             alert.alertStyle = .critical
             alert.messageText = NSLocalizedString("The file has been deleted, please reselect a file.", comment: "")
             alert.runModal()
+            self.hideWaitting()
             return
         }
 
@@ -92,6 +97,8 @@ class KMCompareWindowController: KMBaseWindowController {
             config.fileNewAttribute.pagesType = .all
             
             compareView.reloadData()
+            
+            self.hideWaitting()
             return
         }
 
@@ -105,6 +112,8 @@ class KMCompareWindowController: KMBaseWindowController {
             config.fileOldAttribute.pagesType = .all
 
             compareView.reloadData()
+            
+            self.hideWaitting()
             return
         }
 
@@ -136,17 +145,25 @@ class KMCompareWindowController: KMBaseWindowController {
                 pdfCompareOverlay?.setBlendMod(config.blendMod())
 
                 if (pdfCompareOverlay?.compare() == true) {
+                    DispatchQueue.main.async {
+                        self.progressController?.doubleValue = 30.0
+                    }
+                    
                     guard let document = pdfCompareOverlay?.comparisonDocument() else {
                         DispatchQueue.main.async {
                             let alert = NSAlert()
                             alert.alertStyle = .critical
                             alert.messageText = NSLocalizedString("Failure", comment: "")
                             alert.runModal()
+                            
+                            self.hideWaitting()
                         }
                         return
                     }
                     
+                    
                     DispatchQueue.main.async {
+                        self.hideWaitting()
                         self.coveringComplete?(self, document)
                     }
                     debugPrint("合并成功")
@@ -184,6 +201,9 @@ class KMCompareWindowController: KMBaseWindowController {
 //                if self._compareCancel {
 //                    return
 //                }
+                DispatchQueue.main.async {
+                    self.progressController?.doubleValue = 30.0
+                }
                 
                 for i in 0..<maxIndex {
                     let oldPageIndex: Int
@@ -212,6 +232,7 @@ class KMCompareWindowController: KMBaseWindowController {
                 }
                 
                 DispatchQueue.main.async {
+                    self.hideWaitting()
                     self.contentComplete?(self, pdfCompareContent!, results, oldDoc!, doc!)
                     if results.count > 0 {
                         // Handle success case
@@ -227,3 +248,38 @@ class KMCompareWindowController: KMBaseWindowController {
 
     }
 }
+
+extension KMCompareWindowController {
+    func showWaitting() {
+        if self.maskView == nil {
+            self.maskView = KMBookletMaskView(frame: CGRect(x: 0, y: 0, width: self.window?.frame.size.width ?? 0, height: self.window?.frame.size.height ?? 0))
+        }
+        self.window?.contentView?.addSubview(self.maskView!)
+        
+        let progress = SKProgressController()
+        progress.window?.backgroundColor = NSColor.km_init(hex: "#36383B")
+        progress.window?.contentView?.wantsLayer = true
+        progress.window?.contentView?.layer?.backgroundColor = NSColor.km_init(hex: "#36383B").cgColor
+        progress.progressField.textColor = NSColor.white
+        progress.message = NSLocalizedString("Translating...", comment: "")
+
+        progress.closeBlock = { [unowned self] in
+            
+        }
+        
+        self.progressController = progress
+        self.window?.beginSheet(progress.window!)
+    }
+    func hideWaitting() {
+        DispatchQueue.main.async {
+            self.progressController?.doubleValue = 99.0
+        }
+        
+        self.maskView?.removeFromSuperview()
+
+        if (self.progressController != nil) {
+            self.window?.endSheet((self.progressController?.window)!)
+            self.progressController = nil
+        }
+    }
+}

+ 10 - 3
PDF Office/PDF Master/Class/PDFTools/Watermark/New/View/KMWatermarkView.swift

@@ -94,7 +94,16 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
     var password: String = ""
     var originalWatermark: KMWatermarkModel = KMWatermarkModel()
     var watermark: KMWatermarkModel = KMWatermarkModel()
-    var type: KMWatermarkManagerType = .use
+    var type: KMWatermarkManagerType = .use {
+        didSet {
+            if type == .edit {
+                
+            } else {
+                watermark.watermarkID = KMWatermarkManager.defaultManager.fetchAvailableName()
+            }
+            self.templateNameTextField.stringValue = self.watermark.watermarkID
+        }
+    }
     var pdfDocument: CPDFDocument? {
         didSet {
             self._fileAttri = KMFileAttribute()
@@ -251,8 +260,6 @@ class KMWatermarkView: KMBaseXibView, NSTextFieldDelegate, NSComboBoxDelegate, N
         self.horizentalGapTextField.delegate = self
         self.spacingHorTextField.delegate = self
         self.spacingVerTextField.delegate = self
-        
-        watermark.watermarkID = KMWatermarkManager.defaultManager.fetchAvailableName()
     }
 
     

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

@@ -1760,7 +1760,7 @@
         NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
         switch (_annotationType) {
             case CAnnotationTypeTextField:
-                backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationTextWidgetBackgroundColorKey];
+                backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationTextWidgetBackgroundColorKey] ? : NSColor.grayColor;
                 break;
             case CAnnotationTypeRadioButton:
                 backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationRadioButtonWidgetBackgroundColorKey];
@@ -1769,10 +1769,10 @@
                 backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationCheckBoxWidgetBackgroundColorKey];
                 break;
             case CAnnotationTypeComboBox:
-                backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationActionButtonWidgetBackgroundColorKey];
+                backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationActionButtonWidgetBackgroundColorKey] ? : NSColor.grayColor;
                 break;
             case CAnnotationTypeListMenu:
-                backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationChoiceListWidgetBackgroundColorKey];
+                backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationChoiceListWidgetBackgroundColorKey] ? : NSColor.grayColor;
                 break;
             case CAnnotationTypeActionButton:
                 backgroundColor = [userDefaults PDFListViewColorForKey:CAnnotationActionButtonWidgetBackgroundColorKey];

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

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

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

@@ -572,55 +572,93 @@ import Cocoa
     }
     
     @IBAction func buttonClicked_ChangeFont(_ sender: Any) {
-        let fontWindowController = KMAnnotationFontWindowController.sharedAnnotationFont
-        let window = fontWindowController!.window
-        if fontWindowController != nil && window != nil {
-//            fontWindowController!.annotations = annotations
-            
-//            fontWindowController!.annotationAlignCallback = { [weak self] selectedCount in
-//                guard let self = self else { return }
-//                
-//                for tAnnotation in self.annotations {
-//                    var annotationString = ""
-//                    
-//                    
-//                    if tAnnotation.buttonWidgetStateString().isEmpty {
-//                        annotationString = " "
-//                    } else {
-//                        let lastString = String(tAnnotation.buttonWidgetStateString().suffix(1))
-//                        
-//                        if lastString == " " {
-//                            annotationString = String(tAnnotation.buttonWidgetStateString().prefix(tAnnotation.buttonWidgetStateString().count - 1))
-//                        } else {
-//                            annotationString = "\(tAnnotation.buttonWidgetStateString()) "
-//                        }
-//                    }
-//                    
-//                    switch selectedCount {
-//                    case 0:
-//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
-//                    case 2:
-//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
-//                    case 1:
-//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
-//                    case 3:
-//                        (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .justified
-//                    default:
-//                        break
-//                    }
-//                    
-//                    tAnnotation.setButtonWidgetStateString(annotationString)
-//                }
-//                
-//                self.updateAnnotation()
-//            }
+        let selectItem = self.fontPopUpButton.selectedItem
+        guard let selectItem = selectItem else { return }
+        
+        let resultAtt = NSMutableAttributedString(attributedString: selectItem.attributedTitle!)
+        let familyString = resultAtt.string
+        let styleString = self.fontStylePopUpButton.selectedItem?.title
+        let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: familyString, .face: styleString as Any])
+        let fontSizeString = fontSizeComboBox.stringValue.replacingOccurrences(of: " pt", with: "")
+        let newFont = NSFont(descriptor: attributeFontDescriptor, size: fontSizeString.stringToCGFloat())
+        var fontAlignment: KMFreeTextAnnotationAlignmentType = .left
+        if annotationModel.alignment() == .left {
+            fontAlignment = .left
+        } else if annotationModel.alignment() == .center {
+            fontAlignment = .center
+        } else if annotationModel.alignment() == .right {
+            fontAlignment = .right
+        }
+        let fontModel = KMFontModel(fontName: familyString, fontWeight: styleString!, fontSize: fontSizeString.stringToCGFloat(), fontColor: colorPickerView.color ?? .black, fontAlignment: fontAlignment, annotationType: annotationModel.annotationType)
+        
+        let fontWindowController = KMAnnotationFontWindowController.initWindowController(fontModel)
+        let window = fontWindowController.window
+        fontWindowController.callback = { [weak self] model in
+            self!.colorPickerView.color = model.fontColor
             
-//            fontWindowController.annotationCallback = {
-//                
-//            }
+            DispatchQueue.global(qos: .default).async { [self]
+                let fonts = NSFontManager.shared.availableFontFamilies
+                let menu = NSMenu()
+                var selectedIndex = 0
+                
+                for (index, fontName) in fonts.enumerated() {
+                    if let font = NSFont(name: fontName, size: 12.0) {
+                        let attributedString = NSAttributedString(string: fontName, attributes: [.font: font])
+                        let item = NSMenuItem()
+                        item.attributedTitle = attributedString
+                        menu.addItem(item)
+                        
+                        if let family = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.family) as? String,
+                           let style = font.fontDescriptor.object(forKey: NSFontDescriptor.AttributeName.face) as? String {
+                            if model.fontName == family {
+                                selectedIndex = index
+                            }
+                        }
+                    }
+                }
+                DispatchQueue.main.async {
+                    if self != nil {
+                        self!.fontPopUpButton.menu = menu
+                        self!.fontPopUpButton.selectItem(at: selectedIndex)
+                    }
+                }
+            }
+            let selectedStyleIndex = self!.setFontStyle(withFontName: model.fontName, currentStyle: model.fontWeight)
+            self!.fontStylePopUpButton.selectItem(at: Int(selectedStyleIndex))
+            self!.fontSizeComboBox.stringValue = String(format: "%.f pt", model.fontSize)
             
-            window!.orderFront(sender)
+            if self!.annotationModel.annotations != nil {
+                let attributeFontDescriptor = NSFontDescriptor(fontAttributes: [.family: model.fontName, .face: model.fontWeight])
+                let annotationFont = NSFont(descriptor: attributeFontDescriptor, size: model.fontSize)
+
+                for tAnnotation in self!.annotations {
+                    if tAnnotation is CPDFTextWidgetAnnotation {
+                        (tAnnotation as! CPDFTextWidgetAnnotation).font = annotationFont
+                        (tAnnotation as! CPDFTextWidgetAnnotation).fontColor = model.fontColor
+                        if model.fontAlignment == .left {
+                            (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .left
+                        } else if model.fontAlignment == .center {
+                            (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .center
+                        } else if model.fontAlignment == .right {
+                            (tAnnotation as! CPDFTextWidgetAnnotation).alignment = .right
+                        }
+                    }
+                }
+                self!.updateAnnotation()
+            } else {
+                self!.annotationModel.setFontName(model.fontName)
+                self!.annotationModel.setFontSize(model.fontSize)
+                self!.annotationModel.setFontColor(model.fontColor)
+                if model.fontAlignment == .left {
+                    self!.annotationModel.setAlignment(.left)
+                } else if model.fontAlignment == .center {
+                    self!.annotationModel.setAlignment(.center)
+                } else if model.fontAlignment == .right {
+                    self!.annotationModel.setAlignment(.right)
+                }
+            }
         }
+        window?.orderFront(sender)
     }
 
     // MARK: NSNotification Action

+ 4 - 3
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -3489,11 +3489,12 @@ extension KMMainViewController {
         if IAPProductsManager.default().isAvailableAllFunction() {
             return
         }
-        if recommondPopWindowVC == nil {
-            recommondPopWindowVC = KMRecommondPopWindow()
-        }
         
         if let info = KMAdvertisementManager.manager.info.popWindowContent?.content?.first {
+            
+            if recommondPopWindowVC == nil {
+                recommondPopWindowVC = KMRecommondPopWindow()
+            }
             recommondPopWindowVC?.recommondInfo = info
             
             guard let windowFrame = self.view.window?.frame, let popWindowFrame = recommondPopWindowVC?.window?.frame else {

+ 6 - 2
PDF Office/PDF Master/Class/Purchase/DMG/KMPurchaseCompareDMGWindowController.m

@@ -462,13 +462,15 @@ static NSString *const KMPurchaseCompareDMGCellIdentifier       = @"KMPurchaseCo
     
     if (KMAdvertisementManager.manager.info.discountContent.content.count > 0) {
         KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.discountContent.content.firstObject;
-        if ([info.show isEqual:@"1"] ) {
+        if ([KMAdvertisementManager checkAdvertisementValid:info]) {
             self.discountTipImage.hidden = NO;
             
             NSURL *url = [NSURL URLWithString:[KMAdvertisementModelTransition transitionImagePathWithImage:info.image highlight:NO]];
             self.discountTipImage.image = [KMAdvertisementImage imageWithURLWithUrl:url completion:^(NSImage * _Nonnull image) {
                 self.discountTipImage.image = image;
             }];
+        } else {
+            self.discountTipImage.hidden = YES;
         }
     }
 }
@@ -652,9 +654,11 @@ static NSString *const KMPurchaseCompareDMGCellIdentifier       = @"KMPurchaseCo
     dispatch_async(dispatch_get_main_queue(), ^{
         if (KMAdvertisementManager.manager.info.discountContent.content.count > 0) {
             KMAdvertisementItemInfo *info = KMAdvertisementManager.manager.info.discountContent.content.firstObject;
-            if ([info.show isEqual:@"1"] ) {
+            if ([KMAdvertisementManager checkAdvertisementValid:info]) {
                 self.discountTipImage.hidden = NO;
                 self.discountTipImage.image = info.image;
+            } else {
+                self.discountTipImage.hidden = YES;
             }
         }
     });