Revision: 14273
          http://sourceforge.net/p/skim-app/code/14273
Author:   hofman
Date:     2024-05-29 16:12:56 +0000 (Wed, 29 May 2024)
Log Message:
-----------
Draw stamp images for placeholder page thumbnail as highlights when drawing 
thumbnail so we don't need to add them to the image

Modified Paths:
--------------
    trunk/SKMainWindowController.m

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2024-05-29 14:27:58 UTC (rev 14272)
+++ trunk/SKMainWindowController.m      2024-05-29 16:12:56 UTC (rev 14273)
@@ -183,6 +183,16 @@
 
 #pragma mark -
 
+@interface SKPageImage : NSObject {
+    NSImage *image;
+    NSRect rect;
+    CGFloat fraction;
+}
+- (instancetype)initWithImage:(NSImage *)anImage rect:(NSRect)aRect 
fraction:(CGFloat)aFraction;
+- (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
active:(BOOL)active;
+@end
+    
+
 @interface SKMainWindowController (SKPrivate)
 
 - (void)cleanup;
@@ -2849,17 +2859,19 @@
 - (void)resetThumbnails {
     NSMutableArray *newThumbnails = [NSMutableArray array];
     if ([pageLabels count] > 0) {
-        BOOL isLocked = [[pdfView document] isLocked];
         PDFPage *firstPage = [[pdfView document] pageAtIndex:0];
+        PDFDisplayBox box = [pdfView displayBox];
+        NSRect bounds = [firstPage boundsForBox:box];
+        if ([firstPage rotation] % 180 != 0)
+            bounds = NSMakeRect(0.0, 0.0, NSHeight(bounds), NSWidth(bounds));
+        else
+            bounds.origin = NSZeroPoint;
         PDFPage *emptyPage = [[SKPDFPage alloc] init];
-        [emptyPage setBounds:[firstPage boundsForBox:kPDFDisplayBoxCropBox] 
forBox:kPDFDisplayBoxCropBox];
-        [emptyPage setBounds:[firstPage boundsForBox:kPDFDisplayBoxMediaBox] 
forBox:kPDFDisplayBoxMediaBox];
-        [emptyPage setRotation:[firstPage rotation]];
-        NSImage *pageImage = [emptyPage thumbnailWithSize:thumbnailCacheSize 
forBox:[pdfView displayBox]];
-        NSRect rect = NSZeroRect;
-        rect.size = [pageImage size];
-        CGFloat width = 0.8 * fmin(NSWidth(rect), NSHeight(rect));
-        rect = NSInsetRect(rect, 0.5 * (NSWidth(rect) - width), 0.5 * 
(NSHeight(rect) - width));
+        [emptyPage setBounds:bounds forBox:kPDFDisplayBoxCropBox];
+        [emptyPage setBounds:bounds forBox:kPDFDisplayBoxMediaBox];
+        CGFloat width = ceil(0.8 * fmin(NSWidth(bounds), NSHeight(bounds)));
+        NSRect rect = NSInsetRect(bounds, 0.5 * (NSWidth(bounds) - width), 0.5 
* (NSHeight(bounds) - width));
+        NSMutableArray *stamps = [NSMutableArray array];
         
         NSString *type = [[self document] fileType];
         if ([type isEqualToString:SKPostScriptDocumentType])
@@ -2873,12 +2885,12 @@
         else
             type = @"PDF";
 
-        [pageImage lockFocus];
-        [[NSImage stampForType:type] drawInRect:rect fromRect:NSZeroRect 
operation:NSCompositingOperationSourceOver fraction:1.0];
-        if (isLocked)
-            [[[NSWorkspace sharedWorkspace] 
iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] drawInRect:rect 
fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:0.5];
-        [pageImage unlockFocus];
+        [stamps addObject:[[SKPageImage alloc] initWithImage:[NSImage 
stampForType:type] rect:rect fraction:1.0]];
+        if ([[pdfView document] isLocked])
+            [stamps addObject:[[SKPageImage alloc] initWithImage:[[NSWorkspace 
sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kLockedBadgeIcon)] 
rect:rect fraction:0.5]];
         
+        NSImage *pageImage = [emptyPage thumbnailWithSize:thumbnailCacheSize 
forBox:box shadowBlurRadius:round(thumbnailCacheSize / 32.0) highlights:stamps];
+        
         [pageLabels enumerateObjectsUsingBlock:^(NSString *label, NSUInteger 
i, BOOL *stop) {
             SKThumbnail *thumbnail = [[SKThumbnail alloc] 
initWithImage:pageImage label:label pageIndex:i];
             [thumbnail setDirty:YES];
@@ -3136,3 +3148,24 @@
 }
 
 @end
+
+
+@implementation SKPageImage
+
+- (instancetype)initWithImage:(NSImage *)anImage rect:(NSRect)aRect 
fraction:(CGFloat)aFraction {
+    self = [super init];
+    if (self) {
+        image = anImage;
+        rect = aRect;
+        fraction = aFraction;
+    }
+    return self;
+}
+
+- (void)drawForPage:(PDFPage *)pdfPage withBox:(PDFDisplayBox)box 
active:(BOOL)active {
+    [pdfPage transformContext:[[NSGraphicsContext currentContext] CGContext] 
forBox:box];
+    [image drawInRect:rect fromRect:NSZeroRect 
operation:NSCompositingOperationSourceOver fraction:fraction];
+}
+
+@end
+

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

Reply via email to