A static face gives you one design. A variable font lets you pick an in-between weight without swapping files, but you may need to re-measure the text.
OneFont is a free, open-source .NET library from Recursive AI, licensed under MIT or Apache-2.0. NuGet · GitHub · Getting started
dotnet new console dotnet add package RecursiveAI.OneFont --version 1.5.1
Variable font support starts in OneFont 1.5.0. Download the pinned static Noto Sans subset and variable Noto Sans subset beside the project, then run this program.
curl -fLO 'https://raw.githubusercontent.com/recursive-ai-oss/onefont-csharp/8c71b3fc22254ad7ff2561eb3abd171f1abdea0c/tests/testdata/fonts/NotoSans-Subset-Regular.ttf' && curl -fLO 'https://raw.githubusercontent.com/recursive-ai-oss/onefont-csharp/8c71b3fc22254ad7ff2561eb3abd171f1abdea0c/tests/testdata/fonts/variable/NotoSans-Variable-Subset.ttf'
using OneFont; using OneFont.Fonts; using System.Globalization; CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; var fixedFace = FontFace.Load(File.ReadAllBytes("NotoSans-Subset-Regular.ttf")); var variable = FontFace.Load(File.ReadAllBytes("NotoSans-Variable-Subset.ttf")); var heavier = variable.WithVariations(FontVariation.Weight(650)); Show("Static", fixedFace); Show("Variable default", variable); Show("Variable 650", heavier); static void Show(string label, FontFace face) { var run = TextShaping.ShapeRun("AV", face); var width = run.Sum(cluster => cluster.Advance) * 32.0 / face.UnitsPerEm; var (left, _, right, _) = face.GetOutline(face.GetGlyphIndex('A')).TightBox(); Console.WriteLine($"{label}: AV {width:F2} px; A ink width {right - left:F2} units"); }
Static: AV 38.37 px; A ink width 638.00 units Variable default: AV 38.37 px; A ink width 638.00 units Variable 650: AV 40.99 px; A ink width 680.20 units
At 32 px, both Regular faces gave the same advance for “AV” in these fixtures. At weight 650 the run took 40.99 px, so the text would overflow a label 40 px wide. The A also had a wider outline. These are different measurements: ink width is how wide the contour is, while advance is how far the pen moves after shaping. See font units vs. pixels for the scale conversion.
Axes, named instances, and static faces
An OpenType variation axis is a named range with a minimum, default, and maximum. wght controls weight, wdth controls width, and opsz tunes the design for an optical size; it does not replace your rendering size. Not every file has every axis. A named instance, such as “Bold,” is a font-supplied preset of axis coordinates, not another file or a limit on the values you can pick.
| Static faces | Variable font |
|---|---|
| Choose a style | |
| Select a fixed face, often in a separate font file. | Set axis values or choose a named instance from the same font. |
| Measure text | |
| Measure using the selected face; Regular and Bold can have different metrics. | Measure using the selected instance; even an intermediate weight can change advances. |
| Ship files | |
| Ship only the fixed styles you need. | One file can serve several styles within its ranges. Compare the actual bytes you would ship; fewer files do not guarantee fewer bytes. |
In OneFont, loading a variable file starts at its default instance. The instance can change outlines, horizontal advances, side bearings, font-wide metrics such as ascenders and descenders, and shaping, depending on what the font supplies. Shape, measure, and draw with the same instance. If you cache runs, include the instance in the key; a font filename and point size alone cannot distinguish different axis settings.
Which should you ship?
Use fixed faces if you need only a small set of approved styles or another part of your pipeline can’t apply variations. Use a variable font when the design needs positions between those styles or multiple values across axes. Test tight labels, line breaks, and page breaks using the actual faces or instances you will ship.
OneFont 1.5.1 reads variable TrueType outlines and OpenType CFF2, but not WOFF or WOFF2, and does not apply vertical metrics or avar version 2 mappings. See the format and variation limits. For the API details, see how to list the axes a font provides, set an axis value, or select a named instance.