Inspect OpenType’s −1 to 1 scale. The program reads Newsreader.ttf from the working directory (the file comes in the zip); you can replace it with the path to any variable .ttf.
dotnet add package RecursiveAI.OneFontRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using OneFont; var face = FontFace.Load( File.ReadAllBytes("Newsreader.ttf")); var weight = FontVariation.Weight(600); var coords = face.WithVariations(weight) .GetNormalizedCoordinates(); for (int i = 0; i < coords.Length; i++) { var tag = face.Axes[i].Tag; var line = FormattableString.Invariant( $"{tag}: {coords[i]:F8}"); Console.WriteLine(line); }
Paste the code above into Program.cs of a new dotnet new console project and dotnet run, or unzip the example and dotnet run.
Prints the normalized values in font axis order for a weight of 600.
wght: 0.42401123 opsz: 0.00000000
At the default instance the coordinate array is empty, so the loop prints nothing rather than one zero per axis. The zip includes the sample’s SIL Open Font License.
Variations
Check the default and the endpoints
Append this to see the default’s empty array and the normalized bounds for wght:
var low = face.WithVariations( FontVariation.Weight(200)); var high = face.WithVariations( FontVariation.Weight(800)); var defaults = face.GetNormalizedCoordinates(); Console.WriteLine(defaults.Length); Console.WriteLine(low.GetNormalizedCoordinates()[0]); Console.WriteLine(high.GetNormalizedCoordinates()[0]);
0 -1 1
Related recipes
Read variable font axes and ranges
Set variable font weight and optical size
The short answer
After selecting a face with WithVariations, read GetNormalizedCoordinates(). For a nonempty result, pair the returned values with Axes by index, not by a presumed order of weight, width, and size. These are the font’s normalized values after remapping and rounding. To display the weight in a settings panel, use Variations instead: the user-space weight for the example is 600 even though the normalized weight is about 0.424.
How does OpenType normalize variation coordinates?
The OpenType normalization algorithm starts with the axis minimum, default, and maximum from fvar. It clamps the input to the range and maps those three landmarks to −1, 0, and 1. Below the default it scales by the distance from minimum to default; above the default it scales by the distance from default to maximum. This matters for an axis whose default isn’t halfway between its endpoints. For this font, 600 is halfway from the default weight 400 to the maximum 800, so the first mapping gives 0.5, not a fraction measured from the minimum of 200.
What does the OpenType avar table do?
The avar table can remap intermediate positions after that initial scaling. Newsreader remaps the weight position at 0.5 to approximately 0.424. The untouched optical size sits at its default, so the corresponding coordinate is zero. OneFont’s pinned documentation describes the final step as “round to the 2.14 grid”: that means increments of 1/16,384. The sample prints eight decimal places for inspection. OneFont applies the version 1 segment maps but not the extra version 2 mappings, which can matter when you compare the numbers with another reader.
Why is the normalized coordinate array empty at the default instance?
OpenType’s normalized default corresponds to zero on each axis. OneFont’s GetNormalizedCoordinates() represents the default by an empty array. That is not the same as an absence of axes: check IsVariable to distinguish a default variable face from a nonvariable font. If you need a row in a diagnostic table for every axis, supply zero for each declared axis when the array is empty. If only one axis moves off default, the nonempty result still includes the other axes in font order, as the opsz row in the example shows.