Просмотр исходного кода

【注释】鼠标悬浮在页面上已添加的便签注释上,缺少预览面板 -- 修复

lizhe 11 месяцев назад
Родитель
Сommit
e5fdd5ce13

+ 3 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -151,9 +151,12 @@ NSNotificationName const KMPDFViewTableAnnotationDidChangeNotification = @"KMPDF
         for (CPDFPage *page in [self visiblePages]) {
             for (CPDFAnnotation *annotation in [page annotations]) {
                 if ([annotation isNote] || (hasLinkToolTips && [annotation linkDestination])) {
+//                    NSLog(@"%@",NSStringFromRect([annotation bounds]));
                     NSRect rect = NSIntersectionRect([self convertRect:[annotation bounds] fromPage:page], visibleRect);
                     if (NSIsEmptyRect(rect) == NO) {
                         rect = [self convertRect:rect toView:docView];
+//                        NSLog(@"%@",NSStringFromRect(rect));
+                        
                         NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:annotation, SKAnnotationKey, nil];
                         NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:rect options:NSTrackingMouseEnteredAndExited | NSTrackingActiveInActiveApp owner:self userInfo:userInfo];
                         [docView addTrackingArea:area];

+ 68 - 21
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMImageToolTipContext.swift

@@ -7,13 +7,46 @@
 
 import Foundation
 
+let TEXT_MARGIN_X = 2.0
+let TEXT_MARGIN_Y = 2.0
+
+let SKToolTipWidthKey  = "SKToolTipWidth"
+let SKToolTipHeightKey = "SKToolTipHeight"
+
 @objc protocol KMImageToolTipContext: NSObjectProtocol {
     func toolTipImage() -> NSImage?
 }
 
 extension NSAttributedString: KMImageToolTipContext {
+//    func toolTipImage() -> NSImage? {
+//        return nil
+//    }
+    
     func toolTipImage() -> NSImage? {
-        return nil
+        let backgroundColor: NSColor = {
+            if #available(OSX 10.9, *) {
+                return NSColor(calibratedRed: 0.95, green: 0.95, blue: 0.95, alpha: 1.0)
+            } else {
+                return NSColor(calibratedRed: 1.0, green: 1.0, blue: 0.75, alpha: 1.0)
+            }
+        }()
+        
+        let width = UserDefaults.standard.double(forKey: SKToolTipWidthKey) - 2.0 * TEXT_MARGIN_X
+        let height = UserDefaults.standard.double(forKey: SKToolTipHeightKey) - 2.0 * TEXT_MARGIN_Y
+        var textRect = self.boundingRect(with: NSSize(width: width, height: height), options: .usesLineFragmentOrigin)
+        
+        textRect.origin = NSPoint(x: TEXT_MARGIN_X, y: TEXT_MARGIN_Y)
+        textRect.size.height = min(textRect.height, height)
+        textRect = NSInsetRect(NSIntegralRect(textRect), -TEXT_MARGIN_X, -TEXT_MARGIN_Y)
+        
+        let image = NSImage(size: textRect.size, flipped: false) { rect in
+            backgroundColor.setFill()
+            rect.fill()
+            self.draw(with: NSRect(x: TEXT_MARGIN_X, y: TEXT_MARGIN_Y, width: rect.width - 2 * TEXT_MARGIN_X, height: rect.height - 2 * TEXT_MARGIN_Y), options: .usesLineFragmentOrigin)
+            return true
+        }
+        
+        return image
     }
 }
 
@@ -165,24 +198,38 @@ extension CPDFPage: KMImageToolTipContext {
     }
 }
 
-extension NSParagraphStyle{
-    static var defaultClippingParagraphStyle: NSParagraphStyle {
-        var style: NSParagraphStyle? = nil
-        if style == nil {
-            let tmpParagraphStyle = (NSParagraphStyle.default as! NSMutableParagraphStyle).mutableCopy() as! NSMutableParagraphStyle
-            tmpParagraphStyle.lineBreakMode = .byClipping
-            style = tmpParagraphStyle.copy() as? NSParagraphStyle
-        }
-        return style!
-    }
-
-    static var defaultTruncatingTailParagraphStyle: NSParagraphStyle {
-        var style: NSParagraphStyle? = nil
-        if style == nil {
-            let tmpParagraphStyle = (NSParagraphStyle.default as! NSMutableParagraphStyle).mutableCopy() as! NSMutableParagraphStyle
-            tmpParagraphStyle.lineBreakMode = .byTruncatingTail
-            style = tmpParagraphStyle.copy() as? NSParagraphStyle
-        }
-        return style!
-    }
+extension NSParagraphStyle {
+    static var defaultClippingParagraphStyle: NSParagraphStyle = {
+        let tmpParagraphStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
+        tmpParagraphStyle.lineBreakMode = .byClipping
+        return tmpParagraphStyle.copy() as! NSParagraphStyle
+    }()
+    
+    static var defaultTruncatingTailParagraphStyle: NSParagraphStyle = {
+        let tmpParagraphStyle = NSMutableParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle
+        tmpParagraphStyle.lineBreakMode = .byTruncatingTail
+        return tmpParagraphStyle.copy() as! NSParagraphStyle
+    }()
 }
+
+//extension NSParagraphStyle{
+//    static var defaultClippingParagraphStyle: NSParagraphStyle {
+//        var style: NSParagraphStyle? = nil
+//        if style == nil {
+//            let tmpParagraphStyle = (NSParagraphStyle.default as! NSMutableParagraphStyle).mutableCopy() as! NSMutableParagraphStyle
+//            tmpParagraphStyle.lineBreakMode = .byClipping
+//            style = tmpParagraphStyle.copy() as? NSParagraphStyle
+//        }
+//        return style!
+//    }
+//
+//    static var defaultTruncatingTailParagraphStyle: NSParagraphStyle {
+//        var style: NSParagraphStyle? = nil
+//        if style == nil {
+//            let tmpParagraphStyle = (NSParagraphStyle.default as! NSMutableParagraphStyle).mutableCopy() as! NSMutableParagraphStyle
+//            tmpParagraphStyle.lineBreakMode = .byTruncatingTail
+//            style = tmpParagraphStyle.copy() as? NSParagraphStyle
+//        }
+//        return style!
+//    }
+//}