Revision: 5354
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5354&view=rev
Author:   hofman
Date:     2009-05-06 17:16:22 +0000 (Wed, 06 May 2009)

Log Message:
-----------
Allow reading and writing PS and DVI with Skim notes

Modified Paths:
--------------
    trunk/English.lproj/InfoPlist.strings
    trunk/Info.plist
    trunk/SKDocumentController.h
    trunk/SKDocumentController.m
    trunk/SKPDFDocument.h
    trunk/SKPDFDocument.m

Modified: trunk/English.lproj/InfoPlist.strings
===================================================================
(Binary files differ)

Modified: trunk/Info.plist
===================================================================
--- trunk/Info.plist    2009-05-06 09:01:26 UTC (rev 5353)
+++ trunk/Info.plist    2009-05-06 17:16:22 UTC (rev 5354)
@@ -167,7 +167,7 @@
                        <key>CFBundleTypeName</key>
                        <string>PostScript document</string>
                        <key>CFBundleTypeRole</key>
-                       <string>Viewer</string>
+                       <string>Editor</string>
                        <key>LSItemContentTypes</key>
                        <array>
                                <string>com.adobe.postscript</string>
@@ -178,6 +178,8 @@
                        <string>SKPDFDocument</string>
                        <key>NSExportableAs</key>
                        <array>
+                               <string>PostScript document</string>
+                               <string>PostScript Without Notes</string>
                                <string>NSPDFPboardType</string>
                                <string>PDF Bundle</string>
                                <string>PDF With Embedded Notes</string>
@@ -190,6 +192,8 @@
                        </array>
                        <key>NSExportableTypes</key>
                        <array>
+                               <string>com.adobe.postscript</string>
+                               
<string>net.sourceforge.skim-app.bare.postscript</string>
                                <string>com.adobe.pdf</string>
                                <string>net.sourceforge.skim-app.pdfd</string>
                                
<string>net.sourceforge.skim-app.embedded.pdf</string>
@@ -219,7 +223,7 @@
                                <string>*DVI</string>
                        </array>
                        <key>CFBundleTypeRole</key>
-                       <string>Viewer</string>
+                       <string>Editor</string>
                        <key>LSItemContentTypes</key>
                        <array>
                                <string>net.sourceforge.skim-app.dvi</string>
@@ -230,6 +234,8 @@
                        <string>SKPDFDocument</string>
                        <key>NSExportableAs</key>
                        <array>
+                               <string>DVI document</string>
+                               <string>DVI Without Notes</string>
                                <string>NSPDFPboardType</string>
                                <string>PDF Bundle</string>
                                <string>PDF With Embedded Notes</string>
@@ -242,6 +248,8 @@
                        </array>
                        <key>NSExportableTypes</key>
                        <array>
+                               <string>net.sourceforge.skim-app.dvi</string>
+                               
<string>net.sourceforge.skim-app.bare.dvi</string>
                                <string>com.adobe.pdf</string>
                                <string>net.sourceforge.skim-app.pdfd</string>
                                
<string>net.sourceforge.skim-app.embedded.pdf</string>
@@ -567,7 +575,7 @@
                                <string>public.data</string>
                        </array>
                        <key>UTTypeDescription</key>
-                       <string>DVI</string>
+                       <string>DVI document</string>
                        <key>UTTypeIdentifier</key>
                        <string>net.sourceforge.skim-app.dvi</string>
                        <key>UTTypeTagSpecification</key>
@@ -587,7 +595,7 @@
                        <key>UTTypeDescription</key>
                        <string>PDF With Embedded Notes</string>
                        <key>UTTypeIconFile</key>
-                       <string>PDFDDocument</string>
+                       <string>PDFDocument</string>
                        <key>UTTypeIdentifier</key>
                        <string>net.sourceforge.skim-app.embedded.pdf</string>
                        <key>UTTypeTagSpecification</key>
@@ -607,7 +615,7 @@
                        <key>UTTypeDescription</key>
                        <string>PDF Without Notes</string>
                        <key>UTTypeIconFile</key>
-                       <string>PDFDDocument</string>
+                       <string>PDFDocument</string>
                        <key>UTTypeIdentifier</key>
                        <string>net.sourceforge.skim-app.bare.pdf</string>
                        <key>UTTypeTagSpecification</key>
@@ -618,6 +626,46 @@
                                </array>
                        </dict>
                </dict>
+               <dict>
+                       <key>UTTypeConformsTo</key>
+                       <array>
+                               <string>public.data</string>
+                               <string>public.composite-content</string>
+                       </array>
+                       <key>UTTypeDescription</key>
+                       <string>PostScript Without Notes</string>
+                       <key>UTTypeIconFile</key>
+                       <string>PSDocument</string>
+                       <key>UTTypeIdentifier</key>
+                       
<string>net.sourceforge.skim-app.bare.postscript</string>
+                       <key>UTTypeTagSpecification</key>
+                       <dict>
+                               <key>public.filename-extension</key>
+                               <array>
+                                       <string>ps</string>
+                               </array>
+                       </dict>
+               </dict>
+               <dict>
+                       <key>UTTypeConformsTo</key>
+                       <array>
+                               <string>public.data</string>
+                               <string>public.composite-content</string>
+                       </array>
+                       <key>UTTypeDescription</key>
+                       <string>DVI Without Notes</string>
+                       <key>UTTypeIconFile</key>
+                       <string>DVIDocument</string>
+                       <key>UTTypeIdentifier</key>
+                       <string>net.sourceforge.skim-app.bare.dvi</string>
+                       <key>UTTypeTagSpecification</key>
+                       <dict>
+                               <key>public.filename-extension</key>
+                               <array>
+                                       <string>dvi</string>
+                               </array>
+                       </dict>
+               </dict>
        </array>
 </dict>
 </plist>

Modified: trunk/SKDocumentController.h
===================================================================
--- trunk/SKDocumentController.h        2009-05-06 09:01:26 UTC (rev 5353)
+++ trunk/SKDocumentController.h        2009-05-06 17:16:22 UTC (rev 5354)
@@ -50,7 +50,9 @@
 extern BOOL SKIsNotesRTFDDocumentType(NSString *docType);
 extern BOOL SKIsNotesFDFDocumentType(NSString *docType);
 extern BOOL SKIsPostScriptDocumentType(NSString *docType);
+extern BOOL SKIsBarePostScriptDocumentType(NSString *docType);
 extern BOOL SKIsDVIDocumentType(NSString *docType);
+extern BOOL SKIsBareDVIDocumentType(NSString *docType);
 
 extern NSString *SKNormalizedDocumentType(NSString *docType);
 
@@ -64,7 +66,9 @@
 extern NSString *SKNotesRTFDDocumentType;
 extern NSString *SKNotesFDFDocumentType;
 extern NSString *SKPostScriptDocumentType;
+extern NSString *SKBarePostScriptDocumentType;
 extern NSString *SKDVIDocumentType;
+extern NSString *SKBareDVIDocumentType;
 
 extern NSString *SKDocumentSetupAliasKey;
 extern NSString *SKDocumentSetupFileNameKey;

Modified: trunk/SKDocumentController.m
===================================================================
--- trunk/SKDocumentController.m        2009-05-06 09:01:26 UTC (rev 5353)
+++ trunk/SKDocumentController.m        2009-05-06 17:16:22 UTC (rev 5354)
@@ -63,7 +63,9 @@
 #define SKNotesRTFDDocumentTypeName @"Notes as RTFD"
 #define SKNotesFDFDocumentTypeName @"Notes as FDF"
 #define SKPostScriptDocumentTypeName @"PostScript document"
+#define SKBarePostScriptDocumentTypeName @"PostScript Without Notes"
 #define SKDVIDocumentTypeName @"DVI document"
+#define SKBareDVIDocumentTypeName @"DVI Without Notes"
 
 #define SKPDFDocumentTypeUTI @"com.adobe.pdf"
 #define SKPDFBundleDocumentTypeUTI @"net.sourceforge.skim-app.pdfd"
@@ -76,8 +78,10 @@
 // I don't know the UTI for fdf, is there one?
 #define SKNotesFDFDocumentTypeUTI @"com.adobe.fdf"
 #define SKPostScriptDocumentTypeUTI @"com.adobe.postscript"
+#define SKBarePostScriptDocumentTypeUTI 
@"net.sourceforge.skim-app.bare.postscript"
 // I don't know the UTI for dvi, is there one?
 #define SKDVIDocumentTypeUTI @"net.sourceforge.skim-app.dvi"
+#define SKBareDVIDocumentTypeUTI @"net.sourceforge.skim-app.bare.dvi"
 
 NSString *SKPDFDocumentType = nil;
 NSString *SKPDFBundleDocumentType = nil;
@@ -89,7 +93,9 @@
 NSString *SKNotesRTFDDocumentType = nil;
 NSString *SKNotesFDFDocumentType = nil;
 NSString *SKPostScriptDocumentType = nil;
+NSString *SKBarePostScriptDocumentType = nil;
 NSString *SKDVIDocumentType = nil;
+NSString *SKBareDVIDocumentType = nil;
 
 static BOOL SKIsEqualToDocumentType(NSString *docType, NSString *docTypeName, 
NSString *docUTI) {
     return ([[NSWorkspace sharedWorkspace] 
respondsToSelector:@selector(type:conformsToType:)] && [[NSWorkspace 
sharedWorkspace] type:docType conformsToType:docUTI]) || [docType 
isEqualToString:docTypeName];
@@ -107,7 +113,9 @@
 DEFINE_IS_DOCUMENT_TYPE(NotesRTFD)
 DEFINE_IS_DOCUMENT_TYPE(NotesFDF)
 DEFINE_IS_DOCUMENT_TYPE(PostScript)
+DEFINE_IS_DOCUMENT_TYPE(BarePostScript)
 DEFINE_IS_DOCUMENT_TYPE(DVI)
+DEFINE_IS_DOCUMENT_TYPE(BareDVI)
 
 #define RETURN_IF_IS_DOCUMENT_TYPE(name) if 
(SKIs##name##DocumentType(docType)) return SK##name##DocumentType
 
@@ -122,7 +130,9 @@
     RETURN_IF_IS_DOCUMENT_TYPE(NotesRTFD);
     RETURN_IF_IS_DOCUMENT_TYPE(NotesFDF);
     RETURN_IF_IS_DOCUMENT_TYPE(PostScript);
+    RETURN_IF_IS_DOCUMENT_TYPE(BarePostScript);
     RETURN_IF_IS_DOCUMENT_TYPE(DVI);
+    RETURN_IF_IS_DOCUMENT_TYPE(BareDVI);
     return docType;
 }
 
@@ -173,6 +183,16 @@
         // this is interpreted as SKEmbeddedPDFDocumentType, even though we 
don't declare that as a readable type
         type = SKPDFDocumentType;
     }
+    else if (SKIsBarePostScriptDocumentType(type)) {
+        // fix of bug when reading a PostScript file on 10.4
+        // this is interpreted as SKBarePostScriptDocumentType, even though we 
don't declare that as a readable type
+        type = SKPostScriptDocumentType;
+    }
+    else if (SKIsBareDVIDocumentType(type)) {
+        // fix of bug when reading a DVI file on 10.4
+        // this is interpreted as SKBareDVIDocumentType, even though we don't 
declare that as a readable type
+        type = SKDVIDocumentType;
+    }
        return type;
 }
 

Modified: trunk/SKPDFDocument.h
===================================================================
--- trunk/SKPDFDocument.h       2009-05-06 09:01:26 UTC (rev 5353)
+++ trunk/SKPDFDocument.h       2009-05-06 17:16:22 UTC (rev 5354)
@@ -71,6 +71,7 @@
     
     // variables to be saved:
     NSData *pdfData;
+    NSData *psOrDviData;
     
     // temporary variables:
     PDFDocument *pdfDocument;

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2009-05-06 09:01:26 UTC (rev 5353)
+++ trunk/SKPDFDocument.m       2009-05-06 17:16:22 UTC (rev 5354)
@@ -94,6 +94,7 @@
 @interface SKPDFDocument (SKPrivate)
 
 - (void)setPDFData:(NSData *)data;
+- (void)setPSOrDVIData:(NSData *)data;
 - (void)setPDFDoc:(PDFDocument *)doc;
 - (void)setNoteDicts:(NSArray *)array;
 - (void)setOpenMetaTags:(NSArray *)array;
@@ -127,6 +128,7 @@
     [presentationNotesDocument release];
     [watchedFile release];
     [pdfData release];
+    [psOrDviData release];
     [pdfDocument release];
     [noteDicts release];
     [openMetaTags release];
@@ -243,6 +245,14 @@
 
 - (NSArray *)writableTypesForSaveOperation:(NSSaveOperationType)saveOperation {
     NSMutableArray *writableTypes = [[[super 
writableTypesForSaveOperation:saveOperation] mutableCopy] autorelease];
+    if (SKIsPostScriptDocumentType([self fileType]) == NO) {
+        [writableTypes removeObject:SKPostScriptDocumentType];
+        [writableTypes removeObject:SKBarePostScriptDocumentType];
+    }
+    if (SKIsDVIDocumentType([self fileType]) == NO) {
+        [writableTypes removeObject:SKDVIDocumentType];
+        [writableTypes removeObject:SKBareDVIDocumentType];
+    }
     if (saveOperation == NSSaveToOperation) {
         [[NSDocumentController sharedDocumentController] 
resetCustomExportTemplateFiles];
         [writableTypes addObjectsFromArray:[[NSDocumentController 
sharedDocumentController] customExportTemplateFiles]];
@@ -310,7 +320,7 @@
     NSError *error = nil;
     
     // we check for notes and may save a .skim as well:
-    if (SKIsPDFDocumentType(typeName)) {
+    if (SKIsPDFDocumentType(typeName) || SKIsPostScriptDocumentType(typeName) 
|| SKIsDVIDocumentType(typeName)) {
         
         NSFileManager *fm = [NSFileManager defaultManager];
         
@@ -433,11 +443,10 @@
         // this must be checked before PDF, as we check for comformance to the 
UTI
         [[self mainWindowController] removeTemporaryAnnotations];
         didWrite = [[self pdfDocument] writeToURL:absoluteURL];
-    } else if (SKIsBarePDFDocumentType(typeName)) {
-        // this must be checked before PDF, as we check for comformance to the 
UTI
+    } else if (SKIsPDFDocumentType(typeName) || 
SKIsBarePDFDocumentType(typeName)) {
         didWrite = [pdfData writeToURL:absoluteURL options:0 error:&error];
-    } else if (SKIsPDFDocumentType(typeName)) {
-        didWrite = [pdfData writeToURL:absoluteURL options:0 error:&error];
+    } else if (SKIsPostScriptDocumentType(typeName) || 
SKIsDVIDocumentType(typeName) || SKIsBarePostScriptDocumentType(typeName) || 
SKIsBareDVIDocumentType(typeName)) {
+        didWrite = [psOrDviData writeToURL:absoluteURL options:0 error:&error];
     } else if (SKIsPDFBundleDocumentType(typeName)) {
         NSString *name = [[[absoluteURL path] lastPathComponent] 
stringByDeletingPathExtension];
         if ([name caseInsensitiveCompare:BUNDLE_DATA_FILENAME] == 
NSOrderedSame)
@@ -555,7 +564,7 @@
     NSMutableDictionary *dict = [[[super 
fileAttributesToWriteToURL:absoluteURL ofType:typeName 
forSaveOperation:saveOperation originalContentsURL:absoluteOriginalContentsURL 
error:outError] mutableCopy] autorelease];
     
     // only set the creator code for our native types
-    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && (SKIsPDFDocumentType(typeName) || 
SKIsPDFBundleDocumentType(typeName) || SKIsNotesDocumentType(typeName)))
+    if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKShouldSetCreatorCodeKey] && (SKIsPDFDocumentType(typeName) || 
SKIsPDFBundleDocumentType(typeName) || SKIsPostScriptDocumentType(typeName) || 
SKIsDVIDocumentType(typeName) || SKIsNotesDocumentType(typeName)))
         [dict setObject:[NSNumber numberWithUnsignedLong:'SKim'] 
forKey:NSFileHFSCreatorCode];
     
     if ([[[absoluteURL path] pathExtension] isEqualToString:@"pdf"] || 
@@ -587,6 +596,13 @@
     }
 }
 
+- (void)setPSOrDVIData:(NSData *)data {
+    if (psOrDviData != data) {
+        [psOrDviData release];
+        psOrDviData = [data retain];
+    }
+}
+
 - (void)setPDFDoc:(PDFDocument *)doc {
     if (pdfDocument != doc) {
         [pdfDocument release];
@@ -652,19 +668,32 @@
 
 - (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)docType 
error:(NSError **)outError{
     BOOL didRead = NO;
+    NSData *fileData = nil;
     NSData *data = nil;
     PDFDocument *pdfDoc = nil;
     NSError *error = nil;
     
     [self setPDFData:nil];
+    [self setPSOrDVIData:nil];
     [self setPDFDoc:nil];
     [self setNoteDicts:nil];
     [self setOpenMetaTags:nil];
     [self setOpenMetaRating:0.0];
     
-    if (SKIsPDFDocumentType(docType)) {
-        if ((data = [[NSData alloc] initWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) &&
-            (pdfDoc = [[PDFDocument alloc] initWithURL:absoluteURL])) {
+    if (SKIsPDFDocumentType(docType) || SKIsPostScriptDocumentType(docType) || 
SKIsDVIDocumentType(docType)) {
+        if (fileData = [[NSData alloc] initWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) {
+            if (SKIsPDFDocumentType(docType)) {
+                if (data = [fileData retain])
+                    pdfDoc = [[PDFDocument alloc] initWithURL:absoluteURL];
+            } else if (SKIsPostScriptDocumentType(docType)) {
+                if (data = [[SKConversionProgressController 
PDFDataWithPostScriptData:fileData] retain])
+                    pdfDoc = [[PDFDocument alloc] initWithData:data];
+            } else if (SKIsDVIDocumentType(docType)) {
+                if (data = [[SKConversionProgressController 
PDFDataWithDVIFile:[absoluteURL path]] retain])
+                    pdfDoc = [[PDFDocument alloc] initWithData:data];
+            }
+        }
+        if (pdfDoc) {
             NSArray *array = [[NSFileManager defaultManager] 
readSkimNotesFromExtendedAttributesAtURL:absoluteURL error:&error];
             if ([array count]) {
                 [self setNoteDicts:array];
@@ -677,6 +706,8 @@
                                                        otherButton:nil
                                          
informativeTextWithFormat:NSLocalizedString(@"Skim was not able to read the 
notes at %...@. %@ Do you want to continue to open the PDF document anyway?", 
@"Informative text in alert dialog"), [[absoluteURL path] 
stringByAbbreviatingWithTildeInPath], [[error userInfo] 
objectForKey:NSLocalizedDescriptionKey]];
                     if ([alert runModal] == NSAlertDefaultReturn) {
+                        [fileData release];
+                        fileData = nil;
                         [data release];
                         data = nil;
                         [pdfDoc release];
@@ -731,16 +762,6 @@
                 }
             }
         }
-    } else if (SKIsPostScriptDocumentType(docType)) {
-        if (data = [NSData dataWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) {
-            if (data = [[SKConversionProgressController 
PDFDataWithPostScriptData:data] retain])
-                pdfDoc = [[PDFDocument alloc] initWithData:data];
-        }
-    } else if (SKIsDVIDocumentType(docType)) {
-        if (data = [NSData dataWithContentsOfURL:absoluteURL 
options:NSUncachedRead error:&error]) {
-            if (data = [[SKConversionProgressController 
PDFDataWithDVIFile:[absoluteURL path]] retain])
-                pdfDoc = [[PDFDocument alloc] initWithData:data];
-        }
     }
     
     if (data) {
@@ -748,6 +769,8 @@
             didRead = YES;
             [self setPDFData:data];
             [self setPDFDoc:pdfDoc];
+            if (SKIsPostScriptDocumentType(docType) || 
SKIsDVIDocumentType(docType))
+                [self setPSOrDVIData:fileData];
             [pdfDoc release];
             docFlags.fileChangedOnDisk = NO;
             [lastModifiedDate release];
@@ -779,6 +802,7 @@
             [self setPDFData:nil];
         }
         [data release];
+        [fileData release];
     }
     
     if (didRead == NO && outError != NULL)
@@ -996,6 +1020,10 @@
 }
 
 - (IBAction)convertNotes:(id)sender {
+    if (SKIsPDFDocumentType([self fileType]) == NO || 
SKIsPDFBundleDocumentType([self fileType]) == NO) {
+        NSBeep();
+        return;
+    }
     NSString *message = NSLocalizedString(@"This will convert PDF annotations 
to Skim notes. Do you want to proceed?", @"Informative text in alert dialog");
     if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_4)
         message = NSLocalizedString(@"This will convert PDF annotations to 
Skim notes. This will loose the Table of Contents. Do you want to proceed?", 
@"Informative text in alert dialog");
@@ -1221,7 +1249,7 @@
     } else if ([anItem action] == @selector(printDocument:)) {
         return [[self pdfDocument] allowsPrinting];
     } else if ([anItem action] == @selector(convertNotes:)) {
-        return [[self pdfDocument] isLocked] == NO;
+        return SKIsPDFDocumentType([self fileType]) && [[self pdfDocument] 
isLocked] == NO;
     } else if ([anItem action] == @selector(saveArchive:) || [anItem action] 
== @selector(saveDiskImage:) || [anItem action] == @selector(emailArchive:) || 
[anItem action] == @selector(emailDiskImage:)) {
         NSString *path = [[self fileURL] path];
         return path && [[NSFileManager defaultManager] fileExistsAtPath:path] 
&& [self isDocumentEdited] == NO;
@@ -2158,7 +2186,8 @@
 }
 
 - (void)handleConvertNotesScriptCommand:(NSScriptCommand *)command {
-    [self convertNotesSheetDidEnd:nil returnCode:NSAlertDefaultReturn 
contextInfo:NULL];
+    if (SKIsPDFDocumentType([self fileType]) || 
SKIsPDFBundleDocumentType([self fileType]))
+        [self convertNotesSheetDidEnd:nil returnCode:NSAlertDefaultReturn 
contextInfo:NULL];
 }
 
 @end


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you'll get full speed at 300 dpi even with all image 
processing features enabled. http://p.sf.net/sfu/kodak-com
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to