Skip to main content

Hershey Font


Hershey font is a python library with built in fonts and low level line and stroke iterators.

What is Hershey Font?

Hershey font is a vector font, designed many years ago. The main use today if for generating text for CNC engraving.

Read more on Wikipedia

Font samples

Overview

Hershey font consists of glyphs, each glyph is assigned to an ASCII value from 32 ('space') until 32+number of glyphs.
Each glyph consits of array of strokes.
A stroke is an array of zero or more continous lines (points of an openend or closed ploygon).

The Python module

The Hershey-Font package is providing the HersheyFonts class.
Great care was taken to be compatible with defulat installation of python 2.7 and python 3.
The HersheyFonts instance is handling only one font at a time. If you need to use multiple type faces as the same time, you can load a new typeface anytime (even during rendering) or create another HersheyFonts instance.

Installing

Sources available on GitHub Installation is available through pip and pip3

#python 3
pip3 install Hershey-Fonts

#python 2.7
pip install Hershey-Fonts

Demo

After successfully installing the Hershey-Font package, you can run the module for a simple demonstration.

#python 3
python3 -m HersheyFonts

#python 2.7
python -m HersheyFonts

Built-in fonts

The python module 1.0.0 has 32 fonts included in the source code as a compressed base64 encoded variable. The module can also load default fonts or from file and iterable string lines. When you make your own font and want to include in the package, please contact me. You can get the list of built-in fonts by looking at

from HersheyFonts import HersheyFonts

print(HersheyFonts().default_font_names)

The order and elements of the list may totally vary with any package release.

Loading a font

To access one of the built-in fonts, use the .load_default_font() method. To read custome fonts you can call the .load_font_file(file_name) or .read_from_string_lines(stringlines) methods. The constructor also gives opportunity to read built-in or external font.

from HersheyFonts import HersheyFonts
thefont = HersheyFonts()
thefont.load_default_font('gothiceng')
thefont.load_default_font(thefont.default_font_names[0])
thefont.load_default_font() #Returns the name of the loaded font
thefont.load_font_file('cyrillic.jhf')
thefont.read_from_string_lines(arrayofstrings)

For more details and all options see doc comments in the sources.

Renderig the loaded font

There are several options to convert a text to font data. The simplest way is to read endpoints of the lines returned by renderer method .lines_for_text(sometext)
There are renderer methods returning list of glyps, list of strokes and list of line endpoints.

The renderers in version 1.0.0 support only single line texts. Rendering is also affected by .render_options property.
There is a .normalize_rendering() method to automatically set the scaling and offsets for easy rendering.

# Minimalistic code for easy start
from HersheyFonts import HersheyFonts
def draw_line(x1, y1, x2, y2):
︙
︙

thefont = HersheyFonts()
thefont.load_default_font()
thefont.normalize_rendering(100)
for (x1, y1), (x2, y2) in thefont.lines_for_text('Hello'):
    draw_line(x1, y1 ,x2 ,y2)

The Hershey-Font API

The API is documented in the source code.

Thank you

Big thanks to all people working on maintaining this old format for the modern age.

Release files for Hershey-Fonts 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Hershey-Fonts 2.1.0
File Size Uploaded
Hershey Fonts-2.1.0.tar.gz 63.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Hershey-Fonts 2.1.0
File Interpreter ABI Platform
Hershey_Fonts-2.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 127.2 kB

Release files / Hershey Fonts-2.1.0.tar.gz

Download URL Hershey Fonts-2.1.0.tar.gz
Size 63.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ebdb0550f9cf78fed2a4bba71b971f5ce5f98ce630da9da9eaa4079b10e8b671
BLAKE2b-256 checksum
How to use checksums
29d46c7071756b5cb3a2995dbb01a6aefccd444ab0498c09e6cee9d0353943ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5

Release files / Hershey_Fonts-2.1.0-py2.py3-none-any.whl

Download URL Hershey_Fonts-2.1.0-py2.py3-none-any.whl
Size 63.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e53ef56bdef231f10f0576a6570f49fcc8442e45115028bc52a7ade15d824581
BLAKE2b-256 checksum
How to use checksums
677b6b42706a7a7bc88aa4aea1d19793c7d44709c4bf115ffeb5216b0ffe2dce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.8.0

2 release files

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page