Revision: 14316
http://sourceforge.net/p/skim-app/code/14316
Author: hofman
Date: 2024-06-08 18:02:48 +0000 (Sat, 08 Jun 2024)
Log Message:
-----------
Move snapshot configuration class to separate class files
Modified Paths:
--------------
trunk/SKMainWindowController.m
trunk/SKSnapshotWindowController.h
trunk/SKSnapshotWindowController.m
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/SKSnapshotConfiguration.h
trunk/SKSnapshotConfiguration.m
Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m 2024-06-08 17:30:41 UTC (rev 14315)
+++ trunk/SKMainWindowController.m 2024-06-08 18:02:48 UTC (rev 14316)
@@ -102,6 +102,7 @@
#import "SKOverviewView.h"
#import "SKThumbnailItem.h"
#import "SKThumbnailView.h"
+#import "SKSnapshotConfiguration.h"
#import "SKDocumentController.h"
#import "NSColor_SKExtensions.h"
#import "NSObject_SKExtensions.h"
Added: trunk/SKSnapshotConfiguration.h
===================================================================
--- trunk/SKSnapshotConfiguration.h (rev 0)
+++ trunk/SKSnapshotConfiguration.h 2024-06-08 18:02:48 UTC (rev 14316)
@@ -0,0 +1,62 @@
+//
+// SKSnapshotConfiguration.h
+// Skim
+//
+// Created by Christiaan Hofman on 08/06/2024.
+/*
+ This software is Copyright (c) 2024
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+#import <Quartz/Quartz.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface SKSnapshotConfiguration : NSObject {
+ NSSize size;
+ CGFloat scaleFactor;
+ PDFDisplayBox displayBox;
+ PDFInterpolationQuality interpolationQuality;
+ 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;
+
+- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale;
+
+@end
+
+NS_ASSUME_NONNULL_END
Added: trunk/SKSnapshotConfiguration.m
===================================================================
--- trunk/SKSnapshotConfiguration.m (rev 0)
+++ trunk/SKSnapshotConfiguration.m 2024-06-08 18:02:48 UTC (rev 14316)
@@ -0,0 +1,103 @@
+//
+// SKSnapshotConfiguration.m
+// Skim
+//
+// Created by Christiaan Hofman on 08/06/2024.
+/*
+ This software is Copyright (c) 2024
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SKSnapshotConfiguration.h"
+#import "NSImage_SKExtensions.h"
+#import "NSShadow_SKExtensions.h"
+#import "NSGeometry_SKExtensions.h"
+
+
+@implementation SKSnapshotConfiguration
+
+@synthesize size, scaleFactor, displayBox, interpolationQuality, pages;
+
+- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale {
+ NSRect bounds = (NSRect){NSZeroPoint, [self size]};
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ NSSize thumbnailSize = bounds.size;
+ CGFloat shadowBlurRadius = 0.0;
+ CGFloat shadowOffset = 0.0;
+ NSImage *image;
+
+ if (aSize > 0.0) {
+ shadowBlurRadius = round(scale * aSize / 32.0) / scale;
+ shadowOffset = -ceil(scale * shadowBlurRadius * 0.75) / scale;
+ if (NSHeight(bounds) > NSWidth(bounds))
+ thumbnailSize = NSMakeSize(round((aSize - 2.0 * shadowBlurRadius)
* NSWidth(bounds) / NSHeight(bounds) + 2.0 * shadowBlurRadius), aSize);
+ else
+ thumbnailSize = NSMakeSize(aSize, round((aSize - 2.0 *
shadowBlurRadius) * NSHeight(bounds) / NSWidth(bounds) + 2.0 *
shadowBlurRadius));
+ [transform translateXBy:shadowBlurRadius yBy:shadowBlurRadius -
shadowOffset];
+ [transform scaleXBy:(thumbnailSize.width - 2.0 * shadowBlurRadius) /
NSWidth(bounds) yBy:(thumbnailSize.height - 2.0 * shadowBlurRadius) /
NSHeight(bounds)];
+ }
+
+ if (NSEqualPoints(bounds.origin, NSZeroPoint) == NO)
+ [transform translateXBy:-NSMinX(bounds) yBy:-NSMinY(bounds)];
+
+ image = [NSImage bitmapImageWithSize:thumbnailSize scale:scale
drawingHandler:^(NSRect dstRect){
+
+ [[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];
+ PDFDisplayBox *box = [self displayBox];
+ CGFloat scale = [self scaleFactor];
+ CGContextSetInterpolationQuality(context, [self interpolationQuality]
+ 1);
+ for (PDFDestination *dest in [self pages]) {
+ NSPoint point = [dest point];
+ CGContextSaveGState(context);
+ CGContextTranslateCTM(context, point.x, point.y);
+ CGContextScaleCTM(context, scale, scale);
+ [[dest page] drawWithBox:box toContext:context];
+ CGContextRestoreGState(context);
+ }
+
+ }];
+
+ return image;
+}
+
+@end
Modified: trunk/SKSnapshotWindowController.h
===================================================================
--- trunk/SKSnapshotWindowController.h 2024-06-08 17:30:41 UTC (rev 14315)
+++ trunk/SKSnapshotWindowController.h 2024-06-08 18:02:48 UTC (rev 14316)
@@ -37,7 +37,6 @@
*/
#import <Cocoa/Cocoa.h>
-#import <Quartz/Quartz.h>
#import "SKSnapshotPDFView.h"
NS_ASSUME_NONNULL_BEGIN
@@ -121,22 +120,4 @@
@end
-@interface SKSnapshotConfiguration : NSObject {
- NSSize size;
- CGFloat scaleFactor;
- PDFDisplayBox displayBox;
- PDFInterpolationQuality interpolationQuality;
- 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;
-
-- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale;
-
-@end
-
NS_ASSUME_NONNULL_END
Modified: trunk/SKSnapshotWindowController.m
===================================================================
--- trunk/SKSnapshotWindowController.m 2024-06-08 17:30:41 UTC (rev 14315)
+++ trunk/SKSnapshotWindowController.m 2024-06-08 18:02:48 UTC (rev 14316)
@@ -43,6 +43,7 @@
#import "SKSnapshotPDFView.h"
#import <SkimNotes/SkimNotes.h>
#import "SKSnapshotWindow.h"
+#import "SKSnapshotConfiguration.h"
#import "NSWindowController_SKExtensions.h"
#import "SKStringConstants.h"
#import "NSUserDefaultsController_SKExtensions.h"
@@ -734,64 +735,3 @@
}
@end
-
-
-@implementation SKSnapshotConfiguration
-
-@synthesize size, scaleFactor, displayBox, interpolationQuality, pages;
-
-- (NSImage *)thumbnailWithSize:(CGFloat)aSize scale:(CGFloat)scale {
- NSRect bounds = (NSRect){NSZeroPoint, [self size]};
- NSAffineTransform *transform = [NSAffineTransform transform];
- NSSize thumbnailSize = bounds.size;
- CGFloat shadowBlurRadius = 0.0;
- CGFloat shadowOffset = 0.0;
- NSImage *image;
-
- if (aSize > 0.0) {
- shadowBlurRadius = round(scale * aSize / 32.0) / scale;
- shadowOffset = -ceil(scale * shadowBlurRadius * 0.75) / scale;
- if (NSHeight(bounds) > NSWidth(bounds))
- thumbnailSize = NSMakeSize(round((aSize - 2.0 * shadowBlurRadius)
* NSWidth(bounds) / NSHeight(bounds) + 2.0 * shadowBlurRadius), aSize);
- else
- thumbnailSize = NSMakeSize(aSize, round((aSize - 2.0 *
shadowBlurRadius) * NSHeight(bounds) / NSWidth(bounds) + 2.0 *
shadowBlurRadius));
- [transform translateXBy:shadowBlurRadius yBy:shadowBlurRadius -
shadowOffset];
- [transform scaleXBy:(thumbnailSize.width - 2.0 * shadowBlurRadius) /
NSWidth(bounds) yBy:(thumbnailSize.height - 2.0 * shadowBlurRadius) /
NSHeight(bounds)];
- }
-
- if (NSEqualPoints(bounds.origin, NSZeroPoint) == NO)
- [transform translateXBy:-NSMinX(bounds) yBy:-NSMinY(bounds)];
-
- image = [NSImage bitmapImageWithSize:thumbnailSize scale:scale
drawingHandler:^(NSRect dstRect){
-
- [[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];
- PDFDisplayBox *box = [self displayBox];
- CGFloat scale = [self scaleFactor];
- CGContextSetInterpolationQuality(context, [self interpolationQuality]
+ 1);
- for (PDFDestination *dest in [self pages]) {
- NSPoint point = [dest point];
- CGContextSaveGState(context);
- CGContextTranslateCTM(context, point.x, point.y);
- CGContextScaleCTM(context, scale, scale);
- [[dest page] drawWithBox:box toContext:context];
- CGContextRestoreGState(context);
- }
-
- }];
-
- return image;
-}
-
-@end
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2024-06-08 17:30:41 UTC (rev
14315)
+++ trunk/Skim.xcodeproj/project.pbxproj 2024-06-08 18:02:48 UTC (rev
14316)
@@ -102,6 +102,7 @@
CE2DE50D0B85DC4000D0DA12 /* PDFPage_SKExtensions.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE2DE50C0B85DC4000D0DA12 /*
PDFPage_SKExtensions.m */; };
CE2DEB1C0B8618DE00D0DA12 /* SKFindController.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE2DEB1B0B8618DE00D0DA12 /* SKFindController.m
*/; };
CE2DED6C0B86334900D0DA12 /* SKFieldEditor.m in Sources */ =
{isa = PBXBuildFile; fileRef = CE2DED6B0B86334900D0DA12 /* SKFieldEditor.m */;
};
+ CE2E9A592C14D2F300044B01 /* SKSnapshotConfiguration.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE2E9A582C14D2F300044B01 /*
SKSnapshotConfiguration.m */; };
CE31A6180C01FC45003612A9 /* SKDocumentController.m in Sources
*/ = {isa = PBXBuildFile; fileRef = CE31A6160C01FC45003612A9 /*
SKDocumentController.m */; };
CE32531F0F4723EA0021BADD /* SKMainWindowController_Actions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE32531E0F4723EA0021BADD /*
SKMainWindowController_Actions.m */; };
CE325592226F73810032390F /* SKAnnotationTypeImageView.m in
Sources */ = {isa = PBXBuildFile; fileRef = CE325591226F73810032390F /*
SKAnnotationTypeImageView.m */; };
@@ -890,6 +891,8 @@
CE2DEB1B0B8618DE00D0DA12 /* SKFindController.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKFindController.m; sourceTree = "<group>"; };
CE2DED6A0B86334900D0DA12 /* SKFieldEditor.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKFieldEditor.h; sourceTree = "<group>"; };
CE2DED6B0B86334900D0DA12 /* SKFieldEditor.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKFieldEditor.m; sourceTree = "<group>"; };
+ CE2E9A572C14D2F300044B01 /* SKSnapshotConfiguration.h */ = {isa
= PBXFileReference; lastKnownFileType = sourcecode.c.h; path =
SKSnapshotConfiguration.h; sourceTree = "<group>"; };
+ CE2E9A582C14D2F300044B01 /* SKSnapshotConfiguration.m */ = {isa
= PBXFileReference; lastKnownFileType = sourcecode.c.objc; path =
SKSnapshotConfiguration.m; sourceTree = "<group>"; };
CE2EF6852022753D004A73D8 /* synctex_parser_advanced.h */ = {isa
= PBXFileReference; lastKnownFileType = sourcecode.c.h; path =
synctex_parser_advanced.h; sourceTree = "<group>"; };
CE2EF68D2022753D004A73D8 /* synctex_version.h */ = {isa =
PBXFileReference; lastKnownFileType = sourcecode.c.h; path = synctex_version.h;
sourceTree = "<group>"; };
CE31A6150C01FC45003612A9 /* SKDocumentController.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKDocumentController.h; sourceTree = "<group>"; };
@@ -1963,6 +1966,8 @@
CE4294A20BBD29120016FDC2 /* SKReadingBar.m */,
CE1991DE256C70CD00FC4E25 /*
SKRecentDocumentInfo.h */,
CE1991DF256C70CD00FC4E25 /*
SKRecentDocumentInfo.m */,
+ CE2E9A572C14D2F300044B01 /*
SKSnapshotConfiguration.h */,
+ CE2E9A582C14D2F300044B01 /*
SKSnapshotConfiguration.m */,
CE26175D16CCFC4900BDCE7C /* SKSyncDot.h */,
CE26175E16CCFC4900BDCE7C /* SKSyncDot.m */,
CE2DE4900B85D48F00D0DA12 /* SKThumbnail.h */,
@@ -2897,6 +2902,7 @@
CE8978CE0CBFC70B00EA2D98 /* SKTemplateTag.m in
Sources */,
CE6C96B20CD925550022D69F /*
SKNotesPanelController.m in Sources */,
CE6DC7BB0D689138003A072F /*
PDFDocument_SKExtensions.m in Sources */,
+ CE2E9A592C14D2F300044B01 /*
SKSnapshotConfiguration.m in Sources */,
CEA8FCD60D89C34A00E8A6F4 /*
SKAnimatedBorderlessWindow.m in Sources */,
CE199DFD0D957A16009B2055 /*
SKAnnotationTypeImageCell.m in Sources */,
CEE54D880DA2E37B0037169F /*
PDFAnnotation_SKExtensions.m in Sources */,
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