62 lines
1.6 KiB
Objective-C
62 lines
1.6 KiB
Objective-C
//
|
|
// MPSumFunctionLayout.m
|
|
// MathPad
|
|
//
|
|
// Created by Kim Wittenburg on 23.04.14.
|
|
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
|
//
|
|
|
|
#import "MPSumFunctionLayout.h"
|
|
#import "MPSumFunction.h"
|
|
|
|
@implementation MPSumFunctionLayout
|
|
|
|
- (MPSumFunction *)sumFunction
|
|
{
|
|
return (MPSumFunction *)self.function;
|
|
}
|
|
|
|
- (CTLineRef)line
|
|
{
|
|
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
|