Revision: 13415 http://sourceforge.net/p/skim-app/code/13415 Author: hofman Date: 2023-04-02 21:31:28 +0000 (Sun, 02 Apr 2023) Log Message: ----------- Set scaleFactor when destination has a zoom. Center page when fitting to a rectangle.
Modified Paths: -------------- trunk/PDFDestination_SKExtensions.m trunk/SKBasePDFView.m Modified: trunk/PDFDestination_SKExtensions.m =================================================================== --- trunk/PDFDestination_SKExtensions.m 2023-04-02 16:20:18 UTC (rev 13414) +++ trunk/PDFDestination_SKExtensions.m 2023-04-02 21:31:28 UTC (rev 13415) @@ -48,7 +48,7 @@ PDFPage *page = [self page]; NSRect bounds = NSZeroRect; NSSize size = pdfView ? [pdfView visibleContentRect].size : NSZeroSize; - CGFloat zoom = kPDFDestinationUnspecifiedValue; + CGFloat zoomX = kPDFDestinationUnspecifiedValue, zoomY = kPDFDestinationUnspecifiedValue; BOOL override = YES; NSInteger type = 0; @try { type = [[self valueForKeyPath:RUNNING_BEFORE(10_12) ? @"_pdfPriv.type" : @"_private.type"] doubleValue]; } @@ -59,8 +59,10 @@ break; case 1: // Fit bounds = pdfView ? [pdfView layoutBoundsForPage:page] : [page boundsForBox:kPDFDisplayBoxCropBox]; - if (pdfView && NSIsEmptyRect(bounds) == NO) - zoom = fmin(size.width / NSWidth(bounds), size.height / NSHeight(bounds)); + if (pdfView && NSIsEmptyRect(bounds) == NO) { + zoomX = size.width / NSWidth(bounds); + zoomY = size.height / NSHeight(bounds); + } break; case 2: // FitH bounds = pdfView ? [pdfView layoutBoundsForPage:page] : [page boundsForBox:kPDFDisplayBoxCropBox]; @@ -67,7 +69,7 @@ @try { point.y = [[self valueForKeyPath:RUNNING_BEFORE(10_12) ? @"_pdfPriv.top" : @"_private.top"] doubleValue]; } @catch (id e) { override = NO; } if (override && pdfView && NSIsEmptyRect(bounds) == NO) - zoom = size.width / NSWidth(bounds); + zoomX = zoomY = size.width / NSWidth(bounds); break; case 3: // FitV bounds = pdfView ? [pdfView layoutBoundsForPage:page] : [page boundsForBox:kPDFDisplayBoxCropBox]; @@ -74,7 +76,7 @@ @try { point.x = [[self valueForKeyPath:RUNNING_BEFORE(10_12) ? @"_pdfPriv.left" : @"_private.left"] doubleValue]; } @catch (id e) { override = NO; } if (override && pdfView && NSIsEmptyRect(bounds) == NO) - zoom = size.height / NSHeight(bounds); + zoomX = zoomY = size.height / NSHeight(bounds); break; case 4: // FitR { @@ -86,14 +88,18 @@ @catch (id e) { override = NO; } @try { bounds.size.height = [[self valueForKeyPath:RUNNING_BEFORE(10_12) ? @"_pdfPriv.top" : @"_private.top"] doubleValue] - NSMinY(bounds); } @catch (id e) { override = NO; } - if (override && pdfView && NSIsEmptyRect(bounds) == NO) - zoom = fmin(size.width / NSWidth(bounds), size.height / NSHeight(bounds)); + if (override && pdfView && NSIsEmptyRect(bounds) == NO) { + zoomX = size.width / NSWidth(bounds); + zoomY = size.height / NSHeight(bounds); + } break; } case 5: // FitB bounds = [page foregroundRect]; - if (pdfView && NSIsEmptyRect(bounds) == NO) - zoom = fmin(size.width / NSWidth(bounds), size.height / NSHeight(bounds)); + if (pdfView && NSIsEmptyRect(bounds) == NO) { + zoomX = size.width / NSWidth(bounds); + zoomY = size.height / NSHeight(bounds); + } break; case 6: // FitBH bounds = [page foregroundRect]; @@ -100,7 +106,7 @@ @try { point.y = [[self valueForKeyPath:RUNNING_BEFORE(10_12) ? @"_pdfPriv.top" : @"_private.top"] doubleValue]; } @catch (id e) { override = NO; } if (override && pdfView && NSIsEmptyRect(bounds) == NO) - zoom = size.width / NSWidth(bounds); + zoomX = zoomY = size.width / NSWidth(bounds); break; case 7: // FitBV bounds = [page foregroundRect]; @@ -107,7 +113,7 @@ @try { point.x = [[self valueForKeyPath:RUNNING_BEFORE(10_12) ? @"_pdfPriv.left" : @"_private.left"] doubleValue]; } @catch (id e) { override = NO; } if (override && pdfView && NSIsEmptyRect(bounds) == NO) - zoom = size.height / NSHeight(bounds); + zoomX = zoomY = size.height / NSHeight(bounds); break; default: override = NO; @@ -118,9 +124,13 @@ point.x = NSMinX(bounds); if (point.y >= kPDFDestinationUnspecifiedValue) point.y = NSMaxY(bounds); + if (zoomX < zoomY) + point.y += 0.5 * (zoomY / zoomX - 1.0) * NSHeight(bounds); + else if (zoomX > zoomY) + point.x -= 0.5 * (zoomX / zoomY - 1.0) * NSWidth(bounds); PDFDestination *destination = [[[PDFDestination alloc] initWithPage:page atPoint:point] autorelease]; - if (zoom < kPDFDestinationUnspecifiedValue) - [destination setZoom:zoom]; + if (zoomX < kPDFDestinationUnspecifiedValue) + [destination setZoom:fmin(zoomX, zoomY)]; return destination; } } Modified: trunk/SKBasePDFView.m =================================================================== --- trunk/SKBasePDFView.m 2023-04-02 16:20:18 UTC (rev 13414) +++ trunk/SKBasePDFView.m 2023-04-02 21:31:28 UTC (rev 13415) @@ -398,7 +398,10 @@ } - (void)goToDestination:(PDFDestination *)destination { - [super goToDestination:[destination effectiveDestinationForView:self]]; + destination = [destination effectiveDestinationForView:self]; + if ([destination zoom] < kPDFDestinationUnspecifiedValue && [destination zoom] > 0.0) + [self setScaleFactor:[destination zoom]]; + [super goToDestination:destination]; } @end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit