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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/webgl/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class FontInfo {

// the cached information for each glyph
this.glyphInfos = {};
// cache for variable font data
this.variableFontCache = new Map();
}
/**
* @method getGlyphInfo
Expand All @@ -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) {
// check the cache
let gi = this.glyphInfos[glyph.index];
let cacheKey = glyph.index;
if (variableValues) {
cacheKey += JSON.stringify(variableValues);
}
let gi = this.glyphInfos[cacheKey];
if (gi) return gi;

// get the bounding box of the glyph from opentype.js
Expand All @@ -181,7 +187,7 @@ class FontInfo {
const cmds = glyph.path.commands;
// don't bother rendering invisible glyphs
if (gWidth === 0 || gHeight === 0 || !cmds.length) {
return (this.glyphInfos[glyph.index] = {});
return (this.glyphInfos[cacheKey] = {});
}

let i;
Expand All @@ -204,13 +210,13 @@ class FontInfo {
strokes.push(v); // add this stroke to the list

/**
* @function minMax
* @param {Number[]} rg the list of values to compare
* @param {Number} min the initial minimum value
* @param {Number} max the initial maximum value
*
* find the minimum & maximum value in a list of values
*/
* @function minMax
* @param {Number[]} rg the list of values to compare
* @param {Number} min the initial minimum value
* @param {Number} max the initial maximum value
*
* find the minimum & maximum value in a list of values
*/
function minMax(rg, min, max) {
for (let i = rg.length; i-- > 0; ) {
const v = rg[i];
Expand Down Expand Up @@ -628,7 +634,7 @@ class FontInfo {
}

// initialize the info for this glyph
gi = this.glyphInfos[glyph.index] = {
gi = this.glyphInfos[cacheKey] = {
glyph,
uGlyphRect: [bb.x1, -bb.y1, bb.x2, -bb.y2],
strokeImageInfo,
Expand Down