Revision: 3616
http://skim-app.svn.sourceforge.net/skim-app/?rev=3616&view=rev
Author: hofman
Date: 2008-04-04 09:32:21 -0700 (Fri, 04 Apr 2008)
Log Message:
-----------
Use CFMutableArray to store rects.
Modified Paths:
--------------
trunk/SKCFCallBacks.h
trunk/SKCFCallBacks.m
trunk/SKPDFAnnotationMarkup.h
trunk/SKPDFAnnotationMarkup.m
Modified: trunk/SKCFCallBacks.h
===================================================================
--- trunk/SKCFCallBacks.h 2008-04-04 16:20:17 UTC (rev 3615)
+++ trunk/SKCFCallBacks.h 2008-04-04 16:32:21 UTC (rev 3616)
@@ -68,3 +68,6 @@
extern const CFDictionaryValueCallBacks SKFloatDictionaryValueCallbacks;
extern const CFDictionaryValueCallBacks SKNSRectDictionaryValueCallbacks;
+
+
+extern const CFArrayCallBacks SKNSRectArrayCallbacks;
Modified: trunk/SKCFCallBacks.m
===================================================================
--- trunk/SKCFCallBacks.m 2008-04-04 16:20:17 UTC (rev 3615)
+++ trunk/SKCFCallBacks.m 2008-04-04 16:32:21 UTC (rev 3616)
@@ -111,3 +111,11 @@
SKNSRectCopyDescription,
SKNSRectEqual
};
+
+const CFArrayCallBacks SKNSRectArrayCallbacks = {
+ 0, // version
+ SKNSRectRetain,
+ SKNSRectRelease,
+ SKNSRectCopyDescription,
+ SKNSRectEqual
+};
Modified: trunk/SKPDFAnnotationMarkup.h
===================================================================
--- trunk/SKPDFAnnotationMarkup.h 2008-04-04 16:20:17 UTC (rev 3615)
+++ trunk/SKPDFAnnotationMarkup.h 2008-04-04 16:32:21 UTC (rev 3616)
@@ -49,8 +49,7 @@
@interface SKPDFAnnotationMarkup : PDFAnnotationMarkup {
- NSRect *lineRects;
- unsigned numberOfLines;
+ CFMutableArrayRef lineRects;
}
- (id)initWithSelection:(PDFSelection *)selection markupType:(int)type;
Modified: trunk/SKPDFAnnotationMarkup.m
===================================================================
--- trunk/SKPDFAnnotationMarkup.m 2008-04-04 16:20:17 UTC (rev 3615)
+++ trunk/SKPDFAnnotationMarkup.m 2008-04-04 16:32:21 UTC (rev 3616)
@@ -43,6 +43,7 @@
#import "PDFSelection_SKExtensions.h"
#import "NSUserDefaultsController_SKExtensions.h"
#import "NSGeometry_SKExtensions.h"
+#import "SKCFCallbacks.h"
NSString *SKPDFAnnotationQuadrilateralPointsKey = @"quadrilateralPoints";
@@ -138,8 +139,7 @@
NSArray *quadPoints = pointStrings ?
createPointsFromStrings(pointStrings) : createQuadPointsWithBounds(bounds,
bounds.origin);
[self setQuadrilateralPoints:quadPoints];
[quadPoints release];
- numberOfLines = 0;
- lineRects = NULL;
+ lineRects = nil;
}
return self;
}
@@ -177,18 +177,11 @@
[quadPoints release];
}
- numberOfLines = 0;
- lineRects = NULL;
+ lineRects = nil;
}
return self;
}
-- (void)addLineRect:(NSRect)aRect {
- numberOfLines++;
- lineRects = NSZoneRealloc([self zone], lineRects, numberOfLines *
sizeof(NSRect));
- lineRects[numberOfLines - 1] = aRect;
-}
-
static BOOL adjacentCharacterBounds(NSRect rect1, NSRect rect2) {
float w = fmaxf(NSWidth(rect2), NSWidth(rect1));
float h = fmaxf(NSHeight(rect2), NSHeight(rect1));
@@ -239,7 +232,7 @@
} else {
// start of a new line
if (NSIsEmptyRect(lineRect) == NO) {
- [self addLineRect:lineRect];
+ CFArrayAppendValue(lineRects, &lineRect);
newBounds = NSUnionRect(lineRect, newBounds);
}
// ignore whitespace at the beginning of the new line
@@ -248,7 +241,7 @@
}
}
if (NSIsEmptyRect(lineRect) == NO) {
- [self addLineRect:lineRect];
+ CFArrayAppendValue(lineRects, &lineRect);
newBounds = NSUnionRect(lineRect, newBounds);
}
if (NSIsEmptyRect(newBounds)) {
@@ -256,8 +249,9 @@
self = nil;
} else {
[self setBounds:newBounds];
- for (i = 0; i < numberOfLines; i++) {
- NSArray *quadLine =
createQuadPointsWithBounds(lineRects[i], [self bounds].origin);
+ iMax = CFArrayGetCount(lineRects);
+ for (i = 0; i < iMax; i++) {
+ NSArray *quadLine = createQuadPointsWithBounds(*(NSRect
*)CFArrayGetValueAtIndex(lineRects, i), [self bounds].origin);
[quadPoints addObjectsFromArray:quadLine];
[quadLine release];
}
@@ -271,7 +265,7 @@
- (void)dealloc
{
- if (lineRects) NSZoneFree([self zone], lineRects);
+ if (lineRects) CFRelease(lineRects);
[super dealloc];
}
@@ -321,20 +315,20 @@
lineRect.size.height = points[1].y - points[2].y;
lineRect.size.width = points[1].x - points[2].x;
lineRect.origin = SKAddPoints(points[2], [self bounds].origin);
- [self addLineRect:lineRect];
+ CFArrayAppendValue(lineRects, &lineRect);
}
}
- (PDFSelection *)selection {
- if (0 == numberOfLines)
+ if (lineRects == nil)
[self regenerateLineRects];
PDFSelection *sel, *selection = nil;
- unsigned i;
+ unsigned i, iMax = CFArrayGetCount(lineRects);
- for (i = 0; i < numberOfLines; i++) {
+ for (i = 0; i < iMax; i++) {
// slightly outset the rect to avoid rounding errors, as
selectionForRect is pretty strict
- if (sel = [[self page] selectionForRect:NSInsetRect(lineRects[i],
-1.0, -1.0)]) {
+ if (sel = [[self page] selectionForRect:NSInsetRect(*(NSRect
*)CFArrayGetValueAtIndex(lineRects, i), -1.0, -1.0)]) {
if (selection == nil)
selection = sel;
else
@@ -350,14 +344,14 @@
return NO;
// archived annotations (or annotations we didn't create) won't have these
- if (0 == numberOfLines)
+ if (lineRects == nil)
[self regenerateLineRects];
- unsigned i = numberOfLines;
+ unsigned i = CFArrayGetCount(lineRects);
BOOL isContained = NO;
while (i-- && NO == isContained)
- isContained = NSPointInRect(point, lineRects[i]);
+ isContained = NSPointInRect(point, *(NSRect
*)CFArrayGetValueAtIndex(lineRects, i));
return isContained;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit