Revision: 14322
          http://sourceforge.net/p/skim-app/code/14322
Author:   hofman
Date:     2024-06-10 22:40:58 +0000 (Mon, 10 Jun 2024)
Log Message:
-----------
custom init for snapshot configuration class, no need for properties

Modified Paths:
--------------
    trunk/SKSnapshotConfiguration.h
    trunk/SKSnapshotConfiguration.m
    trunk/SKSnapshotWindowController.m

Modified: trunk/SKSnapshotConfiguration.h
===================================================================
--- trunk/SKSnapshotConfiguration.h     2024-06-10 15:24:00 UTC (rev 14321)
+++ trunk/SKSnapshotConfiguration.h     2024-06-10 22:40:58 UTC (rev 14322)
@@ -49,11 +49,7 @@
     NSArray<PDFDestination *> *pages;
 }
 
-@property (nonatomic) NSSize size;
-@property (nonatomic) CGFloat scaleFactor;
-@property (nonatomic) PDFDisplayBox displayBox;
-@property (nonatomic) PDFInterpolationQuality interpolationQuality;
-@property (nonatomic, nullable, copy) NSArray<PDFDestination *> *pages;
+- (instancetype)initWithPDFView:(PDFView *)pdfView;
 
 - (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale;
 

Modified: trunk/SKSnapshotConfiguration.m
===================================================================
--- trunk/SKSnapshotConfiguration.m     2024-06-10 15:24:00 UTC (rev 14321)
+++ trunk/SKSnapshotConfiguration.m     2024-06-10 22:40:58 UTC (rev 14322)
@@ -40,14 +40,32 @@
 #import "NSImage_SKExtensions.h"
 #import "NSShadow_SKExtensions.h"
 #import "NSGeometry_SKExtensions.h"
+#import "PDFView_SKExtensions.h"
 
 
 @implementation SKSnapshotConfiguration
 
-@synthesize size, scaleFactor, displayBox, interpolationQuality, pages;
+- (instancetype)initWithPDFView:(PDFView *)pdfView {
+    self = [super init];
+    if (self) {
+        NSRect bounds = [pdfView visibleContentRect];
+        size = bounds.size;
+        displayBox = [pdfView displayBox];
+        scaleFactor = [pdfView scaleFactor];
+        interpolationQuality = [pdfView interpolationQuality];
+        NSMutableArray *dests = [NSMutableArray array];
+        for (PDFPage *page in [pdfView visiblePages]) {
+            NSRect pageRect = [pdfView convertRect:[page 
boundsForBox:displayBox] fromPage:page];
+            if (NSIntersectsRect(pageRect, bounds))
+                [dests addObject:[[PDFDestination alloc] initWithPage:page 
atPoint:SKSubstractPoints(pageRect.origin, bounds.origin)]];
+        }
+        pages = dests;
+    }
+    return self;
+}
 
 - (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale {
-    NSRect bounds = (NSRect){NSZeroPoint, [self size]};
+    NSRect bounds = (NSRect){NSZeroPoint, size};
     NSAffineTransform *transform = [NSAffineTransform transform];
     NSSize thumbnailSize = bounds.size;
     CGFloat shadowBlurRadius = 0.0;
@@ -83,15 +101,13 @@
         [[NSBezierPath bezierPathWithRect:bounds] addClip];
         
         CGContextRef context = [[NSGraphicsContext currentContext] CGContext];
-        PDFDisplayBox *box = [self displayBox];
-        CGFloat scale = [self scaleFactor];
-        CGContextSetInterpolationQuality(context, [self interpolationQuality] 
+ 1);
-        for (PDFDestination *dest in [self pages]) {
+        CGContextSetInterpolationQuality(context, interpolationQuality + 1);
+        for (PDFDestination *dest in pages) {
             NSPoint point = [dest point];
             CGContextSaveGState(context);
             CGContextTranslateCTM(context, point.x, point.y);
-            CGContextScaleCTM(context, scale, scale);
-            [[dest page] drawWithBox:box toContext:context];
+            CGContextScaleCTM(context, scaleFactor, scaleFactor);
+            [[dest page] drawWithBox:displayBox toContext:context];
             CGContextRestoreGState(context);
         }
         

Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m  2024-06-10 15:24:00 UTC (rev 14321)
+++ trunk/SKSnapshotWindowController.m  2024-06-10 22:40:58 UTC (rev 14322)
@@ -395,21 +395,7 @@
 }
 
 - (SKSnapshotConfiguration *)currentConfiguration {
-    SKSnapshotConfiguration *configuration = [[SKSnapshotConfiguration alloc] 
init];
-    NSRect bounds = [pdfView visibleContentRect];
-    PDFDisplayBox box = [pdfView displayBox];
-    NSMutableArray *pages = [NSMutableArray array];
-    for (PDFPage *page in [pdfView visiblePages]) {
-        NSRect pageRect = [pdfView convertRect:[page boundsForBox:box] 
fromPage:page];
-        if (NSIntersectsRect(pageRect, bounds))
-            [pages addObject:[[PDFDestination alloc] initWithPage:page 
atPoint:SKSubstractPoints(pageRect.origin, bounds.origin)]];
-    }
-    [configuration setSize:bounds.size];
-    [configuration setScaleFactor:[pdfView scaleFactor]];
-    [configuration setDisplayBox:box];
-    [configuration setInterpolationQuality:[pdfView interpolationQuality]];
-    [configuration setPages:pages];
-    return configuration;
+    return [[SKSnapshotConfiguration alloc] initWithPDFView:pdfView];
 }
 
 #pragma mark Actions

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