Revision: 15152 http://sourceforge.net/p/skim-app/code/15152 Author: hofman Date: 2025-05-04 14:42:44 +0000 (Sun, 04 May 2025) Log Message: ----------- Pass backingScaleFactor to method to get tool tip image, as it is not safe to get this from NSScreen on a secondary thread
Modified Paths: -------------- trunk/SKImageToolTipContext.h trunk/SKImageToolTipContext.m trunk/SKImageToolTipWindow.m Modified: trunk/SKImageToolTipContext.h =================================================================== --- trunk/SKImageToolTipContext.h 2025-05-04 14:29:24 UTC (rev 15151) +++ trunk/SKImageToolTipContext.h 2025-05-04 14:42:44 UTC (rev 15152) @@ -43,7 +43,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SKImageToolTipContext <NSObject> -- (nullable NSImage *)toolTipImageWithScale:(CGFloat)scale; +- (nullable NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale; @end Modified: trunk/SKImageToolTipContext.m =================================================================== --- trunk/SKImageToolTipContext.m 2025-05-04 14:29:24 UTC (rev 15151) +++ trunk/SKImageToolTipContext.m 2025-05-04 14:42:44 UTC (rev 15152) @@ -99,12 +99,12 @@ @interface PDFDestination (SKImageToolTipContextExtension) -- (NSImage *)toolTipImageWithScale:(CGFloat)scale selections:(NSArray *)selections label:(NSString *)label; +- (NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale selections:(NSArray *)selections label:(NSString *)label; @end @implementation PDFDestination (SKImageToolTipContext) -- (NSImage *)toolTipImageWithScale:(CGFloat)scale selections:(NSArray *)selections label:(NSString *)label { +- (NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale selections:(NSArray *)selections label:(NSString *)label { static NSDictionary *labelAttributes = nil; static NSColor *labelColor = nil; if (labelAttributes == nil) @@ -122,7 +122,7 @@ NSPoint point = [[self effectiveDestinationForView:nil] point]; NSRect bounds = [page boundsForBox:kPDFDisplayBoxCropBox]; CGFloat size = isScaled ? ceil(scale * fmax(NSWidth(bounds), NSHeight(bounds))) : 0.0; - NSImage *pageImage = [page thumbnailWithSize:size scale:[[NSScreen mainScreen] backingScaleFactor] forBox:kPDFDisplayBoxCropBox hasShadow:NO highlights:selections]; + NSImage *pageImage = [page thumbnailWithSize:size scale:backingScale forBox:kPDFDisplayBoxCropBox hasShadow:NO highlights:selections]; NSRect pageImageRect = {NSZeroPoint, [pageImage size]}; NSRect sourceRect = NSZeroRect; PDFSelection *pageSelection = [page selectionForRect:bounds]; @@ -189,8 +189,8 @@ return image; } -- (NSImage *)toolTipImageWithScale:(CGFloat)scale { - return [self toolTipImageWithScale:scale selections:nil label:nil]; +- (NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale { + return [self toolTipImageWithScale:scale backingScale:backingScale selections:nil label:nil]; } @end @@ -198,8 +198,8 @@ @implementation PDFSelection (SKImageToolTipContext) -- (NSImage *)toolTipImageWithScale:(CGFloat)scale { - return [[self destination] toolTipImageWithScale:scale selections:@[self] label:nil]; +- (NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale { + return [[self destination] toolTipImageWithScale:scale backingScale:backingScale selections:@[self] label:nil]; } @end @@ -207,8 +207,8 @@ @implementation SKGroupedSearchResult (SKImageToolTipContext) -- (NSImage *)toolTipImageWithScale:(CGFloat)scale { - return [[[[self matches] firstObject] destination] toolTipImageWithScale:scale selections:[self matches] label:[self label]]; +- (NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale { + return [[[[self matches] firstObject] destination] toolTipImageWithScale:scale backingScale:backingScale selections:[self matches] label:[self label]]; } @end @@ -216,10 +216,10 @@ @implementation PDFAnnotation (SKImageToolTipContext) -- (NSImage *)toolTipImageWithScale:(CGFloat)scale { +- (NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale { if ([self isLink]) { - NSImage *image = [[self destination] toolTipImageWithScale:scale selections:nil label:nil]; + NSImage *image = [[self destination] toolTipImageWithScale:scale backingScale:backingScale selections:nil label:nil]; if (image) { [[[image representations] firstObject] setOpaque:YES]; return image; @@ -264,8 +264,8 @@ @implementation PDFPage (SKImageToolTipContext) -- (NSImage *)toolTipImageWithScale:(CGFloat)scale { - NSImage *image = [self thumbnailWithSize:256.0 scale:[[NSScreen mainScreen] backingScaleFactor] forBox:kPDFDisplayBoxCropBox hasShadow:NO highlights:nil]; +- (NSImage *)toolTipImageWithScale:(CGFloat)scale backingScale:(CGFloat)backingScale { + NSImage *image = [self thumbnailWithSize:256.0 scale:backingScale forBox:kPDFDisplayBoxCropBox hasShadow:NO highlights:nil]; [[[image representations] firstObject] setOpaque:YES]; return image; } Modified: trunk/SKImageToolTipWindow.m =================================================================== --- trunk/SKImageToolTipWindow.m 2025-05-04 14:29:24 UTC (rev 15151) +++ trunk/SKImageToolTipWindow.m 2025-05-04 14:42:44 UTC (rev 15152) @@ -174,6 +174,8 @@ image = nil; shouldShow = NO; + CGFloat backingScale = [[NSScreen mainScreen] backingScaleFactor]; + dispatch_async([[self class] imageQueue], ^{ NSNumber *usedScaleNumber = [[NSUserDefaults standardUserDefaults] objectForKey:SKToolTipScaleKey]; @@ -181,7 +183,7 @@ if (usedScale <= 0.0) usedScale = usedScale < 0.0 ? fmin(aScale, -usedScale) : aScale; - NSImage *anImage = [aContext toolTipImageWithScale:usedScale]; + NSImage *anImage = [aContext toolTipImageWithScale:usedScale backingScale:backingScale]; dispatch_async(dispatch_get_main_queue(), ^{ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit