meta-imp-threesix.mkxl /size: 9 Kb    last modification: 2020-07-01 14:35
1
% not yet a module
2 3
\startluacode
4
local
gsub
,
utfbyte
=
string
.
gsub
,
utf
.
byte
5 6
-- The font from DEK's facs9b.ps (I wish I was clever enough to understand all the good
7
-- stuff in there):
8 9
local
font36
=
{
10
[
"
0
"
]
=
[
[
00111100
01111110
11000011
11000011
11000011
11000011
01111110
00111100
]
]
,
11
[
"
1
"
]
=
[
[
00011100
11111100
11101100
00001100
00001100
00001100
11111111
11111111
]
]
,
12
[
"
2
"
]
=
[
[
00111110
01110011
01110011
00000011
00001110
00111000
11110001
11111111
]
]
,
13
[
"
3
"
]
=
[
[
01111110
01100110
00000110
00111100
00000110
11100111
11100111
01111110
]
]
,
14
[
"
4
"
]
=
[
[
00001110
00011110
00110110
01100110
11111111
11111111
00000110
00001110
]
]
,
15
[
"
5
"
]
=
[
[
01111110
01111110
01000000
01111100
01000111
00000011
11000111
11111110
]
]
,
16
[
"
6
"
]
=
[
[
01111110
01100110
11000000
11011100
11100110
11000011
01100011
01111110
]
]
,
17
[
"
7
"
]
=
[
[
11111111
11111111
10000111
10001110
00011100
00011100
00011100
00011100
]
]
,
18
[
"
8
"
]
=
[
[
01111110
01100110
01100110
00111100
11000011
11000011
11000011
01111110
]
]
,
19
[
"
9
"
]
=
[
[
01111110
11000110
11000011
01100111
00111011
00000011
01100110
01111110
]
]
,
20
[
"
A
"
]
=
[
[
000110000
000111000
001111100
001101100
011001110
011111110
010000110
111100111
]
]
,
21
[
"
B
"
]
=
[
[
1111100
1110110
0110110
0111100
0110011
0110011
1110011
1111100
]
]
,
22
[
"
C
"
]
=
[
[
01111101
11110011
11100001
11100001
11100000
11100000
11100001
01111110
]
]
,
23
[
"
D
"
]
=
[
[
11111100
11100010
01100011
01100011
01100011
01100011
11100010
11111100
]
]
,
24
[
"
E
"
]
=
[
[
1111111
1110001
0110101
0111100
0110100
0110001
1110001
1111111
]
]
,
25
[
"
F
"
]
=
[
[
11111111
11100001
01100101
01111100
01100100
01100000
11111000
11111000
]
]
,
26
[
"
G
"
]
=
[
[
01111010
11100110
11100010
11100000
11100111
11100010
11100010
01111100
]
]
,
27
[
"
H
"
]
=
[
[
11100111
11100111
01000010
01111110
01000010
01000010
11100111
11100111
]
]
,
28
[
"
I
"
]
=
[
[
1111111
1111111
0011000
0011000
0011000
0011000
1111111
1111111
]
]
,
29
[
"
J
"
]
=
[
[
01111111
01111111
00000110
00000110
11110110
01100110
01100110
00111100
]
]
,
30
[
"
K
"
]
=
[
[
11101110
11100100
01101000
01110000
01111000
01101100
11100110
11101111
]
]
,
31
[
"
L
"
]
=
[
[
111111000
111111000
011000000
011000000
011000000
011000011
111000011
111111111
]
]
,
32
[
"
M
"
]
=
[
[
1100000011
1110000111
0111111110
0100110010
0100110010
0100000010
1100000011
1100000011
]
]
,
33
[
"
N
"
]
=
[
[
11000011
11100011
01110010
01111010
01011110
01001110
11100110
11100010
]
]
,
34
[
"
O
"
]
=
[
[
01111110
11000011
11000011
11000011
11000011
11000011
11000011
01111110
]
]
,
35
[
"
P
"
]
=
[
[
11111110
11100011
01100011
01111110
01100000
01100000
11111000
11111000
]
]
,
36
[
"
Q
"
]
=
[
[
01111100
11000110
11000110
11000110
11000110
11001110
11000110
01111101
]
]
,
37
[
"
R
"
]
=
[
[
11111100
11100110
01100110
01111100
01101000
01100100
11100010
11100111
]
]
,
38
[
"
S
"
]
=
[
[
01111110
11100001
11100001
01111000
00011110
10000111
11000011
10111110
]
]
,
39
[
"
T
"
]
=
[
[
1111111111
1100110011
1100110011
0000110000
0000110000
0000110000
0001111000
0001111000
]
]
,
40
[
"
U
"
]
=
[
[
111101111
111101111
011000010
011000010
011000010
011000010
011000010
001111100
]
]
,
41
[
"
V
"
]
=
[
[
11111000111
11111000111
01110000010
00110000100
00111000100
00011001000
00001101000
00001110000
]
]
,
42
[
"
W
"
]
=
[
[
111000000111
111000000111
110000000010
011000000100
011001000100
001101101000
001101101000
000110110000
]
]
,
43
[
"
X
"
]
=
[
[
1111001110
1111000110
0001101000
0000110000
0000110000
0001011000
0110001111
0111001111
]
]
,
44
[
"
Y
"
]
=
[
[
111100011
111100011
011000010
001110100
000111000
000011000
001111110
001111110
]
]
,
45
[
"
Z
"
]
=
[
[
11111111
10000111
00001110
00011100
00111000
01110000
11100001
11111111
]
]
,
46
}
47 48
local
f_code
=
string
.
formatters
[
"
ThreeSix(%s);
"
]
49
local
replace
=
{
[
"
0
"
]
=
"
N;
"
,
[
"
1
"
]
=
"
Y;
"
,
[
"
"
]
=
"
L;
"
}
50 51
local
function
remap
(
str
)
52
-- permit abundant spacing (bonus)
53
str
=
gsub
(
str
,
"
%s+
"
,
"
"
)
54
-- remap what we got to macro calls
55
str
=
gsub
(
str
,
"
.
"
,
replace
)
56
-- return the result
57
return
str
58
end
59 60
function
MP
.
registerthreesix
(
name
)
61
fonts
.
dropins
.
registerglyphs
{
62
name
=
name
,
63
units
=
12
,
64
usecolor
=
true
,
65
preamble
=
"
InitializeThreeSix;
"
,
66
}
67
for
u
,
v
in
table
.
sortedhash
(
font36
)
do
68
local
ny
=
8
69
local
nx
=
(
#
v
-
ny
+
1
)
/
/
ny
70
local
height
=
ny
*
1
.
1
-
0
.
1
71
local
width
=
nx
*
1
.
1
-
0
.
1
72
fonts
.
dropins
.
registerglyph
{
73
category
=
name
,
74
unicode
=
utfbyte
(
u
)
,
75
width
=
width
,
76
height
=
height
,
77
code
=
f_code
(
remap
(
v
)
)
,
78
}
79
end
80
end
81 82
MP
.
registerthreesix
(
"
fontthreesix
"
)
83
\stopluacode
84 85
% \startMPcalculation{simplefun}
86
% def InitializeThreeSix =
87
% save Y, N, L, S ; save dx, dy, nx, ny ;
88
% save shape, fillcolor, mypen, random, currentpen, spread, hoffset ;
89
% string shape, fillcolor, mypen ; boolean random ; pen currentpen ;
90
% dx := 11/10 ;
91
% dy := - 11/10 ;
92
% nx := - dx ;
93
% ny := 0 ;
94
% shape := getparameterdefault "mpsfont" "shape" "circle" ;
95
% random := hasoption "mpsfont" "random" "true" ;
96
% fillcolor := getparameterdefault "mpsfont" "color" "" ;
97
% mypen := getparameterdefault "mpsfont" "pen" "" ;
98
% spread := getparameterdefault "mpsfont" "spread" 0 ;
99
% hoffset := 12 * spread / 2 ;
100
% currentpen := pencircle
101
% if mypen = "fancy" :
102
% xscaled 1/20 yscaled 2/20 rotated 45
103
% else :
104
% scaled 1/20
105
% fi ;
106
% if shape == "square" :
107
% def S =
108
% unitsquare if random : randomized 1/10 fi
109
% shifted (nx,ny)
110
% enddef ;
111
% elseif shape = "diamond" :
112
% def S =
113
% unitdiamond if random : randomized 1/10 fi
114
% shifted (nx,ny)
115
% enddef ;
116
% else :
117
% def S =
118
% unitcircle if random : randomizedcontrols 1/20 fi
119
% shifted (nx,ny)
120
% enddef ;
121
% fi ;
122
% def N =
123
% nx := nx + dx ;
124
% draw S ;
125
% enddef ;
126
% if fillcolor = "random" :
127
% def Y =
128
% nx := nx + dx ;
129
% fillup S withcolor white randomized (2/3,2/3,2/3) ;
130
% enddef ;
131
% elseif fillcolor = "" :
132
% def Y =
133
% nx := nx + dx ;
134
% fillup S ;
135
% enddef ;
136
% else :
137
% def Y =
138
% nx := nx + dx ;
139
% fillup S withcolor fillcolor ;
140
% enddef ;
141
% fi ;
142
% def L =
143
% nx := - dx ;
144
% ny := ny + dy ;
145
% enddef ;
146
% enddef ;
147
%
148
% vardef ThreeSix (text code) =
149
% InitializeThreeSix ;
150
% draw image (code) shifted (hoffset,-ny) ;
151
% enddef ;
152
% \stopMPcalculation
153 154
\startMPcalculation
{
simplefun
}
155
def
InitializeThreeSix
=
156
save
Y
,
N
,
L
,
S
;
157
% save dx, dy, nx, ny ;
158
save
shape
,
fillcolor
,
mypen
,
random
,
threesixpen
,
spread
,
hoffset
;
159
string
shape
,
fillcolor
,
mypen
;
boolean
random
;
pen
threesixpen
;
160
% dx := 11/10 ;
161
% dy := - 11/10 ;
162
% nx := - dx ;
163
% ny := 0 ;
164
shape
:
=
getparameterdefault
"
mpsfont
"
"
shape
"
"
circle
"
;
165
random
:
=
hasoption
"
mpsfont
"
"
random
"
"
true
"
;
166
fillcolor
:
=
getparameterdefault
"
mpsfont
"
"
color
"
"
"
;
167
mypen
:
=
getparameterdefault
"
mpsfont
"
"
pen
"
"
"
;
168
spread
:
=
getparameterdefault
"
mpsfont
"
"
spread
"
0
;
169
hoffset
:
=
12
*
spread
/
2
;
170
threesixpen
:
=
pencircle
171
if
mypen
=
"
fancy
"
:
172
xscaled
1
/
20
yscaled
2
/
20
rotated
45
173
else
:
174
scaled
1
/
20
175
fi
;
176
if
shape
=
=
"
square
"
:
177
def
S
=
178
unitsquare
if
random
:
randomized
1
/
10
fi
179
shifted
(
nx
,
ny
)
180
enddef
;
181
elseif
shape
=
"
diamond
"
:
182
def
S
=
183
unitdiamond
if
random
:
randomized
1
/
10
fi
184
shifted
(
nx
,
ny
)
185
enddef
;
186
else
:
187
def
S
=
188
unitcircle
if
random
:
randomizedcontrols
1
/
20
fi
189
shifted
(
nx
,
ny
)
190
enddef
;
191
fi
;
192
def
N
=
193
nx
:
=
nx
+
dx
;
194
draw
S
;
195
enddef
;
196
if
fillcolor
=
"
random
"
:
197
def
Y
=
198
nx
:
=
nx
+
dx
;
199
fillup
S
withcolor
white
randomized
(
2
/
3
,
2
/
3
,
2
/
3
)
;
200
enddef
;
201
elseif
fillcolor
=
"
"
:
202
def
Y
=
203
nx
:
=
nx
+
dx
;
204
fillup
S
;
205
enddef
;
206
else
:
207
def
Y
=
208
nx
:
=
nx
+
dx
;
209
fillup
S
withcolor
fillcolor
;
210
enddef
;
211
fi
;
212
def
L
=
213
nx
:
=
-
dx
;
214
ny
:
=
ny
+
dy
;
215
enddef
;
216
enddef
;
217 218
vardef
ThreeSix
(
text
code
)
=
219
save
dx
,
dy
,
nx
,
ny
;
220
dx
:
=
11
/
10
;
221
dy
:
=
-
11
/
10
;
222
nx
:
=
-
dx
;
223
ny
:
=
0
;
224
pickup
threesixpen
;
225
draw
image
(
code
)
shifted
(
hoffset
,
-
ny
)
;
226
enddef
;
227
\stopMPcalculation
228 229
\definefontfeature
% black and white, with some spread
230
[
fontthreesix
]
231
[
default
]
232
[
metapost
=
fontthreesix
]
233 234
\definefontfeature
% color, with some spread
235
[
fontthreesix
-
tweak
]
236
[
default
]
237
[
metapost
=
{
category
=
fontthreesix
,
spread
=
.
1
}
]
238 239
\definefontfeature
% color, with some spread
240
[
fontthreesix
-
color
]
241
[
default
]
242
[
metapost
=
{
category
=
fontthreesix
,
shape
=
diamond
,
color
=
random
,
pen
=
fancy
,
spread
=
.
1
}
]
243 244
\definefontfeature
% color, tight
245
[
fontthreesix
-
initial
]
246
[
metapost
=
{
category
=
fontthreesix
,
color
=
random
,
shape
=
circle
}
]
% units?
247 248
\definefont
[
DEKFontA
][
Serif
*
fontthreesix
]
249
\definefont
[
DEKFontB
][
Serif
*
fontthreesix
-
color
]
250
\definefont
[
DEKFontC
][
Serif
*
fontthreesix
-
initial
]
251
\definefont
[
DEKFontD
][
Serif
*
fontthreesix
-
tweak
]
252 253
\endinput
254