Revision: 5002
http://skim-app.svn.sourceforge.net/skim-app/?rev=5002&view=rev
Author: hofman
Date: 2008-11-27 12:51:28 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
Move bitmap for page to pdfpage category. Separate method to draw the page
upright in an image.
Modified Paths:
--------------
trunk/NSBitmapImageRep_SKExtensions.h
trunk/NSBitmapImageRep_SKExtensions.m
trunk/PDFPage_SKExtensions.m
Modified: trunk/NSBitmapImageRep_SKExtensions.h
===================================================================
--- trunk/NSBitmapImageRep_SKExtensions.h 2008-11-27 12:24:20 UTC (rev
5001)
+++ trunk/NSBitmapImageRep_SKExtensions.h 2008-11-27 12:51:28 UTC (rev
5002)
@@ -41,7 +41,6 @@
@interface NSBitmapImageRep (SKExtensions)
-- (NSBitmapImageRep *)initWithPDFPage:(PDFPage *)page
forBox:(PDFDisplayBox)box;
- (NSRect)foregroundRect;
- (void)clear;
Modified: trunk/NSBitmapImageRep_SKExtensions.m
===================================================================
--- trunk/NSBitmapImageRep_SKExtensions.m 2008-11-27 12:24:20 UTC (rev
5001)
+++ trunk/NSBitmapImageRep_SKExtensions.m 2008-11-27 12:51:28 UTC (rev
5002)
@@ -174,49 +174,6 @@
return NSMakeRect(iLeft, jMax + MARGIN - jBottom - 1, iRight + 1 - iLeft,
jBottom + 1 - jTop);
}
-- (NSBitmapImageRep *)initWithPDFPage:(PDFPage *)page
forBox:(PDFDisplayBox)box;
-{
-
- NSRect bounds = [page boundsForBox:box];
- self = [self initWithBitmapDataPlanes:NULL
- pixelsWide:NSWidth(bounds)
- pixelsHigh:NSHeight(bounds)
- bitsPerSample:8
- samplesPerPixel:4
- hasAlpha:YES
- isPlanar:NO
- colorSpaceName:NSCalibratedRGBColorSpace
- bitmapFormat:0
- bytesPerRow:0
- bitsPerPixel:32];
- if (self) {
- [NSGraphicsContext saveGraphicsState];
- [NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:self]];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationNone];
- [[NSGraphicsContext currentContext] setShouldAntialias:NO];
- int rotation = [page rotation];
- if (rotation) {
- NSAffineTransform *transform = [NSAffineTransform transform];
- switch (rotation) {
- case 90:
- [transform translateXBy:NSWidth(bounds) yBy:0.0];
- break;
- case 180:
- [transform translateXBy:NSWidth(bounds)
yBy:NSHeight(bounds)];
- break;
- case 270:
- [transform translateXBy:0.0 yBy:NSHeight(bounds)];
- break;
- }
- [transform rotateByDegrees:rotation];
- [transform concat];
- }
- [page drawWithBox:box];
- [NSGraphicsContext restoreGraphicsState];
- }
- return self;
-}
-
// A fast alternative to filling with [NSColor clearColor].
- (void)clear {
unsigned char *bitmapData = [self bitmapData];
Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m 2008-11-27 12:24:20 UTC (rev 5001)
+++ trunk/PDFPage_SKExtensions.m 2008-11-27 12:51:28 UTC (rev 5002)
@@ -91,26 +91,77 @@
usesSequentialPageNumbering = flag;
}
-// mainly useful for drawing the box in a PDFView while debugging
+- (void)drawUnrotatedWithBox:(PDFDisplayBox)box {
+ NSRect bounds = [self boundsForBox:box];
+ [NSGraphicsContext saveGraphicsState];
+ if ([self rotation]) {
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ switch ([self rotation]) {
+ case 90:
+ [transform translateXBy:NSWidth(bounds) yBy:0.0];
+ break;
+ case 180:
+ [transform translateXBy:NSHeight(bounds) yBy:NSWidth(bounds)];
+ break;
+ case 270:
+ [transform translateXBy:0.0 yBy:NSHeight(bounds)];
+ break;
+ }
+ [transform rotateByDegrees:[self rotation]];
+ [transform concat];
+ }
+ [[self annotations] makeObjectsPerformSelector:@selector(hideIfTemporary)];
+ [self drawWithBox:box];
+ [[self annotations]
makeObjectsPerformSelector:@selector(displayIfTemporary)];
+ [NSGraphicsContext restoreGraphicsState];
+}
+
+- (NSBitmapImageRep *)newBitmapImageRepForBox:(PDFDisplayBox)box {
+
+ NSRect bounds = [self boundsForBox:box];
+ NSBitmapImageRep *imageRep;
+ imageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
+
pixelsWide:NSWidth(bounds)
+
pixelsHigh:NSHeight(bounds)
+ bitsPerSample:8
+ samplesPerPixel:4
+ hasAlpha:YES
+ isPlanar:NO
+
colorSpaceName:NSCalibratedRGBColorSpace
+ bitmapFormat:0
+ bytesPerRow:0
+ bitsPerPixel:32];
+ if (imageRep) {
+ [NSGraphicsContext saveGraphicsState];
+ [NSGraphicsContext setCurrentContext:[NSGraphicsContext
graphicsContextWithBitmapImageRep:imageRep]];
+ [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationNone];
+ [[NSGraphicsContext currentContext] setShouldAntialias:NO];
+ [self drawUnrotatedWithBox:box];
+ [NSGraphicsContext restoreGraphicsState];
+ }
+ return imageRep;
+}
+
- (NSRect)foregroundBox {
-
NSRect *rectPtr = NULL;
if (FALSE == CFDictionaryGetValueIfPresent(bboxCache, (void *)self, (const
void **)&rectPtr)) {
float marginWidth = [[NSUserDefaults standardUserDefaults]
floatForKey:SKAutoCropBoxMarginWidthKey];
float marginHeight = [[NSUserDefaults standardUserDefaults]
floatForKey:SKAutoCropBoxMarginHeightKey];
- NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc]
initWithPDFPage:self forBox:kPDFDisplayBoxMediaBox];
- NSRect r = imageRep ? [imageRep foregroundRect] : NSZeroRect;
- NSRect b = [self boundsForBox:kPDFDisplayBoxMediaBox];
- if (imageRep == nil) {
- r = b;
- } else if (NSEqualRects(NSZeroRect, r)) {
- r = NSMakeRect(NSMidX(b), NSMidY(b), 0.0, 0.0);
+ NSBitmapImageRep *imageRep = [self
newBitmapImageRepForBox:kPDFDisplayBoxMediaBox];
+ NSRect bounds = [self boundsForBox:kPDFDisplayBoxMediaBox];
+ NSRect rect = [imageRep foregroundRect];
+ if (imageRep) {
+ rect = bounds;
+ } else if (NSEqualRects(NSZeroRect, rect)) {
+ rect.origin.x = floorf(NSMidX(bounds));
+ rect.origin.x = ceilf(NSMidY(bounds));
} else {
- r.origin = SKAddPoints(r.origin, b.origin);
+ rect.origin.x += NSMinX(bounds);
+ rect.origin.y += NSMinY(bounds);
}
[imageRep release];
- r = NSIntersectionRect(NSInsetRect(r, -marginWidth, -marginHeight), b);
- rectPtr = &r;
+ rect = NSIntersectionRect(NSInsetRect(rect, -marginWidth,
-marginHeight), bounds);
+ rectPtr = ▭
CFDictionarySetValue(bboxCache, (void *)self, (void *)rectPtr);
}
// dereferencing here should always be safe (if not in the dictionary, it
was initialized)
@@ -130,25 +181,7 @@
[[NSColor whiteColor] set];
bounds.origin = NSZeroPoint;
NSRectFill(bounds);
- if ([self rotation]) {
- NSAffineTransform *transform = [NSAffineTransform transform];
- switch ([self rotation]) {
- case 90:
- [transform translateXBy:NSWidth(bounds) yBy:0.0];
- break;
- case 180:
- [transform translateXBy:NSHeight(bounds) yBy:NSWidth(bounds)];
- break;
- case 270:
- [transform translateXBy:0.0 yBy:NSHeight(bounds)];
- break;
- }
- [transform rotateByDegrees:[self rotation]];
- [transform concat];
- }
- [[self annotations] makeObjectsPerformSelector:@selector(hideIfTemporary)];
- [self drawWithBox:box];
- [[self annotations]
makeObjectsPerformSelector:@selector(displayIfTemporary)];
+ [self drawUnrotatedWithBox:box];
[image unlockFocus];
return [image autorelease];
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