Browse Source

[阅读页] - 右键

liujiajie 1 year ago
parent
commit
bd09ca69db

+ 33 - 33
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFAnnotationModel.m

@@ -392,7 +392,7 @@
 }
 
 - (CGFloat)opacity {
-    CGFloat opacity = 0;
+    CGFloat opacity = 1;
     //多选注释去拿注释类型的默认值
     if (_annotation && self.annotations.count == 1) {
         if ([_annotation isKindOfClass:[CSelfSignAnnotation class]]) {
@@ -406,50 +406,50 @@
             case CAnnotationTypeFreeText:
             case CAnnotationTypeSignText:
             case CAnnotationTypeSignDate:
-                opacity = [userDefaults floatForKey:CFreeTextNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CFreeTextNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeAnchored:
-                opacity = [userDefaults floatForKey:CAnchoredNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CAnchoredNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeCircle:
-                opacity = [userDefaults floatForKey:CCircleNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CCircleNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeSquare:
-                opacity = [userDefaults floatForKey:CSquareNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CSquareNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeHighlight:
-                opacity = [userDefaults floatForKey:CHighlightNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CHighlightNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeUnderline:
-                opacity = [userDefaults floatForKey:CUnderlineNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CUnderlineNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeStrikeOut:
-                opacity = [userDefaults floatForKey:CStrikeOutNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CStrikeOutNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeLine:
-                opacity = [userDefaults floatForKey:CLineNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CLineNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeArrow:
-                opacity = [userDefaults floatForKey:CArrowNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CArrowNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeInk:
             case CAnnotationTypeEraser:
-                opacity = [userDefaults floatForKey:CInkNoteOpacityKey];
+                opacity = [userDefaults floatForKey:CInkNoteOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeSignFalse:
-                opacity = [userDefaults floatForKey:CAnnotationSelfSignFalseOpacityKey];
+                opacity = [userDefaults floatForKey:CAnnotationSelfSignFalseOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeSignTure:
-                opacity = [userDefaults floatForKey:CAnnotationSelfSignTureOpacityKey];
+                opacity = [userDefaults floatForKey:CAnnotationSelfSignTureOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeSignCircle:
-                opacity = [userDefaults floatForKey:CAnnotationSelfSignCircleOpacityKey];
+                opacity = [userDefaults floatForKey:CAnnotationSelfSignCircleOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeSignLine:
-                opacity = [userDefaults floatForKey:CAnnotationSelfSignLineOpacityKey];
+                opacity = [userDefaults floatForKey:CAnnotationSelfSignLineOpacityKey]?:1.0;
                 break;
             case CAnnotationTypeSignDot:
-                opacity = [userDefaults floatForKey:CAnnotationSelfSignDotOpacityKey];
+                opacity = [userDefaults floatForKey:CAnnotationSelfSignDotOpacityKey]?:1.0;
                 break;
             default:
                 break;
@@ -542,7 +542,7 @@
                 style = [userDefaults integerForKey:CFreeTextNoteLineStyleKey];
                 break;
             case CAnnotationTypeCircle:
-                style = [userDefaults integerForKey:CCircleNoteLineStyleKey];
+                style = [userDefaults integerForKey:CCircleNoteLineStyleKey]?:CPDFBorderStyleDashed;
                 break;
             case CAnnotationTypeSquare:
                 style = [userDefaults integerForKey:CSquareNoteLineStyleKey];
@@ -652,7 +652,7 @@
 }
 
 - (CGFloat)lineWidth {
-    CGFloat lineWidth = 0;
+    CGFloat lineWidth = 0.8;
     
     //多选注释去拿注释类型的默认值
     if (_annotation && self.annotations.count == 1) {
@@ -665,43 +665,43 @@
         NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
         switch (_annotationType) {
             case CAnnotationTypeCircle:
-                lineWidth = [userDefaults floatForKey:CCircleNoteLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CCircleNoteLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeSquare:
-                lineWidth = [userDefaults floatForKey:CSquareNoteLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CSquareNoteLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeLine:
-                lineWidth = [userDefaults floatForKey:CLineNoteLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CLineNoteLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeArrow:
-                lineWidth = [userDefaults floatForKey:CArrowNoteLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CArrowNoteLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeInk:
-                lineWidth = [userDefaults floatForKey:CInkNoteLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CInkNoteLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeEraser:
-                lineWidth = [userDefaults floatForKey:CEraserkNoteLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CEraserkNoteLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeTextField:
-                lineWidth = [userDefaults floatForKey:CEraserkNoteLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CEraserkNoteLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeListMenu:
-                lineWidth = [userDefaults floatForKey:CAnnotationChoiceListWidgetLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CAnnotationChoiceListWidgetLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeRadioButton:
-                lineWidth = [userDefaults floatForKey:CAnnotationRadioButtonBoxWidgetLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CAnnotationRadioButtonBoxWidgetLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeCheckBox:
-                lineWidth = [userDefaults floatForKey:CAnnotationCheckBoxWidgetLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CAnnotationCheckBoxWidgetLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeComboBox:
-                lineWidth = [userDefaults floatForKey:CAnnotationChoiceWidgetLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CAnnotationChoiceWidgetLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeActionButton:
-                lineWidth = [userDefaults floatForKey:CAnnotationActionButtonWidgetLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CAnnotationActionButtonWidgetLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeSignature:
-                lineWidth = [userDefaults floatForKey:CAnnotationSignatureWidgetLineWidthKey];
+                lineWidth = [userDefaults floatForKey:CAnnotationSignatureWidgetLineWidthKey]?:0.8;
                 break;
             case CAnnotationTypeSignFalse:
                 lineWidth = [userDefaults floatForKey:CAnnotationSelfSignFalseLineWidthKey];
@@ -875,7 +875,7 @@
         NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
         switch (_annotationType) {
             case CAnnotationTypeAnchored:
-                width = [userDefaults floatForKey:CDefaultAnchoredNoteWidthKey];
+                width = [userDefaults floatForKey:CDefaultAnchoredNoteWidthKey] < 0.001 ? 16 : [userDefaults floatForKey:CDefaultAnchoredNoteWidthKey];
                 break;
             case CAnnotationTypeTextField:
                 width = [userDefaults floatForKey:CDefaultTextFieldNoteWidthKey];
@@ -988,7 +988,7 @@
         NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
         switch (_annotationType) {
             case CAnnotationTypeAnchored:
-                height = [userDefaults floatForKey:CDefaultAnchoredNoteHeightKey];
+                height = [userDefaults floatForKey:CDefaultAnchoredNoteHeightKey] < 0.001 ? 16 : [userDefaults floatForKey:CDefaultAnchoredNoteHeightKey];
                 break;
             case CAnnotationTypeTextField:
                 height = [userDefaults floatForKey:CDefaultTextFieldNoteHeightKey];

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFCircleAnnotation+PDFListView.swift

@@ -41,7 +41,7 @@ import Foundation
         var bounds = annotationModel.annotationImageBounds()
         let lineWidth = annotationModel.lineWidth()
         
-        var image = NSImage(size: bounds.size)
+        let image = NSImage(size: bounds.size)
         image.lockFocus()
         NSGraphicsContext.current?.imageInterpolation = .high
         let context = NSGraphicsContext.current?.cgContext

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFKitExtensions/CPDFAnnotationExtensions/CPDFStampAnnotation+PDFListView.swift

@@ -10,14 +10,14 @@ import Foundation
 @objc extension CPDFStampAnnotation {
     class func annotationImage(annotationModel: CPDFAnnotationModel) -> NSImage? {
         var image: NSImage?
-        var bounds = CGRectMake(0, 0, annotationModel.noteWidth(), annotationModel.noteHeight())
+        let bounds = CGRectMake(0, 0, annotationModel.noteWidth(), annotationModel.noteHeight())
         image = NSImage(size: bounds.size)
         image?.lockFocus()
         NSGraphicsContext.current?.imageInterpolation = .high
         let context = NSGraphicsContext.current?.cgContext
         let lineWidth = annotationModel.lineWidth()
         let color = annotationModel.color()
-        let signFalseOpacity = annotationModel.opacity()
+        _ = annotationModel.opacity()
         var red: CGFloat = 0.0
         var green: CGFloat = 0.0
         var blue: CGFloat = 0.0

+ 73 - 63
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -88,7 +88,7 @@ extension KMMainViewController {
         let submenu = NSMenu(title: "")
         for i in 0 ... fontSizes.count - 1 {
             let fontSize : String = fontSizes.object(at: i) as! String
-            let item = NSMenuItem(title:fontSize as! String, action: #selector(menuItemEditingClick_FontSize), keyEquivalent: "")
+            let item = NSMenuItem(title:fontSize , action: #selector(menuItemEditingClick_FontSize), keyEquivalent: "")
             item.target = self
             item.tag = i
             submenu.addItem(item)
@@ -104,7 +104,7 @@ extension KMMainViewController {
     }
     
     func corpImageMenuItem()->NSMenuItem {
-        var corpImageItem = NSMenuItem(title: NSLocalizedString("Confirm Crop", comment: ""), action: #selector(menuItemEditingClick_CropImage), target: self)
+        let corpImageItem = NSMenuItem(title: NSLocalizedString("Confirm Crop", comment: ""), action: #selector(menuItemEditingClick_CropImage), target: self)
         return corpImageItem
     }
     
@@ -124,17 +124,17 @@ extension KMMainViewController {
     }
     
     func editAddBlanMenu(menu:NSMenu){
-        menu.insertItem(withTitle: NSLocalizedString("Add Text", comment: ""), action: #selector(addImageText), target: self, at: 0)
-        menu.insertItem(withTitle: NSLocalizedString("Add Image", comment: ""), action: #selector(addImageText), target: self, at: 1)
+        _ = menu.insertItem(withTitle: NSLocalizedString("Add Text", comment: ""), action: #selector(addImageText), target: self, at: 0)
+        _ = menu.insertItem(withTitle: NSLocalizedString("Add Image", comment: ""), action: #selector(addImageText), target: self, at: 1)
     }
     
     func addText() -> NSMenuItem {
-        var addTextItem = NSMenuItem(title: NSLocalizedString("Add Text", comment: ""), action: #selector(addImageText), target: self, tag: 0)
+        let addTextItem = NSMenuItem(title: NSLocalizedString("Add Text", comment: ""), action: #selector(addImageText), target: self, tag: 0)
         return addTextItem
     }
     
     func addImage() -> NSMenuItem {
-        var addImageItem = NSMenuItem(title: NSLocalizedString("Add Image", comment: ""), action: #selector(addImageText), target: self, tag: 1)
+        let addImageItem = NSMenuItem(title: NSLocalizedString("Add Image", comment: ""), action: #selector(addImageText), target: self, tag: 1)
         return addImageItem
     }
     
@@ -151,27 +151,27 @@ extension KMMainViewController {
     func exportImageStampItem()->NSMenuItem {
         let exportItem = NSMenuItem(title: NSLocalizedString("Export", comment: ""), action: #selector(menuItemEditingClick_ExportImage), target: self)
         let menu = NSMenu()
-        menu.insertItem(withTitle: NSLocalizedString("PNG", comment: ""), action:#selector(exportStampImage), target: self, tag:0, at: 0)
-        menu.insertItem(withTitle: NSLocalizedString("PDF", comment: ""), action:#selector(exportStampImage), target: self, tag:2, at: 1)
+        let item1 = menu.insertItem(withTitle: NSLocalizedString("PNG", comment: ""), action:#selector(exportStampImage), target: self, tag:0, at: 0)
+        let item2 = menu.insertItem(withTitle: NSLocalizedString("PDF", comment: ""), action:#selector(exportStampImage), target: self, tag:2, at: 1)
         exportItem.submenu = menu
         return exportItem
     }
     
     func exportMenu() -> NSMenu {
         let menu = NSMenu()
-        menu.insertItem(withTitle: NSLocalizedString("PNG", comment: ""), action:#selector(exportCorpImage), target: self, tag:0, at: 0)
-        menu.insertItem(withTitle: NSLocalizedString("JPG", comment: ""), action:#selector(exportCorpImage), target: self, tag:1, at: 1)
-        menu.insertItem(withTitle: NSLocalizedString("PDF", comment: ""), action:#selector(exportCorpImage), target: self, tag:2, at: 2)
+        let item1 = menu.insertItem(withTitle: NSLocalizedString("PNG", comment: ""), action:#selector(exportCorpImage), target: self, tag:0, at: 0)
+        let item2 = menu.insertItem(withTitle: NSLocalizedString("JPG", comment: ""), action:#selector(exportCorpImage), target: self, tag:1, at: 1)
+        let item3 = menu.insertItem(withTitle: NSLocalizedString("PDF", comment: ""), action:#selector(exportCorpImage), target: self, tag:2, at: 2)
         
         return menu
     }
     
     func cropMenu() -> NSMenu {
         let menu = NSMenu()
-        menu.insertItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action:#selector(cropCurrentPage), target: self, at: 0)
-        menu.insertItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action:#selector(cropAllPage), target: self, at: 1)
-        menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
-        menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
+        let item1 = menu.insertItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action:#selector(cropCurrentPage), target: self, at: 0)
+        let item2 = menu.insertItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action:#selector(cropAllPage), target: self, at: 1)
+        let item3 = menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
+        let item4 = menu.insertItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action:#selector(autoCropAll), target: self, at: 2)
         return menu
     }
     
@@ -189,29 +189,29 @@ extension KMMainViewController {
         let stypItem = NSMenuItem(title: NSLocalizedString("Annotation", comment: ""), action: nil, target: self)
         let stypeMenu = NSMenu()
         if listView.currentSelection != nil && listView.currentSelection.selectionType() == .text {
-            stypeMenu.addItem(withTitle: NSLocalizedString("Highlight", comment: ""), action: #selector(addAnnotationForStyleMenu), target: self, tag: 0)
-            stypeMenu.addItem(withTitle: NSLocalizedString("Underline", comment: ""), action: #selector(addAnnotationForStyleMenu), target: self, tag: 1)
-            stypeMenu.addItem(withTitle: NSLocalizedString("Strikethrough", comment: ""), action: #selector(addAnnotationForStyleMenu), target: self, tag: 2)
+            let item1 = stypeMenu.addItem(withTitle: NSLocalizedString("Highlight", comment: ""), action: #selector(addAnnotationForStyleMenu), target: self, tag: 0)
+            let item2 = stypeMenu.addItem(withTitle: NSLocalizedString("Underline", comment: ""), action: #selector(addAnnotationForStyleMenu), target: self, tag: 1)
+            let item3 = stypeMenu.addItem(withTitle: NSLocalizedString("Strikethrough", comment: ""), action: #selector(addAnnotationForStyleMenu), target: self, tag: 2)
             stypeMenu.addItem(NSMenuItem.separator())
         }
 //        stypeMenu.addItem(withTitle: NSLocalizedString("Freehand", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 0)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Text Box", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 1)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Anchored Note", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 2)
+        let item4 = stypeMenu.addItem(withTitle: NSLocalizedString("Text Box", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 1)
+        let item5 = stypeMenu.addItem(withTitle: NSLocalizedString("Anchored Note", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 2)
 //        stypeMenu.insertItem(NSMenuItem.separator(), at: 10000)
         stypeMenu.addItem(NSMenuItem.separator())
-        stypeMenu.addItem(withTitle: NSLocalizedString("Rectangle", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 3)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Circle", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 4)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Arrow", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 5)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Line", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 6)
+        let item6 = stypeMenu.addItem(withTitle: NSLocalizedString("Rectangle", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 3)
+        let item7 = stypeMenu.addItem(withTitle: NSLocalizedString("Circle", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 4)
+        let item8 = stypeMenu.addItem(withTitle: NSLocalizedString("Arrow", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 5)
+        let item9 = stypeMenu.addItem(withTitle: NSLocalizedString("Line", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 6)
 //        stypeMenu.insertItem(NSMenuItem.separator(), at: 10000)
         if self.isReadMode {
             
         } else {
             stypeMenu.addItem(NSMenuItem.separator())
-            stypeMenu.addItem(withTitle: NSLocalizedString("Link", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 7)
-            stypeMenu.addItem(withTitle: NSLocalizedString("Stamp", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 8)
-            stypeMenu.addItem(withTitle: NSLocalizedString("Image", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 10)
-            stypeMenu.addItem(withTitle: NSLocalizedString("Signature", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 9)
+            let item10 = stypeMenu.addItem(withTitle: NSLocalizedString("Link", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 7)
+            let item11 = stypeMenu.addItem(withTitle: NSLocalizedString("Stamp", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 8)
+            let item12 = stypeMenu.addItem(withTitle: NSLocalizedString("Image", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 10)
+            let item13 = stypeMenu.addItem(withTitle: NSLocalizedString("Signature", comment: ""), action: #selector(menuItemAnnotationClick_addStype), target: self, tag: 9)
         }
         stypItem.submenu = stypeMenu
         if self.listView.annotationType == .ink {
@@ -241,23 +241,23 @@ extension KMMainViewController {
     func setAnnotationToolStype() -> NSMenuItem {
         let stypItem = NSMenuItem(title: NSLocalizedString("Tool Mode", comment: ""), action: nil, target: self)
         let stypeMenu = NSMenu()
-        stypeMenu.addItem(withTitle: NSLocalizedString("Text", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 0)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Scroll", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 1)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Magnify", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 2)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Select", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 3)
+        let item1 = stypeMenu.addItem(withTitle: NSLocalizedString("Text", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 0)
+        let item2 = stypeMenu.addItem(withTitle: NSLocalizedString("Scroll", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 1)
+        let item3 = stypeMenu.addItem(withTitle: NSLocalizedString("Magnify", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 2)
+        let item4 = stypeMenu.addItem(withTitle: NSLocalizedString("Select", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 3)
 //        stypeMenu.addItem(withTitle: NSLocalizedString("Zoom to Selected Area", comment: ""), action: #selector(menuItemAnnotationClick_toolModel), target: self, tag: 4)
         stypeMenu.insertItem(NSMenuItem.separator(), at: 4)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Highlight", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 5)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Underline", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 6)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Strikethrough", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 7)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Freehand", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 8)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Text Note", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 9)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Anchored Note", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 10)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Rectangle", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 11)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Circle", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 12)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Arrow", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 13)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Line", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 14)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Link", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 15)
+        let item5 = stypeMenu.addItem(withTitle: NSLocalizedString("Highlight", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 5)
+        let item6 = stypeMenu.addItem(withTitle: NSLocalizedString("Underline", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 6)
+        let item7 = stypeMenu.addItem(withTitle: NSLocalizedString("Strikethrough", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 7)
+        let item8 = stypeMenu.addItem(withTitle: NSLocalizedString("Freehand", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 8)
+        let item9 = stypeMenu.addItem(withTitle: NSLocalizedString("Text Note", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 9)
+        let item10 = stypeMenu.addItem(withTitle: NSLocalizedString("Anchored Note", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 10)
+        let item11 = stypeMenu.addItem(withTitle: NSLocalizedString("Rectangle", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 11)
+        let item12 = stypeMenu.addItem(withTitle: NSLocalizedString("Circle", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 12)
+        let item13 = stypeMenu.addItem(withTitle: NSLocalizedString("Arrow", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 13)
+        let item14 = stypeMenu.addItem(withTitle: NSLocalizedString("Line", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 14)
+        let item15 = stypeMenu.addItem(withTitle: NSLocalizedString("Link", comment: ""), action: #selector(changeAnnotationMode), target: self, tag: 15)
         
         stypItem.submenu = stypeMenu
         if self.toolbarController.toolbarType == .Annatiton {
@@ -341,8 +341,8 @@ extension KMMainViewController {
     func setRotateStype() -> NSMenuItem {
         let stypItem = NSMenuItem(title: NSLocalizedString("Rotate", comment: ""), action: nil, target: self)
         let stypeMenu = NSMenu()
-        stypeMenu.addItem(withTitle: NSLocalizedString("Rotate Left", comment: ""), action: #selector(rotateLeftAction), target: self, tag: 0)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Rotate Right", comment: ""), action: #selector(rotateRightAction), target: self, tag: 1)
+        let item1 = stypeMenu.addItem(withTitle: NSLocalizedString("Rotate Left", comment: ""), action: #selector(rotateLeftAction), target: self, tag: 0)
+        let item2 = stypeMenu.addItem(withTitle: NSLocalizedString("Rotate Right", comment: ""), action: #selector(rotateRightAction), target: self, tag: 1)
         stypItem.submenu = stypeMenu
         if self.toolbarController.toolbarType == .Annatiton {
             stypeMenu.item(at: 0)?.state = .on
@@ -385,8 +385,8 @@ extension KMMainViewController {
     func setSnapshotStype() -> NSMenuItem {
         let stypItem = NSMenuItem(title: NSLocalizedString("Snapshot", comment: ""), action: nil, target: self)
         let stypeMenu = NSMenu()
-        stypeMenu.addItem(withTitle: NSLocalizedString("Auto", comment: ""), action: #selector(takeSnapshot), target: self, tag: 0)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Select Area", comment: ""), action: #selector(takeSnapshotSelectContent), target: self, tag: 1)
+        let item1 = stypeMenu.addItem(withTitle: NSLocalizedString("Auto", comment: ""), action: #selector(takeSnapshot), target: self, tag: 0)
+        let item2 = stypeMenu.addItem(withTitle: NSLocalizedString("Select Area", comment: ""), action: #selector(takeSnapshotSelectContent), target: self, tag: 1)
         stypItem.submenu = stypeMenu
 //        if self.toolbarController.toolbarType == .Annatiton {
 //            stypeMenu.item(at: 0)?.state = .on
@@ -399,13 +399,13 @@ extension KMMainViewController {
     func setServicesStype() -> NSMenuItem {
         let stypItem = NSMenuItem(title: NSLocalizedString("Services", comment: ""), action: nil, target: self)
         let stypeMenu = NSMenu()
-        stypeMenu.addItem(withTitle: NSLocalizedString("Add to Music as a Spoken Track", comment: ""), action: #selector(AddtoMusicasASpokenTrack), target: self, tag: 0)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Convert Text to Simplified Chinese", comment: ""), action: #selector(ConvertTextToSimplifiedChinese), target: self, tag: 1)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Convert Text to Traditional Chinese", comment: ""), action: #selector(ConvertTextToTraditionalChinese), target: self, tag: 2)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Open", comment: ""), action: #selector(OpenItemAction), target: self, tag: 3)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Search With Baidu", comment: ""), action: #selector(searchBaiduAction), target: self, tag: 4)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Show in Finder", comment: ""), action: #selector(showInFinder), target: self, tag: 4)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Show Info in Finder", comment: ""), action: #selector(showInfoInFinder), target: self, tag: 5)
+        let item1 = stypeMenu.addItem(withTitle: NSLocalizedString("Add to Music as a Spoken Track", comment: ""), action: #selector(AddtoMusicasASpokenTrack), target: self, tag: 0)
+        let item2 = stypeMenu.addItem(withTitle: NSLocalizedString("Convert Text to Simplified Chinese", comment: ""), action: #selector(ConvertTextToSimplifiedChinese), target: self, tag: 1)
+        let item3 = stypeMenu.addItem(withTitle: NSLocalizedString("Convert Text to Traditional Chinese", comment: ""), action: #selector(ConvertTextToTraditionalChinese), target: self, tag: 2)
+        let item4 = stypeMenu.addItem(withTitle: NSLocalizedString("Open", comment: ""), action: #selector(OpenItemAction), target: self, tag: 3)
+        let item5 = stypeMenu.addItem(withTitle: NSLocalizedString("Search With Baidu", comment: ""), action: #selector(searchBaiduAction), target: self, tag: 4)
+        let item6 = stypeMenu.addItem(withTitle: NSLocalizedString("Show in Finder", comment: ""), action: #selector(showInFinder), target: self, tag: 4)
+        let item7 = stypeMenu.addItem(withTitle: NSLocalizedString("Show Info in Finder", comment: ""), action: #selector(showInfoInFinder), target: self, tag: 5)
         stypItem.submenu = stypeMenu
 //        if self.toolbarController.toolbarType == .Annatiton {
 //            stypeMenu.item(at: 0)?.state = .on
@@ -417,13 +417,13 @@ extension KMMainViewController {
     func setCropStype() -> NSMenuItem {
         let stypItem = NSMenuItem(title: NSLocalizedString("Crop", comment: ""), action: nil, target: self)
         let stypeMenu = NSMenu()
-        stypeMenu.addItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action: #selector(cropAllPageItem), target: self, tag: 0)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action: #selector(cropCurrentPageItem), target: self, tag: 1)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action: #selector(autoCropAllItem), target: self, tag: 2)
-        stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action: #selector(smartAutoCropAllItem), target: self, tag: 3)
+        let item1 = stypeMenu.addItem(withTitle: NSLocalizedString("Crop All Pages", comment: ""), action: #selector(cropAllPageItem), target: self, tag: 0)
+        let item2 = stypeMenu.addItem(withTitle: NSLocalizedString("Crop Current Page", comment: ""), action: #selector(cropCurrentPageItem), target: self, tag: 1)
+        let item3 = stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Separate", comment: ""), action: #selector(autoCropAllItem), target: self, tag: 2)
+        let item4 = stypeMenu.addItem(withTitle: NSLocalizedString("Auto Crop – Combined", comment: ""), action: #selector(smartAutoCropAllItem), target: self, tag: 3)
 //        if(NSIsEmptyRect(selectionRect)) {
-            stypeMenu.addItem(withTitle: NSLocalizedString("Select Area", comment: ""), action: #selector(selectToolModel), target: self, tag: 4)
-            stypeMenu.addItem(withTitle: NSLocalizedString("Crop Options...", comment: ""), action: #selector(customCropModel), target: self, tag: 5)
+        let item5 = stypeMenu.addItem(withTitle: NSLocalizedString("Select Area", comment: ""), action: #selector(selectToolModel), target: self, tag: 4)
+        let item6 = stypeMenu.addItem(withTitle: NSLocalizedString("Crop Options...", comment: ""), action: #selector(customCropModel), target: self, tag: 5)
 //
 //        }
         
@@ -448,7 +448,7 @@ extension KMMainViewController {
         if highlightLink {
             highlightLinkTitle = NSLocalizedString("Disable Highlight Links", comment: "")
         }
-        var highlightLinksItem = NSMenuItem(title: highlightLinkTitle, action: #selector(highlightLinks), target: self)
+        let highlightLinksItem = NSMenuItem(title: highlightLinkTitle, action: #selector(highlightLinks), target: self)
         return highlightLinksItem
     }
     
@@ -833,7 +833,7 @@ extension KMMainViewController {
     }
     
     @objc func aiTranslationAction(sender: NSMenuItem) {
-        let content = self.listView.currentSelection.string() as? String ?? ""
+        let content = self.listView.currentSelection.string() ?? ""
         let origin = self.listView.currentSelection.bounds.origin
         
         self.aiTranslationWindow = KMAITranslationWindowController.init(windowNibName: "KMAITranslationWindowController")
@@ -862,7 +862,7 @@ extension KMMainViewController {
             
             let currentPoint: NSPoint = self.listView.convert(point!, from: self.listView.superview)
             let currentPage = self.listView.page(for: currentPoint, nearest: true)
-            let pagePoint = self.listView.convert(currentPoint, to: currentPage)
+            var pagePoint = self.listView.convert(currentPoint, to: currentPage)
             
             var annotation: CPDFAnnotation?
             
@@ -943,6 +943,11 @@ extension KMMainViewController {
                 case 1:
 //                    self.listView.annotationType = CAnnotationType.freeText
                     let defaultSize = self.listView.defaultSize(with: .freeText, in: currentPage)
+                    if (pagePoint.x - defaultSize.width > 0){
+                        pagePoint.x -= defaultSize.width;
+                    }else{
+                        pagePoint.x = 0;
+                    }
                     let bounds = CPDFListViewRectFromCenterAndSize(CPDFListViewIntegralPoint(pagePoint), defaultSize)
                     annotation = self.listView.addAnnotation(with: .freeText, selection: nil, page: currentPage, bounds: bounds)
 //                    self.view.window?.makeFirstResponder()
@@ -959,6 +964,11 @@ extension KMMainViewController {
                 case 3:
 //                    self.listView.annotationType = CAnnotationType.square
                     let defaultSize = self.listView.defaultSize(with: .square, in: currentPage)
+                    if (pagePoint.x - defaultSize.width > 0){
+                        pagePoint.x -= defaultSize.width;
+                    }else{
+                        pagePoint.x = 0;
+                    }
                     let bounds = CPDFListViewRectFromCenterAndSize(CPDFListViewIntegralPoint(pagePoint), defaultSize)
                     annotation = self.listView.addAnnotation(with: .square, selection: nil, page: currentPage, bounds: bounds)
                 case 4:

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

@@ -2168,7 +2168,7 @@ import Cocoa
         if  areas.count == 1 {
             let fristAreas = areas.first
             if fristAreas is CPDFEditImageArea {
-                self.listView.selectImageAreas = fristAreas as! CPDFEditImageArea
+                self.listView.selectImageAreas = fristAreas as? CPDFEditImageArea
                 if self.listView.isEditImage {
                     tMenuItems?.removeAll()
                     tMenuItems?.append(self.corpImageMenuItem())