Browse Source

【左边栏】搜索列表补充ToolTip图片预览场景

tangchao 1 year ago
parent
commit
7b1ab5ce53

+ 0 - 80
PDF Office/PDF Master.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -500,86 +500,6 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "288CF4C2-F390-4BFB-94A3-8BF58D72D463"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMImageToolTipContext.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "34"
-            endingLineNumber = "34"
-            landmarkName = "toolTipImage()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "DD702D84-D6C2-401C-AF4D-009D9B821B40"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMImageToolTipContext.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "28"
-            endingLineNumber = "28"
-            landmarkName = "toolTipImage()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "EC0DC115-97D0-4963-BD9B-E98BF406BAD0"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMImageToolTipContext.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "22"
-            endingLineNumber = "22"
-            landmarkName = "toolTipImage()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "41E6AD9C-3A79-4D00-905E-BFC608331422"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMImageToolTipContext.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "16"
-            endingLineNumber = "16"
-            landmarkName = "toolTipImage()"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
-      <BreakpointProxy
-         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
-         <BreakpointContent
-            uuid = "99BCCDA3-033B-4B2E-919A-808602778946"
-            shouldBeEnabled = "Yes"
-            ignoreCount = "0"
-            continueAfterRunningActions = "No"
-            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift"
-            startingColumnNumber = "9223372036854775807"
-            endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "1799"
-            endingLineNumber = "1799"
-            landmarkName = "tableView(_:imageContextForRow:)"
-            landmarkType = "7">
-         </BreakpointContent>
-      </BreakpointProxy>
       <BreakpointProxy
          BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
          <BreakpointContent

+ 16 - 0
PDF Office/PDF Master/Class/Common/Category/NSObject+KMExtension.swift

@@ -563,6 +563,22 @@ extension NSApplication {
     public static let interfaceThemeChangedNotification = NSNotification.Name("AppleInterfaceThemeChangedNotification")
 }
 
+// MARK: - NSParagraphStyle
+
+extension NSParagraphStyle {
+//    public class func defaultClippingParagraphStyle() -> NSParagraphStyle {
+////        static NSParagraphStyle *defaultClippingParagraphStyle = nil;
+////        if (defaultClippingParagraphStyle == nil) {
+//            NSMutableParagraphStyle *tmpParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
+//        var tmpParagraphStyle = NSParagraphStyle.default.mutableCopy() as? NSMutable
+//            [tmpParagraphStyle setLineBreakMode:NSLineBreakByClipping];
+//            defaultClippingParagraphStyle = [tmpParagraphStyle copy];
+//            [tmpParagraphStyle release];
+////        }
+//        return defaultClippingParagraphStyle;
+//    }
+}
+
 // MARK: - Other
 
 func KMSquaredDistanceFromPointToRect(_ point: NSPoint, _ rect: NSRect) -> CGFloat {

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMAnimatedBorderlessWindow.swift

@@ -32,7 +32,7 @@ class KMAnimatedBorderlessWindow: NSPanel {
         }
         set {
             var imageView: NSImageView?
-            if let _ = self.contentView?.responds(to: NSSelectorFromString("setImage:")) {
+            if let data = self.contentView?.responds(to: NSSelectorFromString("setImage:")), data {
                 imageView = self.contentView as? NSImageView
             } else if newValue != nil {
                 imageView = NSImageView()

+ 4 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMBotaTableView.swift

@@ -105,7 +105,9 @@ class KMBotaTableView: NSTableView {
         let row = userInfo?["row"] as? Int
         if row != nil {
             let context = self.botaDelegate?.tableView?(self, imageContextForRow: row!)
-//                [[SKImageToolTipWindow sharedToolTipWindow] showForImageContext:context atPoint:NSZeroPoint];
+            if context is KMImageToolTipContext {
+                KMImageToolTipWindow.shared.showForImageContext(context as! KMImageToolTipContext, at: .zero)
+            }
         }
     }
     
@@ -117,7 +119,7 @@ class KMBotaTableView: NSTableView {
         let userInfo = event.userData as? [String : Any]
         let row = userInfo?["row"] as? Int
         if row != nil {
-//            [[SKImageToolTipWindow sharedToolTipWindow] fadeOut];
+            KMImageToolTipWindow.shared.fadeOut()
         }
     }
     

+ 76 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMImageToolTipContext.swift

@@ -19,7 +19,82 @@ extension NSAttributedString: KMImageToolTipContext {
 
 extension CPDFDestination: KMImageToolTipContext {
     func toolTipImage() -> NSImage? {
-        return nil
+        //        static NSDictionary *labelAttributes = nil;
+        //        static NSColor *labelColor = nil;
+        //        if (labelAttributes == nil)
+                let style = NSMutableParagraphStyle()
+                style.lineBreakMode = .byClipping
+                let labelAttributes: [NSAttributedString.Key : Any] = [.font : NSFont.boldSystemFont(ofSize: 11), .foregroundColor : NSColor.white, .paragraphStyle : style]
+        //        if (labelColor == nil)
+                let labelColor = NSColor(calibratedWhite: 0.5, alpha: 0.8)
+                
+        //        PDFPage *page = [self page];
+        let page = self.page()
+        //        NSImage *pageImage = [page thumbnailWithSize:0.0 forBox:kPDFDisplayBoxCropBox shadowBlurRadius:0.0 readingBar:nil];
+        //        NSRect pageImageRect = {NSZeroPoint, [pageImage size]};
+        //        NSRect bounds = [page boundsForBox:kPDFDisplayBoxCropBox];
+        let bounds = page?.bounds(for: .cropBox) ?? .zero
+                var sourceRect: NSRect = .zero
+        //        PDFSelection *selection = [page selectionForRect:bounds];
+        let selection = page?.selection(for: bounds)
+        //        NSAffineTransform *transform = [page affineTransformForBox:kPDFDisplayBoxCropBox];
+        let transform = page?.transform()
+                
+        //        sourceRect.size.width = [[NSUserDefaults standardUserDefaults] doubleForKey:SKToolTipWidthKey];
+                sourceRect.size.width = 260
+        //        sourceRect.size.height = [[NSUserDefaults standardUserDefaults] doubleForKey:SKToolTipHeightKey];
+                sourceRect.size.height = 120
+        //        sourceRect.origin = SKAddPoints([transform transformPoint:[self point]], offset);
+        sourceRect.origin = self.point
+                sourceRect.origin.y -= NSHeight(sourceRect)
+                
+                
+//                if ([selection hasCharacters]) {
+//                    NSRect selBounds = [selection boundsForPage:page];
+//                    selBounds = SKRectFromPoints([transform transformPoint:SKBottomLeftPoint(selBounds)], [transform transformPoint:SKTopRightPoint(selBounds)]);
+//                    CGFloat top = ceil(fmax(NSMaxY(selBounds), NSMinY(selBounds) + NSHeight(sourceRect)));
+//                    CGFloat left = floor(fmin(NSMinX(selBounds), NSMaxX(selBounds) - NSWidth(sourceRect)));
+//                    if (top < NSMaxY(sourceRect))
+//                        sourceRect.origin.y = top - NSHeight(sourceRect);
+//                    if (left > NSMinX(sourceRect))
+//                        sourceRect.origin.x = left;
+//                }
+                
+//                sourceRect = SKConstrainRect(sourceRect, pageImageRect);
+                
+//                NSAttributedString *labelString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:NSLocalizedString(@"Page %@", @"Tool tip label format"), [page displayLabel]] attributes:labelAttributes];
+//                NSRect labelRect = [labelString boundingRectWithSize:NSZeroSize options:NSStringDrawingUsesLineFragmentOrigin];
+//
+//                labelRect.size.width = floor(NSWidth(labelRect));
+//                labelRect.size.height = 2.0 * floor(0.5 * NSHeight(labelRect)); // make sure the cap radius is integral
+//                labelRect.origin.x = NSWidth(sourceRect) - NSWidth(labelRect) - 0.5 * NSHeight(labelRect) - TEXT_MARGIN_X;
+//                labelRect.origin.y = TEXT_MARGIN_Y;
+//                labelRect = NSIntegralRect(labelRect);
+//
+//                NSImage *image = [NSImage bitmapImageWithSize:sourceRect.size drawingHandler:^(NSRect rect){
+//
+//                    [pageImage drawInRect:rect fromRect:sourceRect operation:NSCompositeCopy fraction:1.0];
+//
+//                    CGFloat radius = 0.5 * NSHeight(labelRect);
+//                    NSBezierPath *path = [NSBezierPath bezierPath];
+//
+//                    [path moveToPoint:SKTopLeftPoint(labelRect)];
+//                    [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(labelRect), NSMidY(labelRect)) radius:radius startAngle:90.0 endAngle:270.0];
+//                    [path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(labelRect), NSMidY(labelRect)) radius:radius startAngle:-90.0 endAngle:90.0];
+//                    [path closePath];
+//
+//                    [labelColor setFill];
+//                    [path fill];
+//
+//                    [labelString drawWithRect:labelRect options:NSStringDrawingUsesLineFragmentOrigin];
+//
+//                }];
+//
+//                [labelString release];
+        let image = page?.thumbnail(of: sourceRect.size)
+                
+                return image
+//        return nil
     }
 }
 

+ 4 - 4
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -1796,10 +1796,10 @@ extension KMLeftSideViewController: KMBotaTableViewDelegate {
             if rowIndex >= self.groupSearchResults.count {
                 return nil
             }
-            let model = self.groupSearchResults[rowIndex]
-            let selection = model.selection
-            let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
-            return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
+//            let model = self.groupSearchResults[rowIndex]
+//            let selection = model.selection
+//            let point = NSPoint(x: NSWidth(selection.bounds) * 0.5, y: NSHeight(selection.bounds) * 0.5)
+//            return CPDFDestination(document: self.listView.document, pageIndex: Int(selection.page.pageIndex()), at: point, zoom: self.listView.scaleFactor)
         }
         return nil
     }