Revision: 3807
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3807&view=rev
Author:   hofman
Date:     2008-04-24 04:27:13 -0700 (Thu, 24 Apr 2008)

Log Message:
-----------
Stop FDF parsing after failure.

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

Modified: trunk/SKFDFParser.m
===================================================================
--- trunk/SKFDFParser.m 2008-04-24 09:25:44 UTC (rev 3806)
+++ trunk/SKFDFParser.m 2008-04-24 11:27:13 UTC (rev 3807)
@@ -205,13 +205,13 @@
         success = NO;
     }
     
-    if (CGPDFDictionaryGetName(annot, SKFDFAnnotationTypeKey, &name)) {
+    if (success && CGPDFDictionaryGetName(annot, SKFDFAnnotationTypeKey, 
&name)) {
         [dictionary setObject:[NSString stringWithFormat:@"%s", name] 
forKey:SKPDFAnnotationTypeKey];
     } else {
         success = NO;
     }
     
-    if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationBoundsKey, &array)) {
+    if (success && CGPDFDictionaryGetArray(annot, SKFDFAnnotationBoundsKey, 
&array)) {
         CGPDFReal l, b, r, t;
         if (CGPDFArrayGetCount(array) == 4 && CGPDFArrayGetNumber(array, 0, 
&l) && CGPDFArrayGetNumber(array, 1, &b) && CGPDFArrayGetNumber(array, 2, &r) 
&& CGPDFArrayGetNumber(array, 3, &t)) {
             bounds = NSMakeRect(l, b, r - l, t - b);
@@ -221,79 +221,81 @@
         success = NO;
     }
     
-    if (CGPDFDictionaryGetInteger(annot, SKFDFAnnotationPageIndexKey, 
&integer)) {
+    if (success && CGPDFDictionaryGetInteger(annot, 
SKFDFAnnotationPageIndexKey, &integer)) {
         [dictionary setObject:[NSNumber numberWithInt:integer] 
forKey:SKPDFAnnotationPageIndexKey];
     } else {
         success = NO;
     }
     
-    if (CGPDFDictionaryGetString(annot, SKFDFAnnotationContentsKey, &string)) {
+    if (success && CGPDFDictionaryGetString(annot, SKFDFAnnotationContentsKey, 
&string)) {
         NSString *contents = (NSString *)CGPDFStringCopyTextString(string);
         if (contents)
             [dictionary setObject:contents forKey:SKPDFAnnotationContentsKey];
         [contents release];
     }
     
-    if (CGPDFDictionaryGetDictionary(annot, SKFDFAnnotationBorderStylesKey, 
&dict)) {
-        if (CGPDFDictionaryGetNumber(dict, SKFDFAnnotationLineWidthKey, 
&real)) {
-            if (real > 0.0) {
+    if (success) {
+        if (CGPDFDictionaryGetDictionary(annot, 
SKFDFAnnotationBorderStylesKey, &dict)) {
+            if (CGPDFDictionaryGetNumber(dict, SKFDFAnnotationLineWidthKey, 
&real)) {
+                if (real > 0.0) {
+                    [dictionary setObject:[NSNumber numberWithFloat:real] 
forKey:SKPDFAnnotationLineWidthKey];
+                    if (CGPDFDictionaryGetName(dict, 
SKFDFAnnotationBorderStyleKey, &name)) {
+                        [dictionary setObject:[NSNumber 
numberWithInt:SKPDFBorderStyleFromFDFBorderStyle(name)] 
forKey:SKPDFAnnotationBorderStyleKey];
+                    }
+                    if (CGPDFDictionaryGetArray(annot, 
SKFDFAnnotationDashPatternKey, &array)) {
+                        size_t i, count = CGPDFArrayGetCount(array);
+                        NSMutableArray *dp = [NSMutableArray array];
+                        for (i = 0; i < count; i++) {
+                            if (CGPDFArrayGetNumber(array, i, &real))
+                                [dp addObject:[NSNumber numberWithFloat:real]];
+                        }
+                        [dictionary setObject:dp 
forKey:SKPDFAnnotationDashPatternKey];
+                    }
+                }
+            }
+        } else if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationBorderKey, 
&array)) {
+            size_t i, count = CGPDFArrayGetCount(array);
+            if (count > 2 && CGPDFArrayGetNumber(array, 2, &real) && real > 
0.0) {
                 [dictionary setObject:[NSNumber numberWithFloat:real] 
forKey:SKPDFAnnotationLineWidthKey];
-                if (CGPDFDictionaryGetName(dict, 
SKFDFAnnotationBorderStyleKey, &name)) {
-                    [dictionary setObject:[NSNumber 
numberWithInt:SKPDFBorderStyleFromFDFBorderStyle(name)] 
forKey:SKPDFAnnotationBorderStyleKey];
-                }
-                if (CGPDFDictionaryGetArray(annot, 
SKFDFAnnotationDashPatternKey, &array)) {
-                    size_t i, count = CGPDFArrayGetCount(array);
-                    NSMutableArray *dp = [NSMutableArray array];
+                CGPDFArrayRef dp;
+                if (count > 3 && CGPDFArrayGetArray(array, 3, &dp)) {
+                    count = CGPDFArrayGetCount(dp);
+                    NSMutableArray *dashPattern = [NSMutableArray 
arrayWithCapacity:count];
                     for (i = 0; i < count; i++) {
-                        if (CGPDFArrayGetNumber(array, i, &real))
-                            [dp addObject:[NSNumber numberWithFloat:real]];
+                        if (CGPDFArrayGetNumber(dp, i, &real))
+                            [dashPattern addObject:[NSNumber 
numberWithFloat:real]];
                     }
-                    [dictionary setObject:dp 
forKey:SKPDFAnnotationDashPatternKey];
+                    [dictionary setObject:dashPattern 
forKey:SKPDFAnnotationDashPatternKey];
+                    [dictionary setObject:[NSNumber 
numberWithInt:kPDFBorderStyleDashed] forKey:SKPDFAnnotationBorderStyleKey];
+                } else {
+                     [dictionary setObject:[NSNumber 
numberWithInt:kPDFBorderStyleSolid] forKey:SKPDFAnnotationBorderStyleKey];
                 }
             }
+        } else {
+            [dictionary setObject:[NSNumber numberWithFloat:1.0] 
forKey:SKPDFAnnotationLineWidthKey];
+            [dictionary setObject:[NSNumber 
numberWithInt:kPDFBorderStyleSolid] forKey:SKPDFAnnotationBorderStyleKey];
         }
-    } else if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationBorderKey, 
&array)) {
-        size_t i, count = CGPDFArrayGetCount(array);
-        if (count > 2 && CGPDFArrayGetNumber(array, 2, &real) && real > 0.0) {
-            [dictionary setObject:[NSNumber numberWithFloat:real] 
forKey:SKPDFAnnotationLineWidthKey];
-            CGPDFArrayRef dp;
-            if (count > 3 && CGPDFArrayGetArray(array, 3, &dp)) {
-                count = CGPDFArrayGetCount(dp);
-                NSMutableArray *dashPattern = [NSMutableArray 
arrayWithCapacity:count];
-                for (i = 0; i < count; i++) {
-                    if (CGPDFArrayGetNumber(dp, i, &real))
-                        [dashPattern addObject:[NSNumber 
numberWithFloat:real]];
-                }
-                [dictionary setObject:dashPattern 
forKey:SKPDFAnnotationDashPatternKey];
-                [dictionary setObject:[NSNumber 
numberWithInt:kPDFBorderStyleDashed] forKey:SKPDFAnnotationBorderStyleKey];
-            } else {
-                 [dictionary setObject:[NSNumber 
numberWithInt:kPDFBorderStyleSolid] forKey:SKPDFAnnotationBorderStyleKey];
-            }
-        }
-    } else {
-        [dictionary setObject:[NSNumber numberWithFloat:1.0] 
forKey:SKPDFAnnotationLineWidthKey];
-        [dictionary setObject:[NSNumber numberWithInt:kPDFBorderStyleSolid] 
forKey:SKPDFAnnotationBorderStyleKey];
     }
     
-    if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationColorKey, &array)) {
+    if (success && CGPDFDictionaryGetArray(annot, SKFDFAnnotationColorKey, 
&array)) {
         CGPDFReal r, g, b;
         if (CGPDFArrayGetCount(array) == 3 && CGPDFArrayGetNumber(array, 0, 
&r) && CGPDFArrayGetNumber(array, 1, &g) && CGPDFArrayGetNumber(array, 2, &b)) {
             [dictionary setObject:[NSColor colorWithCalibratedRed:r green:g 
blue:b alpha:1.0] forKey:SKPDFAnnotationColorKey];
         }
     }
     
-    if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationInteriorColorKey, 
&array)) {
+    if (success && CGPDFDictionaryGetArray(annot, 
SKFDFAnnotationInteriorColorKey, &array)) {
         CGPDFReal r, g, b;
         if (CGPDFArrayGetCount(array) == 3 && CGPDFArrayGetNumber(array, 0, 
&r) && CGPDFArrayGetNumber(array, 1, &g) && CGPDFArrayGetNumber(array, 2, &b)) {
             [dictionary setObject:[NSColor colorWithCalibratedRed:r green:g 
blue:b alpha:1.0] forKey:SKPDFAnnotationInteriorColorKey];
         }
     }
     
-    if (CGPDFDictionaryGetName(annot, SKFDFAnnotationIconTypeKey, &name)) {
+    if (success && CGPDFDictionaryGetName(annot, SKFDFAnnotationIconTypeKey, 
&name)) {
         [dictionary setObject:[NSNumber 
numberWithInt:SKPDFTextAnnotationIconTypeFromFDFTextAnnotationIconType(name)] 
forKey:SKPDFAnnotationIconTypeKey];
     }
     
-    if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationLineStylesKey, &array)) {
+    if (success && CGPDFDictionaryGetArray(annot, 
SKFDFAnnotationLineStylesKey, &array)) {
         int startStyle = kPDFLineStyleNone;
         int endStyle = kPDFLineStyleNone;
         if (CGPDFArrayGetCount(array) == 2) {
@@ -308,7 +310,7 @@
         [dictionary setObject:[NSNumber numberWithInt:startStyle] 
forKey:SKPDFAnnotationStartLineStyleKey];
     }
     
-    if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationLinePointsKey, &array)) {
+    if (success && CGPDFDictionaryGetArray(annot, 
SKFDFAnnotationLinePointsKey, &array)) {
         NSPoint p1, p2;
         if (CGPDFArrayGetCount(array) == 4 && CGPDFArrayGetNumber(array, 0, 
&p1.x) && CGPDFArrayGetNumber(array, 1, &p1.y) && CGPDFArrayGetNumber(array, 2, 
&p2.x) && CGPDFArrayGetNumber(array, 3, &p2.y)) {
             [dictionary setObject:NSStringFromPoint(p1) 
forKey:SKPDFAnnotationStartPointKey];
@@ -316,7 +318,7 @@
         }
     }
     
-    if (CGPDFDictionaryGetArray(annot, SKFDFAnnotationQuadrilateralPointsKey, 
&array)) {
+    if (success && CGPDFDictionaryGetArray(annot, 
SKFDFAnnotationQuadrilateralPointsKey, &array)) {
         size_t i, count = CGPDFArrayGetCount(array);
         if (count % 8 == 0) {
             NSMutableArray *quadPoints = [NSMutableArray 
arrayWithCapacity:count / 2];
@@ -329,7 +331,7 @@
         }
     }
     
-    if (CGPDFDictionaryGetString(annot, SKFDFDefaultAppearanceKey, &string)) {
+    if (success && CGPDFDictionaryGetString(annot, SKFDFDefaultAppearanceKey, 
&string)) {
         NSString *da = (NSString *)CGPDFStringCopyTextString(string);
         if (da) {
             NSScanner *scanner = [NSScanner scannerWithString:da];
@@ -358,24 +360,26 @@
        }
     }
     
-    NSSet *validTypes = [NSSet setWithObjects:SKFreeTextString, SKNoteString, 
SKCircleString, SKSquareString, SKHighlightString, SKUnderlineString, 
SKStrikeOutString, SKLineString, nil];
-    NSString *type = [dictionary objectForKey:SKPDFAnnotationTypeKey];
-    NSString *contents;
-    if ([type isEqualToString:SKTextString]) {
-        [dictionary setObject:SKNoteString forKey:SKPDFAnnotationTypeKey];
-        if (contents = [dictionary objectForKey:SKPDFAnnotationContentsKey]) {
-            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];
-                [dictionary setObject:attrString 
forKey:SKPDFAnnotationTextKey];
-                [dictionary setObject:[contents substringToIndex:r.location] 
forKey:SKPDFAnnotationContentsKey];
+    if (success) {
+        NSSet *validTypes = [NSSet setWithObjects:SKFreeTextString, 
SKNoteString, SKCircleString, SKSquareString, SKHighlightString, 
SKUnderlineString, SKStrikeOutString, SKLineString, nil];
+        NSString *type = [dictionary objectForKey:SKPDFAnnotationTypeKey];
+        NSString *contents;
+        if ([type isEqualToString:SKTextString]) {
+            [dictionary setObject:SKNoteString forKey:SKPDFAnnotationTypeKey];
+            if (contents = [dictionary 
objectForKey:SKPDFAnnotationContentsKey]) {
+                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];
+                    [dictionary setObject:attrString 
forKey:SKPDFAnnotationTextKey];
+                    [dictionary setObject:[contents 
substringToIndex:r.location] forKey:SKPDFAnnotationContentsKey];
+                }
             }
+        } else if ([validTypes containsObject:type] == NO) {
+            success = NO;
         }
-    } else if ([validTypes containsObject:type] == NO) {
-        success = NO;
     }
     
     return success ? dictionary : nil;


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 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to