Use TTFLoader
in useFont
for non-JSON files
#2095
Draft
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.
Why
Resolves #2094
What
I modified
useFont
to rely not only onFontLoader
, but alsoTTFLoader
, which can transform anArrayBuffer
to Typeface.json object. If a string is passed to theText3D.font
prop, or touseFont
directly, and the content type of the fetched response is notapplication/json
, thenTTFLoader
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 aPlaceholder.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 baseLoader
, 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:I also updated the documentation/examples, but any suggestions for improvements there are very welcome!
Checklist