fonts

package module
v0.0.0-...-2da8b60 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2014 License: GPL-2.0 Imports: 11 Imported by: 0

README

fonts

This is a bitmap font library for go. It can load a font definition and glyphs from a file, and then uses the image/draw functions to paint them onto images. It also implements a WrapText function which can be used to split a string into chunks which will fit into a given width for that font.

Font file format

A font consists of 2 files - a textual description and an image with the glyphs. The image should have all the of the glyphs in a single row, appropriately aligned to put the baseline in the desred position. The text file consists of a single line header followed by the glyph definitions.

The header looks like this:

[font name], [glyph image file], [number of glyphs]

Followed by [number of glyph] lines describing the glyphs:

[ascii code], [left-most pixel in image], [width of glyph in pixels]

Documentation

Index

Constants

View Source
const WRAP_THRESH = 10

Variables

This section is empty.

Functions

This section is empty.

Types

type Font

type Font struct {
	// contains filtered or unexported fields
}

func NewFontFromFile

func NewFontFromFile(filename string) *Font

func NewFontFromImage

func NewFontFromImage(name string, glyphs *image.Image,
	letters map[byte]image.Rectangle) *Font

func (*Font) Height

func (f *Font) Height() int

func (*Font) Letters

func (f *Font) Letters() map[byte]image.Rectangle

func (*Font) MakeWord

func (f *Font) MakeWord(word string) *image.Paletted

MakeWord makes an image from a string, black on white

func (*Font) MakeWordColor

func (f *Font) MakeWordColor(word string, bg, fg color.Color) *image.Paletted

MakeWordColor makes an image from a string (with colors)

func (*Font) Name

func (f *Font) Name() string

func (*Font) Width

func (f *Font) Width(word string) int

func (*Font) WrapText

func (f *Font) WrapText(sentence string, width int) []string

WrapText splits a string into chunks which will fit in a given width. It will hyphenate in some cases, but numbers will never be split.

Jump to

Keyboard shortcuts

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