Documentation ¶
Overview ¶
Package pixfont is a simple pixel font library that allows for text drawing in the standard image and image/draw packages. It is very useful when heavyweight TrueType fonts and the freetype-go package are not available or desired. Since fonts are simple bitmap images, scaling is not possible and aliasing will occur.
See the included fontgen tool if you wish to convert or include your own pixel font in your project.
Index ¶
- Variables
- func DrawString(dr Drawable, x, y int, s string, clr color.Color) int
- func MeasureString(s string) int
- type Drawable
- type PixFont
- func (p *PixFont) DrawRune(dr Drawable, x, y int, c rune, clr color.Color) (bool, int)
- func (p *PixFont) DrawString(dr Drawable, x, y int, s string, clr color.Color) int
- func (p *PixFont) GetHeight() int
- func (p *PixFont) MeasureRune(c rune) (bool, int)
- func (p *PixFont) MeasureString(s string) int
- func (p *PixFont) SetVariableWidth(isVar bool)
- type StringDrawable
Constants ¶
This section is empty.
Variables ¶
var DefaultFont = Font8x8
DefaultFont is used by the convienence method DrawString, and is initialized to the Public Domain 8x8 fixed font with some unicode characters.
var Font8x8 = &PixFont{
8, 8,
eightMap,
eightData,
8,
}
Font8x8 is a fixed-width 8x8 pixel font which has been made available in the Public Domain. It looks a little bit like this (somewhat heavy, serifs, typical console font from early PCs)
XXX X XXXX XXXX XX XX XX XX XX XX XX XX XXXX XXXXX XXXXX XX XX XX XX XX XX XXXX XX XX XX XX XX XXXX XX XX XXXX XX XX XX XX XX XX XX XX XXX XX XX XX XX XX XX XX XX X XX XX XX XX XX XX XXXX XXXX XX XX XX XXXX XX XX XXXX
var Spacing = 1
Spacing is the pixel spacing to use between letters (1 px by default)
Functions ¶
func DrawString ¶
DrawString is a convienence method that calls DrawString using the DefaultFont
func MeasureString ¶
MeasureString is a convienence method that calls MeasureString using the DefaultFont
Types ¶
type PixFont ¶
type PixFont struct {
// contains filtered or unexported fields
}
PixFont represents a simple bitmap or pixel-based font that can be drawn using simple opaque-pixel operations (supported by image.Image and easily included in other packages).
func NewPixFont ¶
NewPixFont creates a new PixFont with the provided character width/height and character map of offsets into a packed uint32 array of bits.
func (*PixFont) DrawRune ¶
DrawRune uses this PixFont to display a single rune in the provided color and position in Drawable. The x,y position represents the top-left corner of the rune. Drawable.Set is called for each opaque pixel in the font, leaving all other pixels in the Drawable as-is. If the rune has no representation in the PixFont, then DrawRune returns false and no drawing is done. DrawRune always returns the number of pixels to advance before drawing another character.
func (*PixFont) DrawString ¶
DrawString uses this PixFont to display text in the provided color and the specified start position in Drawable. The x,y position represents the top-left corner of the first letter of s. Text is drawn by repeated calls to DrawRune for each character. DrawString returns the total pixel advance used by the string.
func (*PixFont) MeasureRune ¶
MeasureRune measures the advance of a rune drawn using this PixFont.
func (*PixFont) MeasureString ¶
MeasureString measures the pixel advance of a string drawn using this PixFont.
func (*PixFont) SetVariableWidth ¶
SetVariableWidth toggles the PixFont between drawing using variable width per character or the default fixed-width representation.
type StringDrawable ¶
type StringDrawable struct {
// contains filtered or unexported fields
}
StringDrawable implements Drawable so you can do FIGlet-inspired pixel fonts in text. Obviously it's much simpler though.
func (*StringDrawable) PrefixString ¶
func (s *StringDrawable) PrefixString(p string) string
PrefixString returns the current string representation of this Drawable with a user-provided prefix before each line. Useful for adding output in code comments.
func (*StringDrawable) String ¶
func (s *StringDrawable) String() string
String returns the current string representation of this Drawable.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
bdf2pixfont
Command bdf2pixfont opens a BDF format font and creates a new pixel font for it.
|
Command bdf2pixfont opens a BDF format font and creates a new pixel font for it. |
fontgen
fontgen is a commandline tool for generating pixel fonts supported by pixfont.
|
fontgen is a commandline tool for generating pixel fonts supported by pixfont. |