Revision: 2283 http://skim-app.svn.sourceforge.net/skim-app/?rev=2283&view=rev Author: hofman Date: 2007-06-13 03:07:18 -0700 (Wed, 13 Jun 2007)
Log Message: ----------- AppleScript support for page rotation and editable crop bounds, as well as the foreground box. Modified Paths: -------------- trunk/PDFPage_SKExtensions.h trunk/PDFPage_SKExtensions.m trunk/SKMainWindowController.h trunk/SKMainWindowController.m trunk/Skim.sdef Modified: trunk/PDFPage_SKExtensions.h =================================================================== --- trunk/PDFPage_SKExtensions.h 2007-06-12 22:49:44 UTC (rev 2282) +++ trunk/PDFPage_SKExtensions.h 2007-06-13 10:07:18 UTC (rev 2283) @@ -40,6 +40,8 @@ #import <Quartz/Quartz.h> #import "NSValue_SKExtensions.h" +extern NSString *SKPDFDocumentPageBoundsDidChangeNotification; + @class SKDocument; @interface PDFPage (SKExtensions) @@ -54,7 +56,11 @@ - (NSScriptObjectSpecifier *)objectSpecifier; - (SKDocument *)containingDocument; +- (int)rotationAngle; +- (void)setRotationAngle:(int)angle; - (NSData *)boundsAsQDRect; +- (void)setBoundsAsQDRect:(NSData *)inQDBoundsAsData; +- (NSData *)contentBoundsAsQDRect; - (id)richText; - (NSArray *)notes; - (void)insertInNotes:(id)newNote; Modified: trunk/PDFPage_SKExtensions.m =================================================================== --- trunk/PDFPage_SKExtensions.m 2007-06-12 22:49:44 UTC (rev 2282) +++ trunk/PDFPage_SKExtensions.m 2007-06-13 10:07:18 UTC (rev 2283) @@ -44,6 +44,8 @@ #import "OBUtilities.h" #import "NSBitmapImageRep_SKExtensions.h" +NSString *SKPDFDocumentPageBoundsDidChangeNotification = @"SKPDFDocumentPageBoundsDidChangeNotification"; + @interface PDFPage (SKReplacementMethods) - (void)replacementDealloc; @end @@ -275,11 +277,52 @@ return document; } +- (int)rotationAngle { + return [self rotation]; +} + +- (void)setRotationAngle:(int)angle { + if (angle != [self rotation]) { + NSUndoManager *undoManager = [[self containingDocument] undoManager]; + [[undoManager prepareWithInvocationTarget:self] setRotationAngle:[self rotation]]; + [undoManager setActionName:NSLocalizedString(@"Rotate Page", @"Undo action name")]; + // this will dirty the document, even though no saveable change has been made + // but we cannot undo the document change count because there may be real changes to the document in the script + + [self setRotation:angle]; + + [[NSNotificationCenter defaultCenter] postNotificationName:SKPDFDocumentPageBoundsDidChangeNotification + object:[self document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"rotate", @"action", self, @"page", nil]]; + } +} + - (NSData *)boundsAsQDRect { Rect qdBounds = RectFromNSRect([self boundsForBox:kPDFDisplayBoxCropBox]); return [NSData dataWithBytes:&qdBounds length:sizeof(Rect)]; } +- (void)setBoundsAsQDRect:(NSData *)inQDBoundsAsData { + if ([inQDBoundsAsData length] == sizeof(Rect)) { + NSUndoManager *undoManager = [[self containingDocument] undoManager]; + [[undoManager prepareWithInvocationTarget:self] setBoundsAsQDRect:[self boundsAsQDRect]]; + [undoManager setActionName:NSLocalizedString(@"Crop Page", @"Undo action name")]; + // this will dirty the document, even though no saveable change has been made + // but we cannot undo the document change count because there may be real changes to the document in the script + + const Rect *qdBounds = (const Rect *)[inQDBoundsAsData bytes]; + NSRect newBounds = NSRectFromRect(*qdBounds); + [self setBounds:newBounds forBox:kPDFDisplayBoxCropBox]; + + [[NSNotificationCenter defaultCenter] postNotificationName:SKPDFDocumentPageBoundsDidChangeNotification + object:[self document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"crop", @"action", self, @"page", nil]]; + } +} + +- (NSData *)contentBoundsAsQDRect { + Rect qdBounds = RectFromNSRect([self foregroundBox]); + return [NSData dataWithBytes:&qdBounds length:sizeof(Rect)]; +} + - (id)richText { NSAttributedString *attrString = [self attributedString]; return attrString ? [[[NSTextStorage alloc] initWithAttributedString:attrString] autorelease] : [NSNull null]; Modified: trunk/SKMainWindowController.h =================================================================== --- trunk/SKMainWindowController.h 2007-06-12 22:49:44 UTC (rev 2282) +++ trunk/SKMainWindowController.h 2007-06-13 10:07:18 UTC (rev 2283) @@ -325,6 +325,7 @@ - (void)handleDidMoveAnnotationNotification:(NSNotification *)notification; - (void)handleDoubleClickedAnnotationNotification:(NSNotification *)notification; - (void)handleAnnotationDidChangeNotification:(NSNotification *)notification; +- (void)handlePageBoundsDidChangeNotification:(NSNotification *)notification; - (void)handleDocumentBeginWrite:(NSNotification *)notification; - (void)handleDocumentEndWrite:(NSNotification *)notification; - (void)handleDocumentEndPageWrite:(NSNotification *)notification; Modified: trunk/SKMainWindowController.m =================================================================== --- trunk/SKMainWindowController.m 2007-06-12 22:49:44 UTC (rev 2282) +++ trunk/SKMainWindowController.m 2007-06-13 10:07:18 UTC (rev 2283) @@ -324,6 +324,8 @@ name:@"PDFDidEndDocumentWrite" object:[pdfView document]]; [nc addObserver:self selector:@selector(handleDocumentEndPageWrite:) name:@"PDFDidEndPageWrite" object:[pdfView document]]; + [nc addObserver:self selector:@selector(handlePageBoundsDidChangeNotification:) + name:SKPDFDocumentPageBoundsDidChangeNotification object:[pdfView document]]; } - (void)unregisterForDocumentNotifications { @@ -331,6 +333,7 @@ [nc removeObserver:self name:@"PDFDidBeginDocumentWrite" object:[pdfView document]]; [nc removeObserver:self name:@"PDFDidEndDocumentWrite" object:[pdfView document]]; [nc removeObserver:self name:@"PDFDidEndPageWrite" object:[pdfView document]]; + [nc removeObserver:self name:SKPDFDocumentPageBoundsDidChangeNotification object:[pdfView document]]; } - (void)registerAsObserver { @@ -966,17 +969,9 @@ PDFPage *page = [[pdfView document] pageAtIndex:index]; [page setRotation:[page rotation] + rotation]; - [pdfView layoutDocumentView]; - NSEnumerator *snapshotEnum = [snapshots objectEnumerator]; - SKSnapshotWindowController *wc; - while (wc = [snapshotEnum nextObject]) { - if ([wc isPageVisible:page]) { - [self snapshotNeedsUpdate:wc]; - [wc redisplay]; - } - } - [self updateThumbnailAtPageIndex:index]; + [[NSNotificationCenter defaultCenter] postNotificationName:SKPDFDocumentPageBoundsDidChangeNotification + object:[pdfView document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"rotate", @"action", page, @"page", nil]]; } - (IBAction)rotateRight:(id)sender { @@ -997,12 +992,9 @@ for (i = 0; i < count; i++) { [[[pdfView document] pageAtIndex:i] setRotation:[[[pdfView document] pageAtIndex:i] rotation] + 90]; } - [pdfView layoutDocumentView]; - [snapshots makeObjectsPerformSelector:@selector(redisplay) withObject:nil]; - [self allSnapshotsNeedUpdate]; - - [self allThumbnailsNeedUpdate]; + [[NSNotificationCenter defaultCenter] postNotificationName:SKPDFDocumentPageBoundsDidChangeNotification + object:[pdfView document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"rotate", @"action", nil]]; } - (IBAction)rotateAllLeft:(id)sender { @@ -1015,12 +1007,9 @@ for (i = 0; i < count; i++) { [[[pdfView document] pageAtIndex:i] setRotation:[[[pdfView document] pageAtIndex:i] rotation] - 90]; } - [pdfView layoutDocumentView]; - [snapshots makeObjectsPerformSelector:@selector(redisplay) withObject:nil]; - [self allSnapshotsNeedUpdate]; - - [self allThumbnailsNeedUpdate]; + [[NSNotificationCenter defaultCenter] postNotificationName:SKPDFDocumentPageBoundsDidChangeNotification + object:[pdfView document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"rotate", @"action", nil]]; } - (void)cropPageAtIndex:(unsigned int)index toRect:(NSRect)rect { @@ -1033,17 +1022,9 @@ PDFPage *page = [[pdfView document] pageAtIndex:index]; rect = NSIntersectionRect(rect, [page boundsForBox:kPDFDisplayBoxMediaBox]); [page setBounds:rect forBox:kPDFDisplayBoxCropBox]; - [pdfView layoutDocumentView]; - NSEnumerator *snapshotEnum = [snapshots objectEnumerator]; - SKSnapshotWindowController *wc; - while (wc = [snapshotEnum nextObject]) { - if ([wc isPageVisible:page]) { - [self snapshotNeedsUpdate:wc]; - [wc redisplay]; - } - } - [self updateThumbnailAtPageIndex:index]; + [[NSNotificationCenter defaultCenter] postNotificationName:SKPDFDocumentPageBoundsDidChangeNotification + object:[pdfView document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"crop", @"action", page, @"page", nil]]; } - (IBAction)crop:(id)sender { @@ -1072,13 +1053,9 @@ [undoManager setActionName:NSLocalizedString(@"Crop", @"Undo action name")]; [[self document] updateChangeCount:[undoManager isUndoing] ? NSChangeDone : NSChangeUndone]; - [pdfView layoutDocumentView]; + [[NSNotificationCenter defaultCenter] postNotificationName:SKPDFDocumentPageBoundsDidChangeNotification + object:[pdfView document] userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"crop", @"action", nil]]; - [snapshots makeObjectsPerformSelector:@selector(redisplay) withObject:nil]; - [self allSnapshotsNeedUpdate]; - - [self allThumbnailsNeedUpdate]; - // layout after cropping when you're in the middle of a document can lose the current page [pdfView goToPage:currentPage]; [[pdfView documentView] scrollRectToVisible:[pdfView convertRect:[pdfView convertRect:visibleRect fromPage:currentPage] toView:[pdfView documentView]]]; @@ -2352,6 +2329,33 @@ } } +- (void)handlePageBoundsDidChangeNotification:(NSNotification *)notification { + NSDictionary *info = [notification userInfo]; + PDFPage *page = [info objectForKey:@"page"]; + BOOL displayChanged = [[info objectForKey:@"action"] isEqualToString:@"rotate"] || [pdfView displayBox] == kPDFDisplayBoxCropBox; + + if (displayChanged) + [pdfView layoutDocumentView]; + if (page) { + unsigned int index = [[pdfView document] indexForPage:page]; + NSEnumerator *snapshotEnum = [snapshots objectEnumerator]; + SKSnapshotWindowController *wc; + while (wc = [snapshotEnum nextObject]) { + if ([wc isPageVisible:page]) { + [self snapshotNeedsUpdate:wc]; + [wc redisplay]; + } + } + if (displayChanged) + [self updateThumbnailAtPageIndex:index]; + } else { + [snapshots makeObjectsPerformSelector:@selector(redisplay) withObject:nil]; + [self allSnapshotsNeedUpdate]; + if (displayChanged) + [self allThumbnailsNeedUpdate]; + } +} + - (void)handleDocumentBeginWrite:(NSNotification *)notification { if (progressSheet == nil) { if ([NSBundle loadNibNamed:@"ProgressSheet" owner:self]) { Modified: trunk/Skim.sdef =================================================================== --- trunk/Skim.sdef 2007-06-12 22:49:44 UTC (rev 2282) +++ trunk/Skim.sdef 2007-06-13 10:07:18 UTC (rev 2283) @@ -544,10 +544,18 @@ description="The label of the page."> <cocoa key="label"/> </property> - <property name="bounds" code="pbnd" type="rectangle" access="r" + <property name="bounds" code="pbnd" type="rectangle" description="The bounding rectangle of the page (left, top, right, bottom)."> <cocoa key="boundsAsQDRect"/> </property> + <property name="content bounds" code="CBnd" type="rectangle" access="r" + description="The bounding rectangle for the content of the page (left, top, right, bottom)."> + <cocoa key="contentBoundsAsQDRect"/> + </property> + <property name="rotation" code="PRot" type="integer" + description="The rotation of the page. Must be one of 0, 90, 180, or 270."> + <cocoa key="rotationAngle"/> + </property> <responds-to name="bounds for"> <cocoa method=""/> </responds-to> 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 DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit