---
title: "Read OpenType CFF2 glyph outlines in C#"
url: https://recursiveai.org/onefont/cookbook/read-cff2-glyph-outlines/
description: "Load a variable OpenType CFF2 font, select a weight, and read a glyph’s vector outline and ink bounds in C# with OneFont."
version: "1.5.1"
---

# Read OpenType CFF2 glyph outlines 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/read-cff2-glyph-outlines/read-cff2-glyph-outlines.zip)

Read CFF2 vector shapes with `GetOutline` on a font instance. The zip’s `cjk.otf` is a Noto Sans CJK JP subset.

```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 face = FontFace.Load(
    File.ReadAllBytes("cjk.otf"));
var bold = face.WithVariations(
    FontVariation.Weight(700));
int glyph = bold.GetGlyphIndex('永');
if (glyph == 0)
    throw new Exception("Glyph not found.");
var outline = bold.GetOutline(glyph);
var bounds = outline.TightBox();
Console.WriteLine(FormattableString.Invariant(
    $"Bounds at 700: {bounds}"));
```

Glyph ID 0 means the character is missing; damaged glyph data can throw `FontFormatException` when you call `GetOutline`.

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onefont/cookbook/read-cff2-glyph-outlines/read-cff2-glyph-outlines.zip) and `dotnet run`.

If you paste the code, put `cjk.otf` from the zip next to `Program.cs`, or put your own CFF2 font there and change the filename in the code.

Prints the outline’s ink bounds as `(minX, minY, maxX, maxY)` in font units:

```text
Bounds at 700: (25.839355, -88.28076, 977.74097, 846.3806)
```

## Variations

### Read the same glyph at weight 100

Change `FontVariation.Weight(700)` to the following and change the printed label to `Bounds at 100`:

```csharp
var bold = face.WithVariations(
    FontVariation.Weight(100));
```

```text
Bounds at 100: (43, -68, 952, 830)
```

Weight 100 is this font’s default and gives whole-number bounds here, while interpolation at 700 gives fractional bounds.

## Related recipes

- [Measure a glyph’s ink bounds](https://recursiveai.org/onefont/cookbook/measure-glyph-ink-bounds/)
- [Convert a glyph outline to SVG](https://recursiveai.org/onefont/cookbook/render-glyph-outline-as-svg-path/)
- [Read raw OpenType tables](https://recursiveai.org/onefont/cookbook/read-raw-opentype-tables/)

---

## The short answer

Load the font with `FontFace.Load`, select an instance with `WithVariations`, and call `GetOutline` on that instance. Look up the glyph ID with `GetGlyphIndex` for a single character such as `永`. If you’re drawing a shaped run, use the glyph IDs returned by shaping instead: those can include substitutions that the character map alone won’t find.

## What is the CFF2 table in an OpenType font?

The [OpenType CFF2 specification](https://learn.microsoft.com/en-us/typography/opentype/spec/cff2) describes glyph programs that encode contours. Their curved segments are cubic Béziers, with two control points per segment, rather than the quadratic curves found in TrueType `glyf` outlines. Both are vector data, not pixels. An `.otf` extension doesn’t tell you whether the file has CFF2; check its table directory if you need to distinguish CFF2 from CFF or `glyf`.

OneFont uses the same `GetOutline` API for all three. `TightBox()` measures the drawn shape, not the horizontal advance or the line height. To consume the actual path, replay the outline with `GlyphOutline.Write` into an `IOutlineSink`. Handle `CubicTo` if your sink consumes CFF2, even if it previously only needed `QuadTo` for TrueType. The coordinates are in design units with y pointing up; choose a transform for your destination rather than interpreting those coordinates as pixels.

## How does a variable font change a CFF2 outline?

The weight chooses a location on a font’s `wght` axis; it doesn’t stroke an existing path or pick another file. As documented in the [OneFont shaping guide](https://recursiveai.org/onefont/docs/shaping/), CFF2’s `blend` and `vsindex` operate against the font’s variation store. The same character at weights 100 and 700 can have different contour coordinates, as the bounds above show.

Read `face.Axes` to see the actual axes and their minimum, default and maximum. Values beyond that range are clamped, and axes the font doesn’t have are ignored. Each call to `WithVariations` starts from the default coordinate on every axis, so pass all the settings together if you need both weight and optical size. Keep the selected face for both shaping and outline reads when you render text; choosing a different instance for the path can leave its geometry out of step with the advances you used for layout.
