Added MPExpressionLayout, MPFunctionLayout and MPExpressionStorage as Rendering System for Expressions
This commit is contained in:
60
MathPad/MPExpressionStorage.m
Normal file
60
MathPad/MPExpressionStorage.m
Normal file
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// MPExpressionStorage.m
|
||||
// MathPad
|
||||
//
|
||||
// Created by Kim Wittenburg on 22.04.14.
|
||||
// Copyright (c) 2014 Kim Wittenburg. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MPExpressionStorage.h"
|
||||
#import "MPExpressionLayout.h"
|
||||
|
||||
@interface MPExpressionStorage ()
|
||||
@property (nonatomic, strong) NSLayoutManager *layoutManager;
|
||||
@property (nonatomic, strong) NSTextContainer *textContainer;
|
||||
@property (nonatomic, strong) NSTextStorage *textStorage;
|
||||
@end
|
||||
|
||||
@implementation MPExpressionStorage
|
||||
|
||||
- (instancetype)initWithSymbols:(NSArray *)symbols
|
||||
{
|
||||
self = [super initWithSymbols:symbols];
|
||||
if (self) {
|
||||
_expressionLayout = [[MPExpressionLayout alloc] initRootLayoutWithExpressionStorage:self];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSLayoutManager *)layoutManager
|
||||
{
|
||||
[self ensureTextSystemObjects];
|
||||
return _layoutManager;
|
||||
}
|
||||
|
||||
- (NSTextContainer *)textContainer
|
||||
{
|
||||
[self ensureTextSystemObjects];
|
||||
return _textContainer;
|
||||
}
|
||||
|
||||
- (NSTextStorage *)textStorage
|
||||
{
|
||||
[self ensureTextSystemObjects];
|
||||
return _textStorage;
|
||||
}
|
||||
|
||||
- (void)ensureTextSystemObjects
|
||||
{
|
||||
if (_layoutManager == nil || _textContainer == nil || _textStorage == nil) {
|
||||
_textStorage = [[NSTextStorage alloc] init];
|
||||
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(CGFLOAT_MAX, CGFLOAT_MAX)];
|
||||
NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
|
||||
[layoutManager addTextContainer:textContainer];
|
||||
[_textStorage addLayoutManager:layoutManager];
|
||||
_textContainer = textContainer;
|
||||
_layoutManager = layoutManager;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user