Ver código fonte

【2025】【Edit】背景图片缓存管理

niehaoyu 2 meses atrás
pai
commit
4b136709d5

+ 1 - 4
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/Background/KMBackgroundManager.swift

@@ -146,10 +146,7 @@ class KMBackgroundManager: NSObject  {
         
         let result = newDictionary.write(toFile: kBackgroundPlistPath!, atomically: true)
         if (result) {
-            if (model.type == .image) {
-                let filePath: String = model.imagePath ?? ""
-                try?FileManager.default.removeItem(atPath: filePath)
-            }
+            model.removeModelCacheInfo()
             
             if (self.datas.contains(model)) {
                 self.datas.removeObject(model)

+ 12 - 2
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/Background/KMBackgroundModel.swift

@@ -71,10 +71,19 @@ import Cocoa
         }
     }
     
+    func removeModelCacheInfo() {
+        if let imagePath = self.imagePath {
+            try?FileManager.default.removeItem(atPath: imagePath)
+        }
+        if let imagePath = KMBackgroundManager.defaultManager.kBackgroundImageFolder?.stringByAppendingPathComponent((self.backgroundID + ".png")) {
+            try?FileManager.default.removeItem(atPath: imagePath)
+        }
+    }
+    
     func drawImage(rect: CGRect) -> NSImage {
         let drawRect: CGRect = NSMakeRect(0, 0, 128, 160)
 
-        let image = NSImage(size: drawRect.size)
+        var image = NSImage(size: drawRect.size)
         image.lockFocus()
         NSGraphicsContext.current?.imageInterpolation = .high
 
@@ -137,7 +146,8 @@ import Cocoa
                                                   size.width, size.height));
         } else if (self.type == .image) {
             var size: NSSize = CGSizeZero
-            if let image = self.image() {
+            if let img = self.image() {
+                image = img
                 size = image.size
             }
             size.width *= self.scale

+ 5 - 1
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/Background/Views/KMBGTemplateItem.swift

@@ -21,7 +21,11 @@ import KMComponentLibrary
 class KMBGTemplateItem: NSCollectionViewItem {
   
     @IBOutlet var watermarkItem: ComponentCardWatermark!
-
+    
+    @IBOutlet var iconImage: NSImageView!
+    @IBOutlet var iconImageWidthConst: NSLayoutConstraint!
+    @IBOutlet var iconImageHeightConst: NSLayoutConstraint!
+    
     var backgroundModel: KMBackgroundModel?
     
     var itemSelected: Bool = false

+ 13 - 0
PDF Office/PDF Master/KMClass/KMPDFViewController/EditTool/Background/Views/KMBGTemplateItem.xib

@@ -8,6 +8,9 @@
     <objects>
         <customObject id="-2" userLabel="File's Owner" customClass="KMBGTemplateItem" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
+                <outlet property="iconImage" destination="ZhR-SQ-pB0" id="B21-uw-RIJ"/>
+                <outlet property="iconImageHeightConst" destination="QKF-u3-WNP" id="f4G-Je-Isq"/>
+                <outlet property="iconImageWidthConst" destination="pAn-2A-2YS" id="8qe-lU-29p"/>
                 <outlet property="view" destination="Hz6-mo-xeY" id="0bl-1N-x8E"/>
                 <outlet property="watermarkItem" destination="oEd-9U-hkX" id="ryX-mu-WzP"/>
             </connections>
@@ -24,12 +27,22 @@
                         <customView translatesAutoresizingMaskIntoConstraints="NO" id="oEd-9U-hkX" customClass="ComponentCardWatermark" customModule="KMComponentLibrary">
                             <rect key="frame" x="0.0" y="0.0" width="177" height="255"/>
                         </customView>
+                        <imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="ZhR-SQ-pB0">
+                            <rect key="frame" x="65" y="104" width="48" height="48"/>
+                            <constraints>
+                                <constraint firstAttribute="height" constant="48" id="QKF-u3-WNP"/>
+                                <constraint firstAttribute="width" constant="48" id="pAn-2A-2YS"/>
+                            </constraints>
+                            <imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" id="pOd-6X-9u5"/>
+                        </imageView>
                     </subviews>
                     <constraints>
                         <constraint firstAttribute="trailing" secondItem="oEd-9U-hkX" secondAttribute="trailing" id="5OS-Pm-XdU"/>
+                        <constraint firstItem="ZhR-SQ-pB0" firstAttribute="centerY" secondItem="bBV-cb-Fee" secondAttribute="centerY" id="Ipu-n1-EL4"/>
                         <constraint firstItem="oEd-9U-hkX" firstAttribute="leading" secondItem="bBV-cb-Fee" secondAttribute="leading" id="gQX-7u-wKL"/>
                         <constraint firstAttribute="bottom" secondItem="oEd-9U-hkX" secondAttribute="bottom" id="nko-eV-dLa"/>
                         <constraint firstItem="oEd-9U-hkX" firstAttribute="top" secondItem="bBV-cb-Fee" secondAttribute="top" id="r9E-So-2Uy"/>
+                        <constraint firstItem="ZhR-SQ-pB0" firstAttribute="centerX" secondItem="bBV-cb-Fee" secondAttribute="centerX" id="sQO-qf-yWi"/>
                     </constraints>
                 </customView>
             </subviews>

+ 2 - 2
PDF Office/PDF Reader Pro.xcodeproj/project.pbxproj

@@ -18257,7 +18257,7 @@
 				COMBINE_HIDPI_IMAGES = YES;
 				CURRENT_PROJECT_VERSION = 202410250;
 				DEFINES_MODULE = YES;
-				DEVELOPMENT_TEAM = A2L5C8Y77N;
+				DEVELOPMENT_TEAM = 4GGQPGRTSV;
 				ENABLE_HARDENED_RUNTIME = YES;
 				EXCLUDED_ARCHS = "";
 				FRAMEWORK_SEARCH_PATHS = (
@@ -18424,7 +18424,7 @@
 				COMBINE_HIDPI_IMAGES = YES;
 				CURRENT_PROJECT_VERSION = 202410250;
 				DEFINES_MODULE = YES;
-				DEVELOPMENT_TEAM = A2L5C8Y77N;
+				DEVELOPMENT_TEAM = 4GGQPGRTSV;
 				ENABLE_HARDENED_RUNTIME = YES;
 				EXCLUDED_ARCHS = "";
 				FRAMEWORK_SEARCH_PATHS = (