Revision: 15244 http://sourceforge.net/p/skim-app/code/15244 Author: hofman Date: 2025-05-21 08:49:31 +0000 (Wed, 21 May 2025) Log Message: ----------- simplify transform calculation for drawing freehand in presentation
Modified Paths: -------------- trunk/SKPresentationView.m Modified: trunk/SKPresentationView.m =================================================================== --- trunk/SKPresentationView.m 2025-05-20 09:04:25 UTC (rev 15243) +++ trunk/SKPresentationView.m 2025-05-21 08:49:31 UTC (rev 15244) @@ -867,20 +867,21 @@ - (void)doDrawFreehandNoteWithEvent:(NSEvent *)theEvent { NSRect bounds = [self bounds]; NSRect pageBounds = [page boundsForBox:kPDFDisplayBoxCropBox]; - NSRect pageRect = pageBounds; - if (([page rotation] % 180) != 0) - pageRect = NSMakeRect(0.0, 0.0, NSHeight(pageRect), NSWidth(pageRect)); - CGFloat scale = pvFlags.autoScales ? fmin(NSHeight(bounds) / NSHeight(pageRect), NSWidth(bounds) / NSWidth(pageRect)) : 1.0; - pageRect = NSInsetRect(bounds, 0.5 * (NSWidth(bounds) - scale * NSWidth(pageRect)), 0.5 * (NSHeight(bounds) - scale * NSHeight(pageRect))); + CGFloat scale; + if (pvFlags.autoScales == NO) + scale = 1.0; + else if (([page rotation] % 180)) + scale = fmin(NSHeight(bounds) / NSWidth(pageBounds), NSWidth(bounds) / NSHeight(pageBounds)); + else + scale = fmin(NSHeight(bounds) / NSHeight(pageBounds), NSWidth(bounds) / NSWidth(pageBounds)); - NSAffineTransform *viewFromPage = [NSAffineTransform transform]; - [viewFromPage translateXBy:NSMinX(pageRect) yBy:NSMinY(pageRect)]; - [viewFromPage scaleBy:scale]; - [viewFromPage prependTransform:[page affineTransformForBox:kPDFDisplayBoxCropBox]]; - NSAffineTransform *viewToPage = [[NSAffineTransform alloc] initWithTransform:viewFromPage]; - [viewToPage invert]; + NSAffineTransform *transform = [NSAffineTransform transform]; + [transform translateXBy:NSMidX(pageBounds) yBy:NSMidY(pageBounds)]; + [transform rotateByDegrees:[page rotation]]; + [transform scaleBy:1.0 / scale]; + [transform translateXBy:-NSMidX(bounds) yBy:-NSMidY(bounds)]; - NSPoint point = [viewToPage transformPoint:[theEvent locationInView:self]]; + NSPoint point = [transform transformPoint:[theEvent locationInView:self]]; NSWindow *window = [self window]; BOOL wasMouseCoalescingEnabled = [NSEvent isMouseCoalescingEnabled]; BOOL isOption = ([theEvent modifierFlags] & NSEventModifierFlagOption) != 0; @@ -890,16 +891,15 @@ CGMutablePathRef cgPath = NULL; NSUserDefaults *sud = [NSUserDefaults standardUserDefaults]; CAShapeLayer *layer = nil; - NSRect boxBounds = NSIntersectionRect(pageBounds, SKTransformRect(viewToPage, bounds)); + NSRect boxBounds = pvFlags.autoScales ? pageBounds : NSIntersectionRect(pageBounds, SKTransformRect(transform, bounds)); CGAffineTransform t = CGAffineTransformMakeRotation(-M_PI_2 * [page rotation] / 90.0); NSColor *tmpColor = [sud colorForKey:SKPresentationInkNoteColorKey]; layer = [CAShapeLayer layer]; // transform and place so that the path is in scaled page coordinates [layer setBounds:CGRectMake(scale * NSMinX(boxBounds), scale * NSMinY(boxBounds), scale * NSWidth(boxBounds), scale * NSHeight(boxBounds))]; - [layer setAnchorPoint:CGPointZero]; - [layer setPosition:NSPointToCGPoint([viewFromPage transformPoint:boxBounds.origin])]; + [layer setAnchorPoint:CGPointMake(0.5, 0.5)]; + [layer setPosition:CGPointMake(NSMidX(bounds), NSMidY(bounds))]; [layer setAffineTransform:t]; - [layer setZPosition:1.0]; [layer setMasksToBounds:YES]; [layer setFillColor:NULL]; [layer setLineJoin:kCALineJoinRound]; @@ -937,7 +937,7 @@ [PDFAnnotation addPoint:point toSkimNotesPath:bezierPath]; } - point = [viewToPage transformPoint:[theEvent locationInView:self]]; + point = [transform transformPoint:[theEvent locationInView:self]]; if (isOption && wantsBreak == NO) { NSInteger eltCount = [bezierPath elementCount]; 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