Revision: 13411 http://sourceforge.net/p/skim-app/code/13411 Author: hofman Date: 2023-04-02 08:32:49 +0000 (Sun, 02 Apr 2023) Log Message: ----------- cache non empty content rect separately and add margins for foregroundBox in accessor, so we can use just the context for destination
Modified Paths: -------------- trunk/PDFDestination_SKExtensions.m trunk/PDFPage_SKExtensions.h trunk/PDFPage_SKExtensions.m trunk/SKPDFPage.h trunk/SKPDFPage.m Modified: trunk/PDFDestination_SKExtensions.m =================================================================== --- trunk/PDFDestination_SKExtensions.m 2023-04-02 08:19:15 UTC (rev 13410) +++ trunk/PDFDestination_SKExtensions.m 2023-04-02 08:32:49 UTC (rev 13411) @@ -55,15 +55,15 @@ override = NO; break; case 1: // Fit - bounds = [page foregroundBox]; + bounds = [page foregroundRect]; break; case 2: // FitH - bounds = [page foregroundBox]; + bounds = [page foregroundRect]; @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 foregroundBox]; + bounds = [page foregroundRect]; @try { point.x = [[self valueForKeyPath:RUNNING_BEFORE(10_12) ? @"_pdfPriv.left" : @"_private.left"] doubleValue]; } @catch (id e) { override = NO; } break; Modified: trunk/PDFPage_SKExtensions.h =================================================================== --- trunk/PDFPage_SKExtensions.h 2023-04-02 08:19:15 UTC (rev 13410) +++ trunk/PDFPage_SKExtensions.h 2023-04-02 08:32:49 UTC (rev 13411) @@ -55,6 +55,7 @@ + (BOOL)usesSequentialPageNumbering; + (void)setUsesSequentialPageNumbering:(BOOL)flag; +- (NSRect)foregroundRect; - (NSRect)foregroundBox; - (NSImage *)thumbnailWithSize:(CGFloat)size forBox:(PDFDisplayBox)box; Modified: trunk/PDFPage_SKExtensions.m =================================================================== --- trunk/PDFPage_SKExtensions.m 2023-04-02 08:19:15 UTC (rev 13410) +++ trunk/PDFPage_SKExtensions.m 2023-04-02 08:32:49 UTC (rev 13411) @@ -139,24 +139,26 @@ } // this will be cached in our custom subclass -- (NSRect)foregroundBox { - CGFloat marginWidth = [[NSUserDefaults standardUserDefaults] floatForKey:SKAutoCropBoxMarginWidthKey]; - CGFloat marginHeight = [[NSUserDefaults standardUserDefaults] floatForKey:SKAutoCropBoxMarginHeightKey]; +- (NSRect)foregroundRect { NSBitmapImageRep *imageRep = [self newBitmapImageRepForBox:kPDFDisplayBoxMediaBox]; NSRect bounds = [self boundsForBox:kPDFDisplayBoxMediaBox]; - NSRect foregroundBox = [imageRep foregroundRect]; + NSRect foregroundRect = [imageRep foregroundRect]; if (imageRep == nil) { - foregroundBox = bounds; - } else if (NSIsEmptyRect(foregroundBox)) { - foregroundBox.origin = SKIntegralPoint(SKCenterPoint(bounds)); - foregroundBox.size = NSZeroSize; + foregroundRect = bounds; + } else if (NSIsEmptyRect(foregroundRect)) { + foregroundRect.origin = SKIntegralPoint(SKCenterPoint(bounds)); + foregroundRect.size = NSZeroSize; } else { - foregroundBox.origin = SKAddPoints(foregroundBox.origin, bounds.origin); + foregroundRect.origin = SKAddPoints(foregroundRect.origin, bounds.origin); } [imageRep release]; - return NSIntersectionRect(NSInsetRect(foregroundBox, -marginWidth, -marginHeight), bounds); + return foregroundRect; } +- (NSRect)foregroundBox { + return NSIntersectionRect(NSInsetRect([self foregroundRect], -[[NSUserDefaults standardUserDefaults] floatForKey:SKAutoCropBoxMarginWidthKey], -[[NSUserDefaults standardUserDefaults] floatForKey:SKAutoCropBoxMarginHeightKey]), [self boundsForBox:kPDFDisplayBoxCropBox]); +} + - (NSImage *)thumbnailWithSize:(CGFloat)aSize forBox:(PDFDisplayBox)box { return [self thumbnailWithSize:aSize forBox:box readingBar:nil]; } Modified: trunk/SKPDFPage.h =================================================================== --- trunk/SKPDFPage.h 2023-04-02 08:19:15 UTC (rev 13410) +++ trunk/SKPDFPage.h 2023-04-02 08:32:49 UTC (rev 13411) @@ -41,7 +41,7 @@ @interface SKPDFPage : PDFPage { - NSRect foregroundBox; + NSRect foregroundRect; NSInteger intrinsicRotation; NSInteger characterDirectionAngle; NSInteger lineDirectionAngle; Modified: trunk/SKPDFPage.m =================================================================== --- trunk/SKPDFPage.m 2023-04-02 08:19:15 UTC (rev 13410) +++ trunk/SKPDFPage.m 2023-04-02 08:32:49 UTC (rev 13411) @@ -61,15 +61,15 @@ - (BOOL)isEditable { return YES; } // cache the value calculated in the superclass -- (NSRect)foregroundBox { - if (NSEqualRects(NSZeroRect, foregroundBox)) - foregroundBox = [super foregroundBox]; - return foregroundBox; +- (NSRect)foregroundRect { + if (NSEqualRects(NSZeroRect, foregroundRect)) + foregroundRect = [super foregroundRect]; + return foregroundRect; } - (void)setBounds:(NSRect)bounds forBox:(PDFDisplayBox)box { if (box == kPDFDisplayBoxCropBox) - foregroundBox = NSZeroRect; + foregroundRect = NSZeroRect; [super setBounds:bounds forBox:box]; } @@ -95,14 +95,14 @@ } - (void)addAnnotation:(PDFAnnotation *)annotation { - if (NSContainsRect(foregroundBox, [annotation bounds]) == NO) - foregroundBox = NSZeroRect; + if (NSContainsRect(foregroundRect, [annotation bounds]) == NO) + foregroundRect = NSZeroRect; [super addAnnotation:annotation]; } - (void)removeAnnotation:(PDFAnnotation *)annotation { - if (NSContainsRect(foregroundBox, [annotation bounds]) == NO) - foregroundBox = NSZeroRect; + if (NSContainsRect(foregroundRect, [annotation bounds]) == NO) + foregroundRect = NSZeroRect; [super removeAnnotation:annotation]; } 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