bdf

package
v0.6.11 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package bdf is a standalone reader for BDF (Glyph Bitmap Distribution Format) bitmap fonts. It parses a BDF file into a set of decoded glyphs and rasterises each glyph into a full-cell RGBA pixmap, ink-coloured on a transparent ground.

BDF is the classic X11 bitmap font format. Each glyph is a block:

STARTCHAR <name>
ENCODING <codepoint>
DWIDTH <dx> <dy>            ; device advance width
BBX <w> <h> <xoff> <yoff>  ; bitmap bounding box + offset from origin
BITMAP
<hexrow> ...               ; h rows, each ceil(w/8)*2 hex digits, byte-aligned
ENDCHAR

A BDF font also carries a global FONTBOUNDINGBOX that, together with FONT_ASCENT / FONT_DESCENT, fixes the cell box every glyph is placed into.

This package has no dependency beyond the standard library. It was lifted from the subterm terminal renderer's bdf.go, with the buffer/registry coupling removed so it can be reused on its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Font

type Font struct {
	Name       string
	CellWidth  int // glyph advance (DWIDTH) — the true monospace cell width
	CellHeight int // FONT_ASCENT+FONT_DESCENT — the cell height
	// contains filtered or unexported fields
}

Font holds a parsed BDF font: its cell metrics and decoded glyphs.

func Parse

func Parse(r io.Reader) (*Font, error)

Parse parses a BDF font from r.

func ParseFile

func ParseFile(path string) (*Font, error)

ParseFile parses a BDF file at path into a Font.

func (*Font) GlyphImage

func (f *Font) GlyphImage(r rune, ink color.NRGBA) (img *image.RGBA, ok bool)

GlyphImage renders one glyph into a full-cell RGBA pixmap, placing the glyph's bitmap at the correct offset within the cell box (using BBX offsets and the font ascent), ink-coloured on a transparent ground. Pixels outside the cell box are clipped. If the font has no glyph for r, a blank (fully transparent) cell-sized image is returned and ok is false.

func (*Font) Glyphs

func (f *Font) Glyphs() int

Glyphs returns the number of decoded glyphs.

func (*Font) Has

func (f *Font) Has(r rune) bool

Has reports whether the font has a glyph for r.

Jump to

Keyboard shortcuts

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