Revision: 13688
http://sourceforge.net/p/skim-app/code/13688
Author: hofman
Date: 2023-10-23 14:47:20 +0000 (Mon, 23 Oct 2023)
Log Message:
-----------
draw our own bitmap for pdfviews by drawing pages, Monterey uses the wrong zoom
to draw the bitmap
Modified Paths:
--------------
trunk/SKBasePDFView.m
trunk/SKSnapshotWindowController.m
Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m 2023-10-20 14:15:03 UTC (rev 13687)
+++ trunk/SKBasePDFView.m 2023-10-23 14:47:20 UTC (rev 13688)
@@ -402,4 +402,46 @@
[super goToDestination:destination];
}
+static inline NSRect SKPixelAlignedRect(NSRect rect, CGFloat scale) {
+ CGRect r;
+ r.origin.x = round(NSMinX(rect) * scale) / scale;
+ r.origin.y = round(NSMinY(rect) * scale) / scale;
+ r.size.width = round(NSMaxX(rect) * scale) / scale - NSMinX(r);
+ r.size.height = round(NSMaxY(rect) * scale) / scale - NSMinY(r);
+ return NSWidth(r) > 0.0 && NSHeight(r) > 0.0 ? r : NSZeroRect;
+}
+
+- (NSBitmapImageRep *)bitmapImageRepCachingDisplayInRect:(NSRect)rect {
+ // draw our own bitmap, because macOS 12 does it wrong
+ // ignore background and page shadows because we don't need them where we
use this
+ NSBitmapImageRep *imageRep = [self
bitmapImageRepForCachingDisplayInRect:rect];
+ NSPoint offset = rect.origin;
+ NSRect r = rect;
+ r.origin = NSZeroPoint;
+ PDFDisplayBox *box = [self displayBox];
+ CGFloat scale = [self scaleFactor];
+ CGFloat s = [imageRep pixelsWide] / [imageRep size].width;
+ NSGraphicsContext *context = [NSGraphicsContext
graphicsContextWithBitmapImageRep:imageRep];
+ CGContextRef cgContext = [context CGContext];
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:context];
+ for (PDFPage *page in [self visiblePages]) {
+ NSRect pageRect = [self convertRect:[page boundsForBox:box]
fromPage:page];
+ if (NSIntersectsRect(pageRect, r) == NO) continue;
+ pageRect.origin.x -= offset.x;
+ pageRect.origin.y -= offset.y;
+ [[NSColor whiteColor] setFill];
+ [NSBezierPath fillRect:SKPixelAlignedRect(pageRect, s)];
+ [context saveGraphicsState];
+ NSAffineTransform *t = [NSAffineTransform transform];
+ [t translateXBy:NSMinX(pageRect) yBy:NSMinY(pageRect)];
+ [t scaleBy:scale];
+ [t concat];
+ [page drawWithBox:box toContext:cgContext];
+ [context restoreGraphicsState];
+ }
+ [NSGraphicsContext restoreGraphicsState];
+ return imageRep;
+}
+
@end
Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m 2023-10-20 14:15:03 UTC (rev 13687)
+++ trunk/SKSnapshotWindowController.m 2023-10-23 14:47:20 UTC (rev 13688)
@@ -492,8 +492,7 @@
- (NSImage *)thumbnailWithSize:(CGFloat)size {
NSRect bounds = [pdfView visibleContentRect];
- NSClipView *clipView = [[pdfView scrollView] contentView];
- NSBitmapImageRep *imageRep = [clipView
bitmapImageRepCachingDisplayInRect:[pdfView convertRect:bounds
toView:clipView]];
+ NSBitmapImageRep *imageRep = [pdfView
bitmapImageRepCachingDisplayInRect:bounds];
NSAffineTransform *transform = nil;
NSSize thumbnailSize = bounds.size;
CGFloat shadowBlurRadius = 0.0;
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