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

Use TTFLoader in useFont for non-JSON files #2095

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mz8i
Copy link

@mz8i mz8i commented Sep 17, 2024

Why

Resolves #2094

What

I modified useFont to rely not only on FontLoader, but also TTFLoader, which can transform an ArrayBuffer to Typeface.json object. If a string is passed to the Text3D.font prop, or to useFont directly, and the content type of the fetched response is not application/json, then TTFLoader is used first.

NOTE: the Storybook story is draft for now in that I didn't want to add any .ttf file to the .storybook/public/fonts folder, so the story points to a Placeholder.ttf and will error. I welcome suggestions on what font file should be added to the tests when considering licensing.

Also NOTE: the current implementation doesn't allow for setting properties on the loaders. FontLoader doesn't really have any properties apart from the ones inherited from base Loader, and the original code also didn't give an option to access these. However, TTFLoader does have one important property: reversed (which is the same as the "reverse direction" checkbox on the Facetype.js website and helps deal with issues with rendering of characters such as "8", "b" etc). I haven't figured out yet what would be a nice way to allow for setting this property. Perhaps something like:

<Text3D font="/fonts/Example.ttf" loaderArgs={ ttf: {reversed: true } } >
Text
</Text3D>

I also updated the documentation/examples, but any suggestions for improvements there are very welcome!

Checklist

  • Documentation updated (example)
  • Storybook entry added (example)
  • Ready to be merged

Copy link

vercel bot commented Sep 17, 2024

@mz8i is attempting to deploy a commit to the Poimandres Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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.

Allow Text3D to use TTFLoader
1 participant