Revision: 14223
          http://sourceforge.net/p/skim-app/code/14223
Author:   hofman
Date:     2024-04-19 14:29:19 +0000 (Fri, 19 Apr 2024)
Log Message:
-----------
define function to get pixel aligned rect in one place

Modified Paths:
--------------
    trunk/NSGraphics_SKExtensions.h
    trunk/NSGraphics_SKExtensions.m
    trunk/SKBasePDFView.m
    trunk/SKLoupeController.m
    trunk/SKMainWindowController_FullScreen.m

Modified: trunk/NSGraphics_SKExtensions.h
===================================================================
--- trunk/NSGraphics_SKExtensions.h     2024-04-19 09:37:09 UTC (rev 14222)
+++ trunk/NSGraphics_SKExtensions.h     2024-04-19 14:29:19 UTC (rev 14223)
@@ -55,6 +55,10 @@
 
 #pragma mark -
 
+extern CGRect SKPixelAlignedRect(CGRect rect, CGContextRef context);
+
+#pragma mark -
+
 extern NSArray *SKColorEffectFilters(void);
 
 NS_ASSUME_NONNULL_END

Modified: trunk/NSGraphics_SKExtensions.m
===================================================================
--- trunk/NSGraphics_SKExtensions.m     2024-04-19 09:37:09 UTC (rev 14222)
+++ trunk/NSGraphics_SKExtensions.m     2024-04-19 14:29:19 UTC (rev 14223)
@@ -156,7 +156,18 @@
     [cell drawWithFrame:rect inView:controlView];
     [cell setControlView:nil];
 }
+#pragma mark -
 
+CGRect SKPixelAlignedRect(CGRect rect, CGContextRef context) {
+    CGRect r;
+    rect = CGContextConvertRectToDeviceSpace(context, rect);
+    r.origin.x = round(CGRectGetMinX(rect));
+    r.origin.y = round(CGRectGetMinY(rect));
+    r.size.width = round(CGRectGetMaxX(rect)) - r.origin.x;
+    r.size.height = round(CGRectGetMaxY(rect)) - r.origin.y;
+    return CGRectGetWidth(r) > 0.0 && CGRectGetHeight(r) > 0.0 ? 
CGContextConvertRectToUserSpace(context, r) : CGRectZero;
+}
+
 #pragma mark -
 
 #define LR 0.2126
@@ -163,7 +174,7 @@
 #define LG 0.7152
 #define LB 0.0722
 
-extern NSArray *SKColorEffectFilters(void) {
+NSArray *SKColorEffectFilters(void) {
     NSMutableArray *filters = [NSMutableArray array];
     CIFilter *filter;
     CGFloat sepia = [[NSUserDefaults standardUserDefaults] 
doubleForKey:SKSepiaToneKey];

Modified: trunk/SKBasePDFView.m
===================================================================
--- trunk/SKBasePDFView.m       2024-04-19 09:37:09 UTC (rev 14222)
+++ trunk/SKBasePDFView.m       2024-04-19 14:29:19 UTC (rev 14223)
@@ -362,16 +362,6 @@
     }
 }
 
-static inline CGRect SKPixelAlignedRect(CGRect rect, CGContextRef context) {
-    CGRect r;
-    rect = CGContextConvertRectToDeviceSpace(context, rect);
-    r.origin.x = round(CGRectGetMinX(rect));
-    r.origin.y = round(CGRectGetMinY(rect));
-    r.size.width = round(CGRectGetMaxX(rect)) - r.origin.x;
-    r.size.height = round(CGRectGetMaxY(rect)) - r.origin.y;
-    return CGRectGetWidth(r) > 0.0 && CGRectGetHeight(r) > 0.0 ? 
CGContextConvertRectToUserSpace(context, r) : CGRectZero;
-}
-
 - (void)drawPagesInRect:(NSRect)rect toContext:(CGContextRef)context {
     PDFDisplayBox *box = [self displayBox];
     CGFloat scale = [self scaleFactor];

Modified: trunk/SKLoupeController.m
===================================================================
--- trunk/SKLoupeController.m   2024-04-19 09:37:09 UTC (rev 14222)
+++ trunk/SKLoupeController.m   2024-04-19 14:29:19 UTC (rev 14223)
@@ -230,15 +230,6 @@
     return YES;
 }
 
-static inline CGRect SKPixelAlignedRect(CGRect rect, CGFloat scale) {
-    CGRect r;
-    r.origin.x = round(CGRectGetMinX(rect) * scale) / scale;
-    r.origin.y = round(CGRectGetMinY(rect) * scale) / scale;
-    r.size.width = round(CGRectGetMaxX(rect) * scale) / scale - r.origin.x;
-    r.size.height = round(CGRectGetMaxY(rect) * scale) / scale - r.origin.y;
-    return CGRectGetWidth(r) > 0.0 && CGRectGetHeight(r) > 0.0 ? r : 
CGRectZero;
-}
-
 - (void)drawLayer:(CALayer *)aLayer inContext:(CGContextRef)context {
     NSPoint mouseLoc = [pdfView convertPointFromScreen:[NSEvent 
mouseLocation]];
     
@@ -264,7 +255,6 @@
     CGInterpolationQuality interpolation = [pdfView interpolationQuality] + 1;
     PDFDisplayBox box = [pdfView displayBox];
     NSRect scaledRect = NSMakeRect(mouseLoc.x + (NSMinX(magRect) - mouseLoc.x) 
/ magnification, mouseLoc.y + (NSMinY(magRect) - mouseLoc.y) / magnification, 
NSWidth(magRect) / magnification, NSHeight(magRect) / magnification);
-    CGFloat backingScale = [window backingScaleFactor];
     NSRange pageRange;
     if ([pdfView displaysRTL] && ([pdfView displayMode] & kPDFDisplayTwoUp)) {
         pageRange.location = [[pdfView 
pageForPoint:SKTopRightPoint(scaledRect) nearest:YES] pageIndex];
@@ -283,7 +273,7 @@
         CGRect pageRect = NSRectToCGRect([pdfView convertRect:[page 
boundsForBox:box] fromPage:page]);
         CGPoint pageOrigin = pageRect.origin;
         
-        pageRect = SKPixelAlignedRect(CGRectApplyAffineTransform(pageRect, t), 
backingScale);
+        pageRect = SKPixelAlignedRect(CGRectApplyAffineTransform(pageRect, t), 
context);
         
         // only draw the page when there is something to draw
         if (CGRectIntersectsRect(shadedRect, pageRect) == NO)

Modified: trunk/SKMainWindowController_FullScreen.m
===================================================================
--- trunk/SKMainWindowController_FullScreen.m   2024-04-19 09:37:09 UTC (rev 
14222)
+++ trunk/SKMainWindowController_FullScreen.m   2024-04-19 14:29:19 UTC (rev 
14223)
@@ -345,16 +345,6 @@
     [window setAlphaValue:0.0];
 }
 
-static inline CGRect SKPixelAlignedRect(CGRect rect, CGContextRef context) {
-    CGRect r;
-    rect = CGContextConvertRectToDeviceSpace(context, rect);
-    r.origin.x = round(CGRectGetMinX(rect));
-    r.origin.y = round(CGRectGetMinY(rect));
-    r.size.width = round(CGRectGetMaxX(rect)) - r.origin.x;
-    r.size.height = round(CGRectGetMaxY(rect)) - r.origin.y;
-    return CGRectGetWidth(r) > 0.0 && CGRectGetHeight(r) > 0.0 ? 
CGContextConvertRectToUserSpace(context, r) : CGRectZero;
-}
-
 - (void)displayStaticContentInPresentationWindow:(NSWindow *)window {
     NSRect rect = [[window contentView] bounds];
     NSBitmapImageRep *imageRep = nil;

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

Reply via email to