Jelajahi Sumber

【综合】bota大概图片预览调式

tangchao 1 tahun lalu
induk
melakukan
2d581da3d7

+ 23 - 0
PDF Office/PDF Master/Class/Common/Category/CPDFKit/CPDFPage+KMExtension.swift

@@ -22,4 +22,27 @@ import Foundation
             return "\(self.pageIndex() + 1)"
         }
     }
+    
+    @objc func km_affineTransform(for box: CPDFDisplayBox) -> NSAffineTransform {
+        let bounds = self.bounds(for: box)
+        let transform = NSAffineTransform()
+        transform.rotate(byDegrees: -CGFloat(self.rotation))
+        switch self.rotation {
+        case 0:
+            transform.translateX(by: -NSMinX(bounds), yBy: -NSMinY(bounds))
+            break
+        case 90:
+            transform.translateX(by: -NSMaxX(bounds), yBy: -NSMinY(bounds))
+            break
+        case 180:
+            transform.translateX(by: -NSMaxX(bounds), yBy: -NSMaxY(bounds))
+            break
+        case 270:
+            transform.translateX(by: -NSMinX(bounds), yBy: -NSMaxY(bounds))
+            break
+        default:
+            break
+        }
+        return transform
+    }
 }

+ 77 - 70
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMImageToolTipContext.swift

@@ -17,85 +17,92 @@ extension NSAttributedString: KMImageToolTipContext {
     }
 }
 
+var _km_dest_labelAttributes: [NSAttributedString.Key : Any]?
+var _km_dest_labelColor: NSColor?
+
+var _km_text_margin_x: CGFloat = 2
+var _km_text_margin_y: CGFloat = 2
+
 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)
+        return self._toolTipImage(offset: NSMakePoint(-50.0, 20.0))
+    }
+
+    @objc private func _toolTipImage(offset: NSPoint) -> NSImage? {
+        guard let page = self.page() else {
+            return nil
+        }
+        
+        if _km_dest_labelAttributes == nil {
+            let style = NSMutableParagraphStyle()
+            style.lineBreakMode = .byClipping
+            _km_dest_labelAttributes = [.font : NSFont.boldSystemFont(ofSize: 11), .foregroundColor : NSColor.white, .paragraphStyle : style]
+        }
+        let attri = _km_dest_labelAttributes ?? [:]
+        
+        if _km_dest_labelColor == nil {
+            _km_dest_labelColor = NSColor(calibratedWhite: 0.5, alpha: 0.8)
+        }
+        let labelColor = _km_dest_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()
-                
+        let pageImage = page.thumbnail(of: page.bounds(for: .cropBox).size)
+        let pageSize = page.bounds(for: .cropBox)
+        let pageImageRect = NSMakeRect(0, 0, pageSize.width, pageSize.height)
+        let bounds = page.bounds(for: .cropBox)
+        var sourceRect: NSRect = .zero
+        let selection = page.selection(for: bounds)
+        
+        let transform = page.km_affineTransform(for: .cropBox)
+
         //        sourceRect.size.width = [[NSUserDefaults standardUserDefaults] doubleForKey:SKToolTipWidthKey];
-                sourceRect.size.width = 260
+        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.size.height = 120
+        sourceRect.origin = KMAddPoints(transform.transform(self.point), offset)
+        sourceRect.origin.y -= NSHeight(sourceRect)
                 
-//                sourceRect = SKConstrainRect(sourceRect, pageImageRect);
+        if let data = selection?.hasCharacters(), data {
+            var selBounds = selection?.bounds(for: page) ?? .zero
+            let blPoint = KMBottomLeftPoint(selBounds)
+            let trPoint = KMTopRightPoint(selBounds)
+            selBounds = KMRectFromPoints(aPoint: blPoint, bPoint: trPoint)
+            let top = ceil(fmax(NSMaxY(selBounds), NSMinY(selBounds) + NSHeight(sourceRect)))
+            let 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
+            }
+        }
                 
-//                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)
+        sourceRect = KMConstrainRect(rect: sourceRect, boundary: pageImageRect)
                 
-                return image
-//        return nil
+        let labelString = NSAttributedString(string: String(format: KMLocalizedString("Page %@", "Tool tip label format"), page.km_displayLabel), attributes: attri)
+        var labelRect = labelString.boundingRect(with: .zero, options: [.usesLineFragmentOrigin])
+        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) - _km_text_margin_x
+        labelRect.origin.y = _km_text_margin_y
+        labelRect = NSIntegralRect(labelRect)
+
+        let image = NSImage.bitmapImage(with: sourceRect.size) { rect in
+            pageImage?.draw(in: rect, from: sourceRect, operation: .copy, fraction: 1)
+            let radius = 0.5 * NSHeight(labelRect)
+            let path = NSBezierPath()
+            path.move(to: KMTopLeftPoint(labelRect))
+            path.appendArc(withCenter: NSMakePoint(NSMinX(labelRect), NSMidY(labelRect)), radius: radius, startAngle: 90.0, endAngle: 270.0)
+            path.appendArc(withCenter: NSMakePoint(NSMaxX(labelRect), NSMidY(labelRect)), radius: radius, startAngle: -90, endAngle: 90)
+            path.close()
+
+            labelColor.setFill()
+            path.fill()
+
+            labelString.draw(with: labelRect, options: [.usesLineFragmentOrigin])
+        }
+
+        return image
     }
 }
 

+ 16 - 0
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -564,5 +564,21 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "67AF60F3-6AB1-473E-B462-0A2E758D9119"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "3205"
+            endingLineNumber = "3205"
+            landmarkName = "outlineView(_:typeSelectHelperSelectionStrings:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>