---
title: "Position a font’s strikethrough in C#"
url: https://recursiveai.org/onefont/cookbook/position-strikethrough-from-font-metrics/
description: "Read a font’s strikethrough position and thickness with OneFont in C#. Scale the metrics and place the line relative to a baseline in y-down coordinates."
version: "1.4.0"
---

# Position a font’s strikethrough 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/position-strikethrough-from-font-metrics/position-strikethrough-from-font-metrics.zip)

Place a strikethrough relative to the text baseline. The zip includes `NotoSans-Regular.ttf`.

```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 data = File.ReadAllBytes(
    "NotoSans-Regular.ttf");
var metrics = FontFace.Load(data).Metrics;
var offset = metrics.StrikeoutPosition;
var thickness = metrics.StrikeoutSize;
foreach (double size in new[] { 16, 32 })
{
    double scale = size / metrics.UnitsPerEm;
    double top = 40 - offset * scale;
    double height = thickness * scale;
    Console.WriteLine(
        FormattableString.Invariant(
            $"({top:0.###}, {height:0.###})"));
}
```

Unzip [the example](https://recursiveai.org/onefont/cookbook/position-strikethrough-from-font-metrics/position-strikethrough-from-font-metrics.zip), then `dotnet run`.

Prints `(top y, thickness)` in pixels for 16 px and 32 px text, both on a baseline at y = 40.

```text
(34.848, 0.8)
(29.696, 1.6)
```

## The full program

```csharp
using OneFont;
var data = File.ReadAllBytes(
    "NotoSans-Regular.ttf");
var metrics = FontFace.Load(data).Metrics;
var offset = metrics.StrikeoutPosition;
var thickness = metrics.StrikeoutSize;
foreach (double size in new[] { 16, 32 })
{
    double scale = size / metrics.UnitsPerEm;
    double top = 40 - offset * scale;
    double height = thickness * scale;
    Console.WriteLine(
        FormattableString.Invariant(
            $"({top:0.###}, {height:0.###})"));
}

Console.WriteLine($"Position: {offset} design units");
Console.WriteLine($"Thickness: {thickness} design units");
```

```text
(34.848, 0.8)
(29.696, 1.6)
Position: 322 design units
Thickness: 50 design units
```

If `StrikeoutSize` is zero or negative, don’t draw a stroke of that thickness; skip it or choose a fallback. Noto Sans is included under the SIL Open Font License.

## Variations

If the drawing API takes the center of a stroke instead of the top of a rectangle, append this to calculate the center y for the 32 px case.

```csharp
// Centerline for a stroke-based drawing API.
double factor = 32.0 / metrics.UnitsPerEm;
double center = 40 - metrics.StrikeoutPosition
    * factor + metrics.StrikeoutSize * factor / 2;
Console.WriteLine($"Stroke center: {center:0.##}");
```

```text
Stroke center: 30.5
```

## Related recipes

- [Read a font’s underline metrics](https://recursiveai.org/onefont/cookbook/read-font-underline-metrics/)
- [Get a font’s x-height and cap height](https://recursiveai.org/onefont/cookbook/read-font-x-height-and-cap-height/)

## The short answer

Read `StrikeoutPosition` and `StrikeoutSize` from `FontFace.Metrics`. Multiply both by `fontSizeInPixels / UnitsPerEm`. On a screen where y increases downward, subtract the scaled position from the baseline y to get the top edge of the rule. Its height is the scaled `StrikeoutSize`. You don’t need a renderer to calculate either value.

## How do you set the vertical position of a strikethrough?

Start with the baseline of the text you’re decorating, not the top of its line box. The [OpenType definition of `yStrikeoutPosition`](https://learn.microsoft.com/en-us/typography/opentype/spec/os2#ystrikeoutposition) specifies the **top** edge. A positive offset moves that edge above the baseline, so the screen y coordinate gets smaller. In a y-up coordinate system you’d add the offset instead.

For a filled rectangle, use the top edge as its y coordinate. Its bottom edge is `top + thickness` in y-down coordinates. If the drawing API centers its stroke around the given path, move the path down by half the thickness as shown in the variation. Otherwise the stroke will sit half its thickness too high. The text run determines the horizontal start and end; the two strikeout metrics only describe the vertical placement.

## How thick should a strikethrough line be?

Use the scaled `yStrikeoutSize` from the font as the default. OneFont reads it alongside `yStrikeoutPosition` in the [`OS/2` table](https://github.com/recursive-ai-oss/onefont-csharp/blob/7db48bc21a7eec46272aa73f4e76acf07645db03/src/OneFont/Fonts/FontFace.cs#L82-L94). Doubling the font size doubles the thickness and the distance from the baseline, but it doesn’t double the baseline y itself. Keep both values as fractions of a pixel until drawing; if you need a minimum visible stroke on a small display, choose that in the rendering code rather than changing the font metric.

For a run containing more than one face, decide whether to follow each face’s metrics or to draw one continuous line with a single face’s settings. The first option preserves each font’s placement, but the line can step where the face changes. The second keeps the line level. In both cases, use the laid-out baseline, not a fixed offset from the top of the text box.
