ekle/waveshareFontGenerator

Some Fonts create zero only glyphs

ExitStatus opened this issue · 11 comments

Hi, I have tried to use your utility to generate some fonts however the files it generates have every character as empty. Using GO 1.16.2.

Eg. copy comic sans from windows fonts folder to current folderm then execute following

go run main.go /f comic.ttf > comic.h

Following ZIP file contains the resulting file.

comic.zip

ekle commented

I have never tried it on windows.

On kubuntu 20.04 it works with golang 1.16.2.
Locally i use the following command to test it go run main.go -f /usr/share/fonts/truetype/msttcorefonts/comic.ttf
The comic.ttf comes from the debian package msttcorefonts.

I get empty too and this error:

GlyphIndex: no glyph index found for the rune '%!(EXTRA int32=94, string=')

I tested also in ubuntu same error but I guess it depends on the font I'm trying to convert.. any link to a list of compatible fonts we can use?

thanks

ekle commented

Maybe this Dockerfile helps you:

FROM golang:1.16.2-buster
RUN apt-get update && apt-get -y install ttf-staypuft
RUN git clone https://github.com/ekle/waveshareFontGenerator.git
RUN cd waveshareFontGenerator && go get 
CMD cd waveshareFontGenerator && go run main.go -f /usr/share/fonts/truetype/ttf-staypuft/StayPuft.ttf

Just tested this font

https://fonts.google.com/specimen/Share+Tech+Mono?preview.text_type=custom#standard-styles

and it works, yep tricky to find the right width but with a couple of test it works.

the problem is that not all fonts works but I guess it's tricky too to implement

I have same issues. Just zeros everywhere. Latest go and Arch Linux.

ekle commented

I tested it with the a comic.ttf from Windows 10 and it looks like it has positive CapHeight where as the file from msttcorefonts returns a negative CapHeight.

I have no clue if this is a bug in golang.org/x/image/font/sfnt or if it has another reason.

In the branch 1-CapHeight-fix i ensure the value is positive.

Can you test it with this branch?

@ekle Well almost it's working!
image
Any font size, or no default size, font is cut off strangely.
I tried different font sizes:
image
image

digital-7.zip
This is font I am experimenting with.

[tekusp@MSI waveshareFontGenerator]$ go version
go version go1.16.3 linux/amd64
[tekusp@MSI waveshareFontGenerator]$ cat /etc/os-release
NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://www.archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
LOGO=archlinux
[tekusp@MSI waveshareFontGenerator]$ uname -r
5.4.72-microsoft-standard-WSL2
ekle commented

I have made all the positioning parameters configurable.
There is no automatic calculation anymore.
Just changing the ppem will not change the other values anymore.
I have choose some default which should usually at least work.

But to get the best result and save some bytes and display space, you should configure all of them to your needs:

  -w, --width=   font width in bytes (default: 2)
  -h, --height=  font height in lines (default: 24)
  -s, --ppem=    font size (default: 20)
  -x, --xoffset= x offset for the runes (default: 0)
  -y, --yoffset= y offset for the runes (default: 18)
  -f, --font=    path to font file
  -d, --debug    display some debug information

It works! Great!