Revision: 4996
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4996&view=rev
Author:   hofman
Date:     2008-11-26 14:10:13 +0000 (Wed, 26 Nov 2008)

Log Message:
-----------
Always replace annotations with new Skim notes when converting from embedded 
notes, as PDFKit does a very bad job saving/reading notes.

Modified Paths:
--------------
    trunk/SKPDFDocument.m

Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m       2008-11-26 12:57:14 UTC (rev 4995)
+++ trunk/SKPDFDocument.m       2008-11-26 14:10:13 UTC (rev 4996)
@@ -894,15 +894,34 @@
         
         while (annotation = [annEnum nextObject]) {
             if ([annotation isSkimNote] == NO && [annotation 
isConvertibleAnnotation]) {
+                NSDictionary *properties = [annotation SkimNoteProperties];
                 if ([[annotation type] isEqualToString:SKNTextString]) {
-                    PDFAnnotation *newAnnotation = [[SKNPDFAnnotationNote 
alloc] initSkimNoteWithProperties:[annotation SkimNoteProperties]];
+                    NSMutableDictionary *tmpProperties = [[properties 
mutableCopy] autorelease];
+                    NSRect bounds = NSRectFromString([properties 
objectForKey:SKNPDFAnnotationBoundsKey]);
+                    NSString *contents = [properties 
objectForKey:SKNPDFAnnotationContentsKey];
+                    [tmpProperties setObject:SKNNoteString 
forKey:SKNPDFAnnotationTypeKey];
+                    bounds.size = SKNPDFAnnotationNoteSize;
+                    [tmpProperties setObject:NSStringFromRect(bounds) 
forKey:SKNPDFAnnotationBoundsKey];
+                    if (contents) {
+                        NSRange r = [contents rangeOfString:@"  "];
+                        if (NSMaxRange(r) < [contents length]) {
+                            NSFont *font = [NSFont 
fontWithName:[[NSUserDefaults standardUserDefaults] 
stringForKey:SKAnchoredNoteFontNameKey]
+                                                           
size:[[NSUserDefaults standardUserDefaults] 
floatForKey:SKAnchoredNoteFontSizeKey]];
+                            NSAttributedString *attrString = 
[[[NSAttributedString alloc] initWithString:[contents 
substringFromIndex:NSMaxRange(r)]
+                                                                
attributes:[NSDictionary dictionaryWithObjectsAndKeys:font, 
NSFontAttributeName, nil]] autorelease];
+                            [tmpProperties setObject:attrString 
forKey:SKNPDFAnnotationTextKey];
+                            [tmpProperties setObject:[contents 
substringToIndex:r.location] forKey:SKNPDFAnnotationContentsKey];
+                        }
+                    }
+                    properties = tmpProperties;
+                }
+                PDFAnnotation *newAnnotation = [[PDFAnnotation alloc] 
initSkimNoteWithProperties:properties];
+                if (newAnnotation) {
                     [[self pdfView] removeAnnotation:annotation];
                     [[self pdfView] addAnnotation:newAnnotation toPage:page];
                     [newAnnotation release];
-                } else {
-                    [self addAsNote:annotation];                
+                    didConvert = YES;
                 }
-                didConvert = YES;
             }
         }
     }


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

Reply via email to