Browse Source

【注释】选中Stamp属性面板旋转实现方法补充

wanjun 1 year ago
parent
commit
a9dcb33d85

+ 0 - 4
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Extension.h

@@ -26,10 +26,6 @@
 
 - (void)addAnnotationWithSignature:(KMSignature *)signature;
 
-- (void)rotateLeftForStampAnnotation:(KMAnnotationStamp *)annotation;
-
-- (void)rotateRightForStampAnnotation:(KMAnnotationStamp *)annotation;
-
 - (void)setStampAnnotation:(KMAnnotationStamp *)annotation forImageAlpha:(CGFloat)alpha;
 
 - (BOOL)canCopy;

+ 0 - 32
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Extension.m

@@ -302,38 +302,6 @@ CGFloat DEFAULT_SNAPSHOT_HEIGHT = 200.0;
     else NSBeep();
 }
 
-- (void)rotateLeftForStampAnnotation:(KMAnnotationStamp *)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 undoManager] prepareWithInvocationTarget:self] rotateRightForStampAnnotation:annotation];
-}
-
-- (void)rotateRightForStampAnnotation:(KMAnnotationStamp *)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 undoManager] prepareWithInvocationTarget:self] rotateLeftForStampAnnotation:annotation];
-}
-
 - (void)setStampAnnotation:(KMAnnotationStamp *)annotation forImageAlpha:(CGFloat)alpha {
     [[[self undoManager] prepareWithInvocationTarget:self] setStampAnnotation:annotation forImageAlpha:annotation.imageAlpha];
 

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

@@ -262,13 +262,6 @@
             self.contentViewController = vc;
         }
         
-    } else if ([annotation isKindOfClass:[KMAnnotationStamp class]]) {
-        KMAnnotationStampViewController *vc = [[KMAnnotationStampViewController alloc] init];
-        vc.pdfView = self.pdfView;
-        vc.annotationModel = annotationModel;
-        vc.view.frame = [self viewControllerRect];
-        [self.view addSubview:vc.view];
-        self.contentViewController = vc;
     } else if ([annotation isKindOfClass:[CPDFListSignatureAnnotation class]]) {
         
     } else if ([annotation isKindOfClass:[CPDFSignatureAnnotation class]]) {
@@ -348,9 +341,7 @@
             annotationMode = CAnnotationTypeFreeText;
         }
     }
-    
     self.annotationMode = annotationMode;
-    
 }
 
 - (void)setAnnotationMode:(CAnnotationType)annotationMode {

+ 19 - 39
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/StampList/KMAnnotationStampViewController.swift

@@ -124,12 +124,12 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
         NotificationCenter.default.removeObserver(self)
         DistributedNotificationCenter.default.removeObserver(self)
 
-        if ((annotationModel?.annotation) != nil) && annotationModel?.annotations.count == 1 {
-            let keys = ["string", "rotation", "imageAlpha"]
-            for key in keys {
-                self.annotation.removeObserver(self, forKeyPath: key)
-            }
-        }
+//        if ((annotationModel?.annotation) != nil) && annotationModel?.annotations.count == 1 {
+//            let keys = ["string", "rotation", "imageAlpha"]
+//            for key in keys {
+//                self.annotation.removeObserver(self, forKeyPath: key)
+//            }
+//        }
         dateComboBox.delegate = nil
         contentTextView.delegate = nil
 
@@ -389,8 +389,8 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
         
         var opacity = 1.0
         if annotationModel?.annotations != nil {
-            if annotation is KMAnnotationStamp {
-                opacity = Double((annotation as! KMAnnotationStamp).imageAlpha)
+            if annotation is CPDFListStampAnnotation {
+                opacity = Double((annotation as! CPDFListStampAnnotation).opacity)
             }
         }
         opacitySlider.floatValue = Float(opacity)
@@ -410,7 +410,9 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
                 blockSelf.leftRotateImage.image = NSImage(named: KMImageNameUXIconPropertybarRotateCounterclockwisePre)
                 
                 for tAnnotation in blockSelf.annotations {
-                    blockSelf.pdfView?.rotateLeft(forStampAnnotation: (tAnnotation as! KMAnnotationStamp))
+                    if tAnnotation is CPDFListStampAnnotation {
+                        blockSelf.pdfView?.rotateStampAnnotation(tAnnotation as! CPDFListStampAnnotation, rotateAngle: -90)
+                    }
                 }
             } else {
                 blockSelf.leftRotateBox.fillColor = KMAppearance.Layout.l1Color()
@@ -432,7 +434,11 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
                 blockSelf.rightRotateImage.image = NSImage(named: KMImageNameUXIconPropertybarRotateClockwisePre)
                 
                 for tAnnotation in blockSelf.annotations {
-                    blockSelf.pdfView?.rotateRight(forStampAnnotation: (tAnnotation as! KMAnnotationStamp))
+                    if tAnnotation is CPDFListStampAnnotation {
+                        if tAnnotation is CPDFListStampAnnotation {
+                            blockSelf.pdfView?.rotateStampAnnotation(tAnnotation as! CPDFListStampAnnotation, rotateAngle: 90)
+                        }
+                    }
                 }
             } else {
                 blockSelf.rightRotateBox.fillColor = KMAppearance.Layout.l1Color()
@@ -444,8 +450,6 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
         if annotationModel?.annotations != nil {
             if annotation is CPDFStampAnnotation {
                 contentTextView.string = (annotation as! CPDFStampAnnotation).string()
-            } else if annotation is KMAnnotationStamp {
-                contentTextView.string = (annotation as! KMAnnotationStamp).contentStr
             }
         }
         contentTextView.textColor = NSColor.labelColor
@@ -454,11 +458,11 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
         contentTextView.delegate = self
         contentTextView.isEditable = false
         
-        sampleImageView.image = annotationModel?.annotationImage
+//        sampleImageView.image = self.annotationModel?.annotationImage
         
         if annotationModel?.annotations != nil {
-            if annotation is KMAnnotationStamp {
-                contentTextView.isHidden = (annotation as! KMAnnotationStamp).image == nil
+            if annotation is CPDFListStampAnnotation {
+                opacityBox.isHidden = (annotation as! CPDFListStampAnnotation).pImage == nil
             }
         }
         opacityBoxTopLayoutConstraint.constant = opacityBox.isHidden ? 16 : 96
@@ -466,28 +470,6 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
         updateViewColor()
     }
     
-    func annotationImage() -> NSImage? {
-        let annotation = self.annotation
-        let image = NSImage(size: annotation.bounds.size)
-        if image.size.width == 0 || image.size.height == 0 {
-            return nil
-        }
-
-        image.lockFocus()
-        NSGraphicsContext.current?.imageInterpolation = .high
-
-        if let context = NSGraphicsContext.current?.cgContext {
-            let boxRect = annotation.page?.bounds(for: .cropBox) ?? CGRect.zero
-            context.translateBy(x: boxRect.origin.x, y: boxRect.origin.y)
-            context.translateBy(x: -annotation.bounds.origin.x, y: -annotation.bounds.origin.y)
-            annotation.draw(with: .cropBox, in: context)
-        }
-
-        NSGraphicsContext.current?.imageInterpolation = .default
-        image.unlockFocus()
-        return image
-    }
-    
     func createStandardTypeStamp() {
         createStampTableView.delegate = self
         createStampTableView.dataSource = self
@@ -1353,8 +1335,6 @@ let KMPDFDynamicStampNeedAuthorKey1 = "km_pdfview_dynamic_stamp_need_author"
             if annotation is CPDFStampAnnotation {
                 contentTextView.string = (annotation as! CPDFStampAnnotation).string()
                 (annotation as! CPDFStampAnnotation).setString(contentTextView.string)
-            } else if annotation is KMAnnotationStamp {
-                (annotation as! KMAnnotationStamp).contentStr = contentTextView.string
             }
             if obj.isEqual(self.contentTextView) {
                 UserDefaults.standard.set(self.contentTextView.string, forKey: "SKAnnotationSelfSignPlaceHolderStringKey")

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/StampList/KMAnnotationStampViewController.xib

@@ -503,7 +503,7 @@
             <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
             <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="NDK-ok-tvh">
                 <rect key="frame" x="1" y="1" width="260" height="597"/>
-                <autoresizingMask key="autoresizingMask"/>
+                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                 <subviews>
                     <view id="Aj7-0M-710">
                         <rect key="frame" x="0.0" y="0.0" width="245" height="582"/>
@@ -631,7 +631,7 @@
                                             <rect key="frame" x="0.0" y="176" width="213" height="110"/>
                                             <clipView key="contentView" drawsBackground="NO" id="wcx-5m-Dzd">
                                                 <rect key="frame" x="0.0" y="0.0" width="213" height="110"/>
-                                                <autoresizingMask key="autoresizingMask"/>
+                                                <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                 <subviews>
                                                     <textView importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" continuousSpellChecking="YES" allowsUndo="YES" usesRuler="YES" allowsNonContiguousLayout="YES" quoteSubstitution="YES" dashSubstitution="YES" spellingCorrection="YES" smartInsertDelete="YES" id="lq6-MU-1hZ">
                                                         <rect key="frame" x="0.0" y="0.0" width="213" height="110"/>