tinygo-org / tinyfont

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

tinyfontgen-ttf: remove NULL character #39

Closed sago35 closed 2 years ago

sago35 commented 2 years ago

When the following font was used for generation, NULL characters were generated in the comments and the build failed.

image

This is not only TinyGo, but also Go cannot be built. Therefore, it has been corrected so that the NULL character is not included in the comment.

arfelickfeather\font.go:18:39: invalid NUL character

After modification, it works well as follows.

https://fontsfree.net/arfelick-feather-font-download.html

$ go run ./cmd/tinyfontgen-ttf --size 32 --package arfelickfeather --fontname ArfelickFeather32pt ./_fonts/FontsFree-NetArfelickFeather.ttf --output arfelickfeather/font.go
package main

import (
    "fmt"
    "image/color"

    "tinygo.org/x/tinyfont"
    "tinygo.org/x/tinyfont/arfelickfeather"
    "tinygo.org/x/tinyfont/examples/initdisplay"
)

func main() {
    font := arfelickfeather.ArfelickFeather32pt
    display := initdisplay.InitDisplay()

    msg := fmt.Sprintf("%s\n1234567890\nHello TinyFont", font.Name)
    tinyfont.WriteLine(display, &font, 10, 35, msg, color.RGBA{A: 0xFF})

    select {}
}

image

doniacld commented 2 years ago

I tested your fix on a classic font, it generated properly the Go file! 🎉 With the feather font, it does not work and I have the following error:

./tinyfontgen-tt --package bfeather --fontname FontsFree-Net-bfeather FontsFree-Net-bfeather.ttf --output birds.go --verbose                                           
2022/08/07 09:47:26 sfnt: invalid OS/2 table

I will not keep digging into the problem for this font and will try another one. Thanks @sago35

I have tried with easter eggs and did not work either

 ❯  ./tinyfontgen-tt --package easter --fontname easter ./test-fonts/Easter_art.ttf --output easter.go --verbose                                                                           09:49:07
2022/08/07 09:57:33 sfnt: invalid cmap table
sago35 commented 2 years ago

At the moment we are unable to handle fonts that would cause golang.org/x/image/font/opentype to return an error. These are know issues, but the situation has not changed for a long time.

https://github.com/golang/go/issues?q=is%3Aissue+is%3Aopen+sfnt

The following two fonts can be rendered by github.com/golang/freetype/example/freetype, but I don't think I can support them for a while.

https://github.com/golang/freetype/tree/master/example/freetype

doniacld commented 2 years ago

Thanks @sago35 for your pointers! That's fine it was not a critical need :)

deadprogram commented 2 years ago

Thank you for the fix @sago35 now merging.