Revision: 15185
          http://sourceforge.net/p/skim-app/code/15185
Author:   hofman
Date:     2025-05-11 14:59:46 +0000 (Sun, 11 May 2025)
Log Message:
-----------
There shouldbe no need to clip the bitmaps to the pages. Pass intersectied rect 
and forward flag to animation block.

Modified Paths:
--------------
    trunk/SKPresentationView.m
    trunk/SKTransitionController.h
    trunk/SKTransitionController.m

Modified: trunk/SKPresentationView.m
===================================================================
--- trunk/SKPresentationView.m  2025-05-11 14:14:19 UTC (rev 15184)
+++ trunk/SKPresentationView.m  2025-05-11 14:59:46 UTC (rev 15185)
@@ -164,7 +164,7 @@
     if (([aPage rotation] % 180) != 0)
         pageRect = NSMakeRect(0.0, 0.0, NSHeight(pageRect), NSWidth(pageRect));
     CGFloat scale = [self autoScales] ? fmin(NSHeight(bounds) / 
NSHeight(pageRect), NSWidth(bounds) / NSWidth(pageRect)) : 1.0;
-    return NSInsetRect(bounds, 0.5 * (NSWidth(bounds) - scale * 
NSWidth(pageRect)), 0.5 * (NSHeight(bounds) - scale * NSHeight(pageRect)));
+    return NSInsetRect(bounds, 0.5 * fmax(0.0, NSWidth(bounds) - scale * 
NSWidth(pageRect)), 0.5 * fmax(0.0, NSHeight(bounds) - scale * 
NSHeight(pageRect)));
 }
 
 static inline BOOL equalStrings(NSString *s1, NSString *s2) {
@@ -174,9 +174,10 @@
 - (BOOL)animateTransitionAtIndex:(NSUInteger)idx forward:(BOOL)forward 
toPage:(PDFPage *)toPage {
     if ([transitionController pageTransitions] ||
         ([[transitionController transition] style] != SKNoTransition && 
equalStrings([page label], [toPage label]) == NO)) {
-        SKTransitionAnimation animation = [transitionController 
animationAtIndex:idx forView:self fromRect:[self pageRect:page] toRect:[self 
pageRect:toPage] forward:forward];
+        SKTransitionAnimation animation = [transitionController 
animationAtIndex:idx forView:self];
         if (animation) {
-            [self setPage:toPage completionHandler:^{ animation(nil); }];
+            NSRect rect = NSUnionRect([self pageRect:page], [self 
pageRect:toPage]);
+            [self setPage:toPage completionHandler:^{ animation(rect, forward, 
nil); }];
             return YES;
         }
     }
@@ -188,8 +189,13 @@
     NSUInteger idx = [page pageIndex];
     if (idx + 1 < [pdfDoc pageCount]) {
         PDFPage *toPage = [pdfDoc pageAtIndex:idx + 1];
-        SKTransitionAnimation animation = [transitionController 
animationAtIndex:idx forView:self fromRect:[self pageRect:page] toRect:[self 
pageRect:toPage] forward:YES];
-        [self setPage:toPage completionHandler:animation ? ^{ 
animation(completionHandler); } : completionHandler];
+        SKTransitionAnimation animation = [transitionController 
animationAtIndex:idx forView:self];
+        if (animation) {
+            NSRect rect = NSUnionRect([self pageRect:page], [self 
pageRect:toPage]);
+            [self setPage:toPage completionHandler:^{ animation(rect, YES, 
completionHandler); }];
+        } else {
+            [self setPage:toPage completionHandler:completionHandler];
+        }
     } else {
         completionHandler();
     }

Modified: trunk/SKTransitionController.h
===================================================================
--- trunk/SKTransitionController.h      2025-05-11 14:14:19 UTC (rev 15184)
+++ trunk/SKTransitionController.h      2025-05-11 14:59:46 UTC (rev 15185)
@@ -40,7 +40,7 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
-typedef void (^SKTransitionAnimation)(void (^ _Nullable 
completionHandler)(void));
+typedef void (^SKTransitionAnimation)(NSRect rect, BOOL forward, void (^ 
_Nullable completionHandler)(void));
 
 @class SKTransitionView, SKTransitionInfo;
 
@@ -58,7 +58,7 @@
 
 @property (nonatomic) BOOL shouldScale;
 
-- (nullable SKTransitionAnimation)animationAtIndex:(NSUInteger)anIndex 
forView:(NSView *)view fromRect:(NSRect)rect toRect:(NSRect)toRect 
forward:(BOOL)forward;
+- (nullable SKTransitionAnimation)animationAtIndex:(NSUInteger)anIndex 
forView:(NSView *)view;
 
 @end
 

Modified: trunk/SKTransitionController.m
===================================================================
--- trunk/SKTransitionController.m      2025-05-11 14:14:19 UTC (rev 15184)
+++ trunk/SKTransitionController.m      2025-05-11 14:59:46 UTC (rev 15185)
@@ -154,12 +154,10 @@
     return transitionFilter;
 }
 
-- (CIImage *)currentImageForRect:(NSRect)rect inView:(NSView *)view 
scale:(CGFloat *)scalePtr {
+- (CIImage *)currentImageForView:(NSView *)view scale:(CGFloat *)scalePtr {
     NSRect bounds = [view bounds];
     NSBitmapImageRep *contentBitmap = [view bitmapImageRepCachingDisplay];
-    CIImage *tmpImage = [[CIImage alloc] initWithBitmapImageRep:contentBitmap];
-    CGFloat scale = CGRectGetWidth([tmpImage extent]) / NSWidth(bounds);
-    CIImage *image = [tmpImage 
imageByCroppingToRect:CGRectIntegral(scaleRect(NSIntersectionRect(rect, 
bounds), scale))];
+    CIImage *image = [[CIImage alloc] initWithBitmapImageRep:contentBitmap];
     NSArray *colorFilters = SKColorEffectFilters();
     if ([colorFilters count] > 0) {
         for (CIFilter *filter in colorFilters) {
@@ -167,11 +165,11 @@
             image = [filter outputImage];
         }
     }
-    if (scalePtr) *scalePtr = scale;
+    if (scalePtr) *scalePtr = CGRectGetWidth([image extent]) / NSWidth(bounds);
     return image;
 }
 
-- (SKTransitionAnimation)animationAtIndex:(NSUInteger)idx forView:(NSView 
*)view fromRect:(NSRect)rect toRect:(NSRect)toRect forward:(BOOL)forward {
+- (SKTransitionAnimation)animationAtIndex:(NSUInteger)idx forView:(NSView 
*)view {
     if (animating)
         return nil;
     
@@ -184,14 +182,14 @@
     
     animating = YES;
     
-    CIImage *initialImage = [self currentImageForRect:rect inView:view 
scale:NULL];
+    CIImage *initialImage = [self currentImageForView:view scale:NULL];
     
-    return ^(void (^completionHandler)(void)){
+    return ^(NSRect rect, BOOL forward, void (^completionHandler)(void)){
         
         NSRect bounds = [view bounds];
         CGFloat imageScale = 1.0;
-        CIImage *finalImage = [self currentImageForRect:toRect inView:view 
scale:&imageScale];
-        CGRect cgRect = 
CGRectIntegral(scaleRect(NSIntersectionRect(NSUnionRect(rect, toRect), bounds), 
imageScale));
+        CIImage *finalImage = [self currentImageForView:view 
scale:&imageScale];
+        CGRect cgRect = CGRectIntegral(scaleRect(rect, imageScale));
         CGRect cgBounds = scaleRect(bounds, imageScale);
         CGRect extent = [currentTransition shouldRestrict] ? cgRect : cgBounds;
         NSString *filterName = [currentTransition styleName];

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

Reply via email to