Skip to content

Enumerate available fonts through the native API on macOS - #263

Merged
JimBobSquarePants merged 4 commits into
SixLabors:mainfrom
0xced:MacSystemFonts
May 16, 2022
Merged

Enumerate available fonts through the native API on macOS#263
JimBobSquarePants merged 4 commits into
SixLabors:mainfrom
0xced:MacSystemFonts

Conversation

@0xced

@0xced 0xced commented Apr 26, 2022

Copy link
Copy Markdown
Contributor

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following matches the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

macOS provides the CTFontManagerCopyAvailableFontURLs() method to get a list of all available fonts. Use it to iterate available fonts on macOS instead of scanning a list of hardcoded directories.

Use the Switch.SixLabors.Fonts.DoNotUseNativeSystemFontsEnumeration AppContext switch to opt-out of the native system fonts enumeration.

Running the ListFonts sample code before this change on my Mac would yield 628 fonts and 726 after this change because CTFontManagerCopyAvailableFontURLs knows about downloadable fonts.

0xced added 2 commits April 26, 2022 23:24
macOS provides the CTFontManagerCopyAvailableFontURLs() method to get a list of all available fonts. Use it to iterate available fonts on macOS instead of scanning a list of hardcoded directories.

Use the `Switch.SixLabors.Fonts.DoNotUseNativeSystemFontsEnumeration` AppContext switch to opt-out of the native system fonts enumeration.
@codecov

codecov Bot commented Apr 26, 2022

Copy link
Copy Markdown

Codecov Report

Merging #263 (7f953ed) into main (5359ec7) will decrease coverage by 0%.
The diff coverage is 27%.

@@         Coverage Diff         @@
##           main   #263   +/-   ##
===================================
- Coverage    83%    83%   -1%     
===================================
  Files       186    187    +1     
  Lines      9474   9517   +43     
  Branches   1493   1499    +6     
===================================
+ Hits       7936   7939    +3     
- Misses     1193   1231   +38     
- Partials    345    347    +2     
Flag Coverage Δ
unittests 83% <27%> (-1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...SixLabors.Fonts/Native/MacSystemFontsEnumerator.cs 0% <0%> (ø)
src/SixLabors.Fonts/SystemFontCollection.cs 57% <69%> (-3%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5359ec7...7f953ed. Read the comment docs.

@JimBobSquarePants

Copy link
Copy Markdown
Member

Well this is cool! Thanks!

I'm not super well versed with dll Importing so I'm gonna see if I can get a second opinion for reviewing.

@JimBobSquarePants JimBobSquarePants left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks like it's working well to me an is very well documented to approving.

Thanks @0xced for your help! 👍

@JimBobSquarePants
JimBobSquarePants merged commit 2832534 into SixLabors:main May 16, 2022
@JimBobSquarePants JimBobSquarePants added this to the 1.0.0-rc1 milestone May 16, 2022
@0xced
0xced deleted the MacSystemFonts branch May 16, 2022 16:29
@0xced

0xced commented May 17, 2022

Copy link
Copy Markdown
Contributor Author

Awesome, thanks for merging. Once the cff-support support branch will be merged, a lot of fonts will be available on macOS! 😀

Also, I'll make sure not to use file scoped namespaces in my future pull requests.

@JimBobSquarePants

Copy link
Copy Markdown
Member

No worries!

Working hard on CFF but it's a huge task. Could take me a while.

Also, I'll make sure not to use file scoped namespaces in my future pull requests.

Once I finally shift a V1 I'll be moving everything to the latest and greatest so we can use things like that without issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants