Revision: 5711
http://skim-app.svn.sourceforge.net/skim-app/?rev=5711&view=rev
Author: hofman
Date: 2009-09-08 15:15:44 +0000 (Tue, 08 Sep 2009)
Log Message:
-----------
create new notes for scripting in the PDFPage class using new Leopard method
Modified Paths:
--------------
trunk/PDFAnnotation_SKExtensions.m
trunk/PDFPage_SKExtensions.m
trunk/SKMainDocument.m
Modified: trunk/PDFAnnotation_SKExtensions.m
===================================================================
--- trunk/PDFAnnotation_SKExtensions.m 2009-09-08 11:38:26 UTC (rev 5710)
+++ trunk/PDFAnnotation_SKExtensions.m 2009-09-08 15:15:44 UTC (rev 5711)
@@ -237,100 +237,6 @@
#pragma mark Scripting support
-// to support the 'make' command
-- (id)init {
- [[self initWithBounds:NSZeroRect] release];
- self = nil;
- NSScriptCommand *currentCommand = [NSScriptCommand currentCommand];
- if ([currentCommand isKindOfClass:[NSCreateCommand class]]) {
- FourCharCode classCode = [[(NSCreateCommand *)currentCommand
createClassDescription] appleEventCode];
- NSRect bounds = NSMakeRect(100.0, 100.0, 0.0, 0.0);
- bounds.size.width = [[NSUserDefaults standardUserDefaults]
floatForKey:SKDefaultNoteWidthKey];
- bounds.size.height = [[NSUserDefaults standardUserDefaults]
floatForKey:SKDefaultNoteHeightKey];
-
- if (classCode == SKPDFAnnotationScriptingNoteClassCode) {
-
- NSDictionary *properties = [(NSCreateCommand *)currentCommand
resolvedKeyDictionary];
- FourCharCode type = [[properties
objectForKey:SKPDFAnnotationScriptingNoteTypeKey] unsignedLongValue];
-
- if (type == 0) {
- [currentCommand
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
- [currentCommand setScriptErrorString:NSLocalizedString(@"New
notes need a type.", @"Error description")];
- } else if (type == SKScriptingHighlightNote || type ==
SKScriptingStrikeOutNote || type == SKScriptingUnderlineNote) {
- id selSpec = [properties
objectForKey:SKPDFAnnotationSelectionSpecifierKey];
- PDFSelection *selection;
- NSInteger markupType = 0;
-
- if (selSpec == nil) {
- [currentCommand
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
- [currentCommand
setScriptErrorString:NSLocalizedString(@"New markup notes need a selection.",
@"Error description")];
- } else if (selection = [PDFSelection
selectionWithSpecifier:selSpec]) {
- if (type == SKScriptingHighlightNote)
- markupType = kPDFMarkupTypeHighlight;
- else if (type == SKScriptingUnderlineNote)
- markupType = kPDFMarkupTypeUnderline;
- else if (type == SKScriptingStrikeOutNote)
- markupType = kPDFMarkupTypeStrikeOut;
- if (self = [[PDFAnnotationMarkup alloc]
initSkimNoteWithSelection:selection markupType:markupType]) {
- PDFPage *page = [[selection pages] objectAtIndex:0];
- if (page && [self
respondsToSelector:@selector(setPage:)])
- [self performSelector:@selector(setPage:)
withObject:page];
- }
- }
- } else if (type == SKScriptingInkNote) {
- NSArray *pointLists = [properties
objectForKey:SKPDFAnnotationScriptingPointListsKey];
- if ([pointLists isKindOfClass:[NSArray class]] == NO) {
- [currentCommand
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
- [currentCommand
setScriptErrorString:NSLocalizedString(@"New markup notes need a selection.",
@"Error description")];
- } else {
- NSMutableArray *paths = [[NSMutableArray alloc]
initWithCapacity:[pointLists count]];
- NSEnumerator *listEnum = [pointLists objectEnumerator];
- NSArray *list;
- while (list = [listEnum nextObject]) {
- if ([list isKindOfClass:[NSArray class]]) {
- NSBezierPath *path = [[NSBezierPath alloc] init];
- NSEnumerator *ptEnum = [list objectEnumerator];
- id pt;
- while (pt = [ptEnum nextObject]) {
- NSPoint point;
- if ([pt isKindOfClass:[NSData class]]) {
- point = [pt pointValueAsQDPoint];
- } else if ([pt isKindOfClass:[NSArray class]]
&& [pt count] == 2) {
- Point qdPoint;
- qdPoint.v = [[pt objectAtIndex:0]
intValue];
- qdPoint.h = [[pt objectAtIndex:1]
intValue];
- point = SKNSPointFromQDPoint(qdPoint);
- } else continue;
- if ([path elementCount])
- [path lineToPoint:point];
- else
- [path moveToPoint:point];
- }
- if ([path elementCount] > 1)
- [paths addObject:path];
- [path release];
- }
- }
- self = [[PDFAnnotationInk alloc]
initSkimNoteWithPaths:paths];
- [paths release];
- }
- } else if (type == SKScriptingTextNote) {
- self = [[PDFAnnotationFreeText alloc]
initSkimNoteWithBounds:bounds];
- } else if (type == SKScriptingAnchoredNote) {
- bounds.size = SKNPDFAnnotationNoteSize;
- self = [[SKNPDFAnnotationNote alloc]
initSkimNoteWithBounds:bounds];
- } else if (type == SKScriptingCircleNote) {
- self = [[PDFAnnotationCircle alloc]
initSkimNoteWithBounds:bounds];
- } else if (type == SKScriptingSquareNote) {
- self = [[PDFAnnotationSquare alloc]
initSkimNoteWithBounds:bounds];
- } else if (type == SKScriptingLineNote) {
- self = [[PDFAnnotationLine alloc]
initSkimNoteWithBounds:bounds];
- }
- }
- }
- return self;
-}
-
- (NSScriptObjectSpecifier *)objectSpecifier {
NSUInteger idx = [[[self page] notes] indexOfObjectIdenticalTo:self];
if (idx != NSNotFound) {
Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m 2009-09-08 11:38:26 UTC (rev 5710)
+++ trunk/PDFPage_SKExtensions.m 2009-09-08 15:15:44 UTC (rev 5711)
@@ -52,6 +52,9 @@
#import "NSUserDefaults_SKExtensions.h"
#import "SKMainWindowController.h"
#import "NSAffineTransform_SKExtensions.h"
+#import "PDFAnnotation_SKExtensions.h"
+#import "PDFAnnotationMarkup_SKExtensions.h"
+#import "PDFAnnotationInk_SKExtensions.h"
NSString *SKPDFPageBoundsDidChangeNotification =
@"SKPDFPageBoundsDidChangeNotification";
@@ -461,6 +464,99 @@
[[pdfView undoManager] setActionName:NSLocalizedString(@"Remove Note",
@"Undo action name")];
}
+- (id)newScriptingObjectOfClass:(Class)class forValueForKey:(NSString *)key
withContentsValue:(id)contentsValue properties:(NSDictionary *)properties {
+ if ([key isEqualToString:@"notes"]) {
+ PDFAnnotation *annotation = nil;
+
+ NSRect bounds = NSMakeRect(100.0, 100.0, 0.0, 0.0);
+ bounds.size.width = [[NSUserDefaults standardUserDefaults]
floatForKey:SKDefaultNoteWidthKey];
+ bounds.size.height = [[NSUserDefaults standardUserDefaults]
floatForKey:SKDefaultNoteHeightKey];
+
+ FourCharCode type = [[properties
objectForKey:SKPDFAnnotationScriptingNoteTypeKey] unsignedLongValue];
+
+ if (type == 0) {
+ [[NSScriptCommand currentCommand]
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
+ [[NSScriptCommand currentCommand]
setScriptErrorString:NSLocalizedString(@"New notes need a type.", @"Error
description")];
+ } else if (type == SKScriptingHighlightNote || type ==
SKScriptingStrikeOutNote || type == SKScriptingUnderlineNote) {
+ id selSpec = [properties
objectForKey:SKPDFAnnotationSelectionSpecifierKey];
+ PDFSelection *selection;
+ NSInteger markupType = 0;
+
+ if (selSpec == nil) {
+ [[NSScriptCommand currentCommand]
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
+ [[NSScriptCommand currentCommand]
setScriptErrorString:NSLocalizedString(@"New markup notes need a selection.",
@"Error description")];
+ } else if (selection = [PDFSelection
selectionWithSpecifier:selSpec]) {
+ if (type == SKScriptingHighlightNote)
+ markupType = kPDFMarkupTypeHighlight;
+ else if (type == SKScriptingUnderlineNote)
+ markupType = kPDFMarkupTypeUnderline;
+ else if (type == SKScriptingStrikeOutNote)
+ markupType = kPDFMarkupTypeStrikeOut;
+ annotation = [[PDFAnnotationMarkup alloc]
initSkimNoteWithSelection:selection markupType:markupType];
+ }
+ } else if (type == SKScriptingInkNote) {
+ NSArray *pointLists = [properties
objectForKey:SKPDFAnnotationScriptingPointListsKey];
+ if ([pointLists isKindOfClass:[NSArray class]] == NO) {
+ [[NSScriptCommand currentCommand]
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
+ [[NSScriptCommand currentCommand]
setScriptErrorString:NSLocalizedString(@"New markup notes need a selection.",
@"Error description")];
+ } else {
+ NSMutableArray *paths = [[NSMutableArray alloc]
initWithCapacity:[pointLists count]];
+ NSEnumerator *listEnum = [pointLists objectEnumerator];
+ NSArray *list;
+ while (list = [listEnum nextObject]) {
+ if ([list isKindOfClass:[NSArray class]]) {
+ NSBezierPath *path = [[NSBezierPath alloc] init];
+ NSEnumerator *ptEnum = [list objectEnumerator];
+ id pt;
+ while (pt = [ptEnum nextObject]) {
+ NSPoint point;
+ if ([pt isKindOfClass:[NSData class]]) {
+ point = [pt pointValueAsQDPoint];
+ } else if ([pt isKindOfClass:[NSArray class]] &&
[pt count] == 2) {
+ Point qdPoint;
+ qdPoint.v = [[pt objectAtIndex:0] intValue];
+ qdPoint.h = [[pt objectAtIndex:1] intValue];
+ point = SKNSPointFromQDPoint(qdPoint);
+ } else continue;
+ if ([path elementCount])
+ [path lineToPoint:point];
+ else
+ [path moveToPoint:point];
+ }
+ if ([path elementCount] > 1)
+ [paths addObject:path];
+ [path release];
+ }
+ }
+ annotation = [[PDFAnnotationInk alloc]
initSkimNoteWithPaths:paths];
+ [paths release];
+ }
+ } else if (type == SKScriptingTextNote) {
+ annotation = [[PDFAnnotationFreeText alloc]
initSkimNoteWithBounds:bounds];
+ } else if (type == SKScriptingAnchoredNote) {
+ bounds.size = SKNPDFAnnotationNoteSize;
+ annotation = [[SKNPDFAnnotationNote alloc]
initSkimNoteWithBounds:bounds];
+ } else if (type == SKScriptingCircleNote) {
+ annotation = [[PDFAnnotationCircle alloc]
initSkimNoteWithBounds:bounds];
+ } else if (type == SKScriptingSquareNote) {
+ annotation = [[PDFAnnotationSquare alloc]
initSkimNoteWithBounds:bounds];
+ } else if (type == SKScriptingLineNote) {
+ annotation = [[PDFAnnotationLine alloc]
initSkimNoteWithBounds:bounds];
+ }
+ if (annotation) {
+ NSMutableDictionary *props = [properties mutableCopy];
+ [props removeObjectForKey:SKPDFAnnotationScriptingNoteTypeKey];
+ [props removeObjectForKey:SKPDFAnnotationSelectionSpecifierKey];
+ [props removeObjectForKey:SKPDFAnnotationScriptingPointListsKey];
+ if ([props count])
+ [annotation setScriptingProperties:props];
+ [props release];
+ }
+ return annotation;
+ }
+ return [super newScriptingObjectOfClass:class forValueForKey:key
withContentsValue:contentsValue properties:properties];
+}
+
- (id)handleGrabScriptCommand:(NSScriptCommand *)command {
NSDictionary *args = [command evaluatedArguments];
NSData *boundsData = [args objectForKey:@"Bounds"];
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2009-09-08 11:38:26 UTC (rev 5710)
+++ trunk/SKMainDocument.m 2009-09-08 15:15:44 UTC (rev 5711)
@@ -77,6 +77,7 @@
#import "NSResponder_SKExtensions.h"
#import "SKRuntime.h"
#import "SKTextFieldSheetController.h"
+#import "PDFAnnotationMarkup_SKExtensions.h"
#define BUNDLE_DATA_FILENAME @"data"
#define PRESENTATION_OPTIONS_KEY
@"net_sourceforge_skim-app_presentation_options"
@@ -1964,6 +1965,23 @@
return info;
}
+- (id)newScriptingObjectOfClass:(Class)class forValueForKey:(NSString *)key
withContentsValue:(id)contentsValue properties:(NSDictionary *)properties {
+ if ([key isEqualToString:@"notes"]) {
+ PDFAnnotation *annotation = nil;
+ PDFSelection *selection = [PDFSelection
selectionWithSpecifier:[properties
objectForKey:SKPDFAnnotationSelectionSpecifierKey]];
+ PDFPage *page = [[selection pages] count] ? [[selection pages]
objectAtIndex:0] : nil;
+ if (page == nil) {
+ [[NSScriptCommand currentCommand]
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+ } else {
+ annotation = [page newScriptingObjectOfClass:class
forValueForKey:key withContentsValue:contentsValue properties:properties];
+ if ([annotation respondsToSelector:@selector(setPage:)])
+ [annotation performSelector:@selector(setPage:)
withObject:page];
+ }
+ return annotation;
+ }
+ return [super newScriptingObjectOfClass:class forValueForKey:key
withContentsValue:contentsValue properties:properties];
+}
+
// fix a bug in Apple's implementation, which ignores the file type (for
export), also make some more sensible choice of save operation
- (id)handleSaveScriptCommand:(NSScriptCommand *)command {
NSDictionary *args = [command evaluatedArguments];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit