Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Swift Package Manager #173

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ Carthage/Build

fastlane/report.xml
fastlane/screenshots

# Swift Package Manager
.swiftpm/
.build/
44 changes: 0 additions & 44 deletions MathFontBundle/MathFontBundle-Info.plist

This file was deleted.

2 changes: 0 additions & 2 deletions MathFontBundle/en.lproj/InfoPlist.strings

This file was deleted.

40 changes: 40 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// swift-tools-version: 5.6

import PackageDescription

let package = Package(
name: "iosMath",
defaultLocalization: "en",
platforms: [.iOS(.v10), .macOS(.v11)],
products: [
.library(
name: "iosMath",
targets: ["iosMath"])
],
dependencies: [],
targets: [
.target(
name: "iosMath",
dependencies: [],
path: "./iosMath",
resources: [
.process("fonts")
],
cSettings: [
.headerSearchPath("./render"),
.headerSearchPath("./lib"),
.headerSearchPath("./render/internal"),
// Prevent NSAssert from crashing the app in release builds
.define("NS_BLOCK_ASSERTIONS", to: "1", .when(configuration: .release)),
]
),
.testTarget(
name: "iosMathTests",
dependencies: ["iosMath"],
path: "iosMathTests",
cSettings: [
.headerSearchPath("../iosMath/render"),
]
),
]
)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ Additionally for MacOS it requires:

## Installation

### Swift Package Manager
To install iosMath using [Swift Package Manager](https://github.com/apple/swift-package-manager):

1. In Xcode, select "File" -> "Add Packages"
2. Enter `https://github.com/kostub/iosMath.git`

Alternatively, add iosMath to a `Package.swift`:

```
dependencies: [
.package(url: "https://github.com/kostub/iosMath.git", branch: "master")
// Any other dependencies you have...
],
```

You can also follow the [tutorial from developer.apple.com](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app).

### Cocoapods

iosMath is available through [CocoaPods](http://cocoapods.org). To install
Expand Down
1 change: 1 addition & 0 deletions iosMath/fonts
1 change: 1 addition & 0 deletions iosMath/include/MTConfig.h
1 change: 1 addition & 0 deletions iosMath/include/MTFont.h
1 change: 1 addition & 0 deletions iosMath/include/MTFontManager.h
1 change: 1 addition & 0 deletions iosMath/include/MTLabel.h
1 change: 1 addition & 0 deletions iosMath/include/MTMathAtomFactory.h
1 change: 1 addition & 0 deletions iosMath/include/MTMathList.h
1 change: 1 addition & 0 deletions iosMath/include/MTMathListBuilder.h
1 change: 1 addition & 0 deletions iosMath/include/MTMathListDisplay.h
1 change: 1 addition & 0 deletions iosMath/include/MTMathListIndex.h
1 change: 1 addition & 0 deletions iosMath/include/MTMathUILabel.h
1 change: 1 addition & 0 deletions iosMath/include/MTTypesetter.h
1 change: 1 addition & 0 deletions iosMath/include/MTUnicode.h
1 change: 1 addition & 0 deletions iosMath/include/NSBezierPath+addLineToPoint.h
1 change: 1 addition & 0 deletions iosMath/include/NSColor+HexString.h
1 change: 1 addition & 0 deletions iosMath/include/NSView+backgroundColor.h
1 change: 1 addition & 0 deletions iosMath/include/UIColor+HexString.h
13 changes: 8 additions & 5 deletions iosMath/render/MTFont.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ - (instancetype)initFontWithName:(NSString *)name size:(CGFloat)size
NSBundle* bundle = [MTFont fontBundle];
NSString* fontPath = [bundle pathForResource:name ofType:@"otf"];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithFilename(fontPath.UTF8String);
self.defaultCGFont = CGFontCreateWithDataProvider(fontDataProvider);
_defaultCGFont = CGFontCreateWithDataProvider(fontDataProvider);
CFRelease(fontDataProvider);

self.ctFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);
_ctFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);

NSString* mathTablePlist = [bundle pathForResource:name ofType:@"plist"];
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:mathTablePlist];
Expand Down Expand Up @@ -69,6 +69,9 @@ - (void)setCtFont:(CTFontRef)ctFont {

+ (NSBundle*) fontBundle
{
#ifdef SWIFTPM_MODULE_BUNDLE
return SWIFTPM_MODULE_BUNDLE;
#endif
// Uses bundle for class so that this can be access by the unit tests.
return [NSBundle bundleWithURL:[[NSBundle bundleForClass:[self class]] URLForResource:@"mathFonts" withExtension:@"bundle"]];
}
Expand All @@ -77,11 +80,11 @@ - (MTFont *)copyFontWithSize:(CGFloat)size
{
MTFont* copyFont = [[[self class] alloc] init];
copyFont.defaultCGFont = self.defaultCGFont;
// Retain the font as we are adding another reference to it.
CGFontRetain(copyFont.defaultCGFont);
copyFont.ctFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);
CTFontRef newCtFont = CTFontCreateWithGraphicsFont(self.defaultCGFont, size, nil, nil);
copyFont.ctFont = newCtFont;
copyFont.rawMathTable = self.rawMathTable;
copyFont.mathTable = [[MTFontMathTable alloc] initWithFont:copyFont mathTable:copyFont.rawMathTable];
CFRelease(newCtFont);
return copyFont;
}

Expand Down
3 changes: 3 additions & 0 deletions iosMath/render/MTFontManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
/** Get the singleton instance of MTFontManager. */
+ (nonnull instancetype) fontManager;

/** Swift friendly version of `fontManager`. */
+ (nonnull instancetype) sharedInstance;

/** Returns the default font, which is Latin Modern Math with 20pt */
- (nonnull MTFont*) defaultFont;

Expand Down
5 changes: 5 additions & 0 deletions iosMath/render/MTFontManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ + (instancetype) fontManager
return manager;
}

+ (instancetype) sharedInstance
{
return [MTFontManager fontManager];
}

- (instancetype)init
{
self = [super init];
Expand Down
2 changes: 2 additions & 0 deletions iosMath/render/UIColor+HexString.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#if TARGET_OS_IPHONE

@import UIKit;

@interface UIColor (HexString)

+ (UIColor *)colorFromHexString:(NSString *)hexString;
Expand Down