Revision: 12127
http://sourceforge.net/p/skim-app/code/12127
Author: hofman
Date: 2021-02-26 15:53:34 +0000 (Fri, 26 Feb 2021)
Log Message:
-----------
Scale preview tooltips for links with the current scale factor pf the pdfview
Modified Paths:
--------------
trunk/SKImageToolTipContext.h
trunk/SKImageToolTipContext.m
trunk/SKImageToolTipWindow.h
trunk/SKImageToolTipWindow.m
trunk/SKOutlineView.m
trunk/SKPDFView.m
trunk/SKTableView.m
Modified: trunk/SKImageToolTipContext.h
===================================================================
--- trunk/SKImageToolTipContext.h 2021-02-26 15:11:39 UTC (rev 12126)
+++ trunk/SKImageToolTipContext.h 2021-02-26 15:53:34 UTC (rev 12127)
@@ -42,7 +42,7 @@
@protocol SKImageToolTipContext <NSObject>
-- (NSImage *)toolTipImage;
+- (NSImage *)toolTipImageWithScale:(CGFloat)scale;
@end
Modified: trunk/SKImageToolTipContext.m
===================================================================
--- trunk/SKImageToolTipContext.m 2021-02-26 15:11:39 UTC (rev 12126)
+++ trunk/SKImageToolTipContext.m 2021-02-26 15:53:34 UTC (rev 12127)
@@ -65,7 +65,7 @@
@implementation NSAttributedString (SKImageToolTipContext)
-- (NSImage *)toolTipImage {
+- (NSImage *)toolTipImageWithScale:(CGFloat)scale {
NSAttributedString *attrString = [self
attributedStringByAddingControlTextColorAttribute];
CGFloat width = [[NSUserDefaults standardUserDefaults]
doubleForKey:SKToolTipWidthKey] - 2.0 * TEXT_MARGIN_X;
CGFloat height = [[NSUserDefaults standardUserDefaults]
doubleForKey:SKToolTipHeightKey] - 2.0 * TEXT_MARGIN_Y;
@@ -91,12 +91,12 @@
@interface PDFDestination (SKImageToolTipContextExtension)
-- (NSImage *)toolTipImageWithOffset:(NSPoint)offset selections:(NSArray
*)selections;
+- (NSImage *)toolTipImageWithOffset:(NSPoint)offset scale:(CGFloat)scale
selections:(NSArray *)selections;
@end
@implementation PDFDestination (SKImageToolTipContext)
-- (NSImage *)toolTipImageWithOffset:(NSPoint)offset selections:(NSArray
*)selections {
+- (NSImage *)toolTipImageWithOffset:(NSPoint)offset scale:(CGFloat)scale
selections:(NSArray *)selections {
static NSDictionary *labelAttributes = nil;
static NSColor *labelColor = nil;
if (labelAttributes == nil)
@@ -104,13 +104,20 @@
if (labelColor == nil)
labelColor = [[NSColor colorWithCalibratedWhite:0.5 alpha:0.8] retain];
+ BOOL isScaled = fabs(scale - 1.0) > 0.01;
PDFPage *page = [self page];
- NSImage *pageImage = [page thumbnailWithSize:0.0
forBox:kPDFDisplayBoxCropBox shadowBlurRadius:0.0 highlights:selections];
+ NSRect bounds = [page boundsForBox:kPDFDisplayBoxCropBox];
+ CGFloat size = isScaled ? scale * fmax(NSWidth(bounds), NSHeight(bounds))
: 0.0;
+ NSImage *pageImage = [page thumbnailWithSize:size
forBox:kPDFDisplayBoxCropBox shadowBlurRadius:0.0 highlights:selections];
NSRect pageImageRect = {NSZeroPoint, [pageImage size]};
- NSRect bounds = [page boundsForBox:kPDFDisplayBoxCropBox];
NSRect sourceRect = NSZeroRect;
PDFSelection *pageSelection = [page selectionForRect:bounds];
NSAffineTransform *transform = [page
affineTransformForBox:kPDFDisplayBoxCropBox];
+ if (isScaled) {
+ NSAffineTransform *scaleTransform = [NSAffineTransform transform];
+ [scaleTransform scaleBy:scale];
+ [transform appendTransform:scaleTransform];
+ }
sourceRect.size.width = [[NSUserDefaults standardUserDefaults]
doubleForKey:SKToolTipWidthKey];
sourceRect.size.height = [[NSUserDefaults standardUserDefaults]
doubleForKey:SKToolTipHeightKey];
@@ -169,8 +176,8 @@
return image;
}
-- (NSImage *)toolTipImage {
- NSImage *image = [self toolTipImageWithOffset:NSMakePoint(-50.0, 20.0)
selections:nil];
+- (NSImage *)toolTipImageWithScale:(CGFloat)scale {
+ NSImage *image = [self toolTipImageWithOffset:NSMakePoint(-50.0, 20.0)
scale:scale selections:nil];
[[[image representations] firstObject] setOpaque:YES];
return image;
}
@@ -180,12 +187,12 @@
@implementation PDFSelection (SKImageToolTipContext)
-- (NSImage *)toolTipImage {
+- (NSImage *)toolTipImageWithScale:(CGFloat)scale {
PDFSelection *sel = [self copy];
[sel setColor:[NSColor searchHighlightColor]];
NSArray *selections = [NSArray arrayWithObject:sel];
[sel release];
- return [[self destination] toolTipImageWithOffset:NSMakePoint(-50.0, 20.0)
selections:selections];
+ return [[self destination] toolTipImageWithOffset:NSMakePoint(-50.0, 20.0)
scale:scale selections:selections];
}
@end
@@ -193,13 +200,13 @@
@implementation SKGroupedSearchResult (SKImageToolTipContext)
-- (NSImage *)toolTipImage {
+- (NSImage *)toolTipImageWithScale:(CGFloat)scale {
NSArray *selections = [[[NSArray alloc] initWithArray:[self matches]
copyItems:YES] autorelease];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpartial-availability"
[selections setValue:[NSColor findHighlightColor] forKey:@"color"];
#pragma clang diagnostic pop
- return [[[selections firstObject] destination]
toolTipImageWithOffset:NSMakePoint(-50.0, 20.0) selections:selections];
+ return [[[selections firstObject] destination]
toolTipImageWithOffset:NSMakePoint(-50.0, 20.0) scale:scale
selections:selections];
}
@end
@@ -207,16 +214,16 @@
@implementation PDFAnnotation (SKImageToolTipContext)
-- (NSImage *)toolTipImage {
-
+- (NSImage *)toolTipImageWithScale:(CGFloat)scale {
+
if ([self isLink]) {
- NSImage *image = [[self linkDestination]
toolTipImageWithOffset:NSZeroPoint selections:nil];
+ NSImage *image = [[self linkDestination]
toolTipImageWithOffset:NSZeroPoint scale:scale selections:nil];
if (image == nil) {
NSURL *url = [self linkURL];
if (url) {
NSAttributedString *attrString = toolTipAttributedString([url
absoluteString]);
if ([attrString length])
- image = [attrString toolTipImage];
+ image = [attrString toolTipImageWithScale:1.0];
}
}
if (image) {
@@ -247,7 +254,7 @@
attrString = [attrString attributedSubstringFromRange:r];
}
- return [attrString length] ? [attrString toolTipImage] : nil;
+ return [attrString length] ? [attrString toolTipImageWithScale:1.0] : nil;
}
@end
@@ -255,7 +262,7 @@
@implementation PDFPage (SKImageToolTipContext)
-- (NSImage *)toolTipImage {
+- (NSImage *)toolTipImageWithScale:(CGFloat)scale {
NSImage *image = [self thumbnailWithSize:256.0
forBox:kPDFDisplayBoxCropBox shadowBlurRadius:0.0 highlights:nil];
[[[image representations] firstObject] setOpaque:YES];
return image;
Modified: trunk/SKImageToolTipWindow.h
===================================================================
--- trunk/SKImageToolTipWindow.h 2021-02-26 15:11:39 UTC (rev 12126)
+++ trunk/SKImageToolTipWindow.h 2021-02-26 15:53:34 UTC (rev 12127)
@@ -44,6 +44,7 @@
@interface SKImageToolTipWindow : SKAnimatedBorderlessWindow {
id <SKImageToolTipContext> context;
NSPoint point;
+ CGFloat scale;
NSVisualEffectView *backgroundView;
}
@@ -50,7 +51,7 @@
+ (id)sharedToolTipWindow;
// aContext can be a PDFAnnotation, PDFDestination, or PDFPage
-- (void)showForImageContext:(id <SKImageToolTipContext>)aContext
atPoint:(NSPoint)aPoint;
+- (void)showForImageContext:(id <SKImageToolTipContext>)aContext
scale:(CGFloat)aScale atPoint:(NSPoint)aPoint;
@property (nonatomic, readonly) id <SKImageToolTipContext> currentImageContext;
Modified: trunk/SKImageToolTipWindow.m
===================================================================
--- trunk/SKImageToolTipWindow.m 2021-02-26 15:11:39 UTC (rev 12126)
+++ trunk/SKImageToolTipWindow.m 2021-02-26 15:53:34 UTC (rev 12127)
@@ -100,7 +100,7 @@
- (void)showDelayed {
NSPoint thePoint = NSEqualPoints(point, NSZeroPoint) ? [NSEvent
mouseLocation] : point;
NSRect contentRect = NSZeroRect, screenRect = [[NSScreen
screenForPoint:thePoint] frame];
- NSImage *image = [context toolTipImage];
+ NSImage *image = [context toolTipImageWithScale:scale];
BOOL isOpaque = [[[image representations] firstObject] isOpaque];
if (image) {
@@ -157,7 +157,8 @@
[[self class] cancelPreviousPerformRequestsWithTarget:self
selector:@selector(showDelayed) object:nil];
}
-- (void)showForImageContext:(id <SKImageToolTipContext>)aContext
atPoint:(NSPoint)aPoint {
+- (void)showForImageContext:(id <SKImageToolTipContext>)aContext
scale:(CGFloat)aScale atPoint:(NSPoint)aPoint {
+ scale = aScale;
point = aPoint;
if ([aContext isEqual:context] == NO) {
Modified: trunk/SKOutlineView.m
===================================================================
--- trunk/SKOutlineView.m 2021-02-26 15:11:39 UTC (rev 12126)
+++ trunk/SKOutlineView.m 2021-02-26 15:53:34 UTC (rev 12127)
@@ -349,7 +349,7 @@
if (item) {
id <SKImageToolTipContext> context = [[self delegate]
outlineView:self imageContextForItem:item];
if (context)
- [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:context atPoint:NSZeroPoint];
+ [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:context scale:1.0 atPoint:NSZeroPoint];
}
}
return;
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2021-02-26 15:11:39 UTC (rev 12126)
+++ trunk/SKPDFView.m 2021-02-26 15:53:34 UTC (rev 12127)
@@ -2056,7 +2056,7 @@
if ([eventArea owner] == self && [eventArea isEqual:trackingArea]) {
[[self window] setAcceptsMouseMovedEvents:YES];
} else if ([eventArea owner] == self && (annotation = [[eventArea
userInfo] objectForKey:SKAnnotationKey])) {
- [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:annotation atPoint:NSZeroPoint];
+ [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:annotation scale:[self scaleFactor] atPoint:NSZeroPoint];
} else if ([[SKPDFView superclass] instancesRespondToSelector:_cmd]) {
[super mouseEntered:theEvent];
}
@@ -2760,7 +2760,7 @@
NSPoint point = NSMakePoint(NSMinX(bounds) +
TOOLTIP_OFFSET_FRACTION * NSWidth(bounds), NSMinY(bounds) +
TOOLTIP_OFFSET_FRACTION * NSHeight(bounds));
point = [self convertPoint:point fromPage:[annotation page]];
point = [self convertPointToScreen:NSMakePoint(round(point.x),
round(point.y))];
- [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:annotation atPoint:point];
+ [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:annotation scale:[self scaleFactor] atPoint:point];
} else {
[[SKImageToolTipWindow sharedToolTipWindow] orderOut:self];
}
@@ -2808,7 +2808,7 @@
NSPoint point = NSMakePoint(NSMinX(bounds) +
TOOLTIP_OFFSET_FRACTION * NSWidth(bounds), NSMinY(bounds) +
TOOLTIP_OFFSET_FRACTION * NSHeight(bounds));
point = [self convertPoint:point fromPage:[annotation page]] ;
point = [self convertPointToScreen:NSMakePoint(round(point.x),
round(point.y))];
- [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:annotation atPoint:point];
+ [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:annotation scale:[self scaleFactor] atPoint:point];
} else {
[[SKImageToolTipWindow sharedToolTipWindow] orderOut:self];
}
Modified: trunk/SKTableView.m
===================================================================
--- trunk/SKTableView.m 2021-02-26 15:11:39 UTC (rev 12126)
+++ trunk/SKTableView.m 2021-02-26 15:53:34 UTC (rev 12127)
@@ -359,7 +359,7 @@
context = [[self delegate] tableView:self
imageContextForTableColumn:nil row:row];
}
if (context)
- [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:context atPoint:NSZeroPoint];
+ [[SKImageToolTipWindow sharedToolTipWindow]
showForImageContext:context scale:1.0 atPoint:NSZeroPoint];
}
return;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit