Revision: 2275
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2275&view=rev
Author:   hofman
Date:     2007-06-12 02:26:41 -0700 (Tue, 12 Jun 2007)

Log Message:
-----------
Simplified and more efficient parsing of selection specifiers. Get range 
indices directly from standard scriptObjectSpecifier method. 

Declare some selectors.

Modified Paths:
--------------
    trunk/PDFPage_SKExtensions.h
    trunk/PDFSelection_SKExtensions.m
    trunk/SKDocument.h

Modified: trunk/PDFPage_SKExtensions.h
===================================================================
--- trunk/PDFPage_SKExtensions.h        2007-06-11 21:50:30 UTC (rev 2274)
+++ trunk/PDFPage_SKExtensions.h        2007-06-12 09:26:41 UTC (rev 2275)
@@ -58,7 +58,7 @@
 - (id)richText;
 - (NSArray *)notes;
 - (void)insertInNotes:(id)newNote;
+- (void)insertInNotes:(id)newNote atIndex:(unsigned int)index;
 - (void)removeFromNotesAtIndex:(unsigned int)index;
-- (NSScriptObjectSpecifier *)objectSpecifier;
 
 @end

Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m   2007-06-11 21:50:30 UTC (rev 2274)
+++ trunk/PDFSelection_SKExtensions.m   2007-06-12 09:26:41 UTC (rev 2275)
@@ -130,137 +130,63 @@
         if ([spec isKindOfClass:[NSScriptObjectSpecifier class]] == NO)
             continue;
         
-        NSScriptObjectSpecifier *pageSpec = nil;
-        NSScriptObjectSpecifier *textSpec = nil;
-        NSString *key = [spec key];
-        PDFPage *page = nil;
-        int startIndex, endIndex;
-        PDFSelection *sel = nil;
-        
-        textSpec = [spec containerSpecifier];
+        NSScriptObjectSpecifier *textSpec = [spec containerSpecifier];
         if ([[textSpec key] isEqualToString:@"richText"] == NO)
             continue;
         
-        pageSpec = [textSpec containerSpecifier];
-        page = [pageSpec objectsByEvaluatingSpecifier];
+        NSScriptObjectSpecifier *pageSpec = [textSpec containerSpecifier];
+        PDFPage *page = [pageSpec objectsByEvaluatingSpecifier];
         if ([page isKindOfClass:[NSArray class]])
             page = [(NSArray *)page count] ? [(NSArray *)page objectAtIndex:0] 
: nil;
-        if (page == nil)
+        if ([page isKindOfClass:[PDFPage class]] == NO)
             continue;
         
-        if ([spec isKindOfClass:[NSRangeSpecifier class]]) {
-            
-            NSScriptObjectSpecifier *startSpec = [(NSRangeSpecifier *)spec 
startSpecifier];
-            NSScriptObjectSpecifier *endSpec = [(NSRangeSpecifier *)spec 
endSpecifier];
-            if (startSpec == nil && endSpec == nil)
+        NSTextStorage *textStorage = [page richText];
+        
+        int count;
+        int *indices = [spec 
indicesOfObjectsByEvaluatingWithContainer:textStorage count:&count];
+        if (count == -1)
+            continue;
+        
+        int startIndex = indices[0];
+        int endIndex = indices[count - 1];
+        
+        NSString *key = [spec key];
+        
+        if ([key isEqualToString:@"words"]) {
+            NSRange range = [textStorage 
characterRangeForWordAtIndex:startIndex];
+            if (range.location == NSNotFound)
                 continue;
-            
-            if ([key isEqualToString:@"characters"]) {
-                
-                startIndex = (startSpec && [startSpec 
isKindOfClass:[NSIndexSpecifier class]]) ? [(NSIndexSpecifier *)startSpec 
index] : 0;
-                endIndex = (endSpec && [endSpec 
isKindOfClass:[NSIndexSpecifier class]]) ? [(NSIndexSpecifier *)endSpec index] 
: -1;
-                if (startIndex < 0)
-                    startIndex += [[page string] length];
-                if (endIndex < 0)
-                    endIndex += [[page string] length];
-                
-            } else if ([key isEqualToString:@"words"]) {
-                
-                NSRange startRange, endRange;
-                NSTextStorage *textStorage = [textSpec 
objectsByEvaluatingSpecifier];
-                if ([textStorage isKindOfClass:[NSArray class]])
-                    textStorage = [(NSArray *)textStorage count] ? [(NSArray 
*)textStorage objectAtIndex:0] : nil;
-                
-                startIndex = (startSpec && [startSpec 
isKindOfClass:[NSIndexSpecifier class]]) ? [(NSIndexSpecifier *)startSpec 
index] : 0;
-                endIndex = (endSpec && [endSpec 
isKindOfClass:[NSIndexSpecifier class]]) ? [(NSIndexSpecifier *)endSpec index] 
: -1;
-                if (startIndex < 0)
-                    startIndex += [[textStorage words] count];
-                if (endIndex < 0)
-                    endIndex += [[textStorage words] count];
-                startRange = [textStorage 
characterRangeForWordAtIndex:startIndex];
-                endRange = [textStorage characterRangeForWordAtIndex:endIndex];
-                if (startRange.location == NSNotFound || endRange.location == 
NSNotFound)
-                    continue;
-                
-                startIndex = startRange.location;
-                endIndex = NSMaxRange(endRange);
-                
-            } else if ([key isEqualToString:@"paragraphs"]) {
-                
-                NSRange startRange, endRange;
-                NSTextStorage *textStorage = [textSpec 
objectsByEvaluatingSpecifier];
-                if ([textStorage isKindOfClass:[NSArray class]])
-                    textStorage = [(NSArray *)textStorage count] ? [(NSArray 
*)textStorage objectAtIndex:0] : nil;
-                
-                startIndex = (startSpec && [startSpec 
isKindOfClass:[NSIndexSpecifier class]]) ? [(NSIndexSpecifier *)startSpec 
index] : 0;
-                endIndex = (endSpec && [endSpec 
isKindOfClass:[NSIndexSpecifier class]]) ? [(NSIndexSpecifier *)endSpec index] 
: -1;
-                if (startIndex < 0)
-                    startIndex += [[textStorage paragraphs] count];
-                if (endIndex < 0)
-                    endIndex += [[textStorage paragraphs] count];
-                startRange = [textStorage 
characterRangeForParagraphAtIndex:startIndex];
-                endRange = [textStorage 
characterRangeForParagraphAtIndex:endIndex];
-                if (startRange.location == NSNotFound || endRange.location == 
NSNotFound)
-                    continue;
-                
-                startIndex = startRange.location;
-                endIndex = NSMaxRange(endRange) - 1;
-                
-            } else continue;
-            
-        } else if ([spec isKindOfClass:[NSIndexSpecifier class]]) {
-            
-            if ([key isEqualToString:@"characters"]) {
-                
-                startIndex = [(NSIndexSpecifier *)spec index];
-                if (startIndex < 0)
-                    startIndex += [[page string] length];
-                endIndex = startIndex;
-                
-            } else if ([key isEqualToString:@"words"]) {
-                
-                NSRange range;
-                NSTextStorage *textStorage = [textSpec 
objectsByEvaluatingSpecifier];
-                if ([textStorage isKindOfClass:[NSArray class]])
-                    textStorage = [(NSArray *)textStorage count] ? [(NSArray 
*)textStorage objectAtIndex:0] : nil;
-                
-                startIndex = [(NSIndexSpecifier *)spec index];
-                if (startIndex < 0)
-                    startIndex += [[textStorage words] count];
-                range = [textStorage characterRangeForWordAtIndex:startIndex];
+            startIndex = range.location;
+            if (count > 1) {
+                range = [textStorage characterRangeForWordAtIndex:endIndex];
                 if (range.location == NSNotFound)
                     continue;
-                
-                startIndex = range.location;
-                endIndex = NSMaxRange(range) - 1;
-                
-            } else if ([key isEqualToString:@"paragraphs"]) {
-                
-                NSRange range;
-                NSTextStorage *textStorage = [textSpec 
objectsByEvaluatingSpecifier];
-                if ([textStorage isKindOfClass:[NSArray class]])
-                    textStorage = [(NSArray *)textStorage count] ? [(NSArray 
*)textStorage objectAtIndex:0] : nil;
-                
-                startIndex = [(NSIndexSpecifier *)spec index];
-                if (startIndex < 0)
-                    startIndex += [[textStorage paragraphs] count];
-                range = [textStorage 
characterRangeForParagraphAtIndex:startIndex];
+            }
+            endIndex = NSMaxRange(range) - 1;
+        } else if ([key isEqualToString:@"paragraphs"]) {
+            NSRange range = [textStorage 
characterRangeForParagraphAtIndex:startIndex];
+            if (range.location == NSNotFound)
+                continue;
+            startIndex = range.location;
+            if (count > 1) {
+                range = [textStorage 
characterRangeForParagraphAtIndex:endIndex];
                 if (range.location == NSNotFound)
                     continue;
-                
-                startIndex = range.location;
-                endIndex = NSMaxRange(range) - 1;
-                
-            } else continue;
-            
-        } else continue;
-        
-        if ((endIndex >= startIndex) && (sel = [page 
selectionForRange:NSMakeRange(startIndex, endIndex + 1 - startIndex)])) {
-            if (selection == nil)
-                selection = sel;
-            else
-                [selection addSelection:sel];
+            }
+            endIndex = NSMaxRange(range) - 1;
+        } else if ([key isEqualToString:@"characters"] == NO) {
+            continue;
         }
+        
+        PDFSelection *sel = [page selectionForRange:NSMakeRange(startIndex, 
endIndex + 1 - startIndex)];
+        if (sel == nil)
+            continue;
+        
+        if (selection == nil)
+            selection = sel;
+        else
+            [selection addSelection:sel];
     }
     return selection;
 }
@@ -319,7 +245,7 @@
     
     if (index >= iMax)
         return NSMakeRange(NSNotFound, 0);
-    for (i = 0; i < index; i++) {
+    for (i = 0; i <= index; i++) {
         NSString *word = [[words objectAtIndex:i] string];
         NSRange searchRange = NSMakeRange(NSMaxRange(range), length - 
NSMaxRange(range));
         if ([word length] == 0)
@@ -340,7 +266,7 @@
     
     if (index >= iMax)
         return NSMakeRange(NSNotFound, 0);
-    for (i = 0; i < index; i++) {
+    for (i = 0; i <= index; i++) {
         NSString *paragraph = [[paragraphs objectAtIndex:i] string];
         NSRange searchRange = NSMakeRange(NSMaxRange(range), length - 
NSMaxRange(range));
         if ([paragraph length] == 0)

Modified: trunk/SKDocument.h
===================================================================
--- trunk/SKDocument.h  2007-06-11 21:50:30 UTC (rev 2274)
+++ trunk/SKDocument.h  2007-06-12 09:26:41 UTC (rev 2275)
@@ -88,6 +88,8 @@
 - (unsigned int)countOfPages;
 - (PDFPage *)objectInPagesAtIndex:(unsigned int)index;
 - (NSArray *)notes;
+- (void)insertInNotes:(id)newNote;
+- (void)insertInNotes:(id)newNote atIndex:(unsigned int)index;
 - (void)removeFromNotesAtIndex:(unsigned int)index;
 - (PDFPage *)currentPage;
 - (void)setCurrentPage:(PDFPage *)page;


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 DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to