Archived
1

Layout Improvements (New Fonts)

This commit is contained in:
Kim Wittenburg
2014-11-25 17:48:42 +01:00
parent 66d06cc0f1
commit 8b0f8109c8
10 changed files with 73 additions and 55 deletions

View File

@@ -15,6 +15,7 @@
#import "MPFunctionLayout.h"
#import "MPPowerFunctionLayout.h"
#import "MPToken.h"
#import "NSIndexPath+MPAdditions.h"
@interface MPExpressionLayout (MPLineGeneration)
@@ -31,9 +32,27 @@
if (![element isString]) {
return NULL;
}
NSString *string = element;
NSRange tokensRange = [self.expression convertRange:NSMakeRange(index, 1)
fromReferenceFrame:MPElementReferenceFrame
toReferenceFrame:MPTokenReferenceFrame];
NSArray *tokens = [self.expression itemsInRange:tokensRange
referenceFrame:MPTokenReferenceFrame];
id lineObject = [self cachableObjectForIndex:index generator:^id{
CTLineRef line = [self createLineForString:string];
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] init];
for (id<MPToken> token in tokens) {
NSFont *font;
if (token.tokenType == MPElementaryFunctionToken) {
font = [self specialFontWithSize:self.contextInferredFontSize];
} else {
font = [self normalFontWithSize:self.contextInferredFontSize];
}
NSAttributedString *tokenText = [[NSAttributedString alloc] initWithString:token.stringValue
attributes:@{NSFontAttributeName: font}];
[text appendAttributedString:tokenText];
}
CFAttributedStringRef attributedString = CFBridgingRetain(text);
CTLineRef line = CTLineCreateWithAttributedString(attributedString);
CFRelease(attributedString);
return CFBridgingRelease(line);
}];
return (__bridge CTLineRef)lineObject;