Revision: 4654
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4654&view=rev
Author:   hofman
Date:     2008-09-18 12:45:58 +0000 (Thu, 18 Sep 2008)

Log Message:
-----------
make sure we don't use empty bounds for paths in ink note

Modified Paths:
--------------
    trunk/NSBezierPath_BDSKExtensions.h
    trunk/NSBezierPath_BDSKExtensions.m
    trunk/PDFAnnotationInk_SKExtensions.m
    trunk/SKPDFView.m

Modified: trunk/NSBezierPath_BDSKExtensions.h
===================================================================
--- trunk/NSBezierPath_BDSKExtensions.h 2008-09-18 12:19:02 UTC (rev 4653)
+++ trunk/NSBezierPath_BDSKExtensions.h 2008-09-18 12:45:58 UTC (rev 4654)
@@ -67,4 +67,6 @@
 + (NSBezierPath *)bezierPathWithStarInRect:(NSRect)rect;
 + (NSBezierPath *)bezierPathWithInvertedStarInRect:(NSRect)rect;
 
+- (NSRect)nonEmptyBounds;
+
 @end

Modified: trunk/NSBezierPath_BDSKExtensions.m
===================================================================
--- trunk/NSBezierPath_BDSKExtensions.m 2008-09-18 12:19:02 UTC (rev 4653)
+++ trunk/NSBezierPath_BDSKExtensions.m 2008-09-18 12:45:58 UTC (rev 4654)
@@ -347,5 +347,30 @@
     return path;
 }
 
+- (NSRect)nonEmptyBounds {
+    NSRect bounds = [self bounds];
+    if (NSIsEmptyRect(bounds) && [self elementCount]) {
+        NSPoint points[2];
+        NSPoint point, minPoint = NSZeroPoint, maxPoint = NSZeroPoint;
+        unsigned int i, count = [self elementCount];
+        for (i = 0; i < count; i++) {
+            if ([self elementAtIndex:i associatedPoints:points] == 
NSCurveToBezierPathElement)
+                point = points[2];
+            else
+                point = points[0];
+            if (i == 0) {
+                minPoint = maxPoint = point;
+            } else {
+                minPoint.x = fminf(minPoint.x, point.x);
+                minPoint.y = fminf(minPoint.y, point.y);
+                maxPoint.x = fmaxf(maxPoint.x, point.x);
+                maxPoint.y = fmaxf(maxPoint.y, point.y);
+            }
+        }
+        bounds = NSMakeRect(minPoint.x - 0.1, minPoint.y - 0.1, maxPoint.x - 
minPoint.x + 0.2, maxPoint.y - minPoint.y + 0.2);
+    }
+    return bounds;
+}
+
 @end
 

Modified: trunk/PDFAnnotationInk_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationInk_SKExtensions.m       2008-09-18 12:19:02 UTC (rev 
4653)
+++ trunk/PDFAnnotationInk_SKExtensions.m       2008-09-18 12:45:58 UTC (rev 
4654)
@@ -43,6 +43,7 @@
 #import "SKFDFParser.h"
 #import "NSUserDefaults_SKExtensions.h"
 #import "NSGeometry_SKExtensions.h"
+#import "NSBezierPath_BDSKExtensions.h"
 
 
 @implementation PDFAnnotationInk (SKExtensions)
@@ -122,7 +123,7 @@
     NSBezierPath *path;
     NSRect rect = NSZeroRect;
     while (path = [pathEnum nextObject])
-        rect = NSUnionRect(rect, NSInsetRect([path bounds], -lineWidth, 
-lineWidth));
+        rect = NSUnionRect(rect, NSInsetRect([path nonEmptyBounds], 
-lineWidth, -lineWidth));
     rect.origin = SKAddPoints(rect.origin, bounds.origin);
     return NSUnionRect([super displayRectForBounds:bounds], 
NSIntegralRect(rect));
 }

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2008-09-18 12:19:02 UTC (rev 4653)
+++ trunk/SKPDFView.m   2008-09-18 12:45:58 UTC (rev 4654)
@@ -3135,13 +3135,13 @@
         while (YES) {
             theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask 
| NSLeftMouseDraggedMask];
             [bezierPath lineToPoint:[self convertPoint:[self 
convertPoint:[theEvent locationInWindow] fromView:nil] toPage:page]];
-            [self setNeedsDisplayInRect:[self 
convertRect:NSInsetRect([bezierPath bounds], -8.0, -8.0) fromPage:page]];
+            [self setNeedsDisplayInRect:[self 
convertRect:NSInsetRect([bezierPath nonEmptyBounds], -8.0, -8.0) 
fromPage:page]];
             if ([theEvent type] == NSLeftMouseUp)
                 break;
             didDraw = YES;
         }
         if (didDraw)
-            [self addAnnotationWithType:SKInkNote contents:nil page:page 
bounds:NSInsetRect(NSIntegralRect([bezierPath bounds]), -8.0, -8.0)];
+            [self addAnnotationWithType:SKInkNote contents:nil page:page 
bounds:NSInsetRect(NSIntegralRect([bezierPath nonEmptyBounds]), -8.0, -8.0)];
         [bezierPath release];
         bezierPath = nil;
         


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

Reply via email to