Parcourir la source

【综合】【签名&填写表单】暗黑模式下,对号显示不清(已修复)

tangchao il y a 11 mois
Parent
commit
4c99b867ac

+ 34 - 0
PDF Office/PDF Master/Class/Common/Category/CPDFKit/CPDFOutline+KMExtension.swift

@@ -65,6 +65,15 @@ import Foundation
 // CPDFOutline
 
 @objc extension CPDFDocument {
+    
+    @objc func canPromote(outline ol: CPDFOutline) -> Bool {
+        if self.isLocked {
+            return false
+        }
+        // 存在祖父节点
+        return ol.parent?.parent != nil
+    }
+    
     // 升级大纲 [插入位置 (当前父节点后)]
     
     @objc func promoteNext(outline ol: CPDFOutline) {
@@ -81,6 +90,14 @@ import Foundation
         }
     }
     
+    @objc func canDemote(outline ol: CPDFOutline) -> Bool {
+        if self.isLocked {
+            return false
+        }
+        // 不是第一个节点
+        return ol.index > 0
+    }
+    
     // 降级大纲 [插入位置 (最后)]
     
     @objc func demoteLast(outline ol: CPDFOutline) {
@@ -156,7 +173,19 @@ import Foundation
     static let outlineDemoteKey =           "demote"
     static let outlinePromoteKey =          "promote"
     
+    @objc func canPromote(outline ol: CPDFOutline) -> Bool {
+        return self.document?.canPromote(outline: ol) ?? false
+    }
+    
+    @objc func canDemote(outline ol: CPDFOutline) -> Bool {
+        return self.document?.canDemote(outline: ol) ?? false
+    }
+    
     @objc func demote(outline ol: CPDFOutline) {
+        if self.canDemote(outline: ol) == false {
+            NSSound.beep()
+            return
+        }
         (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_promote(outline: ol, at: ol.index)
         
         self.document?.demoteLast(outline: ol)
@@ -165,6 +194,11 @@ import Foundation
     }
     
     @objc func promote(outline ol: CPDFOutline) {
+        if self.canPromote(outline: ol) == false {
+            NSSound.beep()
+            return
+        }
+        
         (self.undoManager?.prepare(withInvocationTarget: self) as AnyObject)._undo_demote(outline: ol, at: ol.index)
         
         self.document?.promoteNext(outline: ol)

+ 5 - 6
PDF Office/PDF Master/Class/PDFTools/Crop/Tools/KMCropTools.swift

@@ -17,7 +17,7 @@ import Cocoa
     }
     
     class func getPageSizeValue(_ pageSize: String) -> NSSize {
-        var size = NSZeroSize;
+        var size = NSZeroSize
         if (pageSize == "A3") {
             size = NSSize(width:297 , height: 420)
         } else if (pageSize == "A4") {
@@ -57,7 +57,7 @@ import Cocoa
         
         let imageRep = KMCropTools.newBitmapImageRepForBox(page, .mediaBox)
         let bounds = page.bounds(for: .mediaBox)
-        var foregroundBox = imageRep.foregroundRect()
+        var foregroundBox = imageRep?.foregroundRect() ?? .zero
         if (imageRep == nil) {
             foregroundBox = bounds
         } else if (NSIsEmptyRect(foregroundBox)) {
@@ -73,7 +73,7 @@ import Cocoa
         return NSIntegralRect(NSInsetRect(foregroundBox, -marginWidth, -marginHeight))
     }
     
-    class func newBitmapImageRepForBox(_ page: CPDFPage, _ box: CPDFDisplayBox) -> NSBitmapImageRep {
+    class func newBitmapImageRepForBox(_ page: CPDFPage, _ box: CPDFDisplayBox) -> NSBitmapImageRep? {
         let bounds = page.bounds(for: box)
         var imageRep = NSBitmapImageRep(bitmapDataPlanes: nil,
                                         pixelsWide: Int(NSWidth(bounds)),
@@ -106,12 +106,11 @@ import Cocoa
                 transform.concat()
             }
             
-            page.draw(with: box, to: (NSGraphicsContext.current?.cgContext as! CGContext))
-//            page.draw(with: box)
+            page.draw(with: box, to: (NSGraphicsContext.current?.cgContext))
             NSGraphicsContext.current?.imageInterpolation = .default
             NSGraphicsContext.restoreGraphicsState()
         }
         
-        return imageRep!
+        return imageRep
     }
 }

+ 15 - 44
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Action.swift

@@ -714,60 +714,31 @@ extension KMLeftSideViewController: NSMenuItemValidation {
                 }
             } else {
                 let clickedOutline = self.tocOutlineView.item(atRow: self.tocOutlineView.clickedRow) as? CPDFOutline
-                if let data = clickedOutline?.index, data > 0 {
-                    if (action == #selector(outlineContextMenuItemClicked_Demote)) {
-                        return true
+                if (action == #selector(outlineContextMenuItemClicked_Demote)) {
+                    if let data = clickedOutline {
+                        return self.pdfDocument()?.canDemote(outline: data) ?? false
                     }
-                } else {
-                    if (action == #selector(outlineContextMenuItemClicked_Demote)) {
+                    return false
+                }
+                if (action == #selector(outlineContextMenuItemClicked_Promote)) {
+                    if let data = clickedOutline {
+                        return self.pdfDocument()?.canPromote(outline: data) ?? false
+                    } else {
                         return false
                     }
                 }
-                let parentOutLine = clickedOutline?.parent
-                let grandparentOutLine = parentOutLine?.parent
-                //if clicked PDFOutline 's parent exist
-                if (grandparentOutLine != nil) {
-                    //and title is equla "add_AuntOutlineKey"
-                    if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
+                if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
+                    let parentOutLine = clickedOutline?.parent
+                    let grandparentOutLine = parentOutLine?.parent
+                    if (grandparentOutLine != nil) {
                         return true
-                    } else if (action == #selector(outlineContextMenuItemClicked_Promote)){
-                        return true
-                    }
-                } else {
-                    if (action == #selector(outlineContextMenuItemClicked_AddAuntEntry)) {
-                        return false
-                    }else if (action == #selector(outlineContextMenuItemClicked_Promote)){
+                    } else {
                         return false
                     }
                 }
             }
             return true
-        }
-//            else
-//        if ([menuItem action] == @selector(toggleEncryptFilePanel:)) {
-//            [menuItem setTitle:NSLocalizedString(@"Set Passwords", @"Menu item title")];
-//            NSURL *fileURL = [self.pdfView.document documentURL];
-//            if (!fileURL) {
-//                return YES;
-//            }
-//            PDFDocument *pdfDoc = [[[PDFDocument alloc] initWithURL:fileURL] autorelease];
-//
-//            if ([pdfDoc isLocked]) {
-//                [menuItem setTitle:NSLocalizedString(@"Remove Security", @"Menu item title")];
-//            }
-//        } else if (action == @selector(toggleToolbarShow:)) {
-//            NSToolbar *toolbar = [self.window toolbar];
-//            if ([toolbar isVisible])
-//                [menuItem setTitle:NSLocalizedString(@"Hide Toolbar", @"Menu item title")];
-//            else
-//                [menuItem setTitle:NSLocalizedString(@"Show Toolbar", @"Menu item title")];
-//            return YES;
-//        } else if (action == @selector(readMode:)) {
-//            menuItem.state = self.isReadMode ? NSControlStateValueOn : NSControlStateValueOff;
-//            return YES;
-//        } else if (action == @selector(addForm:)) {
-//            return YES;
-        else if action == #selector(toggleOutlineCaseInsensitiveSearch) {
+        } else if action == #selector(toggleOutlineCaseInsensitiveSearch) {
             menuItem.state = self.outlineIgnoreCaseFlag ? .on : .off
             return true
         }

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Toolbar/KMToolbarViewController.swift

@@ -1703,7 +1703,7 @@ extension KMToolbarViewController {
     private func _setupFillSignItem(_ item: KMToolbarItemView?) {
         let identifier = item?.itemIdentifier
         if identifier == KMToolbarToolHookItemIdentifier {
-            item?.image = NSImage(named: "KMImageNameFillSignHook")
+            item?.image = NSImage(named: KMImageNameUXIconSubtoolbarFillsignTick)
             item?.target = self
             item?.btnTag = CAnnotationType.signTure.rawValue
             item?.toolTip = NSLocalizedString("Signature", comment: "")