Documentation ¶
Overview ¶
Library for drawing text through sprites. This library does not render directly but produces sprites that can be rendered using gitlab.com/onikolas/agl/sprite. To render text, use a sprite store with a FontAlas. To draw text, create a TextDrawer. TextDrawer converts text to sprites and can add text to a region on screen (like a text box or label) and can handle wrapping and styling such as tab width.
Index ¶
- func CharacterSetASCII() []rune
- func CharacterSetGreek() []rune
- func RgbaToPng(image *image.RGBA, filename string) error
- type FontAtlas
- func (a *FontAtlas) GetBoundingBoxes() []math.Box2D[int]
- func (a *FontAtlas) GetImage() *image.RGBA
- func (a *FontAtlas) Init(fontBytes []byte, fontSize float64, charSet []rune) error
- func (a *FontAtlas) InitFromFile(fontFile string, fontSize float64, charSet []rune) error
- func (a *FontAtlas) ToFile(imageFile string)
- type GlyphInfo
- type TextDrawer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FontAtlas ¶
type FontAtlas struct { AtlasImage *image.RGBA // atlas image Glyphs map[rune]GlyphInfo // render info per glyph HSpace, VSpace int // spacing between chars/lines (also the glyph diminsions for monospace) CharSet []rune // runes stored in the atlas }
FontAtlas takes a truetype font and renders it into an image. In addition to the rendered image, it stores the location of each glyph on the image and the glyph adjustments needed to correctly place each glyph.
func (*FontAtlas) Init ¶
Produce an image of a given truetype font that contains bitmapped representations of the characters in charSet.
func (*FontAtlas) InitFromFile ¶
type GlyphInfo ¶
type GlyphInfo struct { BBox math.Box2D[int] Origin math.Vector2[int] // unused VAdjust int HAdjust int }
GlyphInfo holds rendering information about a glyph
type TextDrawer ¶
type TextDrawer struct { Area math.Box2D[int] TabWidth int // TODO formatting options struct Depth int Font *FontAtlas // font information Atlas *sprite.Atlas // contains filtered or unexported fields }
TextDrawer converts text into sprites that fit in an area. The placement of the text depends on the font characteristics and formatting parameters
func NewTextDrawer ¶
func NewTextDrawer(font *FontAtlas, area math.Box2D[int], tabWidth int, shader shaders.Shader, maxSprites, renderOrder int) (*TextDrawer, error)
Construct a text drawer. A sprite atlas will be constructed internally.
func (*TextDrawer) AddText ¶
func (t *TextDrawer) AddText(text []rune, shader *shaders.Shader, renderOrder int, sprites []sprite.Sprite) []sprite.Sprite
RunesToSprites converts text into sprites and appends it to the passed sprites array. Subsequent calls add more text.
func (*TextDrawer) GetDrawPosition ¶
func (t *TextDrawer) GetDrawPosition() math.Vector2[int]
Returns the current draw position
func (*TextDrawer) MaxRunes ¶
func (t *TextDrawer) MaxRunes() int
Return the maximum number of characters that can be placed in the area of this TextDrawer. This is a meaningful metric only for monospace fonts
func (*TextDrawer) Reset ¶
func (t *TextDrawer) Reset()
Reset the renderer to start drawing again from the top-left corner.