Revision: 4858
http://skim-app.svn.sourceforge.net/skim-app/?rev=4858&view=rev
Author: hofman
Date: 2008-10-24 12:05:38 +0000 (Fri, 24 Oct 2008)
Log Message:
-----------
Allow selection ranges from the whole document. Make text property of the
document a default container of type rich text.
Modified Paths:
--------------
trunk/PDFSelection_SKExtensions.m
trunk/SKPDFDocument.h
trunk/SKPDFDocument.m
trunk/Skim.sdef
Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m 2008-10-24 09:10:34 UTC (rev 4857)
+++ trunk/PDFSelection_SKExtensions.m 2008-10-24 12:05:38 UTC (rev 4858)
@@ -41,6 +41,7 @@
#import "NSParagraphStyle_SKExtensions.h"
#import "PDFPage_SKExtensions.h"
#import "SKStringConstants.h"
+#import "SKPDFDocument.h"
#define ELLIPSIS_CHARACTER 0x2026
@@ -329,6 +330,44 @@
return rangeDicts;
}
+static PDFSelection *selectionForCharacterRangesInDocument(NSArray *ranges,
PDFDocument *document) {
+ int i, count = [document pageCount];
+ NSRange *pageRanges = NSZoneMalloc(NSDefaultMallocZone(), count *
sizeof(NSRange));
+ unsigned int start = 0;
+
+ for (i = 0; i < count; i++) {
+ pageRanges[i] = NSMakeRange(start, [[[document pageAtIndex:i] string]
length]);
+ start += pageRanges[i].length;
+ }
+
+ PDFSelection *selection = nil;
+
+ NSEnumerator *rangeEnum = [ranges objectEnumerator];
+ NSValue *value;
+
+ while (value = [rangeEnum nextObject]) {
+ NSRange range = [value rangeValue];
+ for (i = 0; i < count && NSMaxRange(range) > pageRanges[i].location;
i++) {
+ PDFSelection *sel;
+ NSRange r = NSIntersectionRange(pageRanges[i], range);
+ if (range.length == 0)
+ continue;
+ r.location -= pageRanges[i].location;
+ if (sel = [[document pageAtIndex:i] selectionForRange:r]) {
+ if (selection == nil)
+ selection = sel;
+ else
+ [selection addSelection:sel];
+ }
+ }
+ }
+
+
+ NSZoneFree(NSDefaultMallocZone(), pageRanges);
+
+ return selection;
+}
+
+ (id)selectionWithSpecifier:(id)specifier {
return [self selectionWithSpecifier:specifier onPage:nil];
}
@@ -365,23 +404,56 @@
PDFDocument *doc = nil;
while (dict = [dictEnum nextObject]) {
- PDFPage *page = [dict objectForKey:@"container"];
- if ([page isKindOfClass:[PDFPage class]] == NO || (aPage && [aPage
isEqual:page] == NO) || (doc && [doc isEqual:[page document]] == NO))
- continue;
+ id container = [dict objectForKey:@"container"];
+ NSEnumerator *rangeEnum = [[dict objectForKey:@"ranges"]
objectEnumerator];
+ NSValue *value;
- NSArray *ranges = [dict objectForKey:@"ranges"];
- unsigned int i, numRanges = [ranges count];
-
- for (i = 0; i < numRanges; i++) {
- PDFSelection *sel;
- NSRange range = [[ranges objectAtIndex:i] rangeValue];
- if (range.length && (sel = [page selectionForRange:range])) {
- doc = [page document];
- if (selection == nil)
- selection = sel;
- else
- [selection addSelection:sel];
+ if ([container isKindOfClass:[SKPDFDocument class]] && (doc == nil
|| [doc isEqual:[container pdfDocument]])) {
+
+ PDFDocument *document = [container pdfDocument];
+ unsigned int i, numPages = [document pageCount];
+ NSRange *pageRanges = NSZoneMalloc(NSDefaultMallocZone(),
numPages * sizeof(NSRange));
+
+ for (i = 0; i < numPages; i++)
+ pageRanges[i] = NSMakeRange(i == 0 ? 0 :
NSMaxRange(pageRanges[i - 1]), [[[document pageAtIndex:i] string] length]);
+
+ while (value = [rangeEnum nextObject]) {
+ NSRange range = [value rangeValue];
+ for (i = 0; (i < numPages) && (NSMaxRange(range) >
pageRanges[i].location); i++) {
+ PDFSelection *sel;
+ NSRange r = NSIntersectionRange(pageRanges[i], range);
+ if (r.length == 0)
+ continue;
+ r.location -= pageRanges[i].location;
+ PDFPage *page = [document pageAtIndex:i];
+ if (aPage && [aPage isEqual:page] == NO)
+ continue;
+ if (sel = [page selectionForRange:r]) {
+ doc = document;
+ if (selection == nil)
+ selection = sel;
+ else
+ [selection addSelection:sel];
+ }
+ }
}
+
+ NSZoneFree(NSDefaultMallocZone(), pageRanges);
+
+ } else if ([container isKindOfClass:[PDFPage class]] && (aPage ==
nil || [aPage isEqual:container]) && (doc == nil || [doc isEqual:[container
document]])) {
+
+ while (value = [rangeEnum nextObject]) {
+ PDFSelection *sel;
+ NSRange range = [value rangeValue];
+ if (range.length && (sel = [container
selectionForRange:range])) {
+ doc = [container document];
+ if (selection == nil)
+ selection = sel;
+ else
+ [selection addSelection:sel];
+ }
+ }
+
}
}
}
Modified: trunk/SKPDFDocument.h
===================================================================
--- trunk/SKPDFDocument.h 2008-10-24 09:10:34 UTC (rev 4857)
+++ trunk/SKPDFDocument.h 2008-10-24 12:05:38 UTC (rev 4858)
@@ -140,7 +140,7 @@
- (void)setCurrentPage:(PDFPage *)page;
- (id)activeNote;
- (void)setActiveNote:(id)note;
-- (NSString *)text;
+- (id)richText;
- (id)selectionSpecifier;
- (void)setSelectionSpecifier:(id)specifier;
- (NSData *)selectionQDRect;
Modified: trunk/SKPDFDocument.m
===================================================================
--- trunk/SKPDFDocument.m 2008-10-24 09:10:34 UTC (rev 4857)
+++ trunk/SKPDFDocument.m 2008-10-24 12:05:38 UTC (rev 4858)
@@ -1839,8 +1839,9 @@
[[self pdfView] setActiveAnnotation:note];
}
-- (NSString *)text {
- return [[self pdfDocument] string];
+- (id)richText {
+ NSAttributedString *attrString = [[[self pdfDocument]
selectionForEntireDocument] attributedString];
+ return attrString ? [[[NSTextStorage alloc]
initWithAttributedString:attrString] autorelease] : [NSNull null];
}
- (id)selectionSpecifier {
Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef 2008-10-24 09:10:34 UTC (rev 4857)
+++ trunk/Skim.sdef 2008-10-24 12:05:38 UTC (rev 4858)
@@ -100,6 +100,10 @@
description="Lines in a TeX source file.">
<cocoa key="lines"/>
</element>
+ <contents name="text" code="ctxt" type="rich text" access="r"
+ description="The text of the document.">
+ <cocoa key="richText"/>
+ </contents>
<property name="name" code="pnam" type="text" access="r"
description="The document's name.">
<cocoa key="displayName"/>
@@ -124,10 +128,6 @@
description="The active note.">
<cocoa key="activeNote"/>
</property>
- <property name="text" code="ctxt" type="text" access="r"
- description="The text of the document.">
- <cocoa key="text"/>
- </property>
<property name="selection" code="sele"
description="The selection of the document.">
<type type="specifier" list="yes"/>
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