Revision: 3339
          http://skim-app.svn.sourceforge.net/skim-app/?rev=3339&view=rev
Author:   hofman
Date:     2007-12-26 05:21:42 -0800 (Wed, 26 Dec 2007)

Log Message:
-----------
Improve calculations for fit to pdf.

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

Modified: trunk/SKMainWindowController.m
===================================================================
--- trunk/SKMainWindowController.m      2007-12-25 22:59:41 UTC (rev 3338)
+++ trunk/SKMainWindowController.m      2007-12-26 13:21:42 UTC (rev 3339)
@@ -1951,31 +1951,40 @@
     }
     
     PDFDisplayMode displayMode = [pdfView displayMode];
+    float scaleFactor = [[self pdfView] scaleFactor];
+    BOOL autoScales = [[self pdfView] autoScales];
+    BOOL isSingleRow;
+    
+    if (displayMode == kPDFDisplaySinglePage || displayMode == 
kPDFDisplayTwoUp)
+        isSingleRow = YES;
+    else if (displayMode == kPDFDisplaySinglePageContinuous || [[self pdfView] 
displaysAsBook])
+        isSingleRow = [[[self pdfView] document] pageCount] <= 1;
+    else
+        isSingleRow = [[[self pdfView] document] pageCount] <= 2;
+    
+    NSRect frame = [[self window] frame];
     NSSize size, oldSize = [[self pdfView] frame].size;
-    NSRect frame = [[self window] frame];
     NSRect documentRect = [[[self pdfView] documentView] convertRect:[[[self 
pdfView] documentView] bounds] toView:nil];
     
-    if ([[self pdfView] autoScales]) {
-        documentRect.size.width /= [[self pdfView] scaleFactor];
-        documentRect.size.height /= [[self pdfView] scaleFactor];
-    }
-    
+    // Calculate the new size for the pdfView
     size.width = NSWidth(documentRect);
-    if (displayMode == kPDFDisplaySinglePage || displayMode == 
kPDFDisplayTwoUp) {
-        size.height = NSHeight(documentRect) + 1.0;
+    if (autoScales)
+        size.width /= scaleFactor;
+    if (isSingleRow) {
+        size.height = NSHeight(documentRect);
     } else {
-        NSRect pageBounds = [[self pdfView] convertRect:[[[self pdfView] 
currentPage] boundsForBox:[[self pdfView] displayBox]] fromPage:[[self pdfView] 
currentPage]];
-        if ([[self pdfView] autoScales]) {
-            pageBounds.size.width /= [[self pdfView] scaleFactor];
-            pageBounds.size.height /= [[self pdfView] scaleFactor];
-        }
-        size.height = NSHeight(pageBounds) + NSWidth(documentRect) - 
NSWidth(pageBounds) + 1.0;
-        if ([[[self pdfView] document] pageCount] > 1)
-            size.width += [NSScroller scrollerWidth];
+        size.height = NSHeight([[self pdfView] convertRect:[[[self pdfView] 
currentPage] boundsForBox:[[self pdfView] displayBox]] fromPage:[[self pdfView] 
currentPage]]);
+        if ([[self pdfView] displaysPageBreaks])
+            size.height += 8.0 * scaleFactor;
+        size.width += [NSScroller scrollerWidth];
     }
+    if (autoScales)
+        size.height /= scaleFactor;
     
-    size.width += NSWidth(frame) - oldSize.width;
-    size.height += NSHeight(frame) - oldSize.height;
+    // Calculate the new size for the window
+    size.width = ceilf(NSWidth(frame) + size.width - oldSize.width);
+    size.height = ceilf(NSHeight(frame) + size.height - oldSize.height);
+    // Align the window frame from the old topleft point and constrain to the 
screen
     frame.origin.y = NSMaxY(frame) - size.height;
     frame.size = size;
     frame = SKConstrainRect(frame, [[[self window] screen] visibleFrame]);


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: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to