Revision: 4817
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4817&view=rev
Author:   hofman
Date:     2008-10-18 19:03:49 +0000 (Sat, 18 Oct 2008)

Log Message:
-----------
Improve selection specifier parsing. Allow just "text" of a page as a 
component. 

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

Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m   2008-10-18 17:13:51 UTC (rev 4816)
+++ trunk/PDFSelection_SKExtensions.m   2008-10-18 19:03:49 UTC (rev 4817)
@@ -157,7 +157,8 @@
     
     // we should get ranges of characters, words, or parapgraphs of the 
richText of a page
     NSString *key = [spec key];
-    if ([key isEqualToString:@"characters"] == NO && [key 
isEqualToString:@"words"] == NO && [key isEqualToString:@"paragraphs"] == NO && 
[key isEqualToString:@"attributeRuns"] == NO)
+    NSSet *textKeys = [NSSet setWithObjects:@"characters", @"words", 
@"paragraphs", @"attributeRuns", nil];
+    if ([textKeys containsObject:key] == NO)
         return nil;
     
     // get the richText specifier
@@ -169,7 +170,7 @@
         return nil;
     
     unsigned int containerOffset = 0;
-    if ([key isEqualToString:@"characters"] || [key isEqualToString:@"words"] 
|| [key isEqualToString:@"paragraphs"] || [key 
isEqualToString:@"attributeRuns"] == NO) {
+    if ([textKeys containsObject:[textSpec key]]) {
         NSArray *textRanges = characterRangesForSpecifier(textSpec, 
containerSpec);
         if ([textRanges count] == 0)
             return nil;
@@ -279,6 +280,8 @@
 }
 
 + (id)selectionWithSpecifier:(id)specifier onPage:(PDFPage *)aPage {
+    NSSet *textKeys = [NSSet setWithObjects:@"characters", @"words", 
@"paragraphs", @"attributeRuns", nil];
+    
     if ([specifier isEqual:[NSNull null]])
         return nil;
     if ([specifier isKindOfClass:[NSArray class]] == NO)
@@ -287,11 +290,12 @@
         NSScriptObjectSpecifier *spec = [specifier objectAtIndex:0];
         if ([spec isKindOfClass:[NSPropertySpecifier class]]) {
             NSString *key = [spec key];
-            if ([key isEqualToString:@"characters"] == NO && [key 
isEqualToString:@"words"] == NO && [key isEqualToString:@"paragraphs"] == NO && 
[key isEqualToString:@"attributeRuns"] == NO)
+            if ([textKeys containsObject:key] == NO && [key 
isEqualToString:@"richText"] == NO) {
                 // this allows to use selection properties directly
                 specifier = [spec objectsByEvaluatingSpecifier];
                 if ([specifier isKindOfClass:[NSArray class]] == NO)
                     specifier = [NSArray arrayWithObject:specifier];
+            }
         }
     }
     
@@ -303,20 +307,33 @@
         if ([spec isKindOfClass:[NSScriptObjectSpecifier class]] == NO)
             continue;
         
-        NSScriptObjectSpecifier *containerSpec = nil;
-        NSArray *ranges = characterRangesForSpecifier(spec, &containerSpec);
-        unsigned int i, numRanges = [ranges count];
+        NSArray *ranges = nil;
+        NSScriptObjectSpecifier *textSpec = nil;
+        NSString *key = [spec key];
         
-        if ([containerSpec isKindOfClass:[NSScriptObjectSpecifier class]] == 
NO || [[containerSpec key] isEqualToString:@"richText"] == NO)
+        if ([key isEqualToString:@"richText"]) {
+            NSTextStorage *textStorage = [spec objectsByEvaluatingSpecifier];
+            if ([textStorage isKindOfClass:[NSArray class]])
+                textStorage = [(NSArray *)textStorage count] ? [(NSArray 
*)textStorage objectAtIndex:0] : nil;
+            if ([textStorage isKindOfClass:[NSTextStorage class]])
+                continue;
+            ranges = [NSArray arrayWithObjects:[NSValue 
valueWithRange:NSMakeRange(0, [textStorage length])], nil];
+            textSpec = spec;
+        } else if ([textKeys containsObject:key] == NO) {
+            ranges = characterRangesForSpecifier(spec, &textSpec);
+            if ([textSpec isKindOfClass:[NSScriptObjectSpecifier class]] == NO 
|| [[textSpec key] isEqualToString:@"richText"] == NO)
+                continue;
+        } else
             continue;
         
-        NSScriptObjectSpecifier *pageSpec = [containerSpec containerSpecifier];
+        NSScriptObjectSpecifier *pageSpec = [textSpec containerSpecifier];
         PDFPage *page = [pageSpec objectsByEvaluatingSpecifier];
         if ([page isKindOfClass:[NSArray class]])
             page = [(NSArray *)page count] ? [(NSArray *)page objectAtIndex:0] 
: nil;
         if ([page isKindOfClass:[PDFPage class]] == NO || (aPage && [aPage 
isEqual:page] == NO))
             continue;
         
+        unsigned int i, numRanges = [ranges count];
         for (i = 0; i < numRanges; i++) {
             PDFSelection *sel;
             NSRange range = [[ranges objectAtIndex:i] rangeValue];


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