Layout Improvements (New Fonts)
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user