text

package
v0.0.0-...-e938fac Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CharacterSetASCII

func CharacterSetASCII() []rune

ascii printable chars

func CharacterSetGreek

func CharacterSetGreek() []rune

Greek characters

func FontToAtlas

func FontToAtlas(font Font, atlas *sprite.Atlas) ([]rune, []int, error)

Adds a font to a sprite atlas. Returns a list of runes and a matching list of sprite ids

func Render

func Render(target *image.RGBA, bounds math.Box2D[int], text string, font Font)

Draw text on target image. Text is confined to the image location given by bounds.

Types

type BitmapFont

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

BitmapFont stores an image with equally sized font characters (runes). The runes are layed out in a grid.

func NewBitmapFont

func NewBitmapFont(imageFile string, rows, columns int, runes []rune) (*BitmapFont, error)

Create a new bitmap from an imageFile. Rows and columns are the number of characters per column and row. glyphs are the characters in this bitmap image, the order of this array matches the order in the image (left to right, top to bot)

func (*BitmapFont) FontMetrics

func (b *BitmapFont) FontMetrics() FontMetrics

func (*BitmapFont) GetRuneBounds

func (b *BitmapFont) GetRuneBounds(r rune) (math.Box2D[int], error)

Get bounding box (in pixels) of the rune in the bitmap image

func (*BitmapFont) Image

func (b *BitmapFont) Image() *image.RGBA

func (*BitmapFont) RuneMetrics

func (b *BitmapFont) RuneMetrics(r rune) RuneMetrics

func (*BitmapFont) Runes

func (b *BitmapFont) Runes() []rune

type Font

type Font interface {
	// Get the image representation of the font
	Image() *image.RGBA
	// Get render information for a rune
	RuneMetrics(r rune) RuneMetrics
	// Get font information
	FontMetrics() FontMetrics
	// Get the runes for which this font has glyphs
	Runes() []rune
}

Font is the common interface for bitmap and ttf fonts

type FontMetrics

type FontMetrics struct {
	Size     int
	YAdvance int
}

type RuneMetrics

type RuneMetrics struct {
	BoundingBox math.Box2D[int] //glyph fits inside this
	Adjust      math.Vector2[int]
	Advance     int
}

RuneMetrics stores rune information: bounding box, origin and advance

type RuneToSpriteMap

type RuneToSpriteMap struct {
	Runes   []rune
	Sprites []int
}

Holds runes and their corresponding sprite ids in two arrays whose indexes match.

func NewRuneToSpriteMap

func NewRuneToSpriteMap(runes []rune, sprites []int) *RuneToSpriteMap

func (*RuneToSpriteMap) Get

func (rm *RuneToSpriteMap) Get(r rune) int

Get sprite for this rune

type TrueTypeFont

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

TrueTypeFont holds an image with renders of characters from a true type font.

func NewTrueTypeFont

func NewTrueTypeFont(fontFile string, fontSize float64, runes []rune) (*TrueTypeFont, error)

func (*TrueTypeFont) FontMetrics

func (t *TrueTypeFont) FontMetrics() FontMetrics

func (*TrueTypeFont) Image

func (t *TrueTypeFont) Image() *image.RGBA

func (*TrueTypeFont) RuneMetrics

func (t *TrueTypeFont) RuneMetrics(r rune) RuneMetrics

func (*TrueTypeFont) Runes

func (t *TrueTypeFont) Runes() []rune

Jump to

Keyboard shortcuts

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