\def\mailname{hershey}
\startmetadata
author {Esger Renkema}
title {hershey.mp}
date {2022-08-24}
version {2022/1.0}
keywords {MetaPost; Hershey fonts}
stopmetadata
\maketitle
This package can read the ⟦jhl⟧ format, used for the well known Hershey Fonts.
Use it like so:
⟦% Where to look for font files (this is also the default)
hersheyFonts := "/usr/share/hershey-fonts/";
% Load the font you want to use
loadHershey timesib;
% Draw a character
beginfig(1)
drawHershey timesib(7) rotated 180 withcolor .75red;
endfig;
% Or typeset a string
beginfig(2)
drawHershey timesib("Hello!") withcolor .75red;
endfig;⟧
Typesetting a string will only make sense for the latin fonts, where Hershey’s
encoding is in ASCII order. For strings, the baseline is adjusted upward by 9~units.
Typical x-height is 14 units (of which 9 are below $y=0$), with an em-space of 21 units.
The paths that make up each character are available to you in the array
⟦hershey.<fontname>[<charid>][]⟧. You will rarely need this, however, since the trailing tokens to ⟦drawHershey⟧ will be applied to all paths.
Proof sheets of Hershey’s original fonts are included in the following pages.
\licencesection \stopelement{Section}
\font\fiverm {Latin Modern Roman:script=latn;protrusion=default;} at 5pt
\runmetapost \hershey {
vardef testfont suffix name =
save c; c := 1;
for i = 1 upto 7: draw (45i+22.5,-22.5) -- (45i+22.5,-45*12-22.5); endfor
for j = 1 upto 11: draw (22.5, -45j-22.5) -- (45*8+22.5, -45j-22.5); endfor
for i = 1 upto 8:
for j = 1 upto 12:
drawHershey.name(c) shifted 45(i,-j);
draw maketext("{\fiverm "&decimal c&"}") shifted (45(i,-j) + (13,16));
c := c + 1;
endfor
endfor
setbounds currentpicture to
unitsquare xscaled 8 yscaled -12 scaled 45 shifted (22.5, -22.5);
enddef; }
\def\testfont#1 #2 {\vfil\break
\chapter{#1}{#2}%
\startelement{Figure}
\setalttext{A listing of the ‘#2’ font.}
\stoptagging
\runmetapostimage \hershey { testfont #2; }
\starttagging
\stopelement{Figure}}