Revision: 5790
http://skim-app.svn.sourceforge.net/skim-app/?rev=5790&view=rev
Author: hofman
Date: 2009-09-23 09:29:32 +0000 (Wed, 23 Sep 2009)
Log Message:
-----------
use pointer array for cropped rects
Modified Paths:
--------------
trunk/NSPointerFunctions_SKExtensions.h
trunk/NSPointerFunctions_SKExtensions.m
trunk/NSWindowController_SKExtensions.m
trunk/SKMainWindowController_Actions.m
Modified: trunk/NSPointerFunctions_SKExtensions.h
===================================================================
--- trunk/NSPointerFunctions_SKExtensions.h 2009-09-23 00:31:24 UTC (rev
5789)
+++ trunk/NSPointerFunctions_SKExtensions.h 2009-09-23 09:29:32 UTC (rev
5790)
@@ -45,6 +45,7 @@
+ (id)integerPointerFunctions;
+ (id)structPointerFunctionsWithSizeFunction:(NSUInteger (*)(const void
*))sizeFunction descriptionFunction:(NSString *(*)(const void
*))descriptionFunction;
+ (id)floatPointerFunctions;
++ (id)pointPointerFunctions;
+ (id)rectPointerFunctions;
+ (id)rangePointerFunctions;
+ (id)caseInsensitiveStringPointerFunctions;
Modified: trunk/NSPointerFunctions_SKExtensions.m
===================================================================
--- trunk/NSPointerFunctions_SKExtensions.m 2009-09-23 00:31:24 UTC (rev
5789)
+++ trunk/NSPointerFunctions_SKExtensions.m 2009-09-23 09:29:32 UTC (rev
5790)
@@ -43,12 +43,16 @@
static NSUInteger floatSizeFunction(const void *item) { return
sizeof(CGFloat); }
+static NSUInteger pointSizeFunction(const void *item) { return
sizeof(NSPoint); }
+
static NSUInteger rectSizeFunction(const void *item) { return sizeof(NSRect); }
static NSUInteger rangeSizeFunction(const void *item) { return
sizeof(NSRange); }
static NSString *floatDescriptionFunction(const void *item) { return [NSString
stringWithFormat:@"%f", *(CGFloat *)item]; }
+static NSString *pointDescriptionFunction(const void *item) { return
NSStringFromPoint(*(NSPointPointer)item); }
+
static NSString *rectDescriptionFunction(const void *item) { return
NSStringFromRect(*(NSRectPointer)item); }
static NSString *rangeDescriptionFunction(const void *item) { return [NSString
stringWithFormat:@"(%lu, %lu)", (unsigned long)((*(NSRange *)item).location),
(unsigned long)((*(NSRange *)item).length)]; }
@@ -102,6 +106,10 @@
return [self structPointerFunctionsWithSizeFunction:&floatSizeFunction
descriptionFunction:&floatDescriptionFunction];
}
++ (id)pointPointerFunctions {
+ return [self structPointerFunctionsWithSizeFunction:&pointSizeFunction
descriptionFunction:&pointDescriptionFunction];
+}
+
+ (id)rectPointerFunctions {
return [self structPointerFunctionsWithSizeFunction:&rectSizeFunction
descriptionFunction:&rectDescriptionFunction];
}
Modified: trunk/NSWindowController_SKExtensions.m
===================================================================
--- trunk/NSWindowController_SKExtensions.m 2009-09-23 00:31:24 UTC (rev
5789)
+++ trunk/NSWindowController_SKExtensions.m 2009-09-23 09:29:32 UTC (rev
5790)
@@ -38,26 +38,29 @@
#import "NSWindowController_SKExtensions.h"
#import "NSInvocation_SKExtensions.h"
+#import "NSPointerFunctions_SKExtensions.h"
@implementation NSWindowController (SKExtensions)
- (void)setWindowFrameAutosaveNameOrCascade:(NSString *)name {
- static NSMutableDictionary *nextWindowLocations = nil;
+ static NSMapTable *nextWindowLocations = nil;
if (nextWindowLocations == nil)
- nextWindowLocations = [[NSMutableDictionary alloc] init];
+ nextWindowLocations = [[NSMapTable alloc]
initWithKeyPointerFunctions:[NSPointerFunctions strongObjectPointerFunctions]
valuePointerFunctions:[NSPointerFunctions pointPointerFunctions] capacity:0];
- NSValue *value = [nextWindowLocations objectForKey:name];
- NSPoint point = [value pointValue];
+ NSPointPointer pointPtr = (NSPointPointer)[nextWindowLocations
objectForKey:name];
+ NSPoint point;
[[self window] setFrameUsingName:name];
[self setShouldCascadeWindows:NO];
- if ([[self window] setFrameAutosaveName:name] || value == nil) {
+ if ([[self window] setFrameAutosaveName:name] || pointPtr == NULL) {
NSRect windowFrame = [[self window] frame];
point = NSMakePoint(NSMinX(windowFrame), NSMaxY(windowFrame));
+ } else {
+ point = *pointPtr;
}
point = [[self window] cascadeTopLeftFromPoint:point];
- [nextWindowLocations setObject:[NSValue valueWithPoint:point] forKey:name];
+ [nextWindowLocations setObject:(id)&point forKey:name];
}
Modified: trunk/SKMainWindowController_Actions.m
===================================================================
--- trunk/SKMainWindowController_Actions.m 2009-09-23 00:31:24 UTC (rev
5789)
+++ trunk/SKMainWindowController_Actions.m 2009-09-23 09:29:32 UTC (rev
5790)
@@ -62,6 +62,7 @@
#import "SKLineInspector.h"
#import "NSEvent_SKExtensions.h"
#import "NSWindowController_SKExtensions.h"
+#import "NSPointerFunctions_SKExtensions.h"
@implementation SKMainWindowController (Actions)
@@ -619,17 +620,18 @@
[self cropPageAtIndex:[page pageIndex] toRect:rect];
}
-- (void)cropPagesToRects:(NSArray *)rects {
+- (void)cropPagesToRects:(NSPointerArray *)rects {
PDFPage *currentPage = [pdfView currentPage];
NSRect visibleRect = [pdfView convertRect:[pdfView convertRect:[[pdfView
documentView] visibleRect] fromView:[pdfView documentView]] toPage:[pdfView
currentPage]];
NSInteger i, count = [[pdfView document] pageCount];
NSInteger rectCount = [rects count];
- NSMutableArray *oldRects = [NSMutableArray arrayWithCapacity:count];
+ NSPointerArray *oldRects = [[[NSPointerArray alloc]
initWithPointerFunctions:[NSPointerFunctions rectPointerFunctions]]
autorelease];
for (i = 0; i < count; i++) {
PDFPage *page = [[pdfView document] pageAtIndex:i];
- NSRect rect = NSIntersectionRect([[rects objectAtIndex:i % rectCount]
rectValue], [page boundsForBox:kPDFDisplayBoxMediaBox]);
- [oldRects addObject:[NSValue valueWithRect:[page
boundsForBox:kPDFDisplayBoxCropBox]]];
+ NSRect rect = NSIntersectionRect(*(NSRectPointer)[rects
pointerAtIndex:i % rectCount], [page boundsForBox:kPDFDisplayBoxMediaBox]);
+ NSRect oldRect = [page boundsForBox:kPDFDisplayBoxCropBox];
+ [oldRects addPointer:&oldRect];
[page setBounds:rect forBox:kPDFDisplayBoxCropBox];
}
@@ -650,7 +652,7 @@
- (IBAction)cropAll:(id)sender {
NSRect rect[2] = {NSIntegralRect([pdfView currentSelectionRect]),
NSZeroRect};
- NSArray *rectArray;
+ NSPointerArray *rectArray = [[[NSPointerArray alloc]
initWithPointerFunctions:[NSPointerFunctions rectPointerFunctions]]
autorelease];
BOOL emptySelection = NSIsEmptyRect(rect[0]);
if (emptySelection) {
@@ -680,9 +682,10 @@
CGFloat h = SKMax(NSHeight(rect[0]), NSHeight(rect[1]));
for (j = 0; j < 2; j++)
rect[j] = NSMakeRect(SKFloor(NSMidX(rect[j]) - 0.5 * w),
SKFloor(NSMidY(rect[j]) - 0.5 * h), w, h);
- rectArray = [NSArray arrayWithObjects:[NSValue valueWithRect:rect[0]],
[NSValue valueWithRect:rect[1]], nil];
+ [rectArray addPointer:rect];
+ [rectArray addPointer:rect + 1];
} else {
- rectArray = [NSArray arrayWithObject:[NSValue valueWithRect:rect[0]]];
+ [rectArray addPointer:rect];
}
[self cropPagesToRects:rectArray];
@@ -694,7 +697,7 @@
}
- (IBAction)autoCropAll:(id)sender {
- NSMutableArray *rectArray = [NSMutableArray array];
+ NSPointerArray *rectArray = [[[NSPointerArray alloc]
initWithPointerFunctions:[NSPointerFunctions rectPointerFunctions]]
autorelease];
PDFDocument *pdfDoc = [pdfView document];
NSInteger i, iMax = [[pdfView document] pageCount];
@@ -704,7 +707,8 @@
[[self progressController] beginSheetModalForWindow:[self window]];
for (i = 0; i < iMax; i++) {
- [rectArray addObject:[NSValue valueWithRect:[[pdfDoc pageAtIndex:i]
foregroundBox]]];
+ NSRect rect = [[pdfDoc pageAtIndex:i] foregroundBox];
+ [rectArray addPointer:&rect];
[[self progressController] incrementBy:1.0];
if (i && i % 10 == 0)
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
@@ -715,7 +719,7 @@
}
- (IBAction)smartAutoCropAll:(id)sender {
- NSMutableArray *rectArray = [NSMutableArray array];
+ NSPointerArray *rectArray = [[[NSPointerArray alloc]
initWithPointerFunctions:[NSPointerFunctions rectPointerFunctions]]
autorelease];
PDFDocument *pdfDoc = [pdfView document];
NSInteger i, iMax = [pdfDoc pageCount];
NSSize size = NSZeroSize;
@@ -743,7 +747,7 @@
rect.origin.y = NSMaxY(rect) - size.height;
rect.size = size;
rect = SKConstrainRect(rect, bounds);
- [rectArray addObject:[NSValue valueWithRect:rect]];
+ [rectArray addPointer:&rect];
if (i && i % 10 == 0) {
[[self progressController] incrementBy:1.0];
if (i && i % 100 == 0)
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit