From c678dfdee91f75b0671af326b3b3980a26d62d3b Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Sun, 10 Jul 2022 22:05:37 +0100 Subject: [PATCH 01/12] Package.swift --- .gitignore | 4 ++++ Package.swift | 40 +++++++++++++++++++++++++++++++++++++++ iosMath/fonts | 1 + iosMath/include/IosMath.h | 1 + iosMath/render/MTFont.m | 10 +++++++++- 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 Package.swift create mode 120000 iosMath/fonts create mode 120000 iosMath/include/IosMath.h 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/Package.swift b/Package.swift new file mode 100644 index 0000000..94bf6e1 --- /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"), + ] + ), + .testTarget( + name: "iosMathTests", + dependencies: ["iosMath"], + path: "iosMathTests", + cSettings: [ + .headerSearchPath("../iosMath/render"), + .headerSearchPath("../iosMath/lib"), + .headerSearchPath("../iosMath/render/internal"), + ] + ), + ] +) 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/IosMath.h b/iosMath/include/IosMath.h new file mode 120000 index 0000000..ca5ae57 --- /dev/null +++ b/iosMath/include/IosMath.h @@ -0,0 +1 @@ +../IosMath.h \ No newline at end of file diff --git a/iosMath/render/MTFont.m b/iosMath/render/MTFont.m index 84d81a6..de70dc1 100644 --- a/iosMath/render/MTFont.m +++ b/iosMath/render/MTFont.m @@ -70,7 +70,15 @@ - (void)setCtFont:(CTFontRef)ctFont { + (NSBundle*) fontBundle { // 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"]]; + NSBundle* classBundle = [NSBundle bundleForClass:[self class]]; + NSURL* bundleURL = [classBundle URLForResource:@"mathFonts" withExtension:@"bundle"]; + if (!bundleURL) { + // Most likely we're running under Swift Package Manager context. + // Try loading the bundle resource corresponding to the `iosMath` target. + bundleURL = [classBundle URLForResource:@"iosMath_iosMath" withExtension:@"bundle"]; + NSAssert(bundleURL, @"SPM bundle resources for target iosMath was not found."); + } + return [NSBundle bundleWithURL: bundleURL]; } - (MTFont *)copyFontWithSize:(CGFloat)size From ce9d69344bfda71591925631447ec25e9f0e7dd3 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Sun, 10 Jul 2022 23:50:33 +0100 Subject: [PATCH 02/12] Fix the error when consuming from swift --- Package.swift | 23 ++++++++++++----------- iosMath/include/IosMath.h | 1 - iosMath/include/MTMathList.h | 1 + iosMath/include/module.modulemap | 9 +++++++++ iosMath/render/MTFont.m | 13 ++++--------- iosMath/render/UIColor+HexString.h | 2 ++ 6 files changed, 28 insertions(+), 21 deletions(-) delete mode 120000 iosMath/include/IosMath.h create mode 120000 iosMath/include/MTMathList.h create mode 100644 iosMath/include/module.modulemap diff --git a/Package.swift b/Package.swift index 94bf6e1..09f8e78 100644 --- a/Package.swift +++ b/Package.swift @@ -3,23 +3,24 @@ import PackageDescription let package = Package( - name: "iosMath", + name: "IosMath", defaultLocalization: "en", platforms: [.iOS(.v10), .macOS(.v11)], products: [ .library( - name: "iosMath", - targets: ["iosMath"]) + name: "IosMath", + targets: ["IosMath"]) ], dependencies: [], targets: [ .target( - name: "iosMath", + name: "IosMath", dependencies: [], - path: "./iosMath", + path: "./IosMath", resources: [ .process("fonts") ], + publicHeadersPath: "include", cSettings: [ .headerSearchPath("./render"), .headerSearchPath("./lib"), @@ -27,13 +28,13 @@ let package = Package( ] ), .testTarget( - name: "iosMathTests", - dependencies: ["iosMath"], - path: "iosMathTests", + name: "IosMathTests", + dependencies: ["IosMath"], + path: "IosMathTests", cSettings: [ - .headerSearchPath("../iosMath/render"), - .headerSearchPath("../iosMath/lib"), - .headerSearchPath("../iosMath/render/internal"), + .headerSearchPath("../IosMath/render"), + .headerSearchPath("../IosMath/lib"), + .headerSearchPath("../IosMath/render/internal"), ] ), ] diff --git a/iosMath/include/IosMath.h b/iosMath/include/IosMath.h deleted file mode 120000 index ca5ae57..0000000 --- a/iosMath/include/IosMath.h +++ /dev/null @@ -1 +0,0 @@ -../IosMath.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/module.modulemap b/iosMath/include/module.modulemap new file mode 100644 index 0000000..08eeb9e --- /dev/null +++ b/iosMath/include/module.modulemap @@ -0,0 +1,9 @@ +module IosMath { + header "../lib/MTMathList.h" + header "../render/MTMathUILabel.h" + header "../render/MTMathListDisplay.h" + header "../lib/MTMathListBuilder.h" + + export * +} + diff --git a/iosMath/render/MTFont.m b/iosMath/render/MTFont.m index de70dc1..6154a26 100644 --- a/iosMath/render/MTFont.m +++ b/iosMath/render/MTFont.m @@ -69,16 +69,11 @@ - (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. - NSBundle* classBundle = [NSBundle bundleForClass:[self class]]; - NSURL* bundleURL = [classBundle URLForResource:@"mathFonts" withExtension:@"bundle"]; - if (!bundleURL) { - // Most likely we're running under Swift Package Manager context. - // Try loading the bundle resource corresponding to the `iosMath` target. - bundleURL = [classBundle URLForResource:@"iosMath_iosMath" withExtension:@"bundle"]; - NSAssert(bundleURL, @"SPM bundle resources for target iosMath was not found."); - } - return [NSBundle bundleWithURL: bundleURL]; + return [NSBundle bundleWithURL:[[NSBundle bundleForClass:[self class]] URLForResource:@"mathFonts" withExtension:@"bundle"]]; } - (MTFont *)copyFontWithSize:(CGFloat)size 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; From c5e5f28dccc5020d406a236e54b60f3724a40063 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Mon, 11 Jul 2022 00:03:25 +0100 Subject: [PATCH 03/12] Rename IosMath -> iosMath --- Package.swift | 22 +++++++++++----------- iosMath/include/module.modulemap | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Package.swift b/Package.swift index 09f8e78..86af0c4 100644 --- a/Package.swift +++ b/Package.swift @@ -3,20 +3,20 @@ import PackageDescription let package = Package( - name: "IosMath", + name: "iosMath", defaultLocalization: "en", platforms: [.iOS(.v10), .macOS(.v11)], products: [ .library( - name: "IosMath", - targets: ["IosMath"]) + name: "iosMath", + targets: ["iosMath"]) ], dependencies: [], targets: [ .target( - name: "IosMath", + name: "iosMath", dependencies: [], - path: "./IosMath", + path: "./iosMath", resources: [ .process("fonts") ], @@ -28,13 +28,13 @@ let package = Package( ] ), .testTarget( - name: "IosMathTests", - dependencies: ["IosMath"], - path: "IosMathTests", + name: "iosMathTests", + dependencies: ["iosMath"], + path: "iosMathTests", cSettings: [ - .headerSearchPath("../IosMath/render"), - .headerSearchPath("../IosMath/lib"), - .headerSearchPath("../IosMath/render/internal"), + .headerSearchPath("../iosMath/render"), + .headerSearchPath("../iosMath/lib"), + .headerSearchPath("../iosMath/render/internal"), ] ), ] diff --git a/iosMath/include/module.modulemap b/iosMath/include/module.modulemap index 08eeb9e..3ebb749 100644 --- a/iosMath/include/module.modulemap +++ b/iosMath/include/module.modulemap @@ -1,4 +1,4 @@ -module IosMath { +module iosMath { header "../lib/MTMathList.h" header "../render/MTMathUILabel.h" header "../render/MTMathListDisplay.h" From 01ca7209675caa2bb899cfa8d13f94f910657254 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Mon, 11 Jul 2022 01:27:02 +0100 Subject: [PATCH 04/12] More include based on MathEditor --- iosMath/include/MTFont.h | 1 + iosMath/include/MTFontManager.h | 1 + iosMath/include/MTMathAtomFactory.h | 1 + iosMath/include/MTMathListBuilder.h | 1 + iosMath/include/MTMathListDisplay.h | 1 + iosMath/include/MTMathListIndex.h | 1 + iosMath/include/MTMathUILabel.h | 1 + iosMath/include/MTTypesetter.h | 1 + iosMath/include/MTUnicode.h | 1 + 9 files changed, 9 insertions(+) create mode 120000 iosMath/include/MTFont.h create mode 120000 iosMath/include/MTFontManager.h create mode 120000 iosMath/include/MTMathAtomFactory.h create mode 120000 iosMath/include/MTMathListBuilder.h create mode 120000 iosMath/include/MTMathListDisplay.h create mode 120000 iosMath/include/MTMathListIndex.h create mode 120000 iosMath/include/MTMathUILabel.h create mode 120000 iosMath/include/MTTypesetter.h create mode 120000 iosMath/include/MTUnicode.h 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/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/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 From 3c1d5c714d6b2d5e760bbac917755998c5147df6 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Wed, 13 Jul 2022 00:30:48 +0100 Subject: [PATCH 05/12] Remove unneed --- MathFontBundle/MathFontBundle-Info.plist | 44 ----------------------- MathFontBundle/en.lproj/InfoPlist.strings | 2 -- Package.swift | 1 - iosMath/include/MTConfig.h | 1 + iosMath/include/UIColor+HexString.h | 1 + iosMath/include/module.modulemap | 9 ----- 6 files changed, 2 insertions(+), 56 deletions(-) delete mode 100644 MathFontBundle/MathFontBundle-Info.plist delete mode 100644 MathFontBundle/en.lproj/InfoPlist.strings create mode 120000 iosMath/include/MTConfig.h create mode 120000 iosMath/include/UIColor+HexString.h delete mode 100644 iosMath/include/module.modulemap 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 index 86af0c4..94bf6e1 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,6 @@ let package = Package( resources: [ .process("fonts") ], - publicHeadersPath: "include", cSettings: [ .headerSearchPath("./render"), .headerSearchPath("./lib"), 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/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/include/module.modulemap b/iosMath/include/module.modulemap deleted file mode 100644 index 3ebb749..0000000 --- a/iosMath/include/module.modulemap +++ /dev/null @@ -1,9 +0,0 @@ -module iosMath { - header "../lib/MTMathList.h" - header "../render/MTMathUILabel.h" - header "../render/MTMathListDisplay.h" - header "../lib/MTMathListBuilder.h" - - export * -} - From 5827ff082331288673db7f1f32ff8186eb595845 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Wed, 13 Jul 2022 00:52:28 +0100 Subject: [PATCH 06/12] Add README --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 From bd4c924eedfdb338e21f19afdab0bfedafa993dc Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Wed, 13 Jul 2022 00:57:59 +0100 Subject: [PATCH 07/12] cleanup package --- Package.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/Package.swift b/Package.swift index 94bf6e1..a80917a 100644 --- a/Package.swift +++ b/Package.swift @@ -32,8 +32,6 @@ let package = Package( path: "iosMathTests", cSettings: [ .headerSearchPath("../iosMath/render"), - .headerSearchPath("../iosMath/lib"), - .headerSearchPath("../iosMath/render/internal"), ] ), ] From ecf823ca0e00156fa977f9dd026a5b89a0ee3cbd Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Mon, 28 Nov 2022 00:03:23 +0000 Subject: [PATCH 08/12] Make it compile for MacOs --- iosMath/include/MTLabel.h | 1 + iosMath/include/NSBezierPath+addLineToPoint.h | 1 + iosMath/include/NSColor+HexString.h | 1 + iosMath/include/NSView+backgroundColor.h | 1 + 4 files changed, 4 insertions(+) create mode 120000 iosMath/include/MTLabel.h create mode 120000 iosMath/include/NSBezierPath+addLineToPoint.h create mode 120000 iosMath/include/NSColor+HexString.h create mode 120000 iosMath/include/NSView+backgroundColor.h 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/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 From 5fa3fcb51e9d5e16c3cf19f05943a359601c1454 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Mon, 28 Nov 2022 11:49:28 +0000 Subject: [PATCH 09/12] Fix memory leak --- iosMath/render/MTFont.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iosMath/render/MTFont.m b/iosMath/render/MTFont.m index 6154a26..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]; @@ -80,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; } From 01d35d968d9c26b56a64598ddc657797d27528b7 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Mon, 28 Nov 2022 11:52:09 +0000 Subject: [PATCH 10/12] Fix memory leak in MTFont --- iosMath/render/MTFont.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/iosMath/render/MTFont.m b/iosMath/render/MTFont.m index 84d81a6..4a9d843 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]; @@ -77,11 +77,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; } From a6f6805ae1be3a0ca79acf80b88e0671d3e79bf0 Mon Sep 17 00:00:00 2001 From: Madiyar Aitbayev Date: Sat, 11 Mar 2023 22:47:56 +0000 Subject: [PATCH 11/12] Add swift friendly shared instance for MTFontManager --- iosMath/render/MTFontManager.h | 3 +++ iosMath/render/MTFontManager.m | 5 +++++ 2 files changed, 8 insertions(+) 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]; From ccbec9697f8faa8c88f748cd62a7e6c93ed57615 Mon Sep 17 00:00:00 2001 From: Eric Horacek Date: Fri, 14 Jun 2024 16:55:03 -0700 Subject: [PATCH 12/12] Prevent NSAssert from crashing the app in release builds --- Package.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Package.swift b/Package.swift index a80917a..3ddc70a 100644 --- a/Package.swift +++ b/Package.swift @@ -24,6 +24,8 @@ let package = Package( .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(