tinyfont icon indicating copy to clipboard operation
tinyfont copied to clipboard

const2bit is broken

Open oxplot opened this issue 2 years ago • 11 comments

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})

oxplot avatar Jul 15 '23 15:07 oxplot

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 avatar Aug 03 '23 12:08 sago35

const2bit works with the following versions of tinyfont.

$ go get tinygo.org/x/tinyfont@34f5899f6c1e34aa6daa4e12e2b96a2ea370dff9

sago35 avatar Aug 03 '23 12:08 sago35

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)

scraly avatar Jan 02 '24 16:01 scraly