Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)drawInteriorWithFrame:(NSRect)cellFrame
- inView:(NSView *)controlView
- {
- NSBezierPath *stringPath = [self bezierPathWithString:self.stringValue
- inFont:self.font];
- [NSGraphicsContext saveGraphicsState];
- _innerShadow = [[NSShadow alloc] init];
- _innerShadow.shadowColor = [NSColor blackColor];
- _innerShadow.shadowBlurRadius = 3.0;
- _innerShadow.shadowOffset = NSMakeSize(10, 0);
- NSSize offset = _innerShadow.shadowOffset;
- NSSize originalOffset = offset;
- CGFloat radius = _innerShadow.shadowBlurRadius;
- NSRect bounds = NSInsetRect(stringPath.bounds, -(ABS(offset.width) + radius), -(ABS(offset.height) + radius));
- offset.height += bounds.size.height;
- _innerShadow.shadowOffset = offset;
- NSBezierPath *drawingPath = [NSBezierPath bezierPathWithRect:bounds];
- [drawingPath setWindingRule:NSEvenOddWindingRule];
- [drawingPath appendBezierPath:stringPath];
- [stringPath addClip];
- [_innerShadow set];
- [[NSColor blackColor] set];
- [drawingPath fill];
- _innerShadow.shadowOffset = originalOffset;
- [NSGraphicsContext restoreGraphicsState];
- }
- - (NSBezierPath *)bezierPathWithString:(NSString *)text
- inFont:(NSFont *)font
- {
- // This has some weird alphabet shifting problem
- // Don't use in production until fixed
- NSBezierPath *aPath = [NSBezierPath bezierPath];
- [aPath moveToPoint:NSZeroPoint];
- NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:text];
- CTLineRef line = CTLineCreateWithAttributedString((CFAttributedStringRef)CFBridgingRetain(attributedString));
- CFArrayRef glyphRuns = CTLineGetGlyphRuns(line);
- CFIndex count = CFArrayGetCount(glyphRuns);
- for (CFIndex index = 0; index < count; index++) {
- CTRunRef currentRun = CFArrayGetValueAtIndex(glyphRuns, index);
- CFIndex glyphCount = CTRunGetGlyphCount(currentRun);
- CGGlyph glyphs[glyphCount];
- CTRunGetGlyphs(currentRun, CTRunGetStringRange(currentRun), glyphs);
- NSGlyph bezierPathGlyphs[glyphCount];
- for (CFIndex glyphIndex = 0; glyphIndex < glyphCount; glyphIndex++) {
- bezierPathGlyphs[glyphIndex] = glyphs[glyphIndex];
- }
- [aPath appendBezierPathWithGlyphs:bezierPathGlyphs
- count:glyphCount
- inFont:font];
- }
- CFRelease(line);
- [aPath transformUsingAffineTransform:[self verticallyFlippedAffineTransformForRect:aPath.bounds]];
- return aPath;
- }
- - (NSAffineTransform *)verticallyFlippedAffineTransformForRect:(NSRect)rect
- {
- NSAffineTransform *affineTransform = [NSAffineTransform transform];
- NSAffineTransformStruct transformStruct;
- transformStruct.m11 = 1.0;
- transformStruct.m12 = 0.0;
- transformStruct.tX = 0;
- transformStruct.m21 = 0.0;
- transformStruct.m22 = -1.0;
- transformStruct.tY = rect.size.height;
- [affineTransform setTransformStruct:transformStruct];
- return affineTransform;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement