---
title: "Font units vs. pixels"
url: https://recursiveai.org/onefont/articles/font-units-vs-pixels/
description: "Convert font units to pixels by multiplying by the font size in pixels and dividing by units per em. The same scale works for horizontal distances and baseline metrics."
date: 2026-11-18
author: OneFont team
---

# Font units vs. pixels

Convert font units to pixels by multiplying by the font size in pixels and dividing by units per em. The same scale works for horizontal distances and baseline metrics.

November 18, 2026 · OneFont team

OneFont, a free, open-source .NET library from Recursive AI ([MIT](https://github.com/recursive-ai-oss/onefont-csharp/blob/7db48bc21a7eec46272aa73f4e76acf07645db03/LICENSE-MIT) or [Apache-2.0](https://github.com/recursive-ai-oss/onefont-csharp/blob/7db48bc21a7eec46272aa73f4e76acf07645db03/LICENSE-APACHE)), loads fonts and shapes text: it picks glyphs and positions for the text. [NuGet](https://www.nuget.org/packages/RecursiveAI.OneFont/1.4.0) · [GitHub](https://github.com/recursive-ai-oss/onefont-csharp) · [Docs](https://recursiveai.org/onefont/docs/)

**Formula:**
 `px = units * fontSizePx / unitsPerEm`

*Set up the console project*

```
dotnet new console
dotnet add package RecursiveAI.OneFont --version 1.4.0
```

## The em sets the scale, not the ink size

The em square is the font’s reference grid. A face with 1,000 units per em places 1,000 design units across one em. At a font size of 16 px, those 1,000 units span 16 px; that does not make every glyph 16 px wide or tall. An advance is how far the pen moves before placing the next glyph.

Use floating-point arithmetic for `fontSizePx / face.UnitsPerEm`. Apply the resulting scale to the shaped advances and offsets, and round only as required by the final layout or rasterizer. If your font size is in CSS pixels, the result is in CSS pixels; apply the output’s device-pixel scale separately. [OneFont returns design units](https://github.com/recursive-ai-oss/onefont-csharp/blob/7db48bc21a7eec46272aa73f4e76acf07645db03/README.md#L24-L51), so the same run can be measured at multiple sizes without reshaping for size alone.

## One shaped run at 16 px and 32 px

Use the .NET 10 SDK and the default console template above (implicit usings enabled). Download the pinned font fixture beside the project, then replace `Program.cs` and run it from that directory. The sample includes a trailing space so the advance and ink distinction is visible in the numbers.

*Download the pinned font fixture*

```
curl -LO https://raw.githubusercontent.com/recursive-ai-oss/onefont-csharp/7db48bc21a7eec46272aa73f4e76acf07645db03/tests/testdata/fonts/NotoSans-Shaping-Subset.ttf
```

*Program.cs · .NET 10*

```
using System.Globalization;
using OneFont;
 
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
var face = FontFace.Load(File.ReadAllBytes("NotoSans-Shaping-Subset.ttf"));
var run = TextShaping.ShapeRun("AV ", face);
var m = face.Metrics;
Console.WriteLine($"Units per em: {face.UnitsPerEm}");
foreach (var cluster in run)
    Console.WriteLine($"Cluster {cluster.Start}: advance {cluster.Advance} units");
 
var advance = run.Sum(cluster => cluster.Advance);
foreach (double size in new[] { 16.0, 32.0 })
{
    double scale = size / face.UnitsPerEm;
    Console.WriteLine($"At {size:F0} px: advance {advance * scale:F3} px");
    Console.WriteLine($"  Ascent {m.Ascender * scale:F3}, descent {m.Descender * scale:F3}, line height {m.LineHeight * scale:F3} px");
}
```

*Observed output · Console*

```
Units per em: 1000
Cluster 0: advance 599 units
Cluster 1: advance 600 units
Cluster 2: advance 260 units
At 16 px: advance 23.344 px
  Ascent 17.104, descent -4.688, line height 21.792 px
At 32 px: advance 46.688 px
  Ascent 34.208, descent -9.376, line height 43.584 px
```

The shaped run advances 1,459 design units, including 260 for the space. At 16 px that space alone advances 4.16 px but paints no ink. At 32 px the run advances twice as far with the same glyph placements in font units. Use the shaped advances, not isolated glyph widths added together: shaping can substitute glyphs or change positions through kerning and other positioning rules.

## Pick the metric that answers your question

- **Where does the next run start?** Use the shaped advance. It measures pen movement, including blank space, not a tight rectangle around the glyphs.
- **Where is the baseline?** Use the face’s ascender and descender as inputs to your line layout. The ascender is positive above the baseline, the descender negative below it. [OneFont’s natural line height](https://github.com/recursive-ai-oss/onefont-csharp/blob/7db48bc21a7eec46272aa73f4e76acf07645db03/src/OneFont/FontMetrics.cs#L37-L50) is ascender minus descender plus line gap, not the height of the visible letters or a required CSS line height. In a drawing coordinate system where y increases downward, subtract the scaled ascender to get the nominal top from the baseline.
- **What pixels can the text cover?** For geometric ink bounds, place each [glyph outline](https://github.com/recursive-ai-oss/onefont-csharp/blob/7db48bc21a7eec46272aa73f4e76acf07645db03/README.md#L24-L33) at its pen position plus its shaped offset, scale it, and bound the resulting curves. Ink may overhang an advance or leave part of it empty. For actual painted pixel bounds, measure the rasterizer’s output; [OneFont does not draw or hint text](https://github.com/recursive-ai-oss/onefont-csharp/blob/7db48bc21a7eec46272aa73f4e76acf07645db03/README.md#L15-L17).
