Revision: 4738
http://skim-app.svn.sourceforge.net/skim-app/?rev=4738&view=rev
Author: hofman
Date: 2008-10-04 23:45:04 +0000 (Sat, 04 Oct 2008)
Log Message:
-----------
clean selection string from private use characters, displayed as aliens
Modified Paths:
--------------
trunk/NSCharacterSet_SKExtensions.h
trunk/NSCharacterSet_SKExtensions.m
trunk/NSString_SKExtensions.h
trunk/NSString_SKExtensions.m
trunk/PDFSelection_SKExtensions.h
trunk/PDFSelection_SKExtensions.m
trunk/SKPDFView.m
Modified: trunk/NSCharacterSet_SKExtensions.h
===================================================================
--- trunk/NSCharacterSet_SKExtensions.h 2008-10-04 22:42:44 UTC (rev 4737)
+++ trunk/NSCharacterSet_SKExtensions.h 2008-10-04 23:45:04 UTC (rev 4738)
@@ -42,4 +42,5 @@
@interface NSCharacterSet (SKExtensions)
+ (id)nonWhitespaceCharacterSet;
+ (id)nonWhitespaceAndNewlineCharacterSet;
++ (id)privateUseCharacterSet;
@end
Modified: trunk/NSCharacterSet_SKExtensions.m
===================================================================
--- trunk/NSCharacterSet_SKExtensions.m 2008-10-04 22:42:44 UTC (rev 4737)
+++ trunk/NSCharacterSet_SKExtensions.m 2008-10-04 23:45:04 UTC (rev 4738)
@@ -68,6 +68,20 @@
return nonWhitespaceAndNewlineCharacterSet;
}
++ (id)privateUseCharacterSet {
+ static NSCharacterSet *privateUseCharacterSet = nil;
+ if (nil == privateUseCharacterSet) {
+ // supplementary private use B
+ NSMutableCharacterSet *mcs = [NSMutableCharacterSet
characterSetWithRange:NSMakeRange(0x100000, 0x10FFFF-0x100000)];
+ // supplementary private use A
+ [mcs addCharactersInRange:NSMakeRange(0xF0000, 0xFFFFF-0xF0000)];
+ // private use area
+ [mcs addCharactersInRange:NSMakeRange(0xE000, 0xF8FF-0xE000)];
+ privateUseCharacterSet = [mcs copy];
+ }
+ return privateUseCharacterSet;
+}
+
+ (void)load {
SKAddClassMethodImplementationFromSelector(self,
@selector(newlineCharacterSet), @selector(replacementNewlineCharacterSet));
}
Modified: trunk/NSString_SKExtensions.h
===================================================================
--- trunk/NSString_SKExtensions.h 2008-10-04 22:42:44 UTC (rev 4737)
+++ trunk/NSString_SKExtensions.h 2008-10-04 23:45:04 UTC (rev 4738)
@@ -44,6 +44,7 @@
- (NSComparisonResult)noteTypeCompare:(id)other;
- (NSString
*)stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines;
+- (NSString *)stringByRemovingAliens;
- (NSString *)stringByAppendingEllipsis;
Modified: trunk/NSString_SKExtensions.m
===================================================================
--- trunk/NSString_SKExtensions.m 2008-10-04 22:42:44 UTC (rev 4737)
+++ trunk/NSString_SKExtensions.m 2008-10-04 23:45:04 UTC (rev 4738)
@@ -143,6 +143,20 @@
return
[(id)SKStringCreateByCollapsingAndTrimmingWhitespaceAndNewlines(CFAllocatorGetDefault(),
(CFStringRef)self) autorelease];
}
+- (NSString *)stringByRemovingAliens {
+ NSCharacterSet *charSet = [NSCharacterSet privateUseCharacterSet];
+ if ([self rangeOfCharacterFromSet:charSet].length) {
+ NSMutableString *ms = [[self mutableCopy] autorelease];
+ NSRange r = [ms rangeOfCharacterFromSet:charSet];
+ while (r.length) {
+ [ms deleteCharactersInRange:r];
+ r = [ms rangeOfCharacterFromSet:charSet];
+ }
+ return ms;
+ }
+ return self;
+}
+
- (NSString *)stringByAppendingEllipsis;
{
return [self stringByAppendingFormat:@"%C", ELLIPSIS_CHARACTER];
Modified: trunk/PDFSelection_SKExtensions.h
===================================================================
--- trunk/PDFSelection_SKExtensions.h 2008-10-04 22:42:44 UTC (rev 4737)
+++ trunk/PDFSelection_SKExtensions.h 2008-10-04 23:45:04 UTC (rev 4738)
@@ -43,6 +43,7 @@
// the search table columns bind to these methods for display
- (NSString *)firstPageLabel;
+- (NSString *)cleanedString;
- (NSAttributedString *)contextString;
- (PDFDestination *)destination;
Modified: trunk/PDFSelection_SKExtensions.m
===================================================================
--- trunk/PDFSelection_SKExtensions.m 2008-10-04 22:42:44 UTC (rev 4737)
+++ trunk/PDFSelection_SKExtensions.m 2008-10-04 23:45:04 UTC (rev 4738)
@@ -58,10 +58,14 @@
return [pages count] ? [[pages objectAtIndex:0] displayLabel] : nil;
}
+- (NSString *)cleanedString {
+ return [[[self string] stringByRemovingAliens]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+}
+
- (NSAttributedString *)contextString {
PDFSelection *extendedSelection = [self copy]; // see remark in
-tableViewSelectionDidChange:
NSMutableAttributedString *attributedSample;
- NSString *searchString = [[self string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ NSString *searchString = [self cleanedString];
NSString *sample;
NSMutableString *attributedString;
NSString *ellipse = [NSString stringWithFormat:@"%C",
ELLIPSIS_CHARACTER];
@@ -75,7 +79,7 @@
[extendedSelection extendSelectionAtEnd:50];
// get the cleaned string
- sample = [[extendedSelection string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ sample = [extendedSelection cleanedString];
// Finally, create attributed string.
attributedSample = [[NSMutableAttributedString alloc]
initWithString:sample];
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2008-10-04 22:42:44 UTC (rev 4737)
+++ trunk/SKPDFView.m 2008-10-04 23:45:04 UTC (rev 4738)
@@ -1884,7 +1884,7 @@
if (selection != nil) {
selection = [self currentSelection];
- text = [[selection string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ text = [selection cleanedString];
// Get bounds (page space) for selection (first page in case
selection spans multiple pages).
page = [[selection pages] objectAtIndex: 0];
@@ -1954,7 +1954,7 @@
if ([[activeAnnotation type] isEqualToString:SKNHighlightString]
&& [[activeAnnotation page] isEqual:page]) {
[sel addSelection:[(PDFAnnotationMarkup *)activeAnnotation
selection]];
[self removeActiveAnnotation:nil];
- text = [[sel string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ text = [sel cleanedString];
}
newAnnotation = [[PDFAnnotationMarkup alloc]
initSkimNoteWithSelection:sel markupType:kPDFMarkupTypeHighlight];
break;
@@ -1962,7 +1962,7 @@
if ([[activeAnnotation type] isEqualToString:SKNUnderlineString]
&& [[activeAnnotation page] isEqual:page]) {
[sel addSelection:[(PDFAnnotationMarkup *)activeAnnotation
selection]];
[self removeActiveAnnotation:nil];
- text = [[sel string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ text = [sel cleanedString];
}
newAnnotation = [[PDFAnnotationMarkup alloc]
initSkimNoteWithSelection:sel markupType:kPDFMarkupTypeUnderline];
break;
@@ -1970,7 +1970,7 @@
if ([[activeAnnotation type] isEqualToString:SKNStrikeOutString]
&& [[activeAnnotation page] isEqual:page]) {
[sel addSelection:[(PDFAnnotationMarkup *)activeAnnotation
selection]];
[self removeActiveAnnotation:nil];
- text = [[sel string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ text = [sel cleanedString];
}
newAnnotation = [[PDFAnnotationMarkup alloc]
initSkimNoteWithSelection:sel markupType:kPDFMarkupTypeStrikeOut];
break;
@@ -1985,7 +1985,7 @@
if (newAnnotation) {
if (annotationType != SKLineNote && annotationType != SKInkNote) {
if (text == nil)
- text = [[[page selectionForRect:[newAnnotation bounds]]
string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ text = [[page selectionForRect:[newAnnotation bounds]]
cleanedString];
if (text)
[newAnnotation setString:text];
}
@@ -2673,7 +2673,7 @@
[activeAnnotation setBounds:newBounds];
if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKDisableUpdateContentsFromEnclosedTextKey] == NO &&
([[activeAnnotation type] isEqualToString:SKNCircleString] ||
[[activeAnnotation type] isEqualToString:SKNSquareString])) {
- NSString *selString = [[[[activeAnnotation page]
selectionForRect:newBounds] string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ NSString *selString = [[[activeAnnotation page]
selectionForRect:newBounds] cleanedString];
if ([selString length])
[activeAnnotation setString:selString];
}
@@ -2921,7 +2921,7 @@
[activeAnnotation setBounds:newBounds];
if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKDisableUpdateContentsFromEnclosedTextKey] == NO &&
([[activeAnnotation type] isEqualToString:SKNCircleString] ||
[[activeAnnotation type] isEqualToString:SKNSquareString])) {
- NSString *selString = [[[[activeAnnotation page]
selectionForRect:newBounds] string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ NSString *selString = [[[activeAnnotation page]
selectionForRect:newBounds] cleanedString];
if ([selString length])
[activeAnnotation setString:selString];
}
@@ -3056,7 +3056,7 @@
accessibilityChildren = nil;
newActiveAnnotation = [[[PDFAnnotationMarkup alloc]
initSkimNoteWithSelection:sel markupType:markupType] autorelease];
- [newActiveAnnotation setString:[[sel string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines]];
+ [newActiveAnnotation setString:[sel cleanedString]];
[self addAnnotation:newActiveAnnotation toPage:page];
[[self undoManager] setActionName:NSLocalizedString(@"Join
Notes", @"Undo action name")];
} else if ([[activeAnnotation type] isEqualToString:SKNInkString])
{
@@ -3159,7 +3159,7 @@
if (draggedAnnotation &&
[[NSUserDefaults standardUserDefaults]
boolForKey:SKDisableUpdateContentsFromEnclosedTextKey] == NO &&
([[activeAnnotation type] isEqualToString:SKNCircleString]
|| [[activeAnnotation type] isEqualToString:SKNSquareString])) {
- NSString *selString = [[[[activeAnnotation page]
selectionForRect:[activeAnnotation bounds]] string]
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+ NSString *selString = [[[activeAnnotation page]
selectionForRect:[activeAnnotation bounds]] cleanedString];
if ([selString length])
[activeAnnotation setString:selString];
}
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