Revision: 16004
http://sourceforge.net/p/skim-app/code/16004
Author: hofman
Date: 2026-01-12 16:07:08 +0000 (Mon, 12 Jan 2026)
Log Message:
-----------
combine scroll to page in single function
Modified Paths:
--------------
trunk/SKBasePDFView.m
Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m 2026-01-12 15:18:38 UTC (rev 16003)
+++ trunk/SKBasePDFView.m 2026-01-12 16:07:08 UTC (rev 16004)
@@ -251,24 +251,25 @@
[clipView scrollPoint:bounds.origin];
}
-static void verticallyScrollToPage(PDFView *pdfView, PDFPage *page, BOOL
scrollHorizontally) {
+static void scrollToPage(PDFView *pdfView, PDFPage *page, BOOL vertically,
BOOL horizontally) {
NSScrollView *scrollView = [pdfView embeddedScrollView];
NSRect pageRect = [pdfView convertRect:[page boundsForBox:[pdfView
displayBox]] fromPage:page];
NSPoint center = SKCenterPoint([pdfView bounds]);
- BOOL scrollVertically = (NSMinY(pageRect) > center.y - 0.5 * [scrollView
contentInsets].top || NSMaxY(pageRect) < center.y);
- scrollHorizontally = scrollHorizontally && (NSMinX(pageRect) > center.x ||
NSMaxX(pageRect) < center.x);
- if (scrollHorizontally == NO && scrollHorizontally == NO)
+ vertically = vertically && (NSMinY(pageRect) > center.y - 0.5 *
[scrollView contentInsets].top || NSMaxY(pageRect) < center.y);
+ horizontally = horizontally && (NSMinX(pageRect) > center.x ||
NSMaxX(pageRect) < center.x);
+ if (vertically == NO && horizontally == NO)
return;
NSClipView *clipView = [scrollView contentView];
NSRect bounds = [clipView bounds];
NSRect docRect = [[scrollView documentView] frame];
CGFloat margin = 0.0;
- if (scrollHorizontally && NSWidth(bounds) >= NSWidth(docRect)) {
- scrollHorizontally = NO;
- if (scrollVertically == NO)
+ if (horizontally && NSWidth(docRect) <= NSWidth(bounds)) {
+ horizontally = NO;
+ if (vertically == NO)
return;
}
- if (scrollVertically) {
+ pageRect = [pdfView convertRect:pageRect toView:clipView];
+ if (vertically) {
CGFloat inset = [clipView contentInsets].top;
CGFloat scrollerWidth = 0.0;
if ([pdfView displaysPageBreaks])
@@ -275,13 +276,12 @@
margin = [pdfView pageBreakMargins].top;
if ([scrollView hasHorizontalScroller] && [scrollView scrollerStyle]
== NSScrollerStyleLegacy)
scrollerWidth = [pdfView convertSize:NSMakeSize(0.0, [NSScroller
effectiveScrollerWidth]) toView:clipView].height;
- pageRect = [pdfView convertRect:pageRect toView:clipView];
if ([clipView isFlipped])
bounds.origin.y = fmin(fmax(fmin(NSMaxY(pageRect) - 0.5 *
(NSHeight(bounds) + fmax(scrollerWidth, inset)), NSMinY(pageRect) - margin -
inset), NSMinY(docRect) - inset), NSMaxY(docRect) - NSHeight(bounds));
else
bounds.origin.y = fmax(fmin(fmax(NSMinY(pageRect) - 0.5 *
(NSHeight(bounds) - fmax(scrollerWidth, inset)), NSMaxY(pageRect) + margin -
NSHeight(bounds) + inset), NSMaxY(docRect) - NSHeight(bounds) + inset),
NSMinY(docRect));
}
- if (scrollHorizontally) {
+ if (horizontally) {
if ([pdfView displaysPageBreaks])
margin = [pdfView pageBreakMargins].left;
bounds.origin.x = fmin(NSMinX(pageRect) - margin, NSMaxX(docRect) -
NSWidth(bounds));
@@ -289,25 +289,6 @@
[clipView scrollPoint:bounds.origin];
}
-static void horizontallyScrollToPage(PDFView *pdfView, PDFPage *page) {
- NSScrollView *scrollView = [pdfView embeddedScrollView];
- NSRect pageRect = [pdfView convertRect:[page boundsForBox:[pdfView
displayBox]] fromPage:page];
- CGFloat midX = NSMidX([pdfView bounds]);
- if (NSMinX(pageRect) <= midX && NSMaxX(pageRect) >= midX)
- return;
- NSClipView *clipView = [scrollView contentView];
- NSRect bounds = [clipView bounds];
- NSRect docRect = [[scrollView documentView] frame];
- if (NSWidth(bounds) >= NSWidth(docRect))
- return;
- CGFloat margin = 0.0;
- if ([pdfView displaysPageBreaks])
- margin = [pdfView pageBreakMargins].left;
- pageRect = [pdfView convertRect:pageRect toView:clipView];
- bounds.origin.x = fmin(NSMinX(pageRect) - margin, NSMaxX(docRect) -
NSWidth(bounds));
- [clipView scrollPoint:bounds.origin];
-}
-
static void verticallyScrollToTop(PDFView *pdfView) {
NSScrollView *scrollView = [pdfView embeddedScrollView];
NSClipView *clipView = [scrollView contentView];
@@ -353,7 +334,7 @@
}
[super goToPreviousPage:sender];
if (page)
- verticallyScrollToPage(self, page, NO);
+ scrollToPage(self, page, YES, NO);
}
}
@@ -374,7 +355,7 @@
}
[super goToNextPage:sender];
if (page)
- verticallyScrollToPage(self, page, NO);
+ scrollToPage(self, page, YES, NO);
}
}
@@ -403,10 +384,9 @@
horizontallyGoToPage(self, page);
} else {
[self goToPage:page];
- if (hasVerticalLayout(self))
- verticallyScrollToPage(self, page, [self displayMode] ==
kPDFDisplayTwoUpContinuous);
- else if ([self displayMode] == kPDFDisplayTwoUp)
- horizontallyScrollToPage(self, page);
+ PDFDisplayMode displayMode = [self displayMode];
+ if (displayMode != kPDFDisplaySinglePage)
+ scrollToPage(self, page, (displayMode &
kPDFDisplaySinglePageContinuous) != 0, (displayMode & kPDFDisplayTwoUp) != 0);
}
}
@@ -422,7 +402,7 @@
dest.point.y -= NSHeight([clipView bounds]) - [clipView
contentInsets].top;
[clipView scrollPoint:dest.point];
} else if (hasVerticalLayout(self)) {
- verticallyScrollToPage(self, page, NO);
+ scrollToPage(self, page, YES, NO);
}
}
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