Revision: 13165
          http://sourceforge.net/p/skim-app/code/13165
Author:   hofman
Date:     2022-11-11 15:33:25 +0000 (Fri, 11 Nov 2022)
Log Message:
-----------
Shadow radius for selected freehand note smaller at small zoom. Draw image in 
context without intermediate CGImage.

Modified Paths:
--------------
    trunk/PDFAnnotationInk_SKExtensions.m
    trunk/SKPDFView.m

Modified: trunk/PDFAnnotationInk_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationInk_SKExtensions.m       2022-11-11 09:55:29 UTC (rev 
13164)
+++ trunk/PDFAnnotationInk_SKExtensions.m       2022-11-11 15:33:25 UTC (rev 
13165)
@@ -265,23 +265,24 @@
 }
 
 - (void)drawSelectionHighlightForView:(PDFView *)pdfView 
inContext:(CGContextRef)context {
-    [super drawSelectionHighlightForView:pdfView inContext:context];
     if (NSIsEmptyRect([self bounds]) == NO && [self isSkimNote]) {
         CGFloat scale = 1.0 / [pdfView unitWidthOnPage:[self page]];
-        NSRect bounds = [self bounds];
-        NSRect rect = NSMakeRect(0.0, 0.0, ceil(scale * NSWidth(bounds)), 
ceil(scale * NSHeight(bounds)));
-        bounds.size = NSMakeSize(NSWidth(rect) / scale, NSHeight(rect) / 
scale);
+        CGFloat r = fmin(2.0 * scale, 2.0);
         NSSize offset = NSZeroSize;
         switch ([[self page] rotation]) {
-            case 0:   offset.height = -2.0; break;
-            case 90:  offset.width = 2.0;   break;
-            case 180: offset.height = 2.0;  break;
-            case 270: offset.width = -2.0;  break;
-            default:  offset.height = -2.0; break;
+            case 0:   offset.height = -r; break;
+            case 90:  offset.width = r;   break;
+            case 180: offset.height = r;  break;
+            case 270: offset.width = -r;  break;
+            default:  offset.height = -r; break;
         }
+        NSRect bounds = NSOffsetRect(NSInsetRect([self bounds], -r / scale, -r 
/ scale), offset.width / scale, offset.height / scale);
+        NSRect rect = NSMakeRect(0.0, 0.0, ceil(scale * NSWidth(bounds)), 
ceil(scale * NSHeight(bounds)));
+        bounds.size = NSMakeSize(NSWidth(rect) / scale, NSHeight(rect) / 
scale);
         NSImage *image = [[NSImage alloc] initWithSize:rect.size];
         [image lockFocus];
         NSAffineTransform *transform = [NSAffineTransform transform];
+        [transform translateXBy:r - offset.width yBy:r - offset.height];
         [transform scaleBy:scale];
         [transform concat];
         NSBezierPath *path = [NSBezierPath bezierPath];
@@ -296,7 +297,7 @@
             [path setLineCapStyle:NSRoundLineCapStyle];
         }
         [NSGraphicsContext saveGraphicsState];
-        [NSShadow setShadowWithColor:[NSColor colorWithGenericGamma22White:0.0 
alpha:0.33333] blurRadius:2.0 offset:offset];
+        [NSShadow setShadowWithColor:[NSColor colorWithGenericGamma22White:0.0 
alpha:0.33333] blurRadius:r offset:offset];
         [[NSColor colorWithGenericGamma22White:0.0 alpha:[[self color] 
alphaComponent]] setStroke];
         [path stroke];
         [NSGraphicsContext restoreGraphicsState];
@@ -304,10 +305,13 @@
         [[NSColor blackColor] setStroke];
         [path stroke];
         [image unlockFocus];
-        CGImageRef cgImage = [image CGImageForProposedRect:&rect 
context:[NSGraphicsContext graphicsContextWithCGContext:context flipped:NO] 
hints:nil];
+        [NSGraphicsContext saveGraphicsState];
+        [NSGraphicsContext setCurrentContext:[NSGraphicsContext 
graphicsContextWithCGContext:context flipped:NO]];
+        [image drawInRect:bounds];
+        [NSGraphicsContext restoreGraphicsState];
         [image release];
-        CGContextDrawImage(context, NSRectToCGRect(bounds), cgImage);
     }
+    [super drawSelectionHighlightForView:pdfView inContext:context];
 }
 
 - (NSArray *)pointLists {

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2022-11-11 09:55:29 UTC (rev 13164)
+++ trunk/SKPDFView.m   2022-11-11 15:33:25 UTC (rev 13165)
@@ -4370,6 +4370,7 @@
     CAShapeLayer *layer = nil;
     NSRect boxBounds = NSIntersectionRect([page boundsForBox:[self 
displayBox]], [self convertRect:[self visibleContentRect] toPage:page]);
     CGAffineTransform t = 
CGAffineTransformRotate(CGAffineTransformMakeScale([self scaleFactor], [self 
scaleFactor]), -M_PI_2 * [page rotation] / 90.0);
+    CGFloat r = fmin(2.0, 2.0 * [self scaleFactor]);
     layer = [CAShapeLayer layer];
     // transform and place so that the path is in page coordinates
     [layer setBounds:NSRectToCGRect(boxBounds)];
@@ -4388,8 +4389,8 @@
             [layer setLineDashPattern:[activeAnnotation dashPattern]];
             [layer setLineCap:kCALineCapButt];
         }
-        [layer setShadowRadius:2.0 / [self scaleFactor]];
-        [layer setShadowOffset:CGSizeApplyAffineTransform(CGSizeMake(0.0, 
-2.0), CGAffineTransformInvert(t))];
+        [layer setShadowRadius:r / [self scaleFactor]];
+        [layer setShadowOffset:CGSizeApplyAffineTransform(CGSizeMake(0.0, -r), 
CGAffineTransformInvert(t))];
         [layer setShadowOpacity:0.33333];
     } else {
         [self setActiveAnnotation:nil];

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