diff --git a/MathPad/Fonts/CMU Sans Serif Italic.ttf b/MathPad/Fonts/CMU Sans Serif Italic.ttf new file mode 100644 index 0000000..bd30a3f Binary files /dev/null and b/MathPad/Fonts/CMU Sans Serif Italic.ttf differ diff --git a/MathPad/Fonts/CMU Sans Serif.ttf b/MathPad/Fonts/CMU Sans Serif.ttf new file mode 100644 index 0000000..d7513c8 Binary files /dev/null and b/MathPad/Fonts/CMU Sans Serif.ttf differ diff --git a/MathPad/Fonts/CMU Serif Italic.ttf b/MathPad/Fonts/CMU Serif Italic.ttf new file mode 100644 index 0000000..993d5c0 Binary files /dev/null and b/MathPad/Fonts/CMU Serif Italic.ttf differ diff --git a/MathPad/MPExpressionLayout.m b/MathPad/MPExpressionLayout.m index ffbcaa3..a07b518 100644 --- a/MathPad/MPExpressionLayout.m +++ b/MathPad/MPExpressionLayout.m @@ -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 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; diff --git a/MathPad/MPExpressionView.m b/MathPad/MPExpressionView.m index ac72ca7..b657b94 100644 --- a/MathPad/MPExpressionView.m +++ b/MathPad/MPExpressionView.m @@ -528,6 +528,7 @@ textField.editable = NO; textField.textColor = [NSColor redColor]; textField.font = [NSFont boldSystemFontOfSize:12.0]; + textField.drawsBackground = NO; _mathErrorTextField = textField; } return _mathErrorTextField; diff --git a/MathPad/MPFunctionLayout.m b/MathPad/MPFunctionLayout.m index c27cf4b..5bac16d 100644 --- a/MathPad/MPFunctionLayout.m +++ b/MathPad/MPFunctionLayout.m @@ -14,14 +14,12 @@ #import "MPParenthesisFunction.h" #import "MPPowerFunction.h" #import "MPFractionFunction.h" -#import "MPRootFunction.h" #import "MPExpressionLayout.h" #import "MPSumFunctionLayout.h" #import "MPParenthesisFunctionLayout.h" #import "MPPowerFunctionLayout.h" #import "MPFractionFunctionLayout.h" -#import "MPRootFunctionLayout.h" #import "NSIndexPath+MPAdditions.h" @@ -40,8 +38,6 @@ return [[MPPowerFunctionLayout alloc] initWithFunction:function parent:parent]; } else if (class == [MPFractionFunction class]) { return [[MPFractionFunctionLayout alloc] initWithFunction:function parent:parent]; - } else if (class == [MPRootFunction class]) { - return [[MPRootFunctionLayout alloc] initWithFunction:function parent:parent]; } return [[self alloc] initWithFunction:function parent:parent]; diff --git a/MathPad/MPFunctionsViewController.xib b/MathPad/MPFunctionsViewController.xib index da61fbd..5c1d0dc 100644 --- a/MathPad/MPFunctionsViewController.xib +++ b/MathPad/MPFunctionsViewController.xib @@ -1,7 +1,8 @@ - + - + + @@ -16,8 +17,23 @@ + + + + + + + + + + + Choose an Element + + + + - + @@ -42,30 +58,15 @@ - - - - - - - - - - - Choose an Element - - - - - - - - - - - + + + + + + + diff --git a/MathPad/MPLayout.h b/MathPad/MPLayout.h index 0904be2..259da07 100644 --- a/MathPad/MPLayout.h +++ b/MathPad/MPLayout.h @@ -23,13 +23,14 @@ - (instancetype)initWithParent:(MPLayout *)parent; #pragma mark Properties -- (NSFont *)font; -- (CGFloat)fontSize; -- (NSFont *)normalFont; +- (NSFont *)normalFontWithSize:(CGFloat)size; +- (NSFont *)specialFontWithSize:(CGFloat)size; +- (CGFloat)contextInferredFontSize; - (CGFloat)normalFontSize; -- (NSFont *)smallFont; - (CGFloat)smallFontSize; +- (NSFont *)font; + #pragma mark Cache Tree @property (readonly, nonatomic, weak) MPLayout *parent; diff --git a/MathPad/MPLayout.m b/MathPad/MPLayout.m index 59d468a..3e03d91 100644 --- a/MathPad/MPLayout.m +++ b/MathPad/MPLayout.m @@ -45,20 +45,21 @@ } #pragma mark Properties -- (NSFont *)font -{ - return self.usesSmallSize ? self.smallFont : self.normalFont; -} - -- (CGFloat)fontSize -{ - return self.usesSmallSize ? self.smallFontSize : self.normalFontSize; -} - -- (NSFont *)normalFont +- (NSFont *)normalFontWithSize:(CGFloat)size { return [NSFont fontWithName:@"CMU Serif" - size:self.fontSize]; + size:size]; +} + +- (NSFont *)specialFontWithSize:(CGFloat)size +{ + return [NSFont fontWithName:@"CMU Sans Serif Oblique" + size:size]; +} + +- (CGFloat)contextInferredFontSize +{ + return self.usesSmallSize ? self.smallFontSize : self.normalFontSize; } - (CGFloat)normalFontSize @@ -66,17 +67,16 @@ return 18.0; } -- (NSFont *)smallFont -{ - return [NSFont fontWithName:@"CMU Serif" - size:self.smallFontSize]; -} - - (CGFloat)smallFontSize { return 12.0; } +- (NSFont *)font +{ + return [self normalFontWithSize:self.contextInferredFontSize]; +} + #pragma mark Cache Tree // Querying and Storing Caches - (BOOL)hasCacheForElementAtIndex:(NSUInteger)index @@ -154,7 +154,7 @@ attributes:@{NSFontAttributeName: font}]; CFAttributedStringRef attributedString = CFBridgingRetain(text); CTLineRef line = CTLineCreateWithAttributedString(attributedString); - CFRelease(attributedString); // TODO: Is this release appropriate? + CFRelease(attributedString); return line; } diff --git a/MathPad/MPSumFunctionLayout.m b/MathPad/MPSumFunctionLayout.m index b855c7a..ee195ab 100644 --- a/MathPad/MPSumFunctionLayout.m +++ b/MathPad/MPSumFunctionLayout.m @@ -62,7 +62,7 @@ CTLineRef line = [self lineForPrivateCacheIndex:0 generator:^CTLineRef{ return [self createLineForString:@"∑" usingFont:[NSFont fontWithName:@"Times New Roman" - size:self.fontSize]]; + size:self.contextInferredFontSize]]; }]; return line; }