Revision: 5533
          http://skim-app.svn.sourceforge.net/skim-app/?rev=5533&view=rev
Author:   hofman
Date:     2009-08-11 12:47:59 +0000 (Tue, 11 Aug 2009)

Log Message:
-----------
Add some escape code to get line rects for a selection in case a future OS 
version changes the private PDFKit methods

Modified Paths:
--------------
    trunk/PDFAnnotationMarkup_SKExtensions.m
    trunk/PDFPage_SKExtensions.m

Modified: trunk/PDFAnnotationMarkup_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationMarkup_SKExtensions.m    2009-08-11 11:12:07 UTC (rev 
5532)
+++ trunk/PDFAnnotationMarkup_SKExtensions.m    2009-08-11 12:47:59 UTC (rev 
5533)
@@ -210,36 +210,46 @@
             NSRect lineRect = NSZeroRect;
             NSRect charRect = NSZeroRect;
             NSRect lastCharRect = NSZeroRect;
-            for (i = 0; i < iMax; i++) {
-                NSRange range = [selection safeRangeAtIndex:i onPage:page];
-                NSUInteger j, jMax = NSMaxRange(range);
-                for (j = range.location; j < jMax; j++) {
-                    lastCharRect = charRect;
-                    charRect = [page characterBoundsAtIndex:j];
-                    BOOL nonWS = NO == [[NSCharacterSet 
whitespaceAndNewlineCharacterSet] characterIsMember:[string 
characterAtIndex:j]];
-                    if (NSIsEmptyRect(lineRect)) {
-                        // beginning of a line, just ignore whitespace
-                        if (nonWS)
-                            lineRect = charRect;
-                    } else if (adjacentCharacterBounds(lastCharRect, 
charRect)) {
-                        // continuation of a line
-                        if (nonWS)
-                            lineRect = NSUnionRect(lineRect, charRect);
-                    } else {
-                        // start of a new line
-                        if (NSIsEmptyRect(lineRect) == NO) {
-                            CFArrayAppendValue([self lineRects], &lineRect);
-                            newBounds = NSUnionRect(lineRect, newBounds);
-                        }
-                        // ignore whitespace at the beginning of the new line
-                        lineRect = nonWS ? charRect : NSZeroRect;
-                   }
+            if (iMax > 0) {
+                for (i = 0; i < iMax; i++) {
+                    NSRange range = [selection safeRangeAtIndex:i onPage:page];
+                    NSUInteger j, jMax = NSMaxRange(range);
+                    for (j = range.location; j < jMax; j++) {
+                        lastCharRect = charRect;
+                        charRect = [page characterBoundsAtIndex:j];
+                        BOOL nonWS = NO == [[NSCharacterSet 
whitespaceAndNewlineCharacterSet] characterIsMember:[string 
characterAtIndex:j]];
+                        if (NSIsEmptyRect(lineRect)) {
+                            // beginning of a line, just ignore whitespace
+                            if (nonWS)
+                                lineRect = charRect;
+                        } else if (adjacentCharacterBounds(lastCharRect, 
charRect)) {
+                            // continuation of a line
+                            if (nonWS)
+                                lineRect = NSUnionRect(lineRect, charRect);
+                        } else {
+                            // start of a new line
+                            if (NSIsEmptyRect(lineRect) == NO) {
+                                CFArrayAppendValue([self lineRects], 
&lineRect);
+                                newBounds = NSUnionRect(lineRect, newBounds);
+                            }
+                            // ignore whitespace at the beginning of the new 
line
+                            lineRect = nonWS ? charRect : NSZeroRect;
+                       }
+                    }
                 }
+                if (NSIsEmptyRect(lineRect) == NO) {
+                    CFArrayAppendValue([self lineRects], &lineRect);
+                    newBounds = NSUnionRect(lineRect, newBounds);
+                }
+            } else if ([selection 
respondsToSelector:@selector(selectionsByLine)]) {
+                NSEnumerator *selEnum = [[selection selectionsByLine] 
objectEnumerator];
+                PDFSelection *sel;
+                while (sel = [selEnum nextObject]) {
+                    lineRect = [sel boundsForPage:page];
+                    if (NSIsEmptyRect(lineRect) == NO)
+                         CFArrayAppendValue([self lineRects], &lineRect);
+                } 
             }
-            if (NSIsEmptyRect(lineRect) == NO) {
-                CFArrayAppendValue([self lineRects], &lineRect);
-                newBounds = NSUnionRect(lineRect, newBounds);
-            }
             if (NSIsEmptyRect(newBounds)) {
                 [self release];
                 self = nil;

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2009-08-11 11:12:07 UTC (rev 5532)
+++ trunk/PDFPage_SKExtensions.m        2009-08-11 12:47:59 UTC (rev 5533)
@@ -382,31 +382,41 @@
     NSString *string = [self string];
     NSRange stringRange = NSMakeRange(0, [string length]);
     
-    for (i = 0; i < iMax; i++) {
-        NSRange range = [sel safeRangeAtIndex:i onPage:self];
-        NSUInteger j, jMax = NSMaxRange(range);
-        
-        for (j = range.location; j < jMax; j++) {
-            if ([indexes containsIndex:j])
-                continue;
+    if (iMax > 0) {
+        for (i = 0; i < iMax; i++) {
+            NSRange range = [sel safeRangeAtIndex:i onPage:self];
+            NSUInteger j, jMax = NSMaxRange(range);
             
-            NSRect r = [self characterBoundsAtIndex:j];
-            PDFSelection *s = [self selectionForLineAtPoint:SKCenterPoint(r)];
-            NSUInteger k, kMax = [s safeNumberOfRangesOnPage:self];
-            BOOL notEmpty = NO;
-            
-            for (k = 0; k < kMax; k++) {
-                NSRange selRange = [s safeRangeAtIndex:k onPage:self];
-                if (selRange.location != NSNotFound) {
-                    [indexes addIndexesInRange:selRange];
-                    // due to a bug in PDFKit, the range of the selection can 
sometimes lie partly outside the range of the string
-                    if ([string rangeOfCharacterFromSet:[NSCharacterSet 
nonWhitespaceAndNewlineCharacterSet] options:0 
range:NSIntersectionRange(selRange, stringRange)].length)
-                        notEmpty = YES;
+            for (j = range.location; j < jMax; j++) {
+                if ([indexes containsIndex:j])
+                    continue;
+                
+                NSRect r = [self characterBoundsAtIndex:j];
+                PDFSelection *s = [self 
selectionForLineAtPoint:SKCenterPoint(r)];
+                NSUInteger k, kMax = [s safeNumberOfRangesOnPage:self];
+                BOOL notEmpty = NO;
+                
+                for (k = 0; k < kMax; k++) {
+                    NSRange selRange = [s safeRangeAtIndex:k onPage:self];
+                    if (selRange.location != NSNotFound) {
+                        [indexes addIndexesInRange:selRange];
+                        // due to a bug in PDFKit, the range of the selection 
can sometimes lie partly outside the range of the string
+                        if ([string rangeOfCharacterFromSet:[NSCharacterSet 
nonWhitespaceAndNewlineCharacterSet] options:0 
range:NSIntersectionRange(selRange, stringRange)].length)
+                            notEmpty = YES;
+                    }
                 }
+                if (notEmpty)
+                    [lines addObject:[NSValue valueWithRect:[s 
boundsForPage:self]]];
             }
-            if (notEmpty)
-                [lines addObject:[NSValue valueWithRect:[s 
boundsForPage:self]]];
         }
+    } else if ([sel respondsToSelector:@selector(selectionsByLine)]) {
+        NSEnumerator *selEnum = [[sel selectionsByLine] objectEnumerator];
+        PDFSelection *s;
+        while (s = [selEnum nextObject]) {
+            NSRect r = [s boundsForPage:self];
+            if (NSIsEmptyRect(r) == NO)
+                [lines addObject:[NSValue valueWithRect:r]];
+        } 
     }
     
     [lines sortUsingSelector:@selector(boundsCompare:)];


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

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to