Skip to content

sample code for parsing the Hershey vector fonts in Python. Also Hershey data in JSON.

License

Notifications You must be signed in to change notification settings

scruss/python-hershey

Repository files navigation

python-hershey

Some simple Python code to parse the Hershey vector fonts. Also included is the complete font set encoded as JSON, should you just want to use the data.

The Python code creates an array of dictionaries (hashes), for example:

glyph = {
    'bbox': [[-4,-5],[4,4]], # glyph bounding box (derived)
	'charcode': 1,           # Hershey (NOT ASCII) character code
	'left':  -5,             # left bearing X coordinate
	'right':  5,             # right bearing X coordinate
	# glyph vectors: a list of lists of lists, or an array of
    #                lines of points
	'lines': [[[0,-5],[-4,4]],[[0,-5],[4,4]],[[-2,1],[2,1]]]
}

The above example has three lines, each with two points, each with an X and a Y coordinate. If you plot the lines, you will get an upside down capital letter A. These data use obsolete machine coordinates instead of the familiar Cartesian convention.

Caveats

While the Hershey fonts were pretty nifty for 1967, they have some problems:

  1. They don't use any standard encoding
  2. They don't use modern font conventions, so aligning, parsing and setting Hershey text is a little complex
  3. Y-coordinates are positive downwards, so everything's upside down. (Or right way up, if you use SVG.)

Requirements

  • Python 2.7.x

Contents

  • hershey-occidental.dat --- the original Usenet Hershey western font data, reformatted without linebreaks (using Kamal Mostafa's hershey-jhf-fix-linebreaks.py), and with a minor error in the side bearing of character #3010 corrected.
  • hershey-oriental.dat --- the original Usenet Hershey Japanese font data, reformatted as above, verbatim.
  • hershey-occidental.json --- the Hershey western data as JSON; essentially the output of hersheyparse.py run over hershey-occidental.dat
  • hershey-oriental.json --- the Hershey Japanese data as JSON.
  • hersheyparse.py --- simple Python parser for reformatted Hershey font files.
  • turtle-hershey-example.py --- tiny demo that uses Python's turtle module to say hello.

Licence

For the work created or modified by me (Stewart C. Russell, aka scruss), dual-licensed CC0 / WTFPL (srsly). Time and link rot haven't been kind to the Hershey fonts since they were first published in 1967, and then republished to mod.sources sometime in the 1980s. References to US Government publications documenting the fonts are mostly dead: tapes of the data are no longer available, and the best we have is Jim Hurt et al's efforts from Usenet.

It asks that the following be kept in any distribution derived from the work of the Usenet Font Consortium:

USE RESTRICTION:
    This distribution of the Hershey Fonts may be used by anyone for
    any purpose, commercial or otherwise, providing that:
            1. The following acknowledgements must be distributed with
                    the font data:
                    - The Hershey Fonts were originally created by Dr.
                            A. V. Hershey while working at the U. S.
                            National Bureau of Standards.
                    - The format of the Font data in this distribution
                            was originally created by
                                    James Hurt
                                    Cognition, Inc.
                                    900 Technology Park Drive
                                    Billerica, MA 01821
                                    (mit-eddie!ci-dandelion!hurt)
            2. The font data in this distribution may be converted into
                    any other format *EXCEPT* the format distributed by
                    the U.S. NTIS (which organization holds the rights
                    to the distribution and use of the font data in that
                    particular format). Not that anybody would really
                    *want* to use their format... each point is described
                    in eight bytes as "xxx yyy:", where xxx and yyy are
                    the coordinate values as ASCII numbers.

More details at Hershey fonts for Ghostscript, where the data are described as being in the public domain.

Other resources

Stewart C. Russell, Toronto - scruss.com - 2014-06-01

About

sample code for parsing the Hershey vector fonts in Python. Also Hershey data in JSON.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages