Revision: 4912
http://skim-app.svn.sourceforge.net/skim-app/?rev=4912&view=rev
Author: hofman
Date: 2008-11-03 19:30:31 +0000 (Mon, 03 Nov 2008)
Log Message:
-----------
Add a command to get PDF or TIFF data from a region on a page
Modified Paths:
--------------
trunk/Skim.sdef
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/SKGrabCommand.h
trunk/SKGrabCommand.m
Added: trunk/SKGrabCommand.h
===================================================================
--- trunk/SKGrabCommand.h (rev 0)
+++ trunk/SKGrabCommand.h 2008-11-03 19:30:31 UTC (rev 4912)
@@ -0,0 +1,43 @@
+//
+// SKGrabCommand.h
+// Skim
+//
+// Created by Christiaan Hofman on 11/3/08.
+/*
+ This software is Copyright (c) 2008
+ 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>
+
+
[EMAIL PROTECTED] SKGrabCommand : NSScriptCommand
[EMAIL PROTECTED]
Added: trunk/SKGrabCommand.m
===================================================================
--- trunk/SKGrabCommand.m (rev 0)
+++ trunk/SKGrabCommand.m 2008-11-03 19:30:31 UTC (rev 4912)
@@ -0,0 +1,107 @@
+//
+// SKGrabCommand.m
+// Skim
+//
+// Created by Christiaan Hofman on 11/3/08.
+/*
+ This software is Copyright (c) 2008
+ 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 "SKGrabCommand.h"
+#import <Quartz/Quartz.h>
+#import "NSData_SKExtensions.h"
+#import "PDFPage_SKExtensions.h"
+
+
[EMAIL PROTECTED] SKGrabCommand
+
+- (id)performDefaultImplementation {
+ NSDictionary *args = [self evaluatedArguments];
+ PDFPage *page = [self evaluatedReceivers];
+ NSData *boundsData = [args objectForKey:@"Bounds"];
+ id asTIFF = [args objectForKey:@"AsTIFF"];
+ NSAppleEventDescriptor *desc = nil;
+
+ if ([page isKindOfClass:[PDFPage class]]) {
+ if ([asTIFF boolValue]) {
+ NSImage *pageImage = [page imageForBox:kPDFDisplayBoxMediaBox];
+ if (boundsData) {
+ NSRect pageBounds = [page boundsForBox:kPDFDisplayBoxMediaBox];
+ NSRect bounds = [boundsData rectValueAsQDRect];
+ NSRect sourceRect = bounds;
+ NSRect targetRect = {NSZeroPoint,sourceRect.size };
+ NSImage *image = nil;
+
+ sourceRect.origin.x -= NSMinX(pageBounds);
+ sourceRect.origin.y -= NSMinY(pageBounds);
+ image = [[NSImage alloc] initWithSize:targetRect.size];
+ [image lockFocus];
+ [pageImage drawInRect:targetRect fromRect:sourceRect
operation:NSCompositeCopy fraction:1.0];
+ [image unlockFocus];
+ pageImage = image;
+ }
+ desc = [NSAppleEventDescriptor descriptorWithDescriptorType:'TIFF'
data:[pageImage TIFFRepresentation]];
+ } else {
+ NSData *data = nil;
+ if (boundsData) {
+ if ([boundsData isKindOfClass:[NSData class]] == NO)
+ return nil;
+ PDFDocument *pdfDoc = [[PDFDocument alloc] initWithData:[page
dataRepresentation]];
+ PDFPage *pageCopy = [pdfDoc pageAtIndex:0];
+ NSRect bounds = [boundsData rectValueAsQDRect];
+
+ if (NSIsEmptyRect(bounds))
+ return nil;
+ if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_4) {
+ [pageCopy setBounds:bounds forBox:kPDFDisplayBoxMediaBox];
+ [pageCopy setBounds:NSZeroRect
forBox:kPDFDisplayBoxCropBox];
+ } else {
+ // setting the media box is buggy on Tiger, see bug #
1928384
+ [pageCopy setBounds:bounds forBox:kPDFDisplayBoxCropBox];
+ }
+ [pageCopy setBounds:NSZeroRect forBox:kPDFDisplayBoxBleedBox];
+ [pageCopy setBounds:NSZeroRect forBox:kPDFDisplayBoxTrimBox];
+ [pageCopy setBounds:NSZeroRect forBox:kPDFDisplayBoxArtBox];
+ data = [pageCopy dataRepresentation];
+ [pdfDoc release];
+ } else {
+ data = [page dataRepresentation];
+ }
+ if (data)
+ desc = [NSAppleEventDescriptor
descriptorWithDescriptorType:'PDF ' data:data];
+ }
+ }
+
+ return desc;
+}
+
[EMAIL PROTECTED]
Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef 2008-11-03 15:34:53 UTC (rev 4911)
+++ trunk/Skim.sdef 2008-11-03 19:30:31 UTC (rev 4912)
@@ -652,6 +652,9 @@
<responds-to name="get pages for">
<cocoa method=""/>
</responds-to>
+ <responds-to name="grab">
+ <cocoa method=""/>
+ </responds-to>
</class>
<class name="note" plural="notes" code="Note"
@@ -1322,6 +1325,23 @@
</result>
</command>
+ <command name="grab" code="SKIMGrab"
+ description="Grab a picture from a page.">
+ <cocoa class="SKGrabCommand"/>
+ <direct-parameter type="page"
+ description="The page for the picture."/>
+ <parameter name="for" type="rectangle" code="for " optional="yes"
+ description="The bounds for the picture.">
+ <cocoa key="Bounds"/>
+ </parameter>
+ <parameter name="TIFF format" type="boolean" code="Tiff"
optional="yes"
+ description="The format for the picture.">
+ <cocoa key="AsTIFF"/>
+ </parameter>
+ <result type="any"
+ description="The data of the picture."/>
+ </command>
+
</suite>
</dictionary>
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2008-11-03 15:34:53 UTC (rev
4911)
+++ trunk/Skim.xcodeproj/project.pbxproj 2008-11-03 19:30:31 UTC (rev
4912)
@@ -199,6 +199,7 @@
CEAFFD7D0C40ED5400C3ECBB /* ToolbarFonts.tiff in Resources */ =
{isa = PBXBuildFile; fileRef = CEAFFD7B0C40ED5400C3ECBB /* ToolbarFonts.tiff
*/; };
CEAFFD9D0C40F2A800C3ECBB /* ToolbarLines.tiff in Resources */ =
{isa = PBXBuildFile; fileRef = CEAFFD9C0C40F2A800C3ECBB /* ToolbarLines.tiff
*/; };
CEB735A20C4A8CD6000350F9 /* TransitionShading.tiff in Resources
*/ = {isa = PBXBuildFile; fileRef = CEB735A10C4A8CD6000350F9 /*
TransitionShading.tiff */; };
+ CEBB6A7F0EBF793100F2768B /* SKGrabCommand.m in Sources */ =
{isa = PBXBuildFile; fileRef = CEBB6A7E0EBF793100F2768B /* SKGrabCommand.m */;
};
CEBD52ED0C9C0AE500FBF6A4 /* SKBookmark.m in Sources */ = {isa =
PBXBuildFile; fileRef = CEBD52EB0C9C0AE500FBF6A4 /* SKBookmark.m */; };
CEBF85E20CCE2DE70057A050 /* NSAffineTransform_SKExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEBF85E00CCE2DE70057A050 /*
NSAffineTransform_SKExtensions.m */; };
CEC3AD240E23EC0300F40B0B /* PDFAnnotationLink_SKExtensions.m in
Sources */ = {isa = PBXBuildFile; fileRef = CEC3AD230E23EC0300F40B0B /*
PDFAnnotationLink_SKExtensions.m */; };
@@ -810,6 +811,8 @@
CEAFFD9C0C40F2A800C3ECBB /* ToolbarLines.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; path = ToolbarLines.tiff;
sourceTree = "<group>"; };
CEB72B890C4A189D000350F9 /* SKTransitionController.h */ = {isa
= PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path
= SKTransitionController.h; sourceTree = "<group>"; };
CEB735A10C4A8CD6000350F9 /* TransitionShading.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; path =
TransitionShading.tiff; sourceTree = "<group>"; };
+ CEBB6A7D0EBF793100F2768B /* SKGrabCommand.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKGrabCommand.h; sourceTree = "<group>"; };
+ CEBB6A7E0EBF793100F2768B /* SKGrabCommand.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKGrabCommand.m; sourceTree = "<group>"; };
CEBD52EA0C9C0AE500FBF6A4 /* SKBookmark.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKBookmark.h; sourceTree = "<group>"; };
CEBD52EB0C9C0AE500FBF6A4 /* SKBookmark.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKBookmark.m; sourceTree = "<group>"; };
CEBF85DF0CCE2DE70057A050 /* NSAffineTransform_SKExtensions.h */
= {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType =
sourcecode.c.h; path = NSAffineTransform_SKExtensions.h; sourceTree =
"<group>"; };
@@ -1405,6 +1408,8 @@
children = (
CE4643DC0DF6B77800CFD8D2 /* SKBoundsCommand.h
*/,
CE4643DD0DF6B77800CFD8D2 /* SKBoundsCommand.m
*/,
+ CEBB6A7D0EBF793100F2768B /* SKGrabCommand.h */,
+ CEBB6A7E0EBF793100F2768B /* SKGrabCommand.m */,
CE4643D90DF6B66000CFD8D2 /* SKIndexCommand.h */,
CE4643DA0DF6B66000CFD8D2 /* SKIndexCommand.m */,
CE4643CD0DF6B5A400CFD8D2 /* SKJoinCommand.h */,
@@ -2130,6 +2135,7 @@
CED6A3120EADF37800E8CD11 /*
NSImageCell_SKExtensions.m in Sources */,
CEE0F5EB0EBB3DEC000A7A8C /*
SKLevelIndicatorCell.m in Sources */,
CE0A3C8E0EBF3AAA00526C74 /*
NSResponder_SKExtensions.m in Sources */,
+ CEBB6A7F0EBF793100F2768B /* SKGrabCommand.m in
Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit