tinygo-org / tinyfont

Text library for TinyGo displays
https://tinygo.org
BSD 3-Clause "New" or "Revised" License
48 stars 12 forks source link

const2bit is broken #43

Open oxplot opened 1 year ago

oxplot commented 1 year ago

Due to the change from Glypher to Glyph.

Attempting to use a font created by tinyfontgen-ttf and using it, yields:

main.go:31:28: cannot use font (variable of type *Font) as tinyfont.Fonter value in argument to tinyfont.WriteLine: *Font does not implement tinyfont.Fonter (wrong type for method GetGlyph)
        have GetGlyph(rune) tinyfont.Glypher
        want GetGlyph(rune) tinyfont.Glyph

Relevant code:

tinyfont.WriteLine(&ssd, TinyFont, 0, 20, "Hi there", color.RGBA{1, 0, 0, 0})
sago35 commented 11 months ago

const2bit is for representing 2-bit color fonts. Glyph cannot handle 2-bit colors. In addition, we would like to support colored emoji in the future, but tinyfont.Glyph cannot handle them either.

However, trying to return a Glypher results in heap allocs for each call to GetGlyph().

Any suggestions? @deadprogram @aykevl @conejoninja

sago35 commented 11 months ago

const2bit works with the following versions of tinyfont.

$ go get tinygo.org/x/tinyfont@34f5899f6c1e34aa6daa4e12e2b96a2ea370dff9
scraly commented 6 months ago

I've tried to convert a TTF font to a tiny go format:

$ go run ./cmd/tinyfontgen-ttf --package fonts --size 32 --fontname Regular58pt ./CharacterCats.ttf --output cats
58.go

But I can`t use it

    tinyfont.DrawChar(&display, &fonts.Regular58pt, 5, 140, 'B', green)
# command-line-arguments
main.go:87:30: cannot use fonts.Regular58pt (variable of type const2bit.Font) as tinyfont.Fonter value in argument to tinyfont.DrawChar: const2bit.Font does not implement tinyfont.Fonter (method GetGlyph has pointer receiver)