diff --git a/.gitignore b/.gitignore index a74cfed..112b595 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,7 @@ Carthage/Build fastlane/report.xml fastlane/screenshots + +# Swift Package Manager +.swiftpm/ +.build/ diff --git a/MathFontBundle/MathFontBundle-Info.plist b/MathFontBundle/MathFontBundle-Info.plist deleted file mode 100644 index 946eb39..0000000 --- a/MathFontBundle/MathFontBundle-Info.plist +++ /dev/null @@ -1,44 +0,0 @@ - - - - - CFBundleDevelopmentRegion - English - CFBundleIconFile - - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - CFPlugInDynamicRegisterFunction - - CFPlugInDynamicRegistration - NO - CFPlugInFactories - - 00000000-0000-0000-0000-000000000000 - MyFactoryFunction - - CFPlugInTypes - - 00000000-0000-0000-0000-000000000000 - - 00000000-0000-0000-0000-000000000000 - - - CFPlugInUnloadFunction - - NSHumanReadableCopyright - Copyright © 2014 MathChat. - - diff --git a/MathFontBundle/en.lproj/InfoPlist.strings b/MathFontBundle/en.lproj/InfoPlist.strings deleted file mode 100644 index 477b28f..0000000 --- a/MathFontBundle/en.lproj/InfoPlist.strings +++ /dev/null @@ -1,2 +0,0 @@ -/* Localized versions of Info.plist keys */ - diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..3ddc70a --- /dev/null +++ b/Package.swift @@ -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"), + ] + ), + ] +) diff --git a/README.md b/README.md index fc22cf0..7483379 100755 --- a/README.md +++ b/README.md @@ -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 diff --git a/iosMath/fonts b/iosMath/fonts new file mode 120000 index 0000000..35bed8b --- /dev/null +++ b/iosMath/fonts @@ -0,0 +1 @@ +../fonts \ No newline at end of file diff --git a/iosMath/include/MTConfig.h b/iosMath/include/MTConfig.h new file mode 120000 index 0000000..119c570 --- /dev/null +++ b/iosMath/include/MTConfig.h @@ -0,0 +1 @@ +../render/MTConfig.h \ No newline at end of file diff --git a/iosMath/include/MTFont.h b/iosMath/include/MTFont.h new file mode 120000 index 0000000..e8fdb66 --- /dev/null +++ b/iosMath/include/MTFont.h @@ -0,0 +1 @@ +../render/MTFont.h \ No newline at end of file diff --git a/iosMath/include/MTFontManager.h b/iosMath/include/MTFontManager.h new file mode 120000 index 0000000..c4941cd --- /dev/null +++ b/iosMath/include/MTFontManager.h @@ -0,0 +1 @@ +../render/MTFontManager.h \ No newline at end of file diff --git a/iosMath/include/MTLabel.h b/iosMath/include/MTLabel.h new file mode 120000 index 0000000..93f4a9b --- /dev/null +++ b/iosMath/include/MTLabel.h @@ -0,0 +1 @@ +../render/MTLabel.h \ No newline at end of file diff --git a/iosMath/include/MTMathAtomFactory.h b/iosMath/include/MTMathAtomFactory.h new file mode 120000 index 0000000..1da410f --- /dev/null +++ b/iosMath/include/MTMathAtomFactory.h @@ -0,0 +1 @@ +../lib/MTMathAtomFactory.h \ No newline at end of file diff --git a/iosMath/include/MTMathList.h b/iosMath/include/MTMathList.h new file mode 120000 index 0000000..2b7b4b7 --- /dev/null +++ b/iosMath/include/MTMathList.h @@ -0,0 +1 @@ +../lib/MTMathList.h \ No newline at end of file diff --git a/iosMath/include/MTMathListBuilder.h b/iosMath/include/MTMathListBuilder.h new file mode 120000 index 0000000..60b60d7 --- /dev/null +++ b/iosMath/include/MTMathListBuilder.h @@ -0,0 +1 @@ +../lib/MTMathListBuilder.h \ No newline at end of file diff --git a/iosMath/include/MTMathListDisplay.h b/iosMath/include/MTMathListDisplay.h new file mode 120000 index 0000000..006d9f9 --- /dev/null +++ b/iosMath/include/MTMathListDisplay.h @@ -0,0 +1 @@ +../render/MTMathListDisplay.h \ No newline at end of file diff --git a/iosMath/include/MTMathListIndex.h b/iosMath/include/MTMathListIndex.h new file mode 120000 index 0000000..098c9d8 --- /dev/null +++ b/iosMath/include/MTMathListIndex.h @@ -0,0 +1 @@ +../lib/MTMathListIndex.h \ No newline at end of file diff --git a/iosMath/include/MTMathUILabel.h b/iosMath/include/MTMathUILabel.h new file mode 120000 index 0000000..3fc02ea --- /dev/null +++ b/iosMath/include/MTMathUILabel.h @@ -0,0 +1 @@ +../render/MTMathUILabel.h \ No newline at end of file diff --git a/iosMath/include/MTTypesetter.h b/iosMath/include/MTTypesetter.h new file mode 120000 index 0000000..af11a00 --- /dev/null +++ b/iosMath/include/MTTypesetter.h @@ -0,0 +1 @@ +../render/internal/MTTypesetter.h \ No newline at end of file diff --git a/iosMath/include/MTUnicode.h b/iosMath/include/MTUnicode.h new file mode 120000 index 0000000..7db786f --- /dev/null +++ b/iosMath/include/MTUnicode.h @@ -0,0 +1 @@ +../lib/MTUnicode.h \ No newline at end of file diff --git a/iosMath/include/NSBezierPath+addLineToPoint.h b/iosMath/include/NSBezierPath+addLineToPoint.h new file mode 120000 index 0000000..22a4c30 --- /dev/null +++ b/iosMath/include/NSBezierPath+addLineToPoint.h @@ -0,0 +1 @@ +../render/NSBezierPath+addLineToPoint.h \ No newline at end of file diff --git a/iosMath/include/NSColor+HexString.h b/iosMath/include/NSColor+HexString.h new file mode 120000 index 0000000..1cfa77e --- /dev/null +++ b/iosMath/include/NSColor+HexString.h @@ -0,0 +1 @@ +../render/NSColor+HexString.h \ No newline at end of file diff --git a/iosMath/include/NSView+backgroundColor.h b/iosMath/include/NSView+backgroundColor.h new file mode 120000 index 0000000..89b5613 --- /dev/null +++ b/iosMath/include/NSView+backgroundColor.h @@ -0,0 +1 @@ +../render/NSView+backgroundColor.h \ No newline at end of file diff --git a/iosMath/include/UIColor+HexString.h b/iosMath/include/UIColor+HexString.h new file mode 120000 index 0000000..1e73541 --- /dev/null +++ b/iosMath/include/UIColor+HexString.h @@ -0,0 +1 @@ +../render/UIColor+HexString.h \ No newline at end of file diff --git a/iosMath/render/MTFont.m b/iosMath/render/MTFont.m index 84d81a6..71d674c 100644 --- a/iosMath/render/MTFont.m +++ b/iosMath/render/MTFont.m @@ -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]; @@ -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"]]; } @@ -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; } diff --git a/iosMath/render/MTFontManager.h b/iosMath/render/MTFontManager.h index 24f4f80..66a1362 100644 --- a/iosMath/render/MTFontManager.h +++ b/iosMath/render/MTFontManager.h @@ -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; diff --git a/iosMath/render/MTFontManager.m b/iosMath/render/MTFontManager.m index 7b1a65b..f4443e6 100644 --- a/iosMath/render/MTFontManager.m +++ b/iosMath/render/MTFontManager.m @@ -31,6 +31,11 @@ + (instancetype) fontManager return manager; } ++ (instancetype) sharedInstance +{ + return [MTFontManager fontManager]; +} + - (instancetype)init { self = [super init]; diff --git a/iosMath/render/UIColor+HexString.h b/iosMath/render/UIColor+HexString.h index 0f84409..16fd3a8 100644 --- a/iosMath/render/UIColor+HexString.h +++ b/iosMath/render/UIColor+HexString.h @@ -8,6 +8,8 @@ #if TARGET_OS_IPHONE +@import UIKit; + @interface UIColor (HexString) + (UIColor *)colorFromHexString:(NSString *)hexString;