Revision: 4660
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4660&view=rev
Author:   hofman
Date:     2008-09-21 00:23:21 +0000 (Sun, 21 Sep 2008)

Log Message:
-----------
Use custom initializer for ink annotations using path array

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

Modified: trunk/PDFAnnotationInk_SKExtensions.h
===================================================================
--- trunk/PDFAnnotationInk_SKExtensions.h       2008-09-20 21:59:00 UTC (rev 
4659)
+++ trunk/PDFAnnotationInk_SKExtensions.h       2008-09-21 00:23:21 UTC (rev 
4660)
@@ -43,6 +43,8 @@
 
 @interface PDFAnnotationInk (SKExtensions)
 
+- (id)initSkimNoteWithPaths:(NSArray *)paths;
+
 - (NSArray *)pointLists;
 
 - (void)setScriptingPointLists:(NSArray *)lists;

Modified: trunk/PDFAnnotationInk_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationInk_SKExtensions.m       2008-09-20 21:59:00 UTC (rev 
4659)
+++ trunk/PDFAnnotationInk_SKExtensions.m       2008-09-21 00:23:21 UTC (rev 
4660)
@@ -63,6 +63,28 @@
     return self;        
 }       
 
+- (id)initSkimNoteWithPaths:(NSArray *)paths {
+    NSRect bounds = NSZeroRect;
+    NSAffineTransform *transform = [NSAffineTransform transform];
+    NSEnumerator *pathEnum;
+    NSBezierPath *path;
+    
+    pathEnum = [paths objectEnumerator];
+    while (path = [pathEnum nextObject])
+        bounds = NSUnionRect(bounds, [path nonEmptyBounds]);
+    bounds = NSInsetRect(NSIntegralRect(bounds), -8.0, -8.0);
+    [transform translateXBy:-NSMinX(bounds) yBy:-NSMinY(bounds)];
+    
+    if (self = [self initSkimNoteWithBounds:bounds]) {
+        pathEnum = [paths objectEnumerator];
+        while (path = [pathEnum nextObject]) {
+            [path transformUsingAffineTransform:transform];
+            [self addBezierPath:path];
+        }
+    }
+    return self;
+}
+
 - (NSString *)fdfString {
     NSMutableString *fdfString = [[[super fdfString] mutableCopy] autorelease];
     NSEnumerator *pathEnum = [[self paths] objectEnumerator];

Modified: trunk/PDFAnnotation_SKExtensions.m
===================================================================
--- trunk/PDFAnnotation_SKExtensions.m  2008-09-20 21:59:00 UTC (rev 4659)
+++ trunk/PDFAnnotation_SKExtensions.m  2008-09-21 00:23:21 UTC (rev 4660)
@@ -282,47 +282,34 @@
                     [currentCommand 
setScriptErrorString:NSLocalizedString(@"New markup notes need a selection.", 
@"Error description")];
                 } else {
                     NSMutableArray *paths = [[NSMutableArray alloc] 
initWithCapacity:[pointLists count]];
-                    NSBezierPath *path;
-                    NSEnumerator *pEnum;
-                    id pt;
                     NSEnumerator *listEnum = [pointLists objectEnumerator];
                     NSArray *list;
-                    bounds = NSZeroRect;
                     while (list = [listEnum nextObject]) {
-                        if ([list isKindOfClass:[NSArray class]] == NO) 
continue;
-                        path = [[NSBezierPath alloc] init];
-                        pEnum = [list objectEnumerator];
-                        while (pt = [pEnum nextObject]) {
-                            NSPoint point;
-                            if ([pt isKindOfClass:[NSData class]]) {
-                                point = [pt pointValueAsQDPoint];
-                            } else if ([pt isKindOfClass:[NSArray class]] && 
[pt count] == 2) {
-                                Point qdPoint;
-                                qdPoint.v = [[pt objectAtIndex:0] intValue];
-                                qdPoint.h = [[pt objectAtIndex:1] intValue];
-                                point = SKNSPointFromQDPoint(qdPoint);
-                            } else continue;
-                            if ([path elementCount])
-                                [path lineToPoint:point];
-                            else
-                                [path moveToPoint:point];
+                        if ([list isKindOfClass:[NSArray class]] == NO) {
+                            NSBezierPath *path = [[NSBezierPath alloc] init];
+                            NSEnumerator *ptEnum = [list objectEnumerator];
+                            id pt;
+                            while (pt = [ptEnum nextObject]) {
+                                NSPoint point;
+                                if ([pt isKindOfClass:[NSData class]]) {
+                                    point = [pt pointValueAsQDPoint];
+                                } else if ([pt isKindOfClass:[NSArray class]] 
&& [pt count] == 2) {
+                                    Point qdPoint;
+                                    qdPoint.v = [[pt objectAtIndex:0] 
intValue];
+                                    qdPoint.h = [[pt objectAtIndex:1] 
intValue];
+                                    point = SKNSPointFromQDPoint(qdPoint);
+                                } else continue;
+                                if ([path elementCount])
+                                    [path lineToPoint:point];
+                                else
+                                    [path moveToPoint:point];
+                            }
+                            if ([path elementCount] > 1)
+                                [paths addObject:path];
+                            [path release];
                         }
-                        if ([path elementCount] > 1) {
-                            [paths addObject:path];
-                            bounds = NSUnionRect(bounds, [path 
nonEmptyBounds]);
-                        }
-                        [path release];
                     }
-                    bounds = NSInsetRect(NSIntegralRect(bounds), -8.0, -8.0);
-                    NSAffineTransform *transform = [NSAffineTransform 
transform];
-                    [transform translateXBy:-NSMinX(bounds) 
yBy:-NSMinY(bounds)];
-                    if (self = [[PDFAnnotationInk alloc] 
initSkimNoteWithBounds:bounds]) {
-                        pEnum = [paths objectEnumerator];
-                        while (path = [pEnum nextObject]) {
-                            [path transformUsingAffineTransform:transform];
-                            [(PDFAnnotationInk *)self addBezierPath:path];
-                        }
-                    }
+                    self = [[PDFAnnotationInk alloc] 
initSkimNoteWithPaths:paths];
                     [paths release];
                 }
             } else if (type == SKScriptingTextNote) {
@@ -336,8 +323,6 @@
                 self = [[PDFAnnotationSquare alloc] 
initSkimNoteWithBounds:bounds];
             } else if (type == SKScriptingLineNote) {
                 self = [[PDFAnnotationLine alloc] 
initSkimNoteWithBounds:bounds];
-            } else if (type == SKScriptingInkNote) {
-                self = [[PDFAnnotationInk alloc] 
initSkimNoteWithBounds:bounds];
             }
         }
     }

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2008-09-20 21:59:00 UTC (rev 4659)
+++ trunk/SKPDFView.m   2008-09-21 00:23:21 UTC (rev 4660)
@@ -43,6 +43,7 @@
 #import <SkimNotes/SkimNotes.h>
 #import "PDFAnnotation_SKExtensions.h"
 #import "PDFAnnotationMarkup_SKExtensions.h"
+#import "PDFAnnotationInk_SKExtensions.h"
 #import "SKPDFAnnotationTemporary.h"
 #import "PDFPage_SKExtensions.h"
 #import "NSString_SKExtensions.h"
@@ -1918,24 +1919,18 @@
             newAnnotation = [[PDFAnnotationLine alloc] 
initSkimNoteWithBounds:bounds];
             break;
         case SKInkNote:
-            if (bezierPath) {
-                newAnnotation = [[PDFAnnotationInk alloc] 
initSkimNoteWithBounds:bounds];
-                NSBezierPath *path = [bezierPath copy];
-                NSAffineTransform *transform = [NSAffineTransform transform];
-                [transform translateXBy:-NSMinX(bounds) yBy:-NSMinY(bounds)];
-                [path transformUsingAffineTransform:transform];
-                [(PDFAnnotationInk *)newAnnotation addBezierPath:path];
-                [path release];
-            }
+            if (bezierPath)
+                newAnnotation = [[PDFAnnotationInk alloc] 
initSkimNoteWithPaths:[NSArray arrayWithObject:[[bezierPath copy] 
autorelease]]];
             break;
        }
     if (newAnnotation) {
-        if (text == nil)
-            text = [[[page selectionForRect:bounds] string] 
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+        if (annotationType != SKLineNote && annotationType != SKInkNote) {
+            if (text == nil)
+                text = [[[page selectionForRect:[newAnnotation bounds]] 
string] 
stringByCollapsingWhitespaceAndNewlinesAndRemovingSurroundingWhitespaceAndNewlines];
+            if (text)
+                [newAnnotation setString:text];
+        }
         
-        if ([[activeAnnotation type] isEqualToString:SKNLineString] == NO && 
[[activeAnnotation type] isEqualToString:SKNInkString] == NO)
-            [newAnnotation setString:text];
-        
         [self addAnnotation:newAnnotation toPage:page];
         [[self undoManager] setActionName:NSLocalizedString(@"Add Note", 
@"Undo action name")];
 
@@ -3006,36 +3001,30 @@
                 [self addAnnotation:newActiveAnnotation toPage:page];
                 [[self undoManager] setActionName:NSLocalizedString(@"Join 
Notes", @"Undo action name")];
             } else if ([[activeAnnotation type] isEqualToString:SKNInkString]) 
{
-                NSEnumerator *pathEnum;
-                NSBezierPath *path;
+                NSMutableArray *paths = [[NSMutableArray alloc] 
initWithArray:[(PDFAnnotationInk *)activeAnnotation paths] copyItems:YES];
+                NSArray *newPaths = [[NSArray alloc] 
initWithArray:[(PDFAnnotationInk *)newActiveAnnotation paths] copyItems:YES];
+                
                 NSAffineTransform *transform = [NSAffineTransform transform];
-                NSRect bounds1 = [activeAnnotation bounds];
-                NSRect bounds2 = [newActiveAnnotation bounds];
-                NSRect bounds3 = NSUnionRect(bounds1, bounds2);
-                PDFAnnotationInk *newAnnotation = [[[PDFAnnotationInk alloc] 
initSkimNoteWithBounds:bounds3] autorelease];
-                [transform translateXBy:NSMinX(bounds1) - NSMinX(bounds3) 
yBy:NSMinY(bounds1) - NSMinY(bounds3)];
-                pathEnum = [[(PDFAnnotationInk *)activeAnnotation paths] 
objectEnumerator];
-                while (path = [pathEnum nextObject]) {
-                    path = [path copy];
-                    [path transformUsingAffineTransform:transform];
-                    [newAnnotation addBezierPath:path];
-                    [path release];
-                }
-                [transform translateXBy:NSMinX(bounds2) - NSMinX(bounds1) 
yBy:NSMinY(bounds2) - NSMinY(bounds1)];
-                pathEnum = [[(PDFAnnotationInk *)newActiveAnnotation paths] 
objectEnumerator];
-                while (path = [pathEnum nextObject]) {
-                    path = [path copy];
-                    [path transformUsingAffineTransform:transform];
-                    [newAnnotation addBezierPath:path];
-                    [path release];
-                }
-                [newAnnotation setString:[activeAnnotation string]];
-                [newAnnotation setColor:[activeAnnotation color]];
-                [newAnnotation setBorder:[activeAnnotation border]];
-                [self removeActiveAnnotation:nil];
+                NSRect bounds = [activeAnnotation bounds];
+                [transform translateXBy:NSMinX(bounds) yBy:NSMinY(bounds)];
+                [paths 
makeObjectsPerformSelector:@selector(transformUsingAffineTransform:) 
withObject:transform];
+                
+                transform = [NSAffineTransform transform];
+                bounds = [newActiveAnnotation bounds];
+                [transform translateXBy:NSMinX(bounds) yBy:NSMinY(bounds)];
+                [newPaths 
makeObjectsPerformSelector:@selector(transformUsingAffineTransform:) 
withObject:transform];
+                
                 [self removeAnnotation:newActiveAnnotation];
-                newActiveAnnotation = newAnnotation;
+                newActiveAnnotation = [[[PDFAnnotationInk alloc] 
initSkimNoteWithPaths:paths] autorelease];
+                [(PDFAnnotationInk *)newActiveAnnotation 
setString:[activeAnnotation string]];
+                [(PDFAnnotationInk *)newActiveAnnotation 
setColor:[activeAnnotation color]];
+                [(PDFAnnotationInk *)newActiveAnnotation 
setBorder:[activeAnnotation border]];
+                [self removeActiveAnnotation:nil];
                 [self addAnnotation:newActiveAnnotation toPage:page];
+                [[self undoManager] setActionName:NSLocalizedString(@"Join 
Notes", @"Undo action name")];
+                
+                [paths release];
+                [newPaths release];
                 [accessibilityChildren release];
                 accessibilityChildren = nil;
             }
@@ -3141,7 +3130,7 @@
             didDraw = YES;
         }
         if (didDraw)
-            [self addAnnotationWithType:SKInkNote contents:nil page:page 
bounds:NSInsetRect(NSIntegralRect([bezierPath nonEmptyBounds]), -8.0, -8.0)];
+            [self addAnnotationWithType:SKInkNote contents:nil page:page 
bounds:NSZeroRect];
         [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