Skip to content

Commit eff878b

Browse files
authored
Merge pull request #31 from AnZhg/MacOSMath
Add support for Mac.
2 parents 34a0dd1 + acbc16b commit eff878b

24 files changed

+1773
-86
lines changed

MacOSMath.xcodeproj/project.pbxproj

+535
Large diffs are not rendered by default.

MacOSMath.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MacOSMathExample/AppDelegate.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// AppDelegate.h
3+
// MacOSMath
4+
//
5+
// Created by 安志钢 on 17-01-08.
6+
// Copyright © 2017年 安志钢. All rights reserved.
7+
//
8+
// This software may be modified and distributed under the terms of the
9+
// MIT license. See the LICENSE file for details.
10+
//
11+
12+
#import <Cocoa/Cocoa.h>
13+
14+
@interface AppDelegate : NSObject <NSApplicationDelegate>
15+
16+
@end

MacOSMathExample/AppDelegate.m

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// AppDelegate.m
3+
// MacOSMath
4+
//
5+
// Created by 安志钢 on 17-01-08.
6+
// Copyright © 2017年 安志钢. All rights reserved.
7+
//
8+
// This software may be modified and distributed under the terms of the
9+
// MIT license. See the LICENSE file for details.
10+
//
11+
12+
#import "AppDelegate.h"
13+
#import "MTMathUILabel.h"
14+
15+
@interface AppDelegate ()
16+
17+
@property (weak) IBOutlet NSWindow *window;
18+
@property (weak) IBOutlet MTMathUILabel *screen;
19+
@property (weak) IBOutlet NSTextField *inputTextField;
20+
21+
@end
22+
23+
@implementation AppDelegate
24+
25+
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
26+
{
27+
// Insert code here to initialize your application
28+
}
29+
30+
31+
- (void)applicationWillTerminate:(NSNotification *)aNotification
32+
{
33+
// Insert code here to tear down your application
34+
}
35+
36+
- (IBAction)clickUpdateButton:(NSButton *)sender
37+
{
38+
self.screen.latex = self.inputTextField.stringValue;
39+
}
40+
41+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"images" : [
3+
{
4+
"idiom" : "mac",
5+
"size" : "16x16",
6+
"scale" : "1x"
7+
},
8+
{
9+
"idiom" : "mac",
10+
"size" : "16x16",
11+
"scale" : "2x"
12+
},
13+
{
14+
"idiom" : "mac",
15+
"size" : "32x32",
16+
"scale" : "1x"
17+
},
18+
{
19+
"idiom" : "mac",
20+
"size" : "32x32",
21+
"scale" : "2x"
22+
},
23+
{
24+
"idiom" : "mac",
25+
"size" : "128x128",
26+
"scale" : "1x"
27+
},
28+
{
29+
"idiom" : "mac",
30+
"size" : "128x128",
31+
"scale" : "2x"
32+
},
33+
{
34+
"idiom" : "mac",
35+
"size" : "256x256",
36+
"scale" : "1x"
37+
},
38+
{
39+
"idiom" : "mac",
40+
"size" : "256x256",
41+
"scale" : "2x"
42+
},
43+
{
44+
"idiom" : "mac",
45+
"size" : "512x512",
46+
"scale" : "1x"
47+
},
48+
{
49+
"idiom" : "mac",
50+
"size" : "512x512",
51+
"scale" : "2x"
52+
}
53+
],
54+
"info" : {
55+
"version" : 1,
56+
"author" : "xcode"
57+
}
58+
}

MacOSMathExample/Base.lproj/MainMenu.xib

+722
Large diffs are not rendered by default.

MacOSMathExample/Info.plist

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>en</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIconFile</key>
10+
<string></string>
11+
<key>CFBundleIdentifier</key>
12+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>$(PRODUCT_NAME)</string>
17+
<key>CFBundlePackageType</key>
18+
<string>APPL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleVersion</key>
22+
<string>1</string>
23+
<key>LSMinimumSystemVersion</key>
24+
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
25+
<key>NSHumanReadableCopyright</key>
26+
<string>Copyright © 2017年 安志钢. All rights reserved.</string>
27+
<key>NSMainNibFile</key>
28+
<string>MainMenu</string>
29+
<key>NSPrincipalClass</key>
30+
<string>NSApplication</string>
31+
</dict>
32+
</plist>

MacOSMathExample/main.m

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// main.m
3+
// MacOSMath
4+
//
5+
// Created by 安志钢 on 17-01-08.
6+
// Copyright © 2017年 安志钢. All rights reserved.
7+
//
8+
// This software may be modified and distributed under the terms of the
9+
// MIT license. See the LICENSE file for details.
10+
//
11+
12+
#import <Cocoa/Cocoa.h>
13+
14+
int main(int argc, const char * argv[]) {
15+
return NSApplicationMain(argc, argv);
16+
}

Podfile

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Needed due to
22
# http://stackoverflow.com/questions/33395675/cocoapods-file-reference-is-a-member-of-multiple-groups
3+
workspace 'iosMath.xcworkspace'
4+
project 'iosMath.xcodeproj'
5+
36
install! 'cocoapods', :deterministic_uuids => false
47

58
target 'iosMathExample' do

README.md

100644100755
File mode changed.

iosMath.xcworkspace/contents.xcworkspacedata

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

iosMath/render/MTConfig.h

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// MTConfig.h
3+
// MacOSMath
4+
//
5+
// Created by 安志钢 on 17-01-09.
6+
//
7+
// This software may be modified and distributed under the terms of the
8+
// MIT license. See the LICENSE file for details.
9+
//
10+
11+
// Make TARGET_OS_IPHONE macro visible.
12+
#include <TargetConditionals.h>
13+
14+
// Type definitions.
15+
#if TARGET_OS_IPHONE
16+
// TARGET_OS_MAC is defined as 1 for both Mac OS and iOS,
17+
// so TARGET_OS_IPHONE is reliable.
18+
@import UIKit;
19+
20+
typedef UIView MTView;
21+
typedef UIColor MTColor;
22+
typedef UIBezierPath MTBezierPath;
23+
typedef UIEdgeInsets MTEdgeInsets;
24+
typedef UILabel MTLabel;
25+
typedef CGRect MTRect;
26+
27+
#define MTEdgeInsetsZero UIEdgeInsetsZero
28+
#define MTGraphicsGetCurrentContext() UIGraphicsGetCurrentContext()
29+
30+
#else
31+
@import AppKit;
32+
#import "NSBezierPath+addLineToPoint.h"
33+
#import "NSView+backgroundColor.h"
34+
#import "MTLabel.h"
35+
36+
typedef NSView MTView;
37+
typedef NSColor MTColor;
38+
typedef NSBezierPath MTBezierPath;
39+
typedef NSEdgeInsets MTEdgeInsets;
40+
typedef NSRect MTRect;
41+
42+
// For backward compatibility, DO NOT use NSEdgeInsetsZero (Available from OS X 10.10).
43+
#define MTEdgeInsetsZero (NSEdgeInsetsMake(0.0f, 0.0f, 0.0f, 0.0f));
44+
#define MTGraphicsGetCurrentContext() ([[NSGraphicsContext currentContext] graphicsPort])
45+
46+
#endif // TARGET_OS_IPHONE

iosMath/render/MTFont.m

+5
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@ - (instancetype)initFontWithName:(NSString *)name size:(CGFloat)size
5050

5151
+ (NSBundle*) fontBundle
5252
{
53+
#if TARGET_OS_IPHONE
5354
// Uses bundle for class so that this can be access by the unit tests.
5455
return [NSBundle bundleWithURL:[[NSBundle bundleForClass:[self class]] URLForResource:@"iosMathFonts" withExtension:@"bundle"]];
56+
#else
57+
// TODO: Font bundle for Mac OS.
58+
return [NSBundle mainBundle];
59+
#endif
5560
}
5661

5762
- (MTFont *)copyFontWithSize:(CGFloat)size

iosMath/render/MTLabel.h

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// MTLabel.h
3+
// MacOSMath
4+
//
5+
// Created by 安志钢 on 17-01-09.
6+
//
7+
// This software may be modified and distributed under the terms of the
8+
// MIT license. See the LICENSE file for details.
9+
//
10+
11+
#include <TargetConditionals.h>
12+
13+
#if !TARGET_OS_IPHONE
14+
@import AppKit;
15+
16+
@interface MTLabel : NSTextField
17+
18+
@property (strong) NSString *text;
19+
20+
@end
21+
#endif

iosMath/render/MTLabel.m

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//
2+
// MTLabel.m
3+
// MacOSMath
4+
//
5+
// Created by 安志钢 on 17-01-09.
6+
//
7+
// This software may be modified and distributed under the terms of the
8+
// MIT license. See the LICENSE file for details.
9+
//
10+
11+
#import "MTLabel.h"
12+
13+
#if !TARGET_OS_IPHONE
14+
@implementation MTLabel
15+
16+
@synthesize bezeled, drawsBackground, editable, selectable, stringValue;
17+
18+
- (instancetype)init
19+
{
20+
self = [super init];
21+
22+
if (self != nil) {
23+
super.bezeled = NO;
24+
super.drawsBackground = NO;
25+
super.editable = NO;
26+
super.selectable = NO;
27+
}
28+
29+
return self;
30+
}
31+
32+
#pragma mark - Customized getter and setter methods for property text.
33+
- (NSString *)text
34+
{
35+
return super.stringValue;
36+
}
37+
38+
- (void)setText:(NSString *)text
39+
{
40+
super.stringValue = text;
41+
}
42+
43+
@end
44+
#endif

iosMath/render/MTMathListDisplay.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@
44
//
55
// Created by Kostub Deshmukh on 8/27/13.
66
// Copyright (C) 2013 MathChat
7-
//
7+
//
88
// This software may be modified and distributed under the terms of the
99
// MIT license. See the LICENSE file for details.
1010
//
1111

1212
@import Foundation;
1313
@import QuartzCore;
14-
@import UIKit;
14+
15+
// This header file is imported by Foudation.
16+
//#include <TargetConditionals.h>
17+
18+
#import "MTConfig.h"
1519

1620
#import "MTFont.h"
1721
#import "MTMathList.h"
@@ -27,7 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
2731
- (CGRect) displayBounds;
2832

2933
/// For debugging. Shows the object in quick look in Xcode.
34+
#if TARGET_OS_IPHONE
3035
- (id) debugQuickLookObject;
36+
#endif
3137

3238
/// The distance from the axis to the top of the display
3339
@property (nonatomic, readonly) CGFloat ascent;
@@ -42,7 +48,7 @@ NS_ASSUME_NONNULL_BEGIN
4248
/// Whether the display has a subscript/superscript following it.
4349
@property (nonatomic, readonly) BOOL hasScript;
4450
/// The text color for this display
45-
@property (nonatomic, nullable) UIColor* textColor;
51+
@property (nonatomic, nullable) MTColor *textColor;
4652

4753
@end
4854

@@ -97,7 +103,7 @@ typedef NS_ENUM(unsigned int, MTLinePosition) {
97103

98104
- (instancetype)init NS_UNAVAILABLE;
99105

100-
/** A display representing the numerator of the fraction. It's position is relative
106+
/** A display representing the numerator of the fraction. It's position is relative
101107
to the parent and is not treated as a sub-display.
102108
*/
103109
@property (nonatomic, readonly) MTMathListDisplay* numerator;

0 commit comments

Comments
 (0)