Revision: 13413
http://sourceforge.net/p/skim-app/code/13413
Author: hofman
Date: 2023-04-02 15:53:25 +0000 (Sun, 02 Apr 2023)
Log Message:
-----------
Use page bounds with margins for Fit, FitH, FitV, and foregroundRect for FitB,
FitBH, FitBV. Convenience method to get bounds of page with margins.
Modified Paths:
--------------
trunk/PDFDestination_SKExtensions.h
trunk/PDFDestination_SKExtensions.m
trunk/PDFView_SKExtensions.h
trunk/PDFView_SKExtensions.m
trunk/SKBasePDFView.m
trunk/SKImageToolTipContext.m
trunk/SKMainWindowController_Actions.m
trunk/SKPDFView.m
trunk/SKReadingBar.m
Modified: trunk/PDFDestination_SKExtensions.h
===================================================================
--- trunk/PDFDestination_SKExtensions.h 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/PDFDestination_SKExtensions.h 2023-04-02 15:53:25 UTC (rev 13413)
@@ -41,6 +41,6 @@
@interface PDFDestination (SKExtensions)
-- (PDFDestination *)effectiveDestinationWithTargetSize:(NSSize)rect;
+- (PDFDestination *)effectiveDestinationForView:(PDFView *)pdfView;
@end
Modified: trunk/PDFDestination_SKExtensions.m
===================================================================
--- trunk/PDFDestination_SKExtensions.m 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/PDFDestination_SKExtensions.m 2023-04-02 15:53:25 UTC (rev 13413)
@@ -38,10 +38,11 @@
#import "PDFDestination_SKExtensions.h"
#import "PDFPage_SKExtensions.h"
+#import "PDFView_SKExtensions.h"
@implementation PDFDestination (SKExtensions)
-- (PDFDestination *)effectiveDestinationWithTargetSize:(NSSize)size {
+- (PDFDestination *)effectiveDestinationForView:(PDFView *)pdfView {
NSPoint point = [self point];
if (point.x >= kPDFDestinationUnspecifiedValue || point.y >=
kPDFDestinationUnspecifiedValue) {
PDFPage *page = [self page];
@@ -55,15 +56,15 @@
override = NO;
break;
case 1: // Fit
- bounds = [page foregroundRect];
+ bounds = pdfView ? [pdfView layoutBoundsForPage:page] : [page
boundsForBox:kPDFDisplayBoxCropBox];
break;
case 2: // FitH
- bounds = [page foregroundRect];
+ bounds = pdfView ? [pdfView layoutBoundsForPage:page] : [page
boundsForBox:kPDFDisplayBoxCropBox];
@try { point.y = [[self valueForKeyPath:RUNNING_BEFORE(10_12)
? @"_pdfPriv.top" : @"_private.top"] doubleValue]; }
@catch (id e) { override = NO; }
break;
case 3: // FitV
- bounds = [page foregroundRect];
+ bounds = pdfView ? [pdfView layoutBoundsForPage:page] : [page
boundsForBox:kPDFDisplayBoxCropBox];
@try { point.x = [[self valueForKeyPath:RUNNING_BEFORE(10_12)
? @"_pdfPriv.left" : @"_private.left"] doubleValue]; }
@catch (id e) { override = NO; }
break;
@@ -80,15 +81,15 @@
break;
}
case 5: // FitB
- bounds = [page boundsForBox:kPDFDisplayBoxCropBox];
+ bounds = [page foregroundRect];
break;
case 6: // FitBH
- bounds = [page boundsForBox:kPDFDisplayBoxCropBox];
+ bounds = [page foregroundRect];
@try { point.y = [[self valueForKeyPath:RUNNING_BEFORE(10_12)
? @"_pdfPriv.top" : @"_private.top"] doubleValue]; }
@catch (id e) { override = NO; }
break;
case 7: // FitBV
- bounds = [page boundsForBox:kPDFDisplayBoxCropBox];
+ bounds = [page foregroundRect];
@try { point.x = [[self valueForKeyPath:RUNNING_BEFORE(10_12)
? @"_pdfPriv.left" : @"_private.left"] doubleValue]; }
@catch (id e) { override = NO; }
break;
@@ -102,8 +103,10 @@
if (point.y >= kPDFDestinationUnspecifiedValue)
point.y = NSMaxY(bounds);
PDFDestination *destination = [[[PDFDestination alloc]
initWithPage:page atPoint:point] autorelease];
- if (size.width > 0.0 && size.height > 0.0 && NSWidth(bounds) > 0.0
&& NSHeight(bounds) > 0.0)
+ if (pdfView && NSWidth(bounds) > 0.0 && NSHeight(bounds) > 0.0) {
+ NSSize size = [pdfView visibleContentRect].size;
[destination setZoom:fmin(size.width / NSWidth(bounds),
size.height / NSHeight(bounds))];
+ }
return destination;
}
}
Modified: trunk/PDFView_SKExtensions.h
===================================================================
--- trunk/PDFView_SKExtensions.h 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/PDFView_SKExtensions.h 2023-04-02 15:53:25 UTC (rev 13413)
@@ -66,6 +66,8 @@
- (void)goToCurrentPage:(PDFPage *)page;
+- (NSRect)layoutBoundsForPage:(PDFPage *)page;
+
@property (nonatomic, readonly) BOOL drawsActiveSelections;
+ (NSColor *)defaultBackgroundColor;
Modified: trunk/PDFView_SKExtensions.m
===================================================================
--- trunk/PDFView_SKExtensions.m 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/PDFView_SKExtensions.m 2023-04-02 15:53:25 UTC (rev 13413)
@@ -64,10 +64,13 @@
- (CGFloat)minScaleFactor;
- (CGFloat)maxScaleFactor;
@property (nonatomic) PDFDisplayDirection displayDirection;
+@property (nonatomic) NSEdgeInsets pageBreakMargins;
@end
#endif
+#define PAGE_BREAK_MARGIN 4.0
+
@implementation PDFView (SKExtensions)
@dynamic physicalScaleFactor, scrollView, displayedPages, minimumScaleFactor,
maximumScaleFactor, visibleContentRect, drawsActiveSelections;
@@ -279,6 +282,43 @@
return rect;
}
+- (NSRect)layoutBoundsForPage:(PDFPage *)page {
+ NSRect pageRect = [page boundsForBox:[self displayBox]];
+ if ([self displaysPageBreaks]) {
+ if (RUNNING_BEFORE(10_13)) {
+ pageRect = NSInsetRect(pageRect, -PAGE_BREAK_MARGIN,
-PAGE_BREAK_MARGIN);
+ } else {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wpartial-availability"
+ NSEdgeInsets margins = [self pageBreakMargins];
+#pragma clang diagnostic pop
+ switch ([page rotation]) {
+ case 0:
+ pageRect = NSInsetRect(pageRect, -margins.left,
-margins.bottom);
+ pageRect.size.width += margins.right - margins.left;
+ pageRect.size.height += margins.top - margins.bottom;
+ break;
+ case 90:
+ pageRect = NSInsetRect(pageRect, -margins.top,
-margins.left);
+ pageRect.size.width += margins.bottom - margins.top;
+ pageRect.size.height += margins.right - margins.left;
+ break;
+ case 180:
+ pageRect = NSInsetRect(pageRect, -margins.right,
-margins.top);
+ pageRect.size.width += margins.left - margins.right;
+ pageRect.size.height += margins.bottom - margins.top;
+ break;
+ case 270:
+ pageRect = NSInsetRect(pageRect, -margins.bottom,
-margins.right);
+ pageRect.size.width += margins.top - margins.bottom;
+ pageRect.size.height += margins.left - margins.right;
+ break;
+ }
+ }
+ }
+ return pageRect;
+}
+
- (CGFloat)maximumScaleFactor {
if ([self respondsToSelector:@selector(maxScaleFactor)])
return [self maxScaleFactor];
Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/SKBasePDFView.m 2023-04-02 15:53:25 UTC (rev 13413)
@@ -398,7 +398,7 @@
}
- (void)goToDestination:(PDFDestination *)destination {
- [super goToDestination:[destination
effectiveDestinationWithTargetSize:[self visibleContentRect].size]];
+ [super goToDestination:[destination effectiveDestinationForView:self]];
}
@end
Modified: trunk/SKImageToolTipContext.m
===================================================================
--- trunk/SKImageToolTipContext.m 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/SKImageToolTipContext.m 2023-04-02 15:53:25 UTC (rev 13413)
@@ -107,7 +107,7 @@
BOOL isScaled = fabs(scale - 1.0) > 0.01;
PDFPage *page = [self page];
- NSPoint point = [[self effectiveDestinationWithTargetSize:NSZeroSize]
point];
+ NSPoint point = [[self effectiveDestinationForView:nil] point];
NSRect bounds = [page boundsForBox:kPDFDisplayBoxCropBox];
CGFloat size = isScaled ? ceil(scale * fmax(NSWidth(bounds),
NSHeight(bounds))) : 0.0;
NSImage *pageImage = [page thumbnailWithSize:size
forBox:kPDFDisplayBoxCropBox shadowBlurRadius:0.0 highlights:selections];
Modified: trunk/SKMainWindowController_Actions.m
===================================================================
--- trunk/SKMainWindowController_Actions.m 2023-04-02 14:59:03 UTC (rev
13412)
+++ trunk/SKMainWindowController_Actions.m 2023-04-02 15:53:25 UTC (rev
13413)
@@ -89,12 +89,6 @@
#define DEFAULT_SPLIT_PDF_FACTOR 0.3
-#if SDK_BEFORE(10_13)
-@interface PDFView (SKHighSierraDeclarations)
-@property (nonatomic) NSEdgeInsets pageBreakMargins;
-@end
-#endif
-
@interface SKMainWindowController (SKPrivateUI)
- (void)updateLineInspector;
- (void)updateNoteFilterPredicate;
@@ -450,49 +444,12 @@
}
}
-static NSRect layoutBoundsForPage(PDFPage *page, PDFView *pdfView) {
- NSRect pageRect = [page boundsForBox:[pdfView displayBox]];
- if ([pdfView displaysPageBreaks]) {
- if (RUNNING_BEFORE(10_13)) {
- pageRect = NSInsetRect(pageRect, -PAGE_BREAK_MARGIN,
-PAGE_BREAK_MARGIN);
- } else {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wpartial-availability"
- NSEdgeInsets margins = [pdfView pageBreakMargins];
-#pragma clang diagnostic pop
- switch ([page rotation]) {
- case 0:
- pageRect = NSInsetRect(pageRect, -margins.left,
-margins.bottom);
- pageRect.size.width += margins.right - margins.left;
- pageRect.size.height += margins.top - margins.bottom;
- break;
- case 90:
- pageRect = NSInsetRect(pageRect, -margins.top,
-margins.left);
- pageRect.size.width += margins.bottom - margins.top;
- pageRect.size.height += margins.right - margins.left;
- break;
- case 180:
- pageRect = NSInsetRect(pageRect, -margins.right,
-margins.top);
- pageRect.size.width += margins.left - margins.right;
- pageRect.size.height += margins.bottom - margins.top;
- break;
- case 270:
- pageRect = NSInsetRect(pageRect, -margins.bottom,
-margins.right);
- pageRect.size.width += margins.top - margins.bottom;
- pageRect.size.height += margins.left - margins.right;
- break;
- }
- }
- }
- return pageRect;
-}
-
// @@ Horizontal layout
- (IBAction)alternateZoomToFit:(id)sender {
PDFDisplayMode displayMode = [pdfView extendedDisplayMode];
NSRect frame = [pdfView frame];
PDFPage *page = [pdfView currentPage];
- NSRect pageRect = layoutBoundsForPage(page, pdfView);
+ NSRect pageRect = [pdfView layoutBoundsForPage:page];
CGFloat width, height;
CGFloat scrollerWidth = 0.0;
CGFloat scaleFactor;
@@ -928,7 +885,7 @@
NSSize size, oldSize = [[self pdfView] frame].size;
NSRect documentRect = [[[self pdfView] documentView] convertRect:[[[self
pdfView] documentView] bounds] toView:nil];
PDFPage *page = [[self pdfView] currentPage];
- NSRect pageRect = layoutBoundsForPage(page, pdfView);
+ NSRect pageRect = [pdfView layoutBoundsForPage:page];
oldSize.height -= [[[self pdfView] scrollView] contentInsets].top;
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/SKPDFView.m 2023-04-02 15:53:25 UTC (rev 13413)
@@ -4970,7 +4970,7 @@
PDFDestination *destination = [annotation linkDestination];
if ([destination page]) {
page = [destination page];
- point = [[destination
effectiveDestinationWithTargetSize:NSZeroSize] point];
+ point = [[destination effectiveDestinationForView:nil] point];
point = [self convertPoint:point fromPage:page];
point.y -= 0.5 * DEFAULT_SNAPSHOT_HEIGHT;
}
Modified: trunk/SKReadingBar.m
===================================================================
--- trunk/SKReadingBar.m 2023-04-02 14:59:03 UTC (rev 13412)
+++ trunk/SKReadingBar.m 2023-04-02 15:53:25 UTC (rev 13413)
@@ -312,7 +312,7 @@
}
if (dest) {
aPage = [dest page];
- point = [[dest effectiveDestinationWithTargetSize:NSZeroSize]
point];
+ point = [[dest effectiveDestinationForView:nil] point];
}
} else if ([location isKindOfClass:[SKLine class]]) {
aPage = [(SKLine *)location page];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit