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

fix: Fix variable fonts in WebGL mode #7459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

AritraDey-Dev
Copy link

@AritraDey-Dev AritraDey-Dev commented Jan 6, 2025

Fixes #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.

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).
Copy link

welcome bot commented Jan 6, 2025

🎉 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!

@AritraDey-Dev
Copy link
Author

Please verify my pr and let me know if any change is required

@dhowe dhowe requested a review from davepagurek January 12, 2025 15:07
Copy link
Contributor

@davepagurek davepagurek left a 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();
Copy link
Contributor

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) {
Copy link
Contributor

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?

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.

[2.0] Make variable Typr p5.Fonts use the same variables as the 2D canvas
2 participants