Read the ranges for controls like weight. 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")); foreach (var axis in face.Axes) { var label = axis.Name ?? axis.Tag; Console.WriteLine($"{axis.Tag}: {label}"); Console.WriteLine( $" Min: {axis.Minimum} " + $"Default: {axis.Default} " + $"Max: {axis.Maximum}"); }
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 tag, name, and minimum, default, and maximum for each axis.
wght: Weight Min: 200 Default: 400 Max: 800 opsz: Optical Size Min: 6 Default: 18 Max: 72
If the file has no usable variation axes, Axes is empty and the loop prints nothing. The zip includes the sample’s SIL Open Font License.
Variations
List the axes to offer in a picker
Append this to skip axes the font marks as hidden:
foreach (var axis in face.Axes) if (!axis.IsHidden) Console.WriteLine(axis.Tag);
wght opsz
Related recipes
Set variable font weight and optical size
Load a variable font named instance
Read normalized variation coordinates
The short answer
Load the font file with FontFace.Load and enumerate face.Axes. For each axis, use Tag as its identifier, Name as its display label when present, and Minimum, Default, and Maximum as the bounds and initial value for a control. These are values in the font’s own axis units, not percentages of the range or normalized coordinates. The sample outputs wght and opsz in the order they were declared in the file.
How can you tell if a font is variable?
Check face.IsVariable. The .ttf or .otf extension isn’t enough to tell a static font from a variable one. OneFont looks for a usable OpenType fvar table, which defines the axes and ranges. The Axes API documents the list as “empty for a font that is not variable.” If a font is meant to be variable but the property is false, verify that you opened the variable file rather than a static export. A damaged fvar table can also leave the face looking static to OneFont. Use an actual font file; OneFont doesn’t read WOFF or WOFF2.
How do variable font axes and ranges work?
An axis describes a setting the font author lets you change. OpenType has registered tags such as wght for weight and opsz for optical size. Fonts can also define custom axes. Read what the file has rather than assuming a particular set of tags. The OpenType fvar specification defines the minimum, default, and maximum for each axis. The default isn’t necessarily the midpoint: in this example the optical-size range is 6–72, but the default is 18. In an editor, initialize a slider at the declared default and use that same value when the user resets the control.
A friendly axis name is optional. OneFont’s FontAxis returns null when it can’t supply a name, so the tag is a useful fallback. Keep the tag for saved settings even when the UI shows a label. A hidden axis can still appear in the metadata; the flag means the font asks the UI not to offer it, not that the axis has been removed.