Revision: 14280
http://sourceforge.net/p/skim-app/code/14280
Author: hofman
Date: 2024-05-31 16:03:17 +0000 (Fri, 31 May 2024)
Log Message:
-----------
Use bitmaps to draw thumbnails for pages and snapshots. Avoid deprecated
lockFocus.
Modified Paths:
--------------
trunk/NSBitmapImageRep_SKExtensions.m
trunk/PDFPage_SKExtensions.m
trunk/SKSnapshotWindowController.m
Modified: trunk/NSBitmapImageRep_SKExtensions.m
===================================================================
--- trunk/NSBitmapImageRep_SKExtensions.m 2024-05-31 15:55:54 UTC (rev
14279)
+++ trunk/NSBitmapImageRep_SKExtensions.m 2024-05-31 16:03:17 UTC (rev
14280)
@@ -231,8 +231,8 @@
}
+ (instancetype)imageRepWithSize:(NSSize)size scale:(CGFloat)scale
drawingHandler:(void (^)(NSRect dstRect))drawingHandler {
- if (scale <= 0.0)
- scale = [[[NSScreen screens]
valueForKeyPath:@"@max.backingScaleFactor"] doubleValue];
+ if (scale < 1.0)
+ scale = fmax(1.0, [[[NSScreen screens]
valueForKeyPath:@"@max.backingScaleFactor"] doubleValue]);
NSBitmapImageRep *bmpImageRep = [[self alloc] initWithBitmapDataPlanes:NULL
pixelsWide:(NSInteger)(size.width * scale)
pixelsHigh:(NSInteger)(size.height * scale)
bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO
Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m 2024-05-31 15:55:54 UTC (rev 14279)
+++ trunk/PDFPage_SKExtensions.m 2024-05-31 16:03:17 UTC (rev 14280)
@@ -186,39 +186,37 @@
pageRect.origin.y -= shadowOffset;
}
- image = [[NSImage alloc] initWithSize:thumbnailSize];
-
- [image lockFocus];
-
- [[NSGraphicsContext currentContext] setImageInterpolation:[[NSUserDefaults
standardUserDefaults] integerForKey:SKInterpolationQualityKey] + 1];
-
- [NSGraphicsContext saveGraphicsState];
- [[NSColor whiteColor] setFill];
- if (shadowBlurRadius > 0.0)
- [NSShadow setShadowWithWhite:0.0 alpha:0.3 blurRadius:shadowBlurRadius
yOffset:shadowOffset];
- NSRectFill(pageRect);
- [NSGraphicsContext restoreGraphicsState];
-
- if (fabs(scale - 1.0) > 0.0 || shadowBlurRadius > 0.0) {
- NSAffineTransform *transform = [NSAffineTransform transform];
+ image = [NSImage bitmapImageWithSize:thumbnailSize scale:0.0
drawingHandler:^(NSRect dstRect){
+
+ [[NSGraphicsContext currentContext]
setImageInterpolation:[[NSUserDefaults standardUserDefaults]
integerForKey:SKInterpolationQualityKey] + 1];
+
+ [NSGraphicsContext saveGraphicsState];
+ [[NSColor whiteColor] setFill];
if (shadowBlurRadius > 0.0)
- [transform translateXBy:NSMinX(pageRect) yBy:NSMinY(pageRect)];
- [transform scaleBy:scale];
- [transform concat];
- }
+ [NSShadow setShadowWithWhite:0.0 alpha:0.3
blurRadius:shadowBlurRadius yOffset:shadowOffset];
+ NSRectFill(pageRect);
+ [NSGraphicsContext restoreGraphicsState];
+
+ if (fabs(scale - 1.0) > 0.0 || shadowBlurRadius > 0.0) {
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ if (shadowBlurRadius > 0.0)
+ [transform translateXBy:NSMinX(pageRect) yBy:NSMinY(pageRect)];
+ [transform scaleBy:scale];
+ [transform concat];
+ }
+
+ [self drawWithBox:box toContext:[[NSGraphicsContext currentContext]
CGContext]];
+
+ for (id highlight in highlights) {
+ // highlight should be a PDFSelection or SKReadingBar
+ if ([highlight
respondsToSelector:@selector(drawForPage:withBox:active:)])
+ [highlight drawForPage:self withBox:box active:YES];
+ }
+
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
+
+ }];
- [self drawWithBox:box toContext:[[NSGraphicsContext currentContext]
CGContext]];
-
- for (id highlight in highlights) {
- // highlight should be a PDFSelection or SKReadingBar
- if ([highlight
respondsToSelector:@selector(drawForPage:withBox:active:)])
- [highlight drawForPage:self withBox:box active:YES];
- }
-
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
-
- [image unlockFocus];
-
return image;
}
@@ -279,13 +277,10 @@
NSAffineTransform *transform = [self affineTransformForBox:box];
NSRect sourceRect = SKTransformRect(transform, rect);
- NSRect destRect = sourceRect;
- destRect.origin = NSZeroPoint;
- NSImage *image = [[NSImage alloc] initWithSize:sourceRect.size];
- [image lockFocus];
- [pageImage drawInRect:destRect fromRect:sourceRect
operation:NSCompositingOperationCopy fraction:1.0];
- [image unlockFocus];
+ NSImage *image = [NSImage bitmapImageWithSize:sourceRect.size scale:0.0
drawingHandler:^(NSRect dstRect){
+ [pageImage drawInRect:dstRect fromRect:sourceRect
operation:NSCompositingOperationCopy fraction:1.0];
+ }];
return [image TIFFRepresentation];
}
Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m 2024-05-31 15:55:54 UTC (rev 14279)
+++ trunk/SKSnapshotWindowController.m 2024-05-31 16:03:17 UTC (rev 14280)
@@ -495,30 +495,28 @@
if (size >= 0.0 && NSEqualPoints(bounds.origin, NSZeroPoint) == NO)
[transform translateXBy:-NSMinX(bounds) yBy:-NSMinY(bounds)];
- image = [[NSImage alloc] initWithSize:thumbnailSize];
+ image = [NSImage bitmapImageWithSize:thumbnailSize scale:0.0
drawingHandler:^(NSRect dstRect){
+
+ if (size < 0.0)
+ [[NSBezierPath bezierPathWithRoundedRect:(NSRect){NSZeroPoint,
thumbnailSize} xRadius:10.0 yRadius:10.0] addClip];
+
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
+ [transform concat];
+
+ [NSGraphicsContext saveGraphicsState];
+ [[NSColor whiteColor] set];
+ if (shadowBlurRadius > 0.0)
+ [NSShadow setShadowWithWhite:0.0 alpha:0.3
blurRadius:shadowBlurRadius yOffset:shadowOffset];
+ NSRectFill(bounds);
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
+ [NSGraphicsContext restoreGraphicsState];
+ [[NSBezierPath bezierPathWithRect:bounds] addClip];
+
+ CGContextRef context = [[NSGraphicsContext currentContext] CGContext];
+ [pdfView drawPagesInRect:bounds toContext:context];
+
+ }];
- [image lockFocus];
-
- if (size < 0.0)
- [[NSBezierPath bezierPathWithRoundedRect:(NSRect){NSZeroPoint,
thumbnailSize} xRadius:10.0 yRadius:10.0] addClip];
-
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
- [transform concat];
-
- [NSGraphicsContext saveGraphicsState];
- [[NSColor whiteColor] set];
- if (shadowBlurRadius > 0.0)
- [NSShadow setShadowWithWhite:0.0 alpha:0.3 blurRadius:shadowBlurRadius
yOffset:shadowOffset];
- NSRectFill(bounds);
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationDefault];
- [NSGraphicsContext restoreGraphicsState];
- [[NSBezierPath bezierPathWithRect:bounds] addClip];
-
- CGContextRef context = [[NSGraphicsContext currentContext] CGContext];
- [pdfView drawPagesInRect:bounds toContext:context];
-
- [image unlockFocus];
-
return image;
}
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