Revision: 13325
          http://sourceforge.net/p/skim-app/code/13325
Author:   hofman
Date:     2023-03-01 16:50:31 +0000 (Wed, 01 Mar 2023)
Log Message:
-----------
get line rects from selection before initializing new markup note

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

Modified: trunk/PDFAnnotationMarkup_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationMarkup_SKExtensions.m    2023-03-01 15:35:36 UTC (rev 
13324)
+++ trunk/PDFAnnotationMarkup_SKExtensions.m    2023-03-01 16:50:31 UTC (rev 
13325)
@@ -171,8 +171,20 @@
 - (id)initSkimNoteWithSelection:(PDFSelection *)selection forPage:(PDFPage 
*)page markupType:(NSInteger)type {
     if (page == nil)
         page = [selection safeFirstPage];
-    NSRect bounds = [selection hasCharacters] ? [selection boundsForPage:page] 
: NSZeroRect;
-    if ([selection hasCharacters] == NO || NSIsEmptyRect(bounds)) {
+    NSRect bounds = NSZeroRect;
+    NSPointerArray *lines = nil;
+    if ([selection hasCharacters]) {
+        for (PDFSelection *sel in [selection selectionsByLine]) {
+            NSRect lineRect = [sel boundsForPage:page];
+            if (NSIsEmptyRect(lineRect) == NO && [[sel string] 
rangeOfCharacterFromSet:[NSCharacterSet 
nonWhitespaceAndNewlineCharacterSet]].length) {
+                if (lines == nil)
+                    lines = [[NSPointerArray alloc] initForRectPointers];
+                [lines addPointer:&lineRect];
+                bounds = NSUnionRect(lineRect, bounds);
+            }
+        }
+    }
+    if (lines == nil) {
         [[self initWithBounds:NSZeroRect] release];
         self = nil;
     } else {
@@ -179,31 +191,14 @@
         self = [self initSkimNoteWithBounds:bounds markupType:type];
         if (self) {
             NSInteger lineAngle = [page lineDirectionAngle];
-            NSRect newBounds = NSZeroRect;
-            NSPointerArray *lines = nil;
-            for (PDFSelection *sel in [selection selectionsByLine]) {
-                NSRect lineRect = [sel boundsForPage:page];
-                if (NSIsEmptyRect(lineRect) == NO && [[sel string] 
rangeOfCharacterFromSet:[NSCharacterSet 
nonWhitespaceAndNewlineCharacterSet]].length) {
-                    if (lines == nil)
-                        lines = [[NSPointerArray alloc] initForRectPointers];
-                    [lines addPointer:&lineRect];
-                    newBounds = NSUnionRect(lineRect, newBounds);
-                }
-            } 
-            if (lines == nil) {
-                [self release];
-                self = nil;
-            } else {
-                NSMutableArray *quadPoints = [[NSMutableArray alloc] init];
-                NSUInteger i, iMax = [lines count];
-                for (i = 0; i < iMax; i++)
-                    addQuadPointsWithBounds(quadPoints, [lines rectAtIndex:i], 
newBounds.origin, lineAngle);
-                [self setBounds:newBounds];
-                [self setQuadrilateralPoints:quadPoints];
-                [[self extraIvars] setLineRects:lines];
-                [quadPoints release];
-                [lines release];
-            }
+            NSMutableArray *quadPoints = [[NSMutableArray alloc] init];
+            NSUInteger i, iMax = [lines count];
+            for (i = 0; i < iMax; i++)
+                addQuadPointsWithBounds(quadPoints, [lines rectAtIndex:i], 
bounds.origin, lineAngle);
+            [self setQuadrilateralPoints:quadPoints];
+            [[self extraIvars] setLineRects:lines];
+            [quadPoints release];
+            [lines release];
         }
     }
     return self;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to