Revision: 5004
http://skim-app.svn.sourceforge.net/skim-app/?rev=5004&view=rev
Author: hofman
Date: 2008-11-27 16:01:19 +0000 (Thu, 27 Nov 2008)
Log Message:
-----------
Copy TIFF images rotated with page, no need to use a separate method to draw
the image. Avoid clipping images when using the media or crop box.
Modified Paths:
--------------
trunk/PDFPage_SKExtensions.h
trunk/PDFPage_SKExtensions.m
trunk/SKMainWindowController_UI.m
Modified: trunk/PDFPage_SKExtensions.h
===================================================================
--- trunk/PDFPage_SKExtensions.h 2008-11-27 15:19:14 UTC (rev 5003)
+++ trunk/PDFPage_SKExtensions.h 2008-11-27 16:01:19 UTC (rev 5004)
@@ -55,8 +55,7 @@
+ (void)setUsesSequentialPageNumbering:(BOOL)flag;
- (NSRect)foregroundBox;
-- (NSImage *)image;
-- (NSImage *)imageForBox:(PDFDisplayBox)box;
+
- (NSImage *)thumbnailWithSize:(float)size forBox:(PDFDisplayBox)box;
- (NSImage *)thumbnailWithSize:(float)size forBox:(PDFDisplayBox)box
readingBarRect:(NSRect)readingBarRect;
- (NSImage *)thumbnailWithSize:(float)size forBox:(PDFDisplayBox)box
shadowBlurRadius:(float)shadowBlurRadius shadowOffset:(NSSize)shadowOffset
readingBarRect:(NSRect)readingBarRect;
Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m 2008-11-27 15:19:14 UTC (rev 5003)
+++ trunk/PDFPage_SKExtensions.m 2008-11-27 16:01:19 UTC (rev 5004)
@@ -167,26 +167,7 @@
// dereferencing here should always be safe (if not in the dictionary, it
was initialized)
return *rectPtr;
}
-
-- (NSImage *)image {
- return [self imageForBox:kPDFDisplayBoxCropBox];
-}
-- (NSImage *)imageForBox:(PDFDisplayBox)box {
- NSRect bounds = [self boundsForBox:box];
- NSImage *image = [[NSImage alloc] initWithSize:bounds.size];
-
- [image lockFocus];
- [[NSGraphicsContext currentContext]
setImageInterpolation:NSImageInterpolationHigh];
- [[NSColor whiteColor] set];
- bounds.origin = NSZeroPoint;
- NSRectFill(bounds);
- [self drawUnrotatedWithBox:box];
- [image unlockFocus];
-
- return [image autorelease];
-}
-
- (NSImage *)thumbnailWithSize:(float)size forBox:(PDFDisplayBox)box {
return [self thumbnailWithSize:size forBox:box readingBarRect:NSZeroRect];
}
@@ -357,19 +338,35 @@
}
- (NSData *)TIFFDataForRect:(NSRect)rect {
- NSImage *pageImage = [self imageForBox:kPDFDisplayBoxMediaBox];
+ PDFDisplayBox box = NSEqualRects(rect, [self
boundsForBox:kPDFDisplayBoxCropBox]) ? kPDFDisplayBoxCropBox :
kPDFDisplayBoxMediaBox;
+ NSImage *pageImage = [self thumbnailWithSize:0.0 forBox:box
shadowBlurRadius:0.0 shadowOffset:NSZeroSize readingBarRect:NSZeroRect];
+ NSRect bounds = [self boundsForBox:box];
- if (NSEqualRects(rect, NSZeroRect))
+ if (NSEqualRects(rect, NSZeroRect) || NSEqualRects(rect, bounds))
return [pageImage TIFFRepresentation];
if (NSIsEmptyRect(rect))
return nil;
- NSRect pageBounds = [self boundsForBox:kPDFDisplayBoxMediaBox];
- NSRect sourceRect = rect;
- NSRect targetRect = {NSZeroPoint, rect.size};
- sourceRect.origin.x -= NSMinX(pageBounds);
- sourceRect.origin.y -= NSMinY(pageBounds);
+ NSAffineTransform *transform = [NSAffineTransform transform];
+ switch ([self rotation]) {
+ case 0:
+ [transform translateXBy:-NSMinX(bounds) yBy:-NSMinY(bounds)];
+ break;
+ case 90:
+ [transform translateXBy:-NSMinY(bounds) yBy:NSMaxX(bounds)];
+ break;
+ case 180:
+ [transform translateXBy:NSMaxX(bounds) yBy:NSMaxY(bounds)];
+ break;
+ case 270:
+ [transform translateXBy:NSMaxY(bounds) yBy:-NSMinX(bounds)];
+ break;
+ }
+ [transform rotateByDegrees:-[self rotation]];
+ NSRect sourceRect = [transform transformRect:rect];
+ NSRect targetRect = {NSZeroPoint, sourceRect.size};
+
NSImage *image = [[NSImage alloc] initWithSize:targetRect.size];
[image lockFocus];
[pageImage drawInRect:targetRect fromRect:sourceRect
operation:NSCompositeCopy fraction:1.0];
Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m 2008-11-27 15:19:14 UTC (rev 5003)
+++ trunk/SKMainWindowController_UI.m 2008-11-27 16:01:19 UTC (rev 5004)
@@ -374,7 +374,7 @@
if (idx != NSNotFound) {
PDFPage *page = [[pdfView document] pageAtIndex:idx];
NSData *pdfData = [page dataRepresentation];
- NSData *tiffData = [[page imageForBox:[pdfView displayBox]]
TIFFRepresentation];
+ NSData *tiffData = [page TIFFDataForRect:[page
boundsForBox:[pdfView displayBox]]];
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard declareTypes:[NSArray arrayWithObjects:NSPDFPboardType,
NSTIFFPboardType, nil] owner:nil];
[pboard setData:pdfData forType:NSPDFPboardType];
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