Layout Improvements (New Fonts)
This commit is contained in:
BIN
MathPad/Fonts/CMU Sans Serif Italic.ttf
Normal file
BIN
MathPad/Fonts/CMU Sans Serif Italic.ttf
Normal file
Binary file not shown.
BIN
MathPad/Fonts/CMU Sans Serif.ttf
Normal file
BIN
MathPad/Fonts/CMU Sans Serif.ttf
Normal file
Binary file not shown.
BIN
MathPad/Fonts/CMU Serif Italic.ttf
Normal file
BIN
MathPad/Fonts/CMU Serif Italic.ttf
Normal file
Binary file not shown.
@@ -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;
|
||||
|
||||
@@ -528,6 +528,7 @@
|
||||
textField.editable = NO;
|
||||
textField.textColor = [NSColor redColor];
|
||||
textField.font = [NSFont boldSystemFontOfSize:12.0];
|
||||
textField.drawsBackground = NO;
|
||||
_mathErrorTextField = textField;
|
||||
}
|
||||
return _mathErrorTextField;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6245" systemVersion="13F34" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14B25" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6245"/>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="MPFunctionsViewController">
|
||||
@@ -16,8 +17,23 @@
|
||||
<rect key="frame" x="0.0" y="0.0" width="320" height="185"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<subviews>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="D89-Gi-YJm">
|
||||
<rect key="frame" x="10" y="10" width="300" height="17"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Description" drawsBackground="YES" id="xrL-Xy-aRm">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<binding destination="-2" name="value" keyPath="currentDescription" id="0Vx-OA-1Zy">
|
||||
<dictionary key="options">
|
||||
<string key="NSNullPlaceholder">Choose an Element</string>
|
||||
</dictionary>
|
||||
</binding>
|
||||
</connections>
|
||||
</textField>
|
||||
<scrollView borderType="none" autohidesScrollers="YES" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="9w0-UQ-Fqx">
|
||||
<rect key="frame" x="10" y="25" width="300" height="150"/>
|
||||
<rect key="frame" x="10" y="27" width="300" height="148"/>
|
||||
<clipView key="contentView" copiesOnScroll="NO" id="Z8C-m4-8Mb">
|
||||
<rect key="frame" x="1" y="1" width="248" height="158"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
@@ -42,30 +58,15 @@
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</scroller>
|
||||
</scrollView>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="D89-Gi-YJm">
|
||||
<rect key="frame" x="-2" y="0.0" width="324" height="17"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="center" title="Description" id="xrL-Xy-aRm">
|
||||
<font key="font" metaFont="system"/>
|
||||
<color key="textColor" name="disabledControlTextColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
<connections>
|
||||
<binding destination="-2" name="value" keyPath="currentDescription" id="0Vx-OA-1Zy">
|
||||
<dictionary key="options">
|
||||
<string key="NSNullPlaceholder">Choose an Element</string>
|
||||
</dictionary>
|
||||
</binding>
|
||||
</connections>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="bottom" secondItem="D89-Gi-YJm" secondAttribute="bottom" id="6QP-Uy-i2A"/>
|
||||
<constraint firstItem="9w0-UQ-Fqx" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="10" id="GOC-rC-AE6"/>
|
||||
<constraint firstItem="9w0-UQ-Fqx" firstAttribute="centerX" secondItem="D89-Gi-YJm" secondAttribute="centerX" id="Qk9-hA-Jcj"/>
|
||||
<constraint firstItem="9w0-UQ-Fqx" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="10" id="RFi-H1-0CV"/>
|
||||
<constraint firstItem="D89-Gi-YJm" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" id="Rup-Ep-vEV"/>
|
||||
<constraint firstItem="D89-Gi-YJm" firstAttribute="top" secondItem="9w0-UQ-Fqx" secondAttribute="bottom" constant="8" symbolic="YES" id="xGL-ZL-fb1"/>
|
||||
<constraint firstAttribute="trailing" secondItem="9w0-UQ-Fqx" secondAttribute="trailing" constant="10" id="zb3-nc-Iai"/>
|
||||
<constraint firstItem="D89-Gi-YJm" firstAttribute="centerX" secondItem="Hz6-mo-xeY" secondAttribute="centerX" id="9WK-zU-g2j"/>
|
||||
<constraint firstItem="D89-Gi-YJm" firstAttribute="leading" secondItem="9w0-UQ-Fqx" secondAttribute="leading" id="FSW-Jj-9RW"/>
|
||||
<constraint firstItem="9w0-UQ-Fqx" firstAttribute="top" secondItem="Hz6-mo-xeY" secondAttribute="top" constant="10" id="OFp-Pr-zZT"/>
|
||||
<constraint firstItem="9w0-UQ-Fqx" firstAttribute="leading" secondItem="Hz6-mo-xeY" secondAttribute="leading" constant="10" id="fPs-mT-ads"/>
|
||||
<constraint firstAttribute="bottom" secondItem="D89-Gi-YJm" secondAttribute="bottom" constant="10" id="mk2-Ph-Kh5"/>
|
||||
<constraint firstItem="D89-Gi-YJm" firstAttribute="top" secondItem="9w0-UQ-Fqx" secondAttribute="bottom" id="nYD-XL-3y1"/>
|
||||
<constraint firstItem="9w0-UQ-Fqx" firstAttribute="trailing" secondItem="D89-Gi-YJm" secondAttribute="trailing" id="w9y-K1-mce"/>
|
||||
</constraints>
|
||||
<point key="canvasLocation" x="-101" y="140.5"/>
|
||||
</customView>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user