Revision: 6760
          http://skim-app.svn.sourceforge.net/skim-app/?rev=6760&view=rev
Author:   hofman
Date:     2010-08-31 09:46:36 +0000 (Tue, 31 Aug 2010)

Log Message:
-----------
create sequential page labels directly when we already know that we should use 
them to avoid getting all the pages

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

Modified: trunk/PDFDocument_SKExtensions.m
===================================================================
--- trunk/PDFDocument_SKExtensions.m    2010-08-31 00:04:25 UTC (rev 6759)
+++ trunk/PDFDocument_SKExtensions.m    2010-08-31 09:46:36 UTC (rev 6760)
@@ -86,55 +86,58 @@
 - (NSArray *)pageLabels {
     NSUInteger pageCount = [self pageCount];
     NSMutableArray *pageLabels = [NSMutableArray array];
-    if ([self respondsToSelector:@selector(documentRef)] &&
-        [[NSUserDefaults standardUserDefaults] 
boolForKey:SKSequentialPageNumberingKey] == NO) {
+    BOOL useSequential = [[NSUserDefaults standardUserDefaults] 
boolForKey:SKSequentialPageNumberingKey];
+    if (useSequential == NO && [self 
respondsToSelector:@selector(documentRef)]) {
         CGPDFDocumentRef doc = (CGPDFDocumentRef)[self documentRef];
         CGPDFDictionaryRef catalog = CGPDFDocumentGetCatalog(doc);
         CGPDFDictionaryRef labelsDict = NULL;
         CGPDFArrayRef labelsArray = NULL;
-        if (catalog &&
-            CGPDFDictionaryGetDictionary(catalog, "PageLabels", &labelsDict) &&
-            CGPDFDictionaryGetArray(labelsDict, "Nums", &labelsArray)) {
-            size_t i = CGPDFArrayGetCount(labelsArray);
-            CGPDFInteger j = pageCount;
-            while (i > 0) {
-                CGPDFInteger labelIndex;
-                CGPDFDictionaryRef labelDict = NULL;
-                const char *labelStyle;
-                CGPDFStringRef labelPDFPrefix;
-                NSString *labelPrefix;
-                CGPDFInteger labelStart;
-                if (false == CGPDFArrayGetDictionary(labelsArray, --i, 
&labelDict) ||
-                    false == CGPDFArrayGetInteger(labelsArray, --i, 
&labelIndex)) {
-                    [pageLabels removeAllObjects];
-                    break;
-                }
-                if (false == CGPDFDictionaryGetName(labelDict, "S", 
&labelStyle))
-                    labelStyle = NULL;
-                if (CGPDFDictionaryGetString(labelDict, "P", &labelPDFPrefix))
-                    labelPrefix = [(NSString 
*)CGPDFStringCopyTextString(labelPDFPrefix) autorelease];
-                else
-                    labelPrefix = nil;
-                if (false == CGPDFDictionaryGetInteger(labelDict, "St", 
&labelStart))
-                    labelStart = 1;
-                while (j > labelIndex) {
-                    NSNumber *labelNumber = [NSNumber numberWithInteger:--j - 
labelIndex + labelStart];
-                    NSMutableString *string = [NSMutableString string];
-                    if (labelPrefix)
-                        [string appendString:labelPrefix];
-                    if (labelStyle) {
-                        if (0 == strcmp(labelStyle, "D"))
-                            [string appendFormat:@"%@", labelNumber];
-                        else if (0 == strcmp(labelStyle, "R"))
-                            [string appendString:[[labelNumber 
romanNumeralValue] uppercaseString]];
-                        else if (0 == strcmp(labelStyle, "r"))
-                            [string appendString:[labelNumber 
romanNumeralValue]];
-                        else if (0 == strcmp(labelStyle, "A"))
-                            [string appendString:[[labelNumber 
alphaCounterValue] uppercaseString]];
-                        else if (0 == strcmp(labelStyle, "a"))
-                            [string appendString:[labelNumber 
alphaCounterValue]];
+        if (catalog) {
+            if(false == CGPDFDictionaryGetDictionary(catalog, "PageLabels", 
&labelsDict)) {
+                useSequential = YES;
+            } else {
+                CGPDFDictionaryGetArray(labelsDict, "Nums", &labelsArray)) {
+                size_t i = CGPDFArrayGetCount(labelsArray);
+                CGPDFInteger j = pageCount;
+                while (i > 0) {
+                    CGPDFInteger labelIndex;
+                    CGPDFDictionaryRef labelDict = NULL;
+                    const char *labelStyle;
+                    CGPDFStringRef labelPDFPrefix;
+                    NSString *labelPrefix;
+                    CGPDFInteger labelStart;
+                    if (false == CGPDFArrayGetDictionary(labelsArray, --i, 
&labelDict) ||
+                        false == CGPDFArrayGetInteger(labelsArray, --i, 
&labelIndex)) {
+                        [pageLabels removeAllObjects];
+                        break;
                     }
-                    [pageLabels insertObject:string atIndex:0];
+                    if (false == CGPDFDictionaryGetName(labelDict, "S", 
&labelStyle))
+                        labelStyle = NULL;
+                    if (CGPDFDictionaryGetString(labelDict, "P", 
&labelPDFPrefix))
+                        labelPrefix = [(NSString 
*)CGPDFStringCopyTextString(labelPDFPrefix) autorelease];
+                    else
+                        labelPrefix = nil;
+                    if (false == CGPDFDictionaryGetInteger(labelDict, "St", 
&labelStart))
+                        labelStart = 1;
+                    while (j > labelIndex) {
+                        NSNumber *labelNumber = [NSNumber 
numberWithInteger:--j - labelIndex + labelStart];
+                        NSMutableString *string = [NSMutableString string];
+                        if (labelPrefix)
+                            [string appendString:labelPrefix];
+                        if (labelStyle) {
+                            if (0 == strcmp(labelStyle, "D"))
+                                [string appendFormat:@"%@", labelNumber];
+                            else if (0 == strcmp(labelStyle, "R"))
+                                [string appendString:[[labelNumber 
romanNumeralValue] uppercaseString]];
+                            else if (0 == strcmp(labelStyle, "r"))
+                                [string appendString:[labelNumber 
romanNumeralValue]];
+                            else if (0 == strcmp(labelStyle, "A"))
+                                [string appendString:[[labelNumber 
alphaCounterValue] uppercaseString]];
+                            else if (0 == strcmp(labelStyle, "a"))
+                                [string appendString:[labelNumber 
alphaCounterValue]];
+                        }
+                        [pageLabels insertObject:string atIndex:0];
+                    }
                 }
             }
         }
@@ -142,7 +145,7 @@
     if ([pageLabels count] != pageCount) {
         NSUInteger i;
         for (i = 0; i < pageCount; i++)
-            [pageLabels addObject:[[self pageAtIndex:i] displayLabel]];
+            [pageLabels addObject:useSequential ? [NSString 
stringWithFormat:@"%lu", (unsigned long)(i + 1)] : [[self pageAtIndex:i] 
displayLabel]];
     }
     return pageLabels;
 }


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

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to