From: <ho...@us...> - 2007-04-05 17:44:23
|
Revision: 1753 http://skim-app.svn.sourceforge.net/skim-app/?rev=1753&view=rev Author: hofman Date: 2007-04-05 10:44:22 -0700 (Thu, 05 Apr 2007) Log Message: ----------- Export notes as RTF. Modified Paths: -------------- trunk/English.lproj/InfoPlist.strings trunk/Info.plist trunk/SKDocument.h trunk/SKDocument.m Modified: trunk/English.lproj/InfoPlist.strings =================================================================== (Binary files differ) Modified: trunk/Info.plist =================================================================== --- trunk/Info.plist 2007-04-05 16:41:38 UTC (rev 1752) +++ trunk/Info.plist 2007-04-05 17:44:22 UTC (rev 1753) @@ -40,6 +40,7 @@ <string>PDF With Embedded Notes</string> <string>PDF Without Notes</string> <string>Skim Notes</string> + <string>Notes as RTF</string> </array> </dict> <dict> @@ -213,6 +214,30 @@ <key>NSPersistentStoreTypeKey</key> <string>Binary</string> </dict> + <dict> + <key>CFBundleTypeExtensions</key> + <array> + <string>rtf</string> + </array> + <key>CFBundleTypeMIMETypes</key> + <array> + <string>text/rtf</string> + </array> + <key>CFBundleTypeName</key> + <string>Notes as RTF</string> + <key>CFBundleTypeOSTypes</key> + <array> + <string>RTF </string> + </array> + <key>CFBundleTypeRole</key> + <string>None</string> + <key>LSTypeIsPackage</key> + <false/> + <key>NSDocumentClass</key> + <string>SKDocument</string> + <key>NSPersistentStoreTypeKey</key> + <string>Binary</string> + </dict> </array> <key>CFBundleExecutable</key> <string>${EXECUTABLE_NAME}</string> Modified: trunk/SKDocument.h =================================================================== --- trunk/SKDocument.h 2007-04-05 16:41:38 UTC (rev 1752) +++ trunk/SKDocument.h 2007-04-05 17:44:22 UTC (rev 1753) @@ -70,6 +70,8 @@ - (SKPDFView *)pdfView; +- (NSData *)notesRTFData; + - (NSDictionary *)currentDocumentSetup; - (void)checkFileUpdatesIfNeeded; Modified: trunk/SKDocument.m =================================================================== --- trunk/SKDocument.m 2007-04-05 16:41:38 UTC (rev 1752) +++ trunk/SKDocument.m 2007-04-05 17:44:22 UTC (rev 1753) @@ -59,6 +59,7 @@ static NSString *SKEmbeddedPDFDocumentType = @"PDF With Embedded Notes"; static NSString *SKBarePDFDocumentType = @"PDF Without Notes"; static NSString *SKNotesDocumentType = @"Skim Notes"; +static NSString *SKNotesRTFDocumentType = @"Notes as RTF"; static NSString *SKPostScriptDocumentType = @"PostScript document"; NSString *SKDocumentWillSaveNotification = @"SKDocumentWillSaveNotification"; @@ -161,6 +162,12 @@ else if (outError != NULL) *outError = [NSError errorWithDomain:SKDocumentErrorDomain code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to write notes", @"Error description"), NSLocalizedDescriptionKey, nil]]; + } else if ([typeName isEqualToString:SKNotesRTFDocumentType]) { + NSData *data = [self notesRTFData]; + if (data) + didWrite = [data writeToURL:absoluteURL options:NSAtomicWrite error:outError]; + else if (outError != NULL) + *outError = [NSError errorWithDomain:SKDocumentErrorDomain code:1 userInfo:[NSDictionary dictionaryWithObjectsAndKeys:NSLocalizedString(@"Unable to write notes as RTF", @"Error description"), NSLocalizedDescriptionKey, nil]]; } return didWrite; } @@ -574,6 +581,59 @@ return [[self mainWindowController] pdfView]; } +- (NSData *)notesRTFData { + NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] init]; + NSEnumerator *noteEnum = [[[self mainWindowController] notes] objectEnumerator]; + PDFAnnotation *note; + NSData *data; + NSFont *standardFont = [NSFont systemFontOfSize:12.0]; + NSAttributedString *newlinesAttrString = [[NSAttributedString alloc] initWithString:@"\n\n" attributes:[NSDictionary dictionaryWithObjectsAndKeys:standardFont, NSFontAttributeName, nil]]; + + while (note = [noteEnum nextObject]) { + NSString *type = [note type]; + NSString *contents = [note contents]; + NSFont *font = [note respondsToSelector:@selector(font)] ? [(PDFAnnotationFreeText *)note font] : standardFont; + NSAttributedString *tmpAttrString = nil; + NSString *tmpString = nil; + + if ([type isEqualToString:@"FreeText"]) + tmpString = @"Text note"; + else if ([type isEqualToString:@"Note"]) + tmpString = @"Anchored note"; + else if ([type isEqualToString:@"Circle"]) + tmpString = @"Circle"; + else if ([type isEqualToString:@"Square"]) + tmpString = @"Box"; + else if ([type isEqualToString:@"MarkUp"] || [type isEqualToString:@"Highlight"]) + tmpString = @"Highlight"; + else if ([type isEqualToString:@"Underline"]) + tmpString = @"Underline"; + else if ([type isEqualToString:@"StrikeOut"]) + tmpString = @"Strike out"; + tmpString = [NSString stringWithFormat:@"%C %@\n page %i at %@", 0x2022, tmpString, [note pageIndex] + 1, NSStringFromRect([note bounds])]; + tmpAttrString = [[NSAttributedString alloc] initWithString:tmpString attributes:[NSDictionary dictionaryWithObjectsAndKeys:standardFont, NSFontAttributeName, nil]]; + [attrString appendAttributedString:tmpAttrString]; + [tmpAttrString release]; + [attrString appendAttributedString:newlinesAttrString]; + + tmpAttrString = [[NSAttributedString alloc] initWithString:contents ? contents : @"" attributes:[NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil]]; + [attrString appendAttributedString:tmpAttrString]; + [tmpAttrString release]; + [attrString appendAttributedString:newlinesAttrString]; + + if (tmpAttrString = [note text]) { + [attrString appendAttributedString:tmpAttrString]; + [attrString appendAttributedString:newlinesAttrString]; + } + } + + data = [attrString RTFFromRange:NSMakeRange(0, [attrString length]) documentAttributes:nil]; + [attrString release]; + [newlinesAttrString release]; + + return data; +} + #pragma mark Scripting support - (unsigned int)countOfPages { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |