Open tsung-ju opened 6 months ago
Latest commit: 3f6b63b27b94a4d0633e7344f18f7578fc1f0dcb
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Thanks for looking at this. We have some work landing soon that introduces an options object as a second parameter to these APIs and that will clash with the approach of this PR currently.
Adding better support for type collections is definitely part of the plan, but want to consider this as a feature on top of the new work landing shortly if thats ok.
Would love to see this!
Sorry, returning to this now that we have completed both the unicode subset work and weight/variant support, and it looks like we didnt end up adding an options object.
I still prefer the extensibility of using an options object here, e.g.:
const metrics = await fromFile('<path>', {
postscriptName: '...'
});
Have just been playing around with how we can improve the DX if users get this wrong, e.g. providing feedback when opening a collection without providing a postscriptName
and was able to extract and build this message which I think is helpful:
Error: Metrics cannot be unpacked for a font collection.
Either provide a single font file or specify a `postscriptName` in the options. For example:
------------------------------------------
const metrics = await fromFile('<path>', {
postscriptName: 'AvenirNext-Bold'
});
------------------------------------------
Available `postscriptNames` in this collection are:
- AvenirNext-Bold
- AvenirNext-BoldItalic
- AvenirNext-DemiBold
- AvenirNext-DemiBoldItalic
- AvenirNext-Italic
- AvenirNext-Medium
- AvenirNext-MediumItalic
- AvenirNext-Regular
- AvenirNext-Heavy
- AvenirNext-HeavyItalic
- AvenirNext-UltraLight
- AvenirNext-UltraLightItalic
Are you happy for me to push to this PR?
Currently passing .ttc files to
fromFile
,fromBlob
orfromUrl
causes an error, because fontkit returns aCollection
instead of aFont
. I added an optionalpostscriptName
parameter which tells fontkit to return a specific font from the collection.Here's an example usage: