Fundamental Redesign of the View and Controller
This commit is contained in:
@@ -16,21 +16,46 @@
|
||||
return (MPSumFunction *)self.function;
|
||||
}
|
||||
|
||||
- (NSBezierPath *)generateBezierPath
|
||||
- (CTLineRef)line
|
||||
{
|
||||
NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"∑"
|
||||
attributes:@{NSFontAttributeName: [NSFont fontWithName:@"Lucida Grande" size:18.0]}];
|
||||
self.textStorage.attributedString = text;
|
||||
NSRange glyphRange = [self.layoutManager glyphRangeForTextContainer:self.textContainer];
|
||||
NSGlyph glyphs[glyphRange.length+1];
|
||||
NSUInteger actualGylphCount = [self.layoutManager getGlyphs:glyphs
|
||||
range:glyphRange];
|
||||
NSBezierPath *path = [NSBezierPath bezierPath];
|
||||
[path moveToPoint:NSZeroPoint];
|
||||
[path appendBezierPathWithGlyphs:glyphs
|
||||
count:actualGylphCount
|
||||
inFont:[NSFont fontWithName:@"Lucida Grande" size:18.0]];
|
||||
return path;
|
||||
CTLineRef line = [self lineForPrivateCacheIndex:0 generator:^CTLineRef{
|
||||
NSAttributedString *text =
|
||||
[[NSAttributedString alloc] initWithString:@"∑"
|
||||
attributes:@{NSFontAttributeName: [NSFont fontWithName:@"Lucida Grande" size:18.0]}];
|
||||
CFAttributedStringRef attributedString = CFBridgingRetain(text);
|
||||
CTLineRef line = CTLineCreateWithAttributedString(attributedString);
|
||||
CFRelease(attributedString); // TODO: Is this release appropriate
|
||||
return line;
|
||||
}];
|
||||
return line;
|
||||
}
|
||||
|
||||
- (NSSize)generateSize
|
||||
{
|
||||
CTLineRef line = [self line];
|
||||
CFRetain(line);
|
||||
CGSize size = CTLineGetBoundsWithOptions(line, /*kCTLineBoundsUseOpticalBounds*/0).size;
|
||||
CFRelease(line);
|
||||
return size;
|
||||
}
|
||||
|
||||
- (void)drawAtPoint:(NSPoint)point
|
||||
{
|
||||
// Get the current context
|
||||
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
|
||||
|
||||
// Set the text matrix
|
||||
CGContextSetTextMatrix(context, CGAffineTransformIdentity);
|
||||
|
||||
// Get the line of text
|
||||
CTLineRef line = [self line];
|
||||
CFRetain(line);
|
||||
|
||||
// Draw the line
|
||||
CGContextSetTextPosition(context, point.x, point.y);
|
||||
CTLineDraw(line, context);
|
||||
|
||||
CFRelease(line);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user