---
title: "Read raw OpenType table bytes in C#"
url: https://recursiveai.org/onefont/cookbook/read-raw-opentype-tables/
description: "Inspect a font’s stored tables by tag, a short name such as head. The NotoSans-Regular.ttf input is included in the example. Runnable C# example with onefont."
version: "1.4.0"
---

# Read raw OpenType table bytes 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-raw-opentype-tables/read-raw-opentype-tables.zip)

Inspect a font’s stored tables by tag, a short name such as `head`. The NotoSans-Regular.ttf input is included in the example.

```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;

byte[] data = File.ReadAllBytes(
    "NotoSans-Regular.ttf");
var head = FontFace.Load(data).GetTable("head");
Console.WriteLine(Convert.ToHexString(
    head.Span[..4]));
```

Unzip [the example](https://recursiveai.org/onefont/cookbook/read-raw-opentype-tables/read-raw-opentype-tables.zip), then `dotnet run`.

Prints:

```text
00010000
```

## The full program

The download includes the unchanged Noto Sans font under the SIL Open Font License, with OFL.txt.

```csharp
using OneFont;

FontFace face = FontFace.Load(
    File.ReadAllBytes("NotoSans-Regular.ttf"));
ReadOnlyMemory<byte> head = face.GetTable("head");
Console.WriteLine($"head: {head.Length} bytes");
Console.WriteLine(Convert.ToHexString(
    head.Span[..4]));
Console.WriteLine($"COLR: {face.HasTable("COLR")}");
```

`dotnet run` prints:

```text
head: 54 bytes
00010000
COLR: False
```

A missing table returns empty memory; use `HasTable` to distinguish it from a present, empty table.

## Variations

Read units per em from the header with an explicit length check:

```csharp
using OneFont;
using System.Buffers.Binary;

FontFace face = FontFace.Load(
    File.ReadAllBytes("NotoSans-Regular.ttf"));
ReadOnlySpan<byte> head = face.GetTable("head").Span;
if (head.Length < 20)
    throw new InvalidDataException("Short head table.");
ushort units = BinaryPrimitives
    .ReadUInt16BigEndian(head.Slice(18, 2));
Console.WriteLine($"Units per em: {units}");
```

```text
Units per em: 1000
```

## Related recipes

[Read a font file](https://recursiveai.org/onefont/cookbook/read-font-file/)

[Apply OpenType features](https://recursiveai.org/onefont/cookbook/opentype-features/)

---

## The short answer

Load the font with `FontFace.Load`, then call `GetTable(tag)` for the stored bytes of a named OpenType table. The result is `ReadOnlyMemory<byte>`. Call `HasTable(tag)` when you need to distinguish a missing table from a present table with no bytes.

This is read-only inspection. The [shaping docs’ table-access section](https://recursiveai.org/onefont/docs/shaping/) says: “The bytes are not validated.” Getting a table does not decode its fields or add support for rendering the feature it describes.

## How do you read OpenType tables in an OTF font?

Use the same `FontFace` API for a supported TTF or OTF font. A table tag identifies which part of the font you want. For example, `head` contains the font header, while `name` contains naming information. Microsoft’s [OpenType file specification](https://learn.microsoft.com/en-us/typography/opentype/spec/otff) describes the table directory and the meaning of its entries.

The sample deliberately uses a named table instead of treating the whole file as that table’s bytes. A file has a directory plus many tables; an offset within a table is not the same as an offset from the beginning of the font file. `GetTable` gives you the table’s stored bytes so field offsets can be interpreted relative to that table.

The supplied Noto Sans font produces a 54-byte `head` table. Its first four bytes print as `00010000`. Those are hexadecimal bytes, not a string extracted from the font. Other tables have different layouts, so use each table’s specification rather than applying the `head` offsets everywhere.

## How do you read the OpenType head table?

The variation reads units per em from offset 18 as an unsigned, big-endian 16-bit field. Microsoft documents that layout in the [head table specification](https://learn.microsoft.com/en-us/typography/opentype/spec/head). The sample prints `1000` for the included font.

Check the available length before slicing. `ReadUInt16BigEndian` expresses the font’s byte order explicitly; reading a native-endian integer would make the result depend on the machine. Microsoft specifies big-endian byte ordering for OpenType data.

That single field read is not a complete header parser. If you build a parser for another table, check its version, lengths and offsets according to its specification before following references within the bytes. Raw access supplies data; it does not check the assumptions made by your parser.

## What is the difference between OTF and TTF when reading tables?

Microsoft’s file specification explains that OpenType can contain TrueType or CFF outlines. The filename extension alone is not a complete table inventory: TrueType outlines can appear in either a `.ttf` or `.otf` file. Ask for the table you need and check its presence instead of inferring it from the suffix.

In the sample, `HasTable("COLR")` is false. `GetTable("COLR")` would therefore be empty, but an empty result alone cannot distinguish absence from a stored zero-length table. Nor does presence demonstrate that the library renders color glyphs or applies font variations. This API exposes bytes, not those rendering operations.

Use the conventional four-character tags, preserving case. onefont accepts tags of one through four Latin-1 characters and pads short tags on the right with spaces. A null tag throws `ArgumentNullException`; an empty, overlong or non-Latin-1 tag throws `ArgumentException`.
