File: hershey.tex

package info (click to toggle)
texlive-base 2022.20230122-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 943,248 kB
  • sloc: perl: 43,776; sh: 5,749; makefile: 3,870; javascript: 3,034; ruby: 2,266; tcl: 2,130; xml: 1,874; python: 1,025; awk: 606; cpp: 549; lisp: 447; ansic: 103; sed: 8
file content (156 lines) | stat: -rw-r--r-- 4,295 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156

\input minim-doc.sty
\closeout0

\newmetapostinstance\hershey
\runmetapost\hershey{
    input "hershey";
    loadHershey timesib;
}

\def\chapter#1\hfill#2\par{%
    \startelement{Chapter}%
    \outline open {#1}%
    \nextpartag{H}\quitvmode
    \startelement{Span}%
    \red{\runmetapostimage\hershey{
        baseline origin;
        pickup pencircle scaled .4pt;
        drawHershey timesib ("hershey.mp") withcolor .75red;
    }\setactualtext{hershey.mp}%
    \stopelement{Span}%
    \hfill#2\bigskip\nobreak}}

\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;⟧

This results in the following pictures:

\bigskip\strut\hfill
\startelement{Figure}
\setalttext{An upside-down ampersand.}
\runmetapostimage \hershey {
baseline origin;
drawHershey timesib(7) rotated 180 withcolor .75red;}
\stopelement{Figure}
\hfill and\hfill
\startelement{Figure}
\setalttext{The text ‘Hello!’.}
\runmetapostimage \hershey {
baseline origin;
drawHershey timesib("Hello!") withcolor .75red;}
\stopelement{Figure}
\hfill\strut\bigskip

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}}

\def\chapter#1#2{%
    \ensurestopelement{Section}%
    \startelement{Chapter}%
    \outline open {#2}%
    \nextpartag{H}\quitvmode
    \vrule depth 20pt height 35pt width 0pt\relax
    \startelement{Span}%
    \red{\runmetapostimage\hershey{
        loadHershey #2;
        baseline origin;
        pickup pencircle scaled .4pt;
        drawHershey #1 ("#2") withcolor .75red;
    }}\setactualtext{#2}\bigskip
    \stopelement{Span}\nobreak}

\testfont timesr      timesr
\testfont timesi      timesi
\testfont timesrb     timesrb
\testfont timesib     timesib
\testfont timesr      timesg
\testfont timesr      cyrillic

\testfont gothiceng   gothiceng
\testfont gothicger   gothicger
\testfont gothicita   gothicita

\testfont rowmans     rowmans
\testfont rowmand     rowmand
\testfont rowmant     rowmant

\testfont futural     futural
\testfont futuram     futuram

\testfont timesr      greeks
\testfont timesr      greekc

\testfont scripts     scripts
\testfont scriptc     scriptc

\testfont timesr      mathlow
\testfont timesr      mathupp

\testfont astrology   astrology
\testfont meteorology meteorology
\testfont timesr      symbolic
\testfont timesr      markers
\testfont music       music

\vfil\break\end