forked from thmghtd/InspectorKit.framework
-
Notifications
You must be signed in to change notification settings - Fork 1
/
NSBezierPath+StrokeExtensions.m
45 lines (33 loc) · 1.2 KB
/
NSBezierPath+StrokeExtensions.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//
// NSBezierPath+StrokeExtensions.m
// By Matt Gemmell <http://iratescotsman.com/>
// and Rainer Brockerhoff <http://www.brockerhoff.net/>
//
#import "NSBezierPath+StrokeExtensions.h"
@implementation NSBezierPath (StrokeExtensions)
- (void)strokeInside
{
/* Stroke within path using no additional clipping rectangle. */
[self strokeInsideWithinRect:NSZeroRect];
}
- (void)strokeInsideWithinRect:(NSRect)clipRect
{
NSGraphicsContext *thisContext = [NSGraphicsContext currentContext];
float lineWidth = [self lineWidth];
/* Save the current graphics context. */
[thisContext saveGraphicsState];
/* Double the stroke width, since -stroke centers strokes on paths. */
[self setLineWidth:(lineWidth * 2.0)];
/* Clip drawing to this path; draw nothing outwith the path. */
[self setClip];
/* Further clip drawing to clipRect, usually the view's frame. */
if (clipRect.size.width > 0.0 && clipRect.size.height > 0.0) {
[NSBezierPath clipRect:clipRect];
}
/* Stroke the path. */
[self stroke];
/* Restore the previous graphics context. */
[thisContext restoreGraphicsState];
[self setLineWidth:lineWidth];
}
@end