Revision: 3656
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3656&view=rev
Author:   hofman
Date:     2008-04-06 10:29:32 -0700 (Sun, 06 Apr 2008)

Log Message:
-----------
Trim whitespaces and newlines from text displayed in hover rect.

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

Modified: trunk/SKPDFHoverWindow.m
===================================================================
--- trunk/SKPDFHoverWindow.m    2008-04-06 16:48:41 UTC (rev 3655)
+++ trunk/SKPDFHoverWindow.m    2008-04-06 17:29:32 UTC (rev 3656)
@@ -259,19 +259,37 @@
         
     } else {
         
-        text = [[annotation text] retain];
+        text = [annotation text];
+        string = [text string];
+        unsigned int i = 0, l = [string length];
+        NSRange r = NSMakeRange(0, l);
         
+        while (i != NSNotFound) {
+            r = NSMakeRange(i, l - i);
+            i = [string rangeOfCharacterFromSet:[NSCharacterSet 
whitespaceAndNewlineCharacterSet] options:NSAnchoredSearch range:r].location;
+        }
+        i = l;
+        while (i != NSNotFound) {
+            r.length = i - r.location;
+            i = [string rangeOfCharacterFromSet:[NSCharacterSet 
whitespaceAndNewlineCharacterSet] options:NSBackwardsSearch | NSAnchoredSearch 
range:r].location;
+        }
+        if (r.length < l)
+            text = [text attributedSubstringFromRange:r];
+        
+        string = nil;
+        
         if ([text length] == 0) {
-            [text release];
             text = nil;
             if ([[annotation string] length])
                 string = [annotation string];
         }
-        
+        // we release text later
+        [text retain];
     }
     
     if (string) {
         NSDictionary *attrs = [[NSDictionary alloc] 
initWithObjectsAndKeys:font, NSFontAttributeName, [NSParagraphStyle 
defaultClippingParagraphStyle], NSParagraphStyleAttributeName, nil];
+        string = [string stringByTrimmingCharactersInSet:[NSCharacterSet 
whitespaceAndNewlineCharacterSet]];
         text = [[NSAttributedString alloc] initWithString:string 
attributes:attrs];
         [attrs release];
     }


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 2008 JavaOne(SM) Conference 
Register now and save $200. Hurry, offer ends at 11:59 p.m., 
Monday, April 7! Use priority code J8TLD2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to