Documentation
¶
Overview ¶
Package bmfont reads bitmap fonts created with AngelCode's bitmap font generator or other tools that generate output in the same format, and draws texts with these fonts on images.
The parser for the font descriptor files (.fnt) reads the text format, not the binary format. Format description: http://www.angelcode.com/products/bmfont/doc/file_format.html
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BitmapFont ¶
type BitmapFont struct { // Descriptor holds the metadata for the font, such as positions and bounds // of the characters in the sheet images. Descriptor *Descriptor // PageSheets contains the loaded sheet images for the pages. The keys // correspond to the keys of the pages map in the descriptor. PageSheets map[int]image.Image }
A BitmapFont is a bitmap font based on one or more sheet images for the characters and a font descriptor.
func Load ¶
func Load(path string) (f *BitmapFont, err error)
Load loads a bitmap font from a BMFont descriptor file (.fnt) in text format including all the referenced page sheet images. The resulting bitmap font is ready to be used to draw text on an image.
func Read ¶
func Read(r io.Reader, sheets SheetReaderFunc) (f *BitmapFont, err error)
Read reads a bitmap font from a BMFont descriptor in text format including all the referenced page sheet images. The page sheet images are read from the readers provided by the given SheetReaderFunc. These sheet readers are closed after use. If you want to keep them open wrap them via io.NopCloser. The resulting bitmap font is ready to be used to draw text on an image.
func (*BitmapFont) DrawText ¶
DrawText draws the given text on the destination image starting at the given position. The start position is on the base line of the first line of text, and the characters usually extend above the base line. The text may contain newlines. Text with multiple lines is drawn left aligned.
func (*BitmapFont) MeasureText ¶
func (f *BitmapFont) MeasureText(text string) image.Rectangle
MeasureText calculates the bounding box for the given text as if it was drawn at position (0, 0). The Min point usually has a negative Y coordinate, since the start position of DrawText is on the base line and the characters extend above the base line. The X coordinate can also be negative, depending on the character offsets.
type ChannelInfo ¶
type ChannelInfo int
const ( Glyph ChannelInfo = iota Outline GlyphAndOutline Zero One )
type Char ¶
type CharPair ¶
type CharPair struct {
First, Second rune
}
CharPair is a pair of characters. It is used as the key in the font's kerning map.
type Common ¶
type Common struct { LineHeight int Base int ScaleW int ScaleH int Packed bool AlphaChannel ChannelInfo RedChannel ChannelInfo GreenChannel ChannelInfo BlueChannel ChannelInfo }
type Descriptor ¶
type Descriptor struct { Info Info Common Common Pages map[int]Page Chars map[rune]Char Kerning map[CharPair]Kerning }
A Descriptor holds metadata for a bitmap font.
func LoadDescriptor ¶
func LoadDescriptor(path string) (d *Descriptor, err error)
LoadDescriptor loads the font descriptor data from a BMFont descriptor file in text format (usually with the file extension .fnt). It does not load the referenced page sheet images. If you also want to load the page sheet images, use the Load function to get a complete BitmapFont instance.
func ReadDescriptor ¶
func ReadDescriptor(r io.Reader) (d *Descriptor, err error)
ReadDescriptor parses font descriptor data in BMFont's text format from a reader. It does not load the referenced page sheet images. If you also want to load the page sheet images, use the Load function to get a complete BitmapFont instance.
type Kerning ¶
type Kerning struct {
Amount int
}
Kerning is a horizontal offset in pixels to be used if a specific character pair occurs when drawing text. It is used for the values in the font's kerning map.
type SheetReaderFunc ¶
type SheetReaderFunc func(filename string) (io.ReadCloser, error)
A SheetReaderFunc is a function that provides a reader for a page sheet image file name. It is used by the Read function to load a font from a different source than only the file system. The filename parameter is the name provided by the File field of a Page in the font descriptor.