package module
Version: v0.0.0-...-dde25ed Latest Latest

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

Go to latest
Published: Dec 19, 2020 License: BSD-3-Clause Imports: 6 Imported by: 0


✍ Bitmap font loader library for Go.

This library loads font data from an image ("bitmap").
It gets loaded into a Go map which means a Glyph can be retrieved with font[glyph], for example font["A"].


bm := bitmap.New()
font := bm.Load("font.png")

x := 0
y := 0
xx := x
yy := y
ch := font[glyph]
for i := 0; i < ch.Height; i++ {
 	bin := ch.Data[i] // Gets a line: a glyph is 8x8
 	binarr := strings.Split(bin, "")

 	for _, pix := range binarr {
 		if pix == "1" { draw(xx, yy) }
	 	xx += 1
	yy += 1
	xx = x

Used by

This library is used in Pinwheel for its pixel font.

If you also use this for reason, you can make a PR to add your use here.


BSD 3-Clause



The bitmap package loads a bitmap font from an image using a descriptor file.

A bitmap font is a font with glyphs that is literally bitmapped, with a transparent pixel being `0`, and any opaque pixel being `1`.

A descriptor file describes the size (width, height) of each glyph. It is a JSON file, the same name as the font itself. An example: the font is `fnt.png`, the descriptor will be `fnt.json`, and would look like: ` [

	"Char": " ",
	"Width": 7,
	"X": 1,
	"Y": 8,
	"W": 2,
	"H": 0,
	"Ox": 0,
	"Oy": 0
	"Char": "!",
	"Width": 5,
	"X": 4,
	"Y": 1,
	"W": 3,
	"H": 7,
	"Ox": 0,
	"Oy": 7





This section is empty.


This section is empty.


This section is empty.


type BitmapFont

type BitmapFont struct {
	// contains filtered or unexported fields

BitmapFont holds a slice of Glyphs.

func New

func New() BitmapFont

Returns a new, empty bitmap font.

func (*BitmapFont) Load

func (b *BitmapFont) Load(filename string) map[string]Glyph

Loads a bitmap font from `filename`. `filename` must include the extension.

type Glyph

type Glyph struct {
	Data             []string
	Width, Height, Y int

Glyph is a single character from the font.

type GlyphInfo

type GlyphInfo struct {
	Char               string
	Width              int
	X, Y, W, H, Ox, Oy int

GlyphInfo is the info about a glyph obtained from the descriptor file.

Source Files

Jump to

Keyboard shortcuts

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