Skip to content
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

Pass optional postscriptName parameter to fontkit #156

Closed
wants to merge 2 commits into from

Conversation

tsung-ju
Copy link

Currently passing .ttc files to fromFile, fromBlob or fromUrl causes an error, because fontkit returns a Collection instead of a Font. I added an optional postscriptName parameter which tells fontkit to return a specific font from the collection.

Here's an example usage:

const metrics = await fromFile('NotoSans.ttc', 'NotoSans');

@tsung-ju tsung-ju requested a review from a team as a code owner December 22, 2023 03:18
Copy link

changeset-bot bot commented Dec 22, 2023

⚠️ No Changeset found

Latest commit: db666da

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.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@michaeltaranto
Copy link
Contributor

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.

@paschun
Copy link

paschun commented May 23, 2024

Would love to see this!

@michaeltaranto
Copy link
Contributor

michaeltaranto commented May 24, 2024

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?

@michaeltaranto
Copy link
Contributor

Closing due to inactivity, but have opened #208 that goes a bit further as described above. Thanks for the push.

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.

3 participants