adrg / sysfont

Golang identification and matching of system fonts
https://pkg.go.dev/github.com/adrg/sysfont
MIT License
44 stars 12 forks source link

Add filename to Match #11

Open Elara6331 opened 3 years ago

Elara6331 commented 3 years ago

I tried this library and noticed that it misses some of my fonts. I then used List to list all the fonts, and noticed some of them had no Name or Family field. If you add the filename to the Match function criteria, it will be able to match some fonts even without a Family or Name field present. Thank you.

gmlewis commented 2 years ago

I ran across this issue as well. If you install any Google Font, for example, it typically ends up in ${HOME}/.local/sharefonts. If I List() the fonts, they show up. However, if I try to use one of them, it always provides a substitute because the Family and Name fields are empty.

For example:


$ go run main.go
2022/08/04 20:09:01 Found 108 fonts:
2022/08/04 20:09:01 font #1: Family "", Name "", Filename "/home/glenn/.local/share/fonts/Baloo-Regular.ttf"
2022/08/04 20:09:01 font #2: Family "", Name "", Filename "/home/glenn/.local/share/fonts/BalsamiqSans-Bold.ttf"
2022/08/04 20:09:01 font #3: Family "", Name "", Filename "/home/glenn/.local/share/fonts/BalsamiqSans-BoldItalic.ttf"
2022/08/04 20:09:01 font #4: Family "", Name "", Filename "/home/glenn/.local/share/fonts/BalsamiqSans-Italic.ttf"
2022/08/04 20:09:01 font #5: Family "", Name "", Filename "/home/glenn/.local/share/fonts/BalsamiqSans-Regular.ttf"
2022/08/04 20:09:01 font #6: Family "", Name "", Filename "/home/glenn/.local/share/fonts/BungeeShade-Regular.ttf"
2022/08/04 20:09:01 font #7: Family "", Name "", Filename "/home/glenn/.local/share/fonts/Modak.ttf"
2022/08/04 20:09:01 font #8: Family "", Name "", Filename "/home/glenn/.local/share/fonts/Monoton-Regular.ttf"
2022/08/04 20:09:01 font #9: Family "DejaVu Sans", Name "DejaVu Sans Bold", Filename "/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf"
...

However, stepping through the code, it makes up a family name based on the filename when doing a search, and therefore compares `"bungeeshade"` (for example) to `""` and doesn't find a match. 

I think it is a simple fix of making up a family name for these files (based on their filename) so that when it comes time to make a match, it doesn't ignore fonts that have no family name.

I'll see if I can put together a PR.