VOOZH about

URL: https://www.nuget.org/packages/OTFontFile2/

⇱ NuGet Gallery | OTFontFile2 0.1.0-alpha




OTFontFile2 0.1.0-alpha

This is a prerelease version of OTFontFile2.
dotnet add package OTFontFile2 --version 0.1.0-alpha
 
 
NuGet\Install-Package OTFontFile2 -Version 0.1.0-alpha
 
 
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OTFontFile2" Version="0.1.0-alpha" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OTFontFile2" Version="0.1.0-alpha" />
 
Directory.Packages.props
<PackageReference Include="OTFontFile2" />
 
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OTFontFile2 --version 0.1.0-alpha
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: OTFontFile2, 0.1.0-alpha"
 
 
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OTFontFile2@0.1.0-alpha
 
 
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OTFontFile2&version=0.1.0-alpha&prerelease
 
Install as a Cake Addin
#tool nuget:?package=OTFontFile2&version=0.1.0-alpha&prerelease
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

OTFontFile2

OTFontFile2 is a modern OpenType parser/writer for .NET, focused on:

  • high performance
  • low allocation
  • span-first table access

It supports both single-font sfnt (.ttf/.otf) and TTC collections (.ttc).

Quick Start

1) Open a font file

using OTFontFile2;

using var file = SfntFile.Open("font.ttf"); // or font.ttc
var font = file.GetFont(0); // first font in file/collection

2) Read common tables

using OTFontFile2.Tables;

if (font.TryGetHead(out var head))
{
 int unitsPerEm = head.UnitsPerEm;
}

if (font.TryGetMaxp(out var maxp))
{
 int glyphCount = maxp.NumGlyphs;
}

if (font.TryGetName(out var name))
{
 string? fullName = name.GetFullNameString();
}

3) Map Unicode to glyph id (cmap)

using OTFontFile2;

if (CmapUnicodeMap.TryCreate(font, out var map) &&
 map.TryMapCodePoint(0x4F60, out uint glyphId)) // U+4F60
{
 // glyphId
}

4) Repack/write font

using OTFontFile2;

using var inFile = SfntFile.Open("in.ttf");
var inFont = inFile.GetFont(0);

using var outStream = File.Create("out.ttf");
SfntWriter.Write(outStream, inFont);

Core API

SfntFile

  • SfntFile.Open(path): open from disk.
  • SfntFile.TryOpen(path, out file, out error): non-throwing open.
  • SfntFile.FromMemory(memory): open from in-memory bytes.
  • FontCount: number of fonts (1 for normal sfnt, >1 for TTC).
  • GetFont(index): get SfntFont.

SfntFont

  • TableCount: number of tables in this font.
  • TryGetTable(tag, out record): table directory lookup.
  • TryGetTableData(tag, out data, out record): raw bytes of a table.
  • TryGetTableSlice(tag, out slice): zero-copy table slice.
  • Generated helpers like TryGetHead, TryGetMaxp, TryGetName, TryGetCmap, TryGetGlyf, etc.

Table views

Most table structs in OTFontFile2.Tables expose:

  • TryCreate(...)
  • typed field properties (e.g. UnitsPerEm, NumGlyphs)
  • helper methods for common read scenarios

Build New sfnt from table bytes

using OTFontFile2;

Tag.TryParse("head", out var headTag);
Tag.TryParse("cmap", out var cmapTag);

var builder = new SfntBuilder
{
 SfntVersion = 0x00010000
};

builder.SetTable(headTag, headBytes);
builder.SetTable(cmapTag, cmapBytes);

using var fs = File.Create("new.ttf");
builder.WriteTo(fs);

Notes

  • API is span-based and optimized for low allocations.
  • Current APIs are designed for safe table access; invalid font data usually returns false instead of throwing.
  • Very large files (>2GB) are not supported by span-based offsets.
Product Versions Compatible and additional computed target framework versions.
.NET net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OTFontFile2:

Package Downloads
Mobsub.Font

Mobsub helper

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha 414 2/28/2026