Revision: 14359
http://sourceforge.net/p/skim-app/code/14359
Author: hofman
Date: 2024-07-01 15:52:58 +0000 (Mon, 01 Jul 2024)
Log Message:
-----------
Add NSBezierPath with affine transform to a CGMutablePathRef instead of copying
a CGPath
Modified Paths:
--------------
trunk/NSBezierPath_SKExtensions.h
trunk/NSBezierPath_SKExtensions.m
trunk/PDFAnnotationInk_SKExtensions.m
trunk/SKPDFView.m
Modified: trunk/NSBezierPath_SKExtensions.h
===================================================================
--- trunk/NSBezierPath_SKExtensions.h 2024-07-01 14:39:39 UTC (rev 14358)
+++ trunk/NSBezierPath_SKExtensions.h 2024-07-01 15:52:58 UTC (rev 14359)
@@ -47,7 +47,7 @@
- (NSPoint)associatedPointForElementAtIndex:(NSUInteger)anIndex;
-- (CGPathRef)copyCGPathWithScaleFactor:(CGFloat)scale;
+- (void)addToCGPath:(CGMutablePathRef)path transform:(const CGAffineTransform
* __nullable)m;
- (void)halfEllipseFromPoint:(NSPoint)halfwayPoint toPoint:(NSPoint)endPoint;
Modified: trunk/NSBezierPath_SKExtensions.m
===================================================================
--- trunk/NSBezierPath_SKExtensions.m 2024-07-01 14:39:39 UTC (rev 14358)
+++ trunk/NSBezierPath_SKExtensions.m 2024-07-01 15:52:58 UTC (rev 14359)
@@ -92,8 +92,7 @@
return bounds;
}
-- (CGPathRef)copyCGPathWithScaleFactor:(CGFloat)scale {
- CGMutablePathRef mutablePath = CGPathCreateMutable();
+- (void)addToCGPath:(CGMutablePathRef)mutablePath transform:(const
CGAffineTransform * __nullable)m {
NSInteger numElements = [self elementCount];
NSPoint points[3];
NSInteger i;
@@ -101,13 +100,13 @@
for (i = 0; i < numElements; i++) {
switch ([self elementAtIndex:i associatedPoints:points]) {
case NSMoveToBezierPathElement:
- CGPathMoveToPoint(mutablePath, NULL, scale * points[0].x,
scale * points[0].y);
+ CGPathMoveToPoint(mutablePath, m, points[0].x, points[0].y);
break;
case NSLineToBezierPathElement:
- CGPathAddLineToPoint(mutablePath, NULL, scale * points[0].x,
scale * points[0].y);
+ CGPathAddLineToPoint(mutablePath, m, points[0].x, points[0].y);
break;
case NSCurveToBezierPathElement:
- CGPathAddCurveToPoint(mutablePath, NULL, scale * points[0].x,
scale * points[0].y, scale * points[1].x, scale * points[1].y, scale *
points[2].x, scale * points[2].y);
+ CGPathAddCurveToPoint(mutablePath, m, points[0].x,
points[0].y, points[1].x, points[1].y, points[2].x, points[2].y);
break;
case NSClosePathBezierPathElement:
CGPathCloseSubpath(mutablePath);
@@ -114,11 +113,6 @@
break;
}
}
-
- CGPathRef path = CGPathCreateCopy(mutablePath);
- CGPathRelease(mutablePath);
-
- return path;
}
// distance ratio for control points to approximate a quarter ellipse by a
cubic bezier curve
Modified: trunk/PDFAnnotationInk_SKExtensions.m
===================================================================
--- trunk/PDFAnnotationInk_SKExtensions.m 2024-07-01 14:39:39 UTC (rev
14358)
+++ trunk/PDFAnnotationInk_SKExtensions.m 2024-07-01 15:52:58 UTC (rev
14359)
@@ -184,11 +184,8 @@
r = fabs(CGSizeApplyAffineTransform(CGSizeMake(r, r), t).height);
t = CGAffineTransformMakeTranslation(NSMinX(bounds), NSMinY(bounds));
CGMutablePathRef path = CGPathCreateMutable();
- for (NSBezierPath *aPath in [self paths]) {
- CGPathRef cgPath = [aPath copyCGPathWithScaleFactor:1.0];
- CGPathAddPath(path, &t, cgPath);
- CGPathRelease(cgPath);
- }
+ for (NSBezierPath *aPath in [self paths])
+ [aPath addToCGPath:path transform:&t];
CGContextSaveGState(context);
CGContextSetAlpha(context, [[self color] alphaComponent]);
CGContextBeginTransparencyLayerWithRect(context, rect, NULL);
Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m 2024-07-01 14:39:39 UTC (rev 14358)
+++ trunk/SKPDFView.m 2024-07-01 15:52:58 UTC (rev 14359)
@@ -4426,7 +4426,7 @@
BOOL wasOption = NO;
BOOL wantsBreak = isOption;
NSBezierPath *bezierPath = nil;
- CGPathRef cgPath = NULL;
+ CGMutablePathRef cgPath = NULL;
CGFloat scale = [self scaleFactor];
CAShapeLayer *layer = nil;
NSRect boxBounds = NSIntersectionRect([page boundsForBox:[self
displayBox]], [self convertRect:[self visibleContentRect] toPage:page]);
@@ -4469,6 +4469,8 @@
[[self layer] addSublayer:layer];
[layer setFilters:SKColorEffectFilters()];
+ t = CGAffineTransformMakeScale(scale, scale);
+
// don't coalesce mouse event from mouse while drawing,
// but not from tablets because those fire very rapidly and lead to
serious delays
if ([NSEvent currentPointingDeviceType] == NSPointingDeviceTypeUnknown)
@@ -4508,7 +4510,8 @@
wasOption = isOption;
wantsBreak = NO;
- cgPath = [bezierPath copyCGPathWithScaleFactor:scale];
+ cgPath = CGPathCreateMutable();
+ [bezierPath addToCGPath:cgPath transform:&t];
[layer setPath:cgPath];
CGPathRelease(cgPath);
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