Revision: 6901
http://skim-app.svn.sourceforge.net/skim-app/?rev=6901&view=rev
Author: hofman
Date: 2010-11-27 18:53:19 +0000 (Sat, 27 Nov 2010)
Log Message:
-----------
use private range method to get the range of text storage sub elements
Modified Paths:
--------------
trunk/PDFSelection_SKExtensions.m
Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m 2010-11-27 13:09:59 UTC (rev 6900)
+++ trunk/PDFSelection_SKExtensions.m 2010-11-27 18:53:19 UTC (rev 6901)
@@ -46,6 +46,11 @@
#define ELLIPSIS_CHARACTER 0x2026
+...@interface NSTextStorage (SKNSSubTextStoragePrivateDeclarations)
+- (NSRange)range;
+...@end
+
+
@interface PDFSelection (PDFSelectionPrivateDeclarations)
// defined on 10.6
- (NSIndexSet *)indexOfCharactersOnPage:(PDFPage *)page;
@@ -373,21 +378,35 @@
}
} else {
// translate from subtext ranges to character ranges
- NSString *string = [textStorage string];
- NSArray *substrings = [[textStorage valueForKey:key]
valueForKey:@"string"];
- if ([substrings count]) {
+ NSArray *subTextStorages = [textStorage valueForKey:key];
+ if ([subTextStorages count]) {
+ NSString *string = nil;
+ NSArray *substrings = nil;
+ // The private subclass NSSubTextStorage has a -range
method
+ BOOL knowsRange = [[subTextStorages objectAtIndex:0]
respondsToSelector:@selector(range)];
+ if (knowsRange == NO) {
+ // if we can't get the range directly, we try to
search a substring
+ string = [textStorage string];
+ substrings = [subTextStorages
valueForKey:@"string"];
+ }
for (i = 0; i < count; i++) {
NSRange range = *(NSRange *)[tmpRanges
pointerAtIndex:i];
- startIndex = MIN(range.location, [substrings
count] - 1);
- endIndex = MIN(NSMaxRange(range) - 1, [substrings
count] - 1);
+ startIndex = MIN(range.location, [subTextStorages
count] - 1);
+ endIndex = MIN(NSMaxRange(range) - 1,
[subTextStorages count] - 1);
if (endIndex == startIndex) endIndex = -1;
if (continuous) {
- range =
rangeOfSubstringOfStringAtIndex(string, substrings, startIndex);
+ if (knowsRange)
+ range = [[subTextStorages
objectAtIndex:startIndex] range];
+ else
+ range =
rangeOfSubstringOfStringAtIndex(string, substrings, startIndex);
if (range.location == NSNotFound)
continue;
startIndex = range.location;
if (endIndex >= 0) {
- range =
rangeOfSubstringOfStringAtIndex(string, substrings, endIndex);
+ if (knowsRange)
+ range = [[subTextStorages
objectAtIndex:endIndex] range];
+ else
+ range =
rangeOfSubstringOfStringAtIndex(string, substrings, endIndex);
if (range.location == NSNotFound)
continue;
}
@@ -398,7 +417,10 @@
if (endIndex == -1) endIndex = startIndex;
NSInteger j;
for (j = startIndex; j <= endIndex; j++) {
- range =
rangeOfSubstringOfStringAtIndex(string, substrings, j);
+ if (knowsRange)
+ range = [[subTextStorages
objectAtIndex:j] range];
+ else
+ range =
rangeOfSubstringOfStringAtIndex(string, substrings, j);
if (range.location == NSNotFound)
continue;
range.location += textRange.location;
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit