Browse Source

【注释】图片图章注释创建逻辑补充

wanjun 1 year ago
parent
commit
f6949b21f9

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

@@ -22,6 +22,8 @@
 
 - (CPDFAnnotation *)addPDFStampAnotationWithPagePoint:(CGPoint)pagePoint withPage:(CPDFPage *)page;
 
+- (void)addAnnotationWithImage:(NSImage *)image isRemoveBGColor:(BOOL)isRemoveBGColor;
+
 - (void)addAnnotationWithStamp:(KMAnnotationStamp *)stamp;
 
 - (void)addAnnotationWithSignature:(KMSignature *)signature;

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

@@ -106,6 +106,175 @@ CGFloat DEFAULT_SNAPSHOT_HEIGHT = 200.0;
     return annotation;
 }
 
+- (void)addAnnotationWithImage:(NSImage *)image isRemoveBGColor:(BOOL)isRemoveBGColor {
+    // First try the current mouse position
+    NSPoint center = [self convertPoint:[[self window] mouseLocationOutsideOfEventStream] fromView:nil];
+    [self addAnnotationWithImage:image center:center isRemoveBGColor:isRemoveBGColor];
+}
+
+- (void)addAnnotationWithImage:(NSImage *)image center:(NSPoint)center isRemoveBGColor:(BOOL)isRemoveBGColor {
+    [self setToolMode:CTextToolMode]; //不支持重复添加,重置状态
+
+    if (isRemoveBGColor) {
+        NSData *imageData = [image TIFFRepresentation];
+        CGImageRef imageRef;
+        if (imageData) {
+            CGImageSourceRef imageSource = CGImageSourceCreateWithData((CFDataRef)imageData, NULL);
+            imageRef = CGImageSourceCreateImageAtIndex(imageSource, 0, NULL);
+        } else {
+            return NSBeep();
+        }
+        
+        const int imageWidth = image.size.width;
+        const int imageHeight = image.size.height;
+        size_t bytesPerRow = imageWidth * 4;
+        uint32_t* rgbImageBuf = (uint32_t*)malloc(bytesPerRow * imageHeight);
+        
+        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+        CGContextRef context = CGBitmapContextCreate(rgbImageBuf,
+                                                     imageWidth,
+                                                     imageHeight,
+                                                     8,
+                                                     bytesPerRow,
+                                                     colorSpace,
+                                                     kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipLast);
+        CGContextDrawImage(context, CGRectMake(0, 0, imageWidth, imageHeight), imageRef);
+        
+        int pixelNum = imageWidth * imageHeight;
+        uint32_t* pCurPtr = rgbImageBuf;
+        for (int i = 0; i < pixelNum; i++, pCurPtr++) {
+            uint8_t* ptr = (uint8_t*)pCurPtr;
+            if (ptr[1] > 240 && ptr[2] > 240 && ptr[3] > 240) {
+                ptr[0] = 0;
+            }
+        }
+        
+        CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, rgbImageBuf, bytesPerRow * imageHeight, nil);
+        imageRef = CGImageCreate(imageWidth,
+                                 imageHeight,
+                                 8,
+                                 32,
+                                 bytesPerRow,
+                                 colorSpace,
+                                 kCGImageAlphaLast |kCGBitmapByteOrder32Little,
+                                 dataProvider,
+                                 NULL,
+                                 true,
+                                 kCGRenderingIntentDefault);
+        CGDataProviderRelease(dataProvider);
+        
+        NSImage *newImage = nil;
+        if (imageRef) {
+            NSRect imageRect = NSMakeRect(0.0, 0.0, 0.0, 0.0);
+            CGContextRef imageContext = nil;
+            
+            // Get the image dimensions.
+            imageRect.size.height = CGImageGetHeight(imageRef);
+            imageRect.size.width = CGImageGetWidth(imageRef);
+            
+            // Create a new image to receive the Quartz image data.
+            newImage = [[NSImage alloc] initWithSize:imageRect.size];
+            [newImage lockFocus];
+            
+            // Get the Quartz context and draw.
+            imageContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+            CGContextDrawImage(imageContext, *(CGRect*)&imageRect, imageRef);
+            [newImage unlockFocus];
+            CGImageRelease(imageRef);
+        }
+        
+        if (newImage) {
+            [self addAnnotationWithImage:newImage center:center];
+        } else {
+            [self addAnnotationWithImage:image center:center];
+        }
+    } else {
+        [self addAnnotationWithImage:image center:center];
+    }
+}
+
+- (void)addAnnotationWithImage:(NSImage *)image center:(NSPoint)center {
+    CPDFPage *page = nil;
+    NSRect bounds = NSZeroRect;
+    CPDFSelection *selection = [self currentSelection];
+    page = [selection safeFirstPage];
+    
+    // if the mouse was in the toolbar and there is a page below the toolbar, we get a point outside of the visible rect
+    page = NSMouseInRect(center, [self visibleContentRect], [self isFlipped]) ? [self pageForPoint:center nearest:NO] : nil;
+    
+    if (page == nil) {
+        // Get center of the PDFView.
+        NSRect viewFrame = [self frame];
+        center = NSMakePoint(NSMidX(viewFrame), NSMidY(viewFrame));
+        page = [self pageForPoint: center nearest: YES];
+        if (page == nil) {
+            // Get center of the current page
+            page = [self currentPage];
+            center = [self convertPoint:NSMakePoint(NSMidX([page boundsForBox:[self displayBox]]), NSMidY([page boundsForBox:[self displayBox]])) fromPage:page];
+        }
+    }
+    
+    CGFloat defaultWidth = 360;
+    CGFloat defaultHeight = 90;
+    NSSize defaultSize = ([page rotation] % 180 == 0) ? NSMakeSize(defaultWidth, defaultHeight) : NSMakeSize(defaultHeight, defaultWidth);
+
+    // Convert to "page space".
+    center = NSMakePoint(round([self convertPoint: center toPage: page].x), round([self convertPoint: center toPage: page].y));
+    NSRect rect;
+    rect.origin.x = center.x - 0.5 * defaultSize.width;
+    rect.origin.y = center.y - 0.5 * defaultSize.height;
+    rect.size = defaultSize;
+    bounds = rect;
+    
+    // Make sure it fits in the page
+    if (NSWidth(bounds) > NSWidth([page boundsForBox:[self displayBox]]))
+        bounds.size.width = NSWidth([page boundsForBox:[self displayBox]]);
+    if (NSHeight(bounds) > NSHeight([page boundsForBox:[self displayBox]]))
+        bounds.size.height = NSHeight([page boundsForBox:[self displayBox]]);
+    
+    if (NSMinX(bounds) < NSMinX([page boundsForBox:[self displayBox]]))
+        bounds.origin.x = NSMinX([page boundsForBox:[self displayBox]]);
+    else if (NSMaxX(bounds) > NSMaxX([page boundsForBox:[self displayBox]]))
+        bounds.origin.x = NSMaxX([page boundsForBox:[self displayBox]]) - NSWidth(bounds);
+    
+    if (NSMinY(bounds) < NSMinY([page boundsForBox:[self displayBox]]))
+        bounds.origin.y = NSMinY([page boundsForBox:[self displayBox]]);
+    else if (NSMaxY(bounds) > NSMaxY([page boundsForBox:[self displayBox]]))
+        bounds.origin.y = NSMaxY([page boundsForBox:[self displayBox]]) - NSHeight(bounds);
+    
+    if (page != nil) {
+        BOOL isInitial = NSEqualSizes(bounds.size, NSZeroSize) && selection == nil;
+        NSRect pageBounds = [page boundsForBox:CPDFDisplayMediaBox];
+
+        // new note added by note tool mode, don't add actual zero sized notes
+        if (isInitial)
+            bounds = SKRectFromCenterAndSquareSize(bounds.origin, 8.0);
+        
+        if(!CGPointEqualToPoint(self.lastAddAnnotationPoint, CGPointZero)) {
+            bounds.origin.x = self.lastAddAnnotationPoint.x + 3.0;
+            bounds.origin.y = self.lastAddAnnotationPoint.y - 3.0;
+            CGFloat pageWidth = pageBounds.size.width;
+            
+            if (bounds.origin.x + bounds.size.width >pageWidth) {
+                bounds.origin.x = pageWidth - bounds.size.width;
+            }
+            if (bounds.origin.y - bounds.size.height < 0) {
+                bounds.origin.y = bounds.size.height;
+            }
+        }
+        self.lastAddAnnotationPoint = bounds.origin;
+        
+        KMAnnotationStamp *newAnnotation = [[KMAnnotationStamp alloc] initWithBounds:bounds];
+//        newAnnotation.image = image;
+        
+        [newAnnotation registerUserName];
+        [self addAnnotation:newAnnotation toPage:page];
+        [[self undoManager] setActionName:NSLocalizedString(@"Add Note", @"Undo action name")];
+        
+        [self setActiveAnnotations:@[newAnnotation]];
+    } else NSBeep();
+}
+
 - (void)addAnnotationWithStamp:(KMAnnotationStamp *)stamp {
     // First try the current mouse position
     NSPoint center = [self convertPoint:[[self window] mouseLocationOutsideOfEventStream] fromView:nil];

+ 1 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/StampList/CreateStamp/Model/KMStampManagerNew.swift

@@ -123,6 +123,7 @@ class KMStampManagerNew: NSObject {
         
         return false
     }
+    
     func addStamp(withImagePath path: String) -> Bool {
         if !FileManager.default.fileExists(atPath: kStampFolderPath.path) {
             do {

+ 0 - 29
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/StampList/CreateStamp/View/KMAnnotationStamp.swift

@@ -88,119 +88,90 @@ let StampStringEdgeSizeScale = 0.1
             self.dateString = ""
             switch _customStampType {
             case .Notapproved:
-//                    self.setName("SBNotApproved")
                 self.contentStr = "Not Approved"
                 self.stampColor = .RedColor
             case .Approved:
-//                    self.setName("SBApproved")
                 self.contentStr = "Approved"
                 self.stampColor = .GreenColor
             case .Completed:
-//                    self.setName("SBCompleted")
                 self.contentStr = "Completed"
                 self.stampColor = .GreenColor
             case .Final:
-//                    self.setName("SBFinal")
                 self.contentStr = "Final"
                 self.stampColor = .GreenColor
             case .Draft:
-//                    self.setName("SBDraft")
                 self.contentStr = "Draft"
                 self.stampColor = .BlueColor
             case .Confidential:
-//                    self.setName("SBConfidential")
                 self.contentStr = "Confidential"
                 self.stampColor = .RedColor
             case .Notforpublicrelease:
-//                    self.setName("SBNotForPublicRelease")
                 self.contentStr = "Not For Public Release"
                 self.stampColor = .BlueColor
             case .Forpublicrelease:
-//                    self.setName("SBForPublicRelease")
                 self.contentStr = "For Public Release"
                 self.stampColor = .BlueColor
             case .Forcomment:
-//                    self.setName("SBForComment")
                 self.contentStr = "For Comment"
                 self.stampColor = .BlueColor
             case .Void:
-//                    self.setName("SBVoid")
                 self.contentStr = "Void"
                 self.stampColor = .RedColor
             case .Preliminaryresults:
-//                    self.setName("SBPreliminaryResults")
                 self.contentStr = "Preliminary Results"
                 self.stampColor = .BlueColor
             case .Informationonly:
-//                    self.setName("SBInformationOnly")
                 self.contentStr = "Information Only"
                 self.stampColor = .BlueColor
             case .Revised:
-//                    self.setName("SHRevised")
                 self.contentStr = "Revised"
                 self.stampColor = .RedColor
             case .Accepted:
-//                    self.setName("SHAccepted")
                 self.contentStr = ""
                 self.stampColor = .DarkGreenColor
             case .Rejected:
-//                    self.setName("SBRejected")
                 self.contentStr = ""
                 self.stampColor = .DarkRedColor
             case .Witness:
-//                    self.setName("SHWitness")
                 self.contentStr = "Witness"
                 self.stampColor = .LightRedColor
             case .Initialhere:
-//                    self.setName("SHInitialHere")
                 self.contentStr = "Initial Here"
                 self.stampColor = .PurpleColor
             case .Signhere:
-//                    self.setName("SHSignHere")
                 self.contentStr = "Sign Here"
                 self.stampColor = .LightRedColor
             case .Cross:
-//                    self.setName("SHCross")
                 self.contentStr = ""
                 self.stampColor = .BlackColor
             case .Chick:
-//                    self.setName("SHChick")
                 self.contentStr = ""
                 self.stampColor = .BlackColor
             case .Circle:
-//                    self.setName("SHCircle")
                 self.contentStr = ""
                 self.stampColor = .BlackColor
             case .Emergency:
-//                    self.setName("SBEmergency")
                 self.contentStr = "EMERGENCY"
                 self.stampColor = .RedColor
             case .Expired:
-//                    self.setName("SBExpired")
                 self.contentStr = "EXPIRED"
                 self.stampColor = .RedColor
             case .Received:
-//                    self.setName("SBReceived")
                 self.contentStr = "RECEIVED"
                 self.stampColor = .GreenColor
             case .Reviewed:
-//                    self.setName("SBReviewed")
                 self.contentStr = "REVIEWED"
                 self.stampColor = .GreenColor
             case .Verified:
-//                    self.setName("SBVerified")
                 self.contentStr = "VERIFIED"
                 self.stampColor = .GreenColor
             case .Accepteder:
-//                    self.setName("SBAccepteder")
                 self.contentStr = "ACCEPTED"
                 self.stampColor = .GreenColor
             case .Rejecteder:
-//                    self.setName("SBRejecteder")
                 self.contentStr = "REJECTED"
                 self.stampColor = .RedColor
             default:
-//                    self.setName("SBApproved")
                 self.contentStr = "Approved"
                 self.stampColor = .GreenColor
             }

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

@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMAnnotationStampViewController" customModule="PDF_Master" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMAnnotationStampViewController" customModule="PDF_Reader_Pro" customModuleProvider="target">
             <connections>
                 <outlet property="addButton" destination="XEv-5I-scI" id="f6Z-MG-7Ce"/>
                 <outlet property="annotationBox" destination="IFI-8g-CYh" id="jHE-xx-RTm"/>
@@ -86,7 +86,7 @@
             <rect key="frame" x="0.0" y="0.0" width="237" height="599"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" flexibleMinY="YES" heightSizable="YES"/>
             <subviews>
-                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="4Ch-5s-yLs" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="4Ch-5s-yLs" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                     <rect key="frame" x="0.0" y="567" width="78" height="32"/>
                     <view key="contentView" id="V6X-u1-jNc">
                         <rect key="frame" x="0.0" y="0.0" width="78" height="32"/>
@@ -108,7 +108,7 @@
                         <constraint firstItem="0E3-F3-2Pg" firstAttribute="centerX" secondItem="4Ch-5s-yLs" secondAttribute="centerX" id="h0G-GB-qie"/>
                     </constraints>
                 </box>
-                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="9dQ-3R-rf8" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="9dQ-3R-rf8" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                     <rect key="frame" x="78" y="567" width="78" height="32"/>
                     <view key="contentView" id="BYe-v1-Pon">
                         <rect key="frame" x="0.0" y="0.0" width="78" height="32"/>
@@ -151,7 +151,7 @@
                         <constraint firstItem="HfE-48-3lV" firstAttribute="centerY" secondItem="9dQ-3R-rf8" secondAttribute="centerY" id="JEM-9c-5Yu"/>
                     </constraints>
                 </box>
-                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="a4J-25-yUn" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                <box boxType="custom" borderWidth="0.0" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="a4J-25-yUn" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                     <rect key="frame" x="156" y="567" width="78" height="32"/>
                     <view key="contentView" id="eMa-S7-OOl">
                         <rect key="frame" x="0.0" y="0.0" width="78" height="32"/>
@@ -232,7 +232,7 @@
                     <rect key="frame" x="0.0" y="60" width="234" height="507"/>
                     <clipView key="contentView" drawsBackground="NO" copiesOnScroll="NO" id="QFb-tg-EJh">
                         <rect key="frame" x="0.0" y="0.0" width="234" height="507"/>
-                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <autoresizingMask key="autoresizingMask"/>
                         <subviews>
                             <tableView verticalHuggingPriority="750" allowsExpansionToolTips="YES" columnAutoresizingStyle="lastColumnOnly" tableStyle="fullWidth" columnSelection="YES" multipleSelection="NO" autosaveColumns="NO" rowHeight="64" viewBased="YES" id="bps-jM-pPg">
                                 <rect key="frame" x="0.0" y="0.0" width="234" height="507"/>
@@ -252,7 +252,7 @@
                                         </textFieldCell>
                                         <tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
                                         <prototypeCellViews>
-                                            <tableCellView identifier="KMAnnotationStampTableviewCell" id="Zvl-qd-COf" customClass="KMAnnotationStampTableviewCell" customModule="PDF_Master" customModuleProvider="target">
+                                            <tableCellView identifier="KMAnnotationStampTableviewCell" id="Zvl-qd-COf" customClass="KMAnnotationStampTableviewCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                                 <rect key="frame" x="0.0" y="0.0" width="234" height="63"/>
                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                 <subviews>
@@ -397,9 +397,9 @@
                         <rect key="frame" x="1" y="1" width="160" height="20"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                         <subviews>
-                            <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wtD-Vt-js7" customClass="KMComboBox" customModule="PDF_Master" customModuleProvider="target">
+                            <comboBox focusRingType="none" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wtD-Vt-js7" customClass="KMComboBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                 <rect key="frame" x="-1" y="-2" width="164" height="23"/>
-                                <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" buttonBordered="NO" completes="NO" numberOfVisibleItems="5" id="oR8-Eg-1Mn" customClass="KMStampComboBoxCell" customModule="PDF_Master" customModuleProvider="target">
+                                <comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" buttonBordered="NO" completes="NO" numberOfVisibleItems="5" id="oR8-Eg-1Mn" customClass="KMStampComboBoxCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                     <font key="font" metaFont="system"/>
                                     <color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
                                     <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
@@ -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" widthSizable="YES" heightSizable="YES"/>
+                <autoresizingMask key="autoresizingMask"/>
                 <subviews>
                     <view id="Aj7-0M-710">
                         <rect key="frame" x="0.0" y="0.0" width="245" height="582"/>
@@ -549,7 +549,7 @@
                                                 <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
                                             </textFieldCell>
                                         </textField>
-                                        <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="6Vm-3i-iSJ" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                                        <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="6Vm-3i-iSJ" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                             <rect key="frame" x="0.0" y="0.0" width="69" height="24"/>
                                             <view key="contentView" id="iFy-rI-1HW">
                                                 <rect key="frame" x="1" y="1" width="67" height="22"/>
@@ -572,7 +572,7 @@
                                                 <constraint firstAttribute="width" constant="69" id="z7x-p4-WCk"/>
                                             </constraints>
                                         </box>
-                                        <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Nf2-e7-zm4" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
+                                        <box boxType="custom" cornerRadius="1" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="Nf2-e7-zm4" customClass="KMBox" customModule="PDF_Reader_Pro" customModuleProvider="target">
                                             <rect key="frame" x="78" y="0.0" width="69" height="24"/>
                                             <view key="contentView" id="5Kl-Jf-ges">
                                                 <rect key="frame" x="1" y="1" width="67" height="22"/>
@@ -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" widthSizable="YES" heightSizable="YES"/>
+                                                <autoresizingMask key="autoresizingMask"/>
                                                 <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"/>
@@ -761,7 +761,7 @@
             <subviews>
                 <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="XEv-5I-scI">
                     <rect key="frame" x="16" y="29" width="205" height="32"/>
-                    <buttonCell key="cell" type="bevel" title="Button" bezelStyle="regularSquare" image="KMImageNameUXIconBtnAddWhite" imagePosition="left" alignment="center" state="on" imageScaling="proportionallyDown" inset="2" id="lDJ-8r-ufg" customClass="KMButtomCell" customModule="PDF_Master" customModuleProvider="target">
+                    <buttonCell key="cell" type="bevel" title="Button" bezelStyle="regularSquare" image="KMImageNameUXIconBtnAddWhite" imagePosition="left" alignment="center" state="on" imageScaling="proportionallyDown" inset="2" id="lDJ-8r-ufg" customClass="KMButtomCell" customModule="PDF_Reader_Pro" customModuleProvider="target">
                         <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                         <font key="font" metaFont="system"/>
                     </buttonCell>

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

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>

+ 86 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -3057,6 +3057,91 @@ extension KMMainViewController {
         }
     }
     
+    // MARK: - 图片注释
+    
+    @IBAction func imageAnnotation(_ sender: Any) {
+        FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_Tools", withProperties: ["SubTbr_Btn": "Btn_SubTbr_Tools_Image"])
+        
+        changeAnnotationMode(sender)
+        guard IAPProductsManager.default().isAvailableAllFunction() else {
+            KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
+            return
+        }
+        
+        let accessoryCtr = KMImageAccessoryController()
+        let openPanel = NSOpenPanel()
+        openPanel.allowedFileTypes = KMImageAccessoryController.supportedImageTypes()
+        openPanel.allowsMultipleSelection = false
+        openPanel.accessoryView = accessoryCtr.view
+        if #available(macOS 10.11, *) {
+            openPanel.canSelectHiddenExtension = true
+        }
+        openPanel.beginSheetModal(for: NSApp.mainWindow!) { [self] (result) in
+            if result == NSApplication.ModalResponse.OK {
+                guard let url = openPanel.url else { return }
+                let filePath = url.path
+                
+                if filePath.pathExtension.lowercased() == "pdf" {
+                    if let pdf = PDFDocument(url: url), pdf.isEncrypted {
+                        __NSBeep()
+                        return
+                    }
+                }
+                
+                let image = NSImage(contentsOfFile: url.path)
+                let isDamageImage: Bool = self.isDamageImage(image!, imagePath: url.path)
+                if isDamageImage {
+                    let alert = NSAlert()
+                    alert.alertStyle = .critical
+                    alert.messageText = String(format: NSLocalizedString("The file \"%@\" could not be opened.", comment: ""), url.lastPathComponent)
+                    alert.informativeText = NSLocalizedString("It may be damaged or use a file format that PDF Reader Pro doesn’t recognize.", comment: "")
+                    alert.addButton(withTitle: NSLocalizedString("Cancel", comment: ""))
+                    alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
+                        if response == .alertFirstButtonReturn {
+                            // Handle cancel button clicked
+                        }
+                    }
+                }
+                let isRemoveBGColor = accessoryCtr.selectedButton.state == .on
+                listView.addAnnotation(with: image, isRemoveBGColor: isRemoveBGColor)
+            }
+        }
+    }
+    
+    func isDamageImage(_ image: NSImage, imagePath path: String) -> Bool {
+        let addImageAnnotation = (NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last! as NSString).appendingPathComponent(Bundle.main.bundleIdentifier!)
+        if !FileManager.default.fileExists(atPath: addImageAnnotation) {
+            try? FileManager.default.createDirectory(atPath: addImageAnnotation, withIntermediateDirectories: false, attributes: nil)
+        }
+        
+        if let data = image.tiffRepresentation,
+           let imageRep = NSBitmapImageRep(data: data) {
+            imageRep.size = image.size
+            var imageData: Data?
+            if path.lowercased() == "png" {
+                imageData = imageRep.representation(using: .png, properties: [:])
+            } else {
+                imageData = imageRep.representation(using: .jpeg, properties: [:])
+            }
+            
+            if let imageData = imageData {
+                let rPath = (addImageAnnotation as NSString).appendingPathComponent((self.tagString() as NSString).appendingPathExtension("png")!)
+                if !((try? imageData.write(to: URL(fileURLWithPath: rPath), options: .atomicWrite)) != nil) {
+                    return true
+                } else {
+                    return false
+                }
+            }
+        }
+        return false
+    }
+    
+    func tagString() -> String {
+        let dateFormatter = DateFormatter()
+        dateFormatter.dateFormat = "yyMMddHHmmss"
+        return "\(dateFormatter.string(from: Date()))\(Int.random(in: 0..<10000))"
+    }
+    
     // MARK: - Split View
     
     @IBAction func secondaryViewOpenFile(_ sender: NSButton) -> Void {
@@ -4435,6 +4520,7 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                     self.showOCRWindow()
                 } else if toolbarItem.itemIdentifier == KMAnnotationImageToolbarItemIdentifier {
                     Swift.debugPrint("KMAnnotationImageToolbarItemIdentifier ...")
+                    self.imageAnnotation(toolbarItem)
                 } else if toolbarItem.itemIdentifier == KMAnnotationTableToolbarItemIdentifier {
                     Swift.debugPrint("KMAnnotationTableToolbarItemIdentifier ...")
                 }