---
title: "Measure text without font kerning in C#"
url: https://recursiveai.org/onefont/cookbook/disable-font-kerning/
description: "Measure text width with font kerning on and off in C#. Shape the same glyph pair with OneFont, sum the advances, and convert font units to pixels."
version: "1.4.0"
---

# Measure text without font kerning in C#

**onefont** is a free, open-source font and text-shaping library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneFont) · [GitHub](https://github.com/recursive-ai-oss/onefont-csharp) · [Docs](https://recursiveai.org/onefont/docs/) · [Download example (.zip)](https://recursiveai.org/onefont/cookbook/disable-font-kerning/disable-font-kerning.zip)

Compare the spacing of `AV` using `sans.ttf` from the zip.

```shell
dotnet add package RecursiveAI.OneFont
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using OneFont;
var noKern = new ShapingOptions
    { Kerning = KerningMode.None };
var face = FontFace.Load(
    File.ReadAllBytes("sans.ttf"));
var normal = TextShaping.ShapeRun("AV", face);
var plain = TextShaping.ShapeRun(
    "AV", face, options: noKern);
Console.WriteLine("Normal: " +
    normal.Sum(c => c.Advance));
Console.WriteLine("None: " +
    plain.Sum(c => c.Advance));
```

Unzip [the example](https://recursiveai.org/onefont/cookbook/disable-font-kerning/disable-font-kerning.zip), then `dotnet run`.

Prints the width of `AV` in font design units: `Normal` applies kerning and `None` disables it.

```text
Normal: 1199
None: 1239
```

If `sans.ttf` isn’t in the working directory, `File.ReadAllBytes` throws `FileNotFoundException`. The zip includes a Noto Sans subset under the SIL Open Font License (`OFL.txt`).

## Variations

### Convert the unkerned width to pixels

Append this to measure at a 20 px font size. It reuses `face` and `noKern` from the snippet at the top.

```csharp
int advance = TextShaping.ShapeRun(
    "AV", face, options: noKern)
    .Sum(c => c.Advance);
float pixels = advance * (20f / face.UnitsPerEm);
Console.WriteLine(FormattableString.Invariant(
    $"{pixels:0.00} px"));
```

```text
24.78 px
```

### Turn off the OpenType `kern` feature directly

Append this if you keep your switches together in a feature list.

```csharp
var features = new ShapingOptions();
features.Features.Add(FontFeature.Off("kern"));
var noPairAdjustment = TextShaping.ShapeRun(
    "AV", face, options: features);
Console.WriteLine(
    noPairAdjustment.Sum(c => c.Advance));
```

```text
1239
```

## Related recipes

- [Measure text width](https://recursiveai.org/onefont/cookbook/measure-text-width/)
- [Measure glyph ink bounds](https://recursiveai.org/onefont/cookbook/measure-glyph-ink-bounds/)
- [Use OpenType features](https://recursiveai.org/onefont/cookbook/opentype-features/)

---

## The short answer

Set `ShapingOptions.Kerning` to `KerningMode.None`, pass those options to `TextShaping.ShapeRun`, and sum `Advance` across the returned clusters. To compare against normal kerning, measure the same text with the same face, direction, language, and feature settings. Only the kerning mode should change.

## What is kerning in typography?

[OpenType kerning](https://learn.microsoft.com/en-us/typography/opentype/spec/features_ko#tag-kern) is a font-supplied spacing adjustment. A pair such as `AV` can fit more closely than its standalone advances suggest: the upper strokes and lower strokes leave space for the neighboring letter. In the bundled font the pair takes 1199 design units with kerning and 1239 without it, a difference of 40 units. That is a measurement of this pair in this face, not a fixed amount to add to all text. A different face or pair may produce the same width with either setting.

### Is kerning the same as letter spacing?

No. Kerning uses the font’s positioning for particular glyph combinations. [Letter spacing](https://www.w3.org/TR/css-text-3/#letter-spacing-property) adds or removes spacing between adjacent typographic character units; disabling kerning doesn’t add a uniform gap. Nor does it switch off ligatures or mark placement. Shape the text with the options you intend to use for drawing, rather than summing widths from isolated characters, which would lose context for other shaping features too.

## How do you measure text width in pixels in C#?

The sum of cluster advances tells you how far the text position moves when laying out a run. OneFont returns that sum in the font’s design units, not pixels. Multiply by the requested pixel size divided by `face.UnitsPerEm`, as in the 20 px variation. Keep the same scale for both measurements and round only when needed. Advance width isn’t an ink bounding box: a glyph can overhang its advance or leave blank space inside it. Use outline bounds if you need the extent of the visible marks.

### Why might setting `KerningMode.None` not change the width?

The chosen pair may not have a kerning adjustment. Also check the feature list. The [shaping guide](https://recursiveai.org/onefont/docs/shaping/) says “an explicit `kern` setting wins over it.” If the options still include `FontFeature.On("kern")`, setting `KerningMode.None` alone won’t take precedence. Remove the conflicting setting or use the explicit `Off("kern")` in the variation above.
