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

Handle avar table version 2 #316

Open
Lorp opened this issue Jul 13, 2023 · 0 comments
Open

Handle avar table version 2 #316

Lorp opened this issue Jul 13, 2023 · 0 comments

Comments

@Lorp
Copy link

Lorp commented Jul 13, 2023

An updated version of the avar table is going through the standardization process, having already been implemented in Apple (macOS and iOS), FreeType and Harfbuzz. The new table allows for the location of one variation axis to be influenced by the locations of other variation axes. This helps multi-axis fonts behave more flexibly and intuitively.

It is described here: boring-expansion-spec/avar2.md

A JavaScript implementation that builds on Fontkit’s existing ItemVariationStore code can potentially be very short. For example, here is the code that Samsa runs each time a new instance is requested:

// at this point, tuple is an array of length axisCount, containing one value per axis, each of which has been normalized by avar v1

const deltas = font.itemVariationStoreInstantiate(avar.itemVariationStore, tuple);
for (let a=0; a<axisCount; a++) {
	const [outer, inner] = avar.axisIndexMap[ Math.min(a, avar.axisIndexMap.length - 1) ]; // use the a’th entry or the last entry of axisIndexMap
	if (outer != 0xffff && inner != 0xffff) {
		tuple[a] += deltas[outer][inner] / 0x4000; // add the interpolated delta to tuple[a]
		tuple[a] = clamp(tuple[a], -1, 1); // clamp the result to [-1,1]
	}
}

// round each tuple entry to nearest 1/16384 here
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

No branches or pull requests

1 participant