fntconv

package module
v0.0.0-...-85873c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 11 Imported by: 0

README

fntconv

Package fntconv serializes TTF fonts to a compact binary format and rasterizes them.

for ASCII characters, the file sizes are as follows:

Font Size (bytes)
Roboto-Regular.ttf 168260
Roboto-Regular-12pt.bin 16300
Roboto-Regular-12pt-45x59.png 40492
Roboto-Regular-12pt.bin.zst 9685

Installation

go install codeberg.org/pierrec/fntconv/cmd/fntconv@latest

Usage

fntconv -size 12 -dpi 72 Roboto-Regular.ttf

Outputs:

  • Roboto-Regular-12pt.bin - Binary font data with vector outlines
  • Roboto-Regular-12pt-WxH.png - Rasterized glyph atlas

License

MIT

Documentation

Index

Constants

View Source
const ASCII = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

ASCII defines all ascii characters.

View Source
const Magic = "FNCV"
View Source
const MagicSDF = "FSDF"

Variables

View Source
var InvalidBinary = fmt.Errorf("fntconv: invalid binary")

Functions

func Marshal

func Marshal(fnt *opentype.Font, options *opentype.FaceOptions, codepoints string) ([]byte, error)

Marshal serializes an OpenType font to a binary format for glyph mapping and rasterization.

Types

type Glyph

type Glyph struct {
	Segments []sfnt.Segment
	Char     rune
	Advance  fixed.Int26_6
}

type Glyphs

type Glyphs struct {
	Glyphs     []Glyph
	MaxAdvance fixed.Int26_6
	PPEM       fixed.Int26_6
	Ascent     fixed.Int26_6
	Height     fixed.Int26_6
	// contains filtered or unexported fields
}

func Unmarshal

func Unmarshal(bin []byte) (Glyphs, error)

Unmarshal decodes a binary font representation into a Glyphs structure, returning an error if the format is invalid.

func (Glyphs) AsImage

func (gs Glyphs) AsImage() (_ *image.RGBA, tileSize image.Point, _ error)

AsImage converts a serialized binary font representation into an image.Image, arranging glyphs in a grid layout.

func (Glyphs) AsImageOutline

func (gs Glyphs) AsImageOutline(strokeWidth float32) (_ *image.RGBA, tileSize image.Point, _ error)

AsImageOutline converts glyphs into an image with outlined (stroked) glyphs instead of filled.

func (Glyphs) AsTexture

func (gs Glyphs) AsTexture() (glen.TextureFont, error)

func (Glyphs) AsTextureFromImage

func (gs Glyphs) AsTextureFromImage(img *image.RGBA, tileSize image.Point) (glen.TextureFont, error)

func (Glyphs) AsTextureOutline

func (gs Glyphs) AsTextureOutline(strokeWidth float32) (glen.TextureFont, error)

Directories

Path Synopsis
cmd
fntconv command
examples
font command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL