Package import | "zappem.net/pub/graphics/hershey" |
---|---|
Documentation | https://pkg.go.dev/zappem.net/pub/graphics/hershey |
Sources | https://github.com/tinkerator/hershey |
The Hershey fonts are a convenient set of definitions of vector font data. This package provides a Go API to use them.
The hershey
package is bundled with an example program that shows
most of the features of the package. For example:
$ git clone https://github.com/tinkerator/hershey.git
$ cd hershey
$ go run examples/query.go --banner="Read Me!"
V
............................................................................................................................................
............................................................................................................................................
.############.........................................................#.......................#...............#..........................#..
.#...........#........................................................#.......................#..............##..........................#..
.#............#.......................................................#.......................#..............##..........................#..
.#............#.......................................................#.......................##............#.#..........................#..
.#.............#......................................................#.......................##............#.#..........................#..
.#.............#......................................................#.......................##............#.#..........................#..
.#.............#......................................................#.......................#.#..........#..#..........................#..
.#............#...........#####.............#####..#...........#####..#.......................#.#..........#..#...........#####..........#..
.#............#.........##.....#..........##.....#.#.........##.....#.#.......................#..#........#...#.........##.....#.........#..
.#...........#.........#........#........#........##........#........##.......................#..#........#...#........#........#........#..
.############.........#.........#.......#..........#.......#..........#.......................#..#........#...#.......#.........#........#..
.#......#............#...........#.....#...........#......#...........#.......................#...#......#....#......#...........#.......#..
>.#.......#...........#...........#.....#...........#......#...........#.......................#...#......#....#......#...........#.......#..
.#.......#...........#############.....#...........#......#...........#.......................#...#......#....#......#############.......#..
.#........#..........#.................#...........#......#...........#.......................#....#....#.....#......#...................#..
.#.........#.........#.................#...........#......#...........#.......................#....#....#.....#......#......................
.#.........#.........#.................#...........#......#...........#.......................#.....#..#......#......#......................
.#..........#........#.................#...........#......#...........#.......................#.....#..#......#......#......................
.#...........#........#..........#......#..........#.......#..........#.......................#.....#..#......#.......#..........#..........
.#...........#.........#........#........#........##........#........##.......................#......##.......#........#........#........#..
.#............#.........##.....#..........##.....#.#.........##.....#.#.......................#......##.......#.........##.....#........#.#.
.#.............#..........#####.............#####..#...........#####..#.......................#.......#.......#...........#####..........#..
............................................................................................................................................
............................................................................................................................................
You can list the known fonts (mapped to utf8 encoding) as follows:
$ go build examples/query.go
$ ./query --ls
2025/05/16 06:09:11 known fonts: ["astrology" "cursive" "futural" "futuram" "gothgbt" "gothgrt" "gothiceng" "gothicger" "gothicita" "gothitt" "rowmand" "rowmans" "rowmant" "scriptc" "scripts" "symbolic" "timesg" "timesi" "timesib" "timesr" "timesrb"]
Full help is availble with the --help
option. Examples:
$ ./query --glyph=33
glyph 33: (-5,-13), (5,10)
V
............
.....#......
.....#......
.....#......
.....#......
.....#......
.....#......
.....#......
.....#......
.....#......
.....#......
.....#......
.....#......
>.....#......
.....#......
.....#......
............
............
............
............
.....#......
....#.#.....
.....#......
............
$ ./query --scan
... the full list of known glyphs in the default font (rowmans) ...
The original font data, in .jhf
format, can be found in the
jhfdata/hershey/
directory.
The query tool can also be used (with go1.24+) to convert these files
from their original encoding to utf8 encoding using the translation
files in the utf8
directory. For example, this will
regenerate the fonts/rowmans.jhf
file:
$ ./query --dir jhfdata/hershey --font rowmans --xlate utf8 --dest fonts
2025/05/11 16:30:41 wrote "fonts/rowmans.jhf"
Please feel free to contribute fixes to the utf8 translation files and add support for more fonts.
The hershey
package has been developed purely out of self-interest
and offers no guarantee of fixes/support. That being said, if you
would like to suggest a feature addition or suggest a fix, please use
the bug tracker.
The Hershey data (everything in the jhfdata/
sub-directory) has a very permissive license, covered by the file
jhfdata/hershey/hershey.txt
file. See
the jhfdata/README.md
for the lineage of this
data.
For the rest of this package, see the LICENSE file: the same BSD 3-clause license as that used by golang itself.