1
0
Fork 0
tetris-go/engine/graphics/font/tilefont.go
2025-09-14 22:16:29 +02:00

41 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package font
import (
"tetris/engine/graphics"
)
// TileFont represents a tile-based font where each character maps
// to a tile location (X, Y) in a tileset or texture atlas.
//
// The character-to-tile mapping is defined in the Charmap.
// If CaseInsensitive is true, uppercase characters ('A''Z')
// are automatically converted to lowercase before lookup.
type TileFont struct {
Charmap map[rune]byte
// CaseInsensitive forces all characters to lowercase before lookup.
CaseInsensitive bool
}
// GetTile returns the Tile corresponding to the given character.
//
// If CaseInsensitive is enabled, uppercase ASCII characters are converted
// to lowercase before lookup. If the character is not found in the Charmap,
// GetTile returns nil.
//
// The resulting Tile assumes a fixed tile size of 8x8 pixels
func (f TileFont) GetTile(char rune) *graphics.Tile {
// convert to lowercase
if f.CaseInsensitive && char >= 'A' && char <= 'Z' {
char = char + 0x20
}
if offset, found := f.Charmap[char]; found {
return &graphics.Tile{
Size: 8,
X: offset & 0xF,
Y: offset >> 4,
}
}
return nil
}