fnt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package fnt implements reading of Total Annihilation bitmap font files.

FNT files contain 1-bit-per-pixel glyph data for up to 256 characters. Format:

  • 2 bytes: uint16 glyph height (all glyphs share the same height)
  • 2 bytes: uint16 unknown/flags
  • 256 × 2 bytes: uint16 offset table (offset from file start to each glyph, 0 = not present)
  • Glyph data: for each glyph at its offset:
  • 1 byte: pixel width
  • ceil(width * height / 8) bytes: 1bpp pixel data, MSB-first continuous bit stream

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WritePNG

func WritePNG(w io.Writer, img image.Image) error

WritePNG encodes an image to PNG.

Types

type Font

type Font struct {
	Height int         // Glyph height in pixels
	Flags  uint16      // Unknown flags field
	Glyphs [256]*Glyph // Glyph for each character (nil if not present)
}

Font is a parsed FNT file.

func LoadFromReader

func LoadFromReader(r io.ReadSeeker) (*Font, error)

LoadFromReader parses an FNT file.

func (*Font) GlyphCount

func (f *Font) GlyphCount() int

GlyphCount returns the number of defined glyphs.

func (*Font) RenderSheet

func (f *Font) RenderSheet(fg, bg color.Color) *image.RGBA

RenderSheet renders all glyphs as a sprite sheet (16 columns).

func (*Font) RenderText

func (f *Font) RenderText(text string, fg, bg color.Color) *image.RGBA

RenderText renders a string using this font.

type Glyph

type Glyph struct {
	Char   int    // Character code (0-255)
	Width  int    // Pixel width
	Height int    // Pixel height (same as font height)
	Pixels []bool // Width × Height pixel values (true = set)
}

Glyph is a single character's bitmap data.

func (*Glyph) RenderImage

func (g *Glyph) RenderImage(fg, bg color.Color) *image.RGBA

RenderGlyph renders a single glyph as an RGBA image.

Jump to

Keyboard shortcuts

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