Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPad/MPSumFunctionLayout.m
2014-08-22 00:54:13 +02:00

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