-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix: Fix variable fonts in WebGL mode #7459
base: main
Are you sure you want to change the base?
Conversation
Fixes processing#7447 Update `FontInfo` class in `src/webgl/text.js` to account for variable font changes and cache by variable value. * Add `variableFontCache` to `FontInfo` class to store variable font data. * Modify `getGlyphInfo` method to use cache key based on glyph index and variable values. * Adjust `getGlyphInfo` method to return cached glyph info based on cache key. * Update initialization of glyph info to use cache key. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/processing/p5.js/issues/7447?shareId=XXXX-XXXX-XXXX-XXXX).
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page! |
Please verify my pr and let me know if any change is required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking into this so far! I have to bits of feedback:
- To fully connect this so that it works with variable fonts, we'll have to edit the code that calls
getGlyphInfo
to pass the current variable states. For the glyph itself to actually represent those variable values, we will need to tell Typr to use those values too (I haven't looked into exactly how to do this since it was only just added to Typr -- @dhowe have you looked into how this works yet?) - Currently, we are caching glyph info by variable values, which is great! But this means we're only ever adding to the cache, never removing old values to keep it at a reasonable size. That would be resolved by making it an LRU cache, which means keeping track of each time we access a cached item (removing it then re-adding it to an object can work) and removing the oldest item when the size gets too large (possibly just doing
delete this.glyphInfos[Object.keys(this.glyphInfos).at(-1)]
. Probably a max of 1000 or so would be good?
@@ -158,6 +158,8 @@ class FontInfo { | |||
|
|||
// the cached information for each glyph | |||
this.glyphInfos = {}; | |||
// cache for variable font data | |||
this.variableFontCache = new Map(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like nothing else is using this yet, is it necessary?
@@ -167,9 +169,13 @@ class FontInfo { | |||
* calculates rendering info for a glyph, including the curve information, | |||
* row & column stripes compiled into textures. | |||
*/ | |||
getGlyphInfo (glyph) { | |||
getGlyphInfo (glyph, variableValues) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now nothing passes in variableValues
to this function, can we also edit the spots that call getGlyphInfo
to pass along this information?
Fixes #7447
Update
FontInfo
class insrc/webgl/text.js
to account for variable font changes and cache by variable value.variableFontCache
toFontInfo
class to store variable font data.getGlyphInfo
method to use cache key based on glyph index and variable values.getGlyphInfo
method to return cached glyph info based on cache key.For more details, open the Copilot Workspace session.