Revision: 2775
          http://skim-app.svn.sourceforge.net/skim-app/?rev=2775&view=rev
Author:   hofman
Date:     2007-08-29 15:10:36 -0700 (Wed, 29 Aug 2007)

Log Message:
-----------
Scale page for thumbnail proportionally, because PDFKit can freeze when drawing 
in a non-proportionally scaled context.

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

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2007-08-29 20:40:12 UTC (rev 2774)
+++ trunk/PDFPage_SKExtensions.m        2007-08-29 22:10:36 UTC (rev 2775)
@@ -147,8 +147,9 @@
     NSRect bounds = [self boundsForBox:box];
     BOOL isScaled = size > 0.0;
     BOOL hasShadow = shadowBlurRadius > 0.0;
-    float scaleX, scaleY;
+    float scale = 1.0;
     NSSize thumbnailSize;
+    NSRect pageRect = NSZeroRect;
     NSImage *image;
     
     if ([self rotation] % 180 == 90)
@@ -159,11 +160,9 @@
             thumbnailSize = NSMakeSize(roundf((size - 2.0 * shadowBlurRadius) 
* NSWidth(bounds) / NSHeight(bounds) + 2.0 * shadowBlurRadius), size);
         else
             thumbnailSize = NSMakeSize(size, roundf((size - 2.0 * 
shadowBlurRadius) * NSHeight(bounds) / NSWidth(bounds) + 2.0 * 
shadowBlurRadius));
-        scaleX = (thumbnailSize.width - 2.0 * shadowBlurRadius) / 
NSWidth(bounds);
-        scaleY = (thumbnailSize.height - 2.0 * shadowBlurRadius) / 
NSHeight(bounds);
+        scale = fminf((thumbnailSize.width - 2.0 * shadowBlurRadius) / 
NSWidth(bounds), (thumbnailSize.height - 2.0 * shadowBlurRadius) / 
NSHeight(bounds));
     } else {
         thumbnailSize = NSMakeSize(NSWidth(bounds) + 2.0 * shadowBlurRadius, 
NSHeight(bounds) + 2.0 * shadowBlurRadius);
-        scaleX = scaleY = 1.0;
     }
     
     readingBarRect.origin = SKSubstractPoints(readingBarRect.origin, 
bounds.origin);
@@ -172,13 +171,6 @@
     [image lockFocus];
     [NSGraphicsContext saveGraphicsState];
     [[NSGraphicsContext currentContext] 
setImageInterpolation:NSImageInterpolationHigh];
-    if (isScaled || hasShadow) {
-        NSAffineTransform *transform = [NSAffineTransform transform];
-        if (isScaled)
-            [transform scaleXBy:scaleX yBy:scaleY];
-        [transform translateXBy:(shadowBlurRadius - shadowOffset.width) / 
scaleX yBy:(shadowBlurRadius - shadowOffset.height) / scaleY];
-        [transform concat];
-    }
     [NSGraphicsContext saveGraphicsState];
     [[NSColor whiteColor] set];
     if (hasShadow) {
@@ -189,14 +181,25 @@
         [shadow set];
         [shadow release];
     }
-    bounds.origin = NSZeroPoint;
-    NSRectFill(bounds);
+    pageRect.size = thumbnailSize;
+    pageRect = NSInsetRect(pageRect, shadowBlurRadius, shadowBlurRadius);
+    pageRect.origin.x -= shadowOffset.width;
+    pageRect.origin.y -= shadowOffset.height;
+    NSRectFill(pageRect);
     [NSGraphicsContext restoreGraphicsState];
+    if (isScaled || hasShadow) {
+        NSAffineTransform *transform = [NSAffineTransform transform];
+        if (isScaled)
+            [transform scaleBy:scale];
+        [transform translateXBy:(shadowBlurRadius - shadowOffset.width) / 
scale yBy:(shadowBlurRadius - shadowOffset.height) / scale];
+        [transform concat];
+    }
     [self drawWithBox:box]; 
     if (NSIsEmptyRect(readingBarRect) == NO) {
         [[NSUnarchiver unarchiveObjectWithData:[[NSUserDefaults 
standardUserDefaults] objectForKey:SKReadingBarColorKey]] setFill];
         if ([[NSUserDefaults standardUserDefaults] 
boolForKey:SKReadingBarInvertKey]) {
             NSRect outRect, ignored;
+            bounds.origin = NSZeroPoint;
             NSDivideRect(bounds, &outRect, &ignored, NSMaxY(bounds) - 
NSMaxY(readingBarRect), NSMaxYEdge);
             [NSBezierPath fillRect:outRect];
             NSDivideRect(bounds, &outRect, &ignored, NSMinY(readingBarRect) - 
NSMinY(bounds), NSMinYEdge);


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: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to