Browse Source

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

tangchao 10 months ago
parent
commit
4fada295a7

+ 5 - 0
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Base/KMHeaderFooterAdjectiveModel.swift

@@ -15,6 +15,11 @@ enum KMHeaderFooterObjectType: Int {
 @objcMembers class KMHeaderFooterAdjectiveModel: KMWatermarkAdjectiveBaseModel , NSCoding {
     var type: KMHeaderFooterObjectType = .headerFooter
     
+    // 是否数据迁移(原App数据迁移)
+    var isMigrate = false
+    // 是否已被更新
+    var isUpdated = false
+    
     var leftMargin: Int = 30
     var rightMargin: Int = 30
     var bottomMargin: Int = 30

+ 37 - 29
PDF Office/PDF Master/Class/PDFTools/HeaderFooter/Tools/KMHeaderFooterManager.swift

@@ -1,6 +1,11 @@
 import Foundation
 
+let kHeaderFooterFolderPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("headerFooter")
+let kHeaderFooterPlistPath = kHeaderFooterFolderPath?.stringByAppendingPathComponent("headerFooter.plist") ?? ""
+let kHeaderFooterRemovedKey = "kHeaderFooterRemovedKey"
+
 private let kHeaderFooterInfoSaveKey = "kHeaderFooterInfoSaveKey"
+let kHeaderFooterManagerInit = "kHeaderFooterManagerInit"
 
 class KMHeaderFooterManager: NSObject, NSCoding {
     var headFooterObjects: [KMHeaderFooterObject] = []
@@ -23,15 +28,22 @@ class KMHeaderFooterManager: NSObject, NSCoding {
 
     func reloadData() {
         do {
-            self.fetchPlistData()
-            
             if let storedData = UserDefaults.standard.value(forKey: kHeaderFooterInfoSaveKey) as? Data {
                 NSKeyedUnarchiver.setClass(KMHeaderFooterObject.self, forClassName: "KMHeaderFooterObject")
                 NSKeyedUnarchiver.setClass(KMHeaderFooterManager.self, forClassName: "KMHeaderFooterManager")
-                if let man = NSKeyedUnarchiver.unarchiveObject(with: storedData) as? KMHeaderFooterManager {
-                    self.headFooterObjects = man.headFooterObjects
+                
+                let pHeadFooterObjects = self.fetchPlistData()
+                self.headFooterObjects = pHeadFooterObjects
+                if UserDefaults.standard.object(forKey: kHeaderFooterManagerInit) == nil {
+                    if let man = NSKeyedUnarchiver.unarchiveObject(with: storedData) as? KMHeaderFooterManager {
+                        UserDefaults.standard.set("1", forKey: kHeaderFooterManagerInit)
+                        for object in  man.headFooterObjects {
+                            object.isMigrate = true
+                            self.headFooterObjects.append(object)
+                        }
+                    }
+                    
                     self.savePlistData()
-                    print(man)
                 }
             }
         } catch {
@@ -105,18 +117,21 @@ class KMHeaderFooterManager: NSObject, NSCoding {
     }
 
     func store() {
-        do {
-            let encodedObject = try NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false)
-            UserDefaults.standard.set(encodedObject, forKey: kHeaderFooterInfoSaveKey)
-            UserDefaults.standard.synchronize()
-        } catch {
-            print("Error while encoding object: \(error)")
-        }
+//        do {
+//            let encodedObject = try NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false)
+//            UserDefaults.standard.set(encodedObject, forKey: kHeaderFooterInfoSaveKey)
+//            UserDefaults.standard.synchronize()
+//        } catch {
+//            print("Error while encoding object: \(error)")
+//        }
+        self.savePlistData()
     }
 
     func clearStored() {
         UserDefaults.standard.removeObject(forKey: kHeaderFooterInfoSaveKey)
         UserDefaults.standard.synchronize()
+        
+        try?FileManager.default.removeItem(atPath: kHeaderFooterPlistPath)
     }
 
     func fetchHeaderFooterAvailableName() -> String {
@@ -148,41 +163,34 @@ class KMHeaderFooterManager: NSObject, NSCoding {
     }
 }
 
-
-let kHeaderFooterFolderPath = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.applicationSupportDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).last?.stringByAppendingPathComponent(Bundle.main.bundleIdentifier!).stringByAppendingPathComponent("headerFooter")
-let kHeaderFooterPlistPath = kHeaderFooterFolderPath?.stringByAppendingPathComponent("headerFooter.plist")
-let kHeaderFooterRemovedKey = "kHeaderFooterRemovedKey"
-
 extension KMHeaderFooterManager {
-    func fetchPlistData() {
+    func fetchPlistData() -> [KMHeaderFooterObject] {
         if (!FileManager.default.fileExists(atPath: kHeaderFooterFolderPath!)) {
             try?FileManager.default.createDirectory(atPath: kHeaderFooterFolderPath!, withIntermediateDirectories: false)
         }
         
-        if (!FileManager.default.fileExists(atPath: kHeaderFooterPlistPath!)) {
-            FileManager.default.createFile(atPath: kHeaderFooterPlistPath!, contents: nil)
+        if (!FileManager.default.fileExists(atPath: kHeaderFooterPlistPath)) {
+            FileManager.default.createFile(atPath: kHeaderFooterPlistPath, contents: nil)
         }
-        print("页眉页脚文件地址 =" + kHeaderFooterPlistPath!)
+        print("页眉页脚文件地址 =" + kHeaderFooterPlistPath)
         
-        let plistData = try NSData(contentsOfFile: kHeaderFooterPlistPath!)
+        let plistData = try NSData(contentsOfFile: kHeaderFooterPlistPath)
         // 解档 plist 数据
-        if let headerFooterObject = try NSKeyedUnarchiver.unarchiveObject(with: plistData as! Data) as? KMHeaderFooterObject {
+        if let headerFooterObjects = try NSKeyedUnarchiver.unarchiveObject(with: plistData as! Data) as? [KMHeaderFooterObject] {
             // 如果解档成功,可以使用 headerFooterObject
-            print("Header footer object: \(headerFooterObject)")
+            print("Header footer object: \(headerFooterObjects)")
+            return headerFooterObjects
         } else {
             print("Failed to unarchive header footer object")
+            return []
         }
-    
-        
-        let dictionary = NSDictionary(contentsOfFile: kHeaderFooterPlistPath!)
-        return
     }
     
     func savePlistData() {
         // 获取 KMHeaderFooterObject 对象的归档数据
         if let archivedData = try? NSKeyedArchiver.archivedData(withRootObject: headFooterObjects, requiringSecureCoding: false) {
             // 将数据写入 plist 文件
-            let plistURL = URL(fileURLWithPath: kHeaderFooterPlistPath!)
+            let plistURL = URL(fileURLWithPath: kHeaderFooterPlistPath)
             do {
                 try archivedData.write(to: plistURL)
                 print("Header footer object saved to plist file")

+ 8 - 8
PDF Office/PDF Master/Class/PDFTools/Merge/MergeNew/KMMergeWindowController.swift

@@ -122,14 +122,14 @@ extension KMMergeWindowController {
 //                    size = size + file.fileSize
 //                }
 //                
-                let file = KMFileAttribute()
-                file.filePath = openPanel.urls.first!.path
-                size = file.fileSize + size
-//                
-                if !IAPProductsManager.default().isAvailableAllFunction() && (files.count >= 2 || size > 20 * 1024 * 1024) {
-                    KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
-                    return
-                }
+//                let file = KMFileAttribute()
+//                file.filePath = openPanel.urls.first!.path
+//                size = file.fileSize + size
+////                
+//                if !IAPProductsManager.default().isAvailableAllFunction() && (files.count >= 2 || size > 20 * 1024 * 1024) {
+//                    KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
+//                    return
+//                }
                 
                 self.mergeView.addFilePaths(urls: array)
             }

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

@@ -626,11 +626,25 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             
             [menu insertItem:[NSMenuItem separatorItem] atIndex:0];
             
+            NSMenuItem * rotateItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Rotate", @"PDFListView") action:nil keyEquivalent:@""];
+            {
+                subMenu = [[NSMenu alloc]init];
+                
+                NSMenuItem * rightItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Rotate Right", @"PDFListView") action:@selector(rotateRightStampAnnotation:) keyEquivalent:@""];
+                NSMenuItem * leftItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Rotate Left", @"PDFListView") action:@selector(rotateLeftStampAnnotation:) keyEquivalent:@""];
+                [subMenu addItem:rightItem];
+                [subMenu addItem:leftItem];
+                rotateItem.submenu = subMenu;
+            }
+            
             if([self.activeAnnotation isKindOfClass:[CPDFMarkupAnnotation class]] ||
                [self.activeAnnotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
                 [menu insertItem:editNoteItem atIndex:0];
             } else if ([self.activeAnnotation isKindOfClass:[CPDFStampAnnotation class]]) {
                 [menu insertItem:editNoteItem atIndex:0];
+                if ([self.activeAnnotation isKindOfClass:[CPDFListStampAnnotation class]]) {
+                    [menu insertItem:rotateItem atIndex:0];
+                }
                 [menu insertItem:lineStyleItem atIndex:0];
                 [menu insertItem:changeColorItem atIndex:0];
             } else if ([self.activeAnnotation isKindOfClass:[CPDFInkAnnotation class]]) {
@@ -763,6 +777,52 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     return menu;
 }
 
+- (void)rotateLeftStampAnnotation:(id)sender {
+    if ([self.activeAnnotation isKindOfClass:[CPDFListStampAnnotation class]]) {
+        [self rotateLeftForStampAnnotation:self.activeAnnotation];
+    }
+}
+
+- (void)rotateRightStampAnnotation:(id)sender {
+    if ([self.activeAnnotation isKindOfClass:[CPDFListStampAnnotation class]]) {
+        [self rotateRightForStampAnnotation:self.activeAnnotation];
+    }
+}
+
+- (void)rotateLeftForStampAnnotation:(CPDFListStampAnnotation *)annotation {
+    NSInteger rotation = annotation.rotation;
+    if (rotation == 0) {
+        rotation = 270;
+    } else if (rotation == 90) {
+        rotation = 0;
+    } else if (rotation == 180) {
+        rotation = 90;
+    } else if (rotation == 270) {
+        rotation = 180;
+    }
+    annotation.rotation = rotation;
+    [self setNeedsDisplay:true];
+
+    [[[self undoManager] prepareWithInvocationTarget:self] rotateRightForStampAnnotation:annotation];
+}
+
+- (void)rotateRightForStampAnnotation:(CPDFListStampAnnotation *)annotation {
+    NSInteger rotation = annotation.rotation;
+    if (rotation == 0) {
+        rotation = 90;
+    } else if (rotation == 90) {
+        rotation = 180;
+    } else if (rotation == 180) {
+        rotation = 270;
+    } else if (rotation == 270) {
+        rotation = 0;
+    }
+    annotation.rotation = rotation;
+    [self setNeedsDisplay:true];
+    
+    [[[self undoManager] prepareWithInvocationTarget:self] rotateLeftForStampAnnotation:annotation];
+}
+
 - (NSMenuItem *)creatExportItem{
     NSMenuItem * exportImageItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"Export", nil) action:@selector(menuItemClick_ExportImage:) keyEquivalent:@""];
     
@@ -870,7 +930,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             return NO;
         } else {
             NSArray *pageAnnotationArray = page.annotations;
-            return ![annotation isEqual:pageAnnotationArray.lastObject];
+            return ![annotation isEqual:pageAnnotationArray.firstObject];
         }
     } else if (action == @selector(menuItemClick_BringFront:)){
         NSDictionary *dict = menuItem.representedObject;
@@ -880,7 +940,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
             return NO;
         } else {
             NSArray *pageAnnotationArray = page.annotations;
-            return ![annotation isEqual:pageAnnotationArray.firstObject];
+            return ![annotation isEqual:pageAnnotationArray.lastObject];
         }
     } else if (action == @selector(menuItemClick_SendBack:)) {
         NSDictionary *dict = menuItem.representedObject;

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

@@ -3087,7 +3087,7 @@ let LOCKED_KEY  = "locked"
 //                currentMenu.insertItem(self.setCropStype(), at: currentMenu.items.count - 15)
 //                currentMenu.insertItem(self.setTTSStype(), at: currentMenu.items.count - 15)
                 if let anno = self.listView.activeAnnotation, anno.isKind(of: CPDFStampAnnotation.self) {
-                    
+//                    currentMenu.insertItem(self.setRotateStype(), at: currentMenu.items.count - 15)
                 } else {
                     currentMenu.insertItem(NSMenuItem.separator(), at: currentMenu.items.count - 15)
                     currentMenu.insertItem(self.setShareStype(), at: currentMenu.items.count - 15)