Archived
1

Added MPExpressionLayout, MPFunctionLayout and MPExpressionStorage as Rendering System for Expressions

This commit is contained in:
Kim Wittenburg
2014-04-23 03:13:55 +02:00
parent 8605a6ac7b
commit 3116925315
8 changed files with 597 additions and 6 deletions

121
MathPad/MPFunctionLayout.m Normal file
View File

@@ -0,0 +1,121 @@
//
// MPFunctionLayout.m
// MathPad
//
// Created by Kim Wittenburg on 22.04.14.
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
//
#import "MPFunctionLayout.h"
#import "MPExpressionLayout.h"
#import "MPExpressionStorage.h"
#import "MPFunction.h"
#import "MPSumFunction.h"
#import "MPSumFunctionLayout.h"
@implementation MPFunctionLayout
#pragma mark Creation Methods
+ (instancetype)functionLayoutForFunctionAtIndexPath:(NSIndexPath *)functionPath
parent:(MPExpressionLayout *)parent
{
MPFunction *function = [parent.expressionStorage symbolAtIndexPath:functionPath];
Class class = [function class];
if (class == [MPSumFunction class]) {
return [[MPSumFunctionLayout alloc] initWithFunctionPath:functionPath parent:parent];
}
return nil;
}
- (id)initWithFunctionPath:(NSIndexPath *)functionPath
parent:(MPExpressionLayout *)parent
{
self = [super init];
if (self) {
_functionPath = functionPath;
_parent = parent;
_childCache = [[NSMutableArray alloc] init];
}
return self;
}
#pragma mark Properties
- (MPExpressionStorage *)expressionStorage
{
return self.parent.expressionStorage;
}
- (MPFunction *)function
{
return [self.expressionStorage symbolAtIndexPath:self.functionPath];
}
- (NSLayoutManager *)layoutManager
{
return self.expressionStorage.layoutManager;
}
- (NSTextContainer *)textContainer
{
return self.expressionStorage.textContainer;
}
- (NSTextStorage *)textStorage
{
return self.expressionStorage.textStorage;
}
#pragma mark Cache Methods
- (void)invalidate
{
_valid = NO;
}
- (BOOL)hasCacheForChildAtIndex:(NSUInteger)index
{
if (index >= _childCache.count) {
return NO;
}
return _childCache[index] != [NSNull null];
}
- (MPExpressionLayout *)expressionLayoutForChildAtIndex:(NSUInteger)index
{
if ([self hasCacheForChildAtIndex:index]) {
return _childCache[index];
}
while (index >= _childCache.count) {
[_childCache addObject:[NSNull null]];
}
MPExpressionLayout *expressionLayout = [[MPExpressionLayout alloc] initWithExpressionPath:[self.functionPath indexPathByAddingIndex:index] parent:self];
_childCache[index] = expressionLayout;
return expressionLayout;
}
#pragma mark Size Calculation Methods
- (NSSize)sizeOfFunction
{
if (!_valid) {
_cachedSize = [self calculateSize];
_valid = YES;
}
return _cachedSize;
}
- (NSSize)calculateSize
{
return NSMakeSize(0, 0);
}
#pragma mark Drawing Methods
- (void)drawFunctionAtPoint:(NSPoint)point
{
}
@end