-
Notifications
You must be signed in to change notification settings - Fork 254
Constant-driven MTFontManager API + caller migration #210
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b5f8b9
[item 9] Add public MTFontName* font-name constants
kostub 11c7b28
[item 10] Remove per-font convenience methods; route defaultFont via …
kostub ee8612e
[item 11] Migrate iOS example to fontWithName: + applyFontWithName:
kostub e05e4f9
[item 12] Migrate SwiftMathExample MathFont to fontWithName: + constants
kostub 7cdf374
[item 13] Update README usage snippet to fontWithName: + constants
kostub 8b36f91
[item 14] Note breaking font-API change and new fonts in CHANGELOG
kostub 73e3fc4
[review] Use fontManager singleton + name constants in examples/docs
kostub 1956418
Make MTFontManager a true singleton; expose via class property
kostub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
MTFontManager()creates a new instance ofMTFontManagerevery timefont(size:)is called. This bypasses the singleton instance and defeats the caching mechanism ofnameToFontMap, leading to redundant font loading and parsing overhead. Use the sharedfontManager()singleton instead.References
MTFontManager.fontManager()instead of creating a newMTFontManagerinstance to leverage the built-in caching mechanism and avoid performance degradation from re-parsing font files.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 73e3fc4. Switched to
MTFontManager.fontManager()so the sharednameToFontMapcache is reused instead of re-parsing the font on everyfont(size:)call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction to the previous reply:
MTFontManager.fontManager()does not compile in Swift. Because the Obj-C+ (instancetype) fontManageris a factory method whose name matches the class, Swift's Clang importer collapses it intoinit()and marksfontManager()as unavailable ('fontManager()' has been replaced by 'init()'). SoMTFontManager()was actually the only spelling Swift offered — and it resolved to-init, producing a fresh, cache-bypassing instance. The original report was correct on both counts.Properly fixed in 1956418:
fontManageris now a class property (@property (class, readonly, strong) MTFontManager *fontManager;) so Swift imports it asMTFontManager.fontManager(no parens, noinit()collapse), andinit/newareNS_UNAVAILABLEso the bypass can't be written at all. This call site now usesMTFontManager.fontManager.font(withName:size:).Verified:
swift test(265 tests), the iOS Obj-C example, and the SwiftMathExample app all build.