1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16\startluacode
17 local riven = moduledata.riven or { }
18 moduledata.riven = riven
19
20 local tonumber = tonumber
21 local reverse = table.reverse
22 local utfchar = utf.char
23 local gsub = string.gsub
24 local concat = table.concat
25 local lpegmatch = lpeg.match
26
27 local f = string.formatters["%N"]
28
29 local slots = { }
30
31 for i=0,24 do
32 slots[i] = fonts.helpers.newprivateslot("riven digit " .. i)
33 end
34
35 function riven.tostring(n)
36 if n >= 0 and n <= 24 then
37 return utfchar(slots[n])
38 else
39 local result = gsub(f(n),"(%d+)",function(s)
40 local digits = { }
41 local count = 1
42 local n = tonumber(s)
43 while true do
44 digits[count] = utfchar(slots[n % 25])
45 n = n // 25
46 if n == 0 then
47 break;
48 end
49 count = count + 1
50 end
51 return concat(reverse(digits))
52 end)
53 return result
54 end
55 end
56
57 interfaces.implement {
58 name = "rivennumerals",
59 arguments = "integer",
60 actions = { riven.tostring, context }
61 }
62\stopluacode
63
64\startMPcalculation{simplefun}
65
66 path riven_glyphs[] ;
67
68 def InitializeRiven =
69
70 riven_glyphs[ 0] := (0,0) -- (4,4) ;
71 riven_glyphs[ 1] := (2,0) -- (2,4) ;
72 riven_glyphs[ 2] := (0,0) .. (2,2) .. (0,4) ;
73 riven_glyphs[ 3] := (2,0) -- (0,2) -- (2,4) ;
74 riven_glyphs[ 4] := (2,0) -- (2,3) -- (4,3) ;
75 riven_glyphs[ 5] := (0,2) -- (4,2) ;
76
77 riven_glyphs[10] := (0,0) .. (2,2) .. (4,0) ;
78 riven_glyphs[15] := (0,2) -- (2,0) -- (4,2) ;
79 riven_glyphs[20] := (1,4) -- (1,2) -- (4,2) ;
80
81 riven_glyphs[ 6] := riven_glyphs[ 5] && riven_glyphs[1] ;
82 riven_glyphs[ 7] := riven_glyphs[ 5] && riven_glyphs[2] ;
83 riven_glyphs[ 8] := riven_glyphs[ 5] && riven_glyphs[3] ;
84 riven_glyphs[ 9] := riven_glyphs[ 5] && riven_glyphs[4] ;
85 riven_glyphs[11] := riven_glyphs[10] && riven_glyphs[1] ;
86 riven_glyphs[12] := riven_glyphs[10] && riven_glyphs[2] ;
87 riven_glyphs[13] := riven_glyphs[10] && riven_glyphs[3] ;
88 riven_glyphs[14] := riven_glyphs[10] && riven_glyphs[4] ;
89 riven_glyphs[16] := riven_glyphs[15] && riven_glyphs[1] ;
90 riven_glyphs[17] := riven_glyphs[15] && riven_glyphs[2] ;
91 riven_glyphs[18] := riven_glyphs[15] && riven_glyphs[3] ;
92 riven_glyphs[19] := riven_glyphs[15] && riven_glyphs[4] ;
93 riven_glyphs[21] := riven_glyphs[20] && riven_glyphs[1] ;
94 riven_glyphs[22] := riven_glyphs[20] && riven_glyphs[2] ;
95 riven_glyphs[23] := riven_glyphs[20] && riven_glyphs[3] ;
96 riven_glyphs[24] := riven_glyphs[20] && riven_glyphs[4] ;
97
98 riven_glyphs[-1] := (0,0) -- (4,0) -- (4,4) -- (0,4) -- cycle ;
99
100 for i=0 upto 24 :
101 riven_glyphs[i] := riven_glyphs[i] && riven_glyphs[-1] ;
102 endfor ;
103
104 enddef ;
105
106 vardef Riven(expr i) =
107 numeric u ; u := 1.5 ;
108 draw image (
109 draw riven_glyphs[i]
110 scaled (10u20 1.5u40)
111 withpen pencircle scaled (3u20) ;
112 ;
113 ) shifted (1.5u20,1.5u20)
114 shifted (4u20,0)
115 enddef ;
116
117 lmt_registerglyphs [
118 name = "riven",
119 units = 4,
120 usecolor = true,
121 width = 3.6,
122 height = 3,
123 depth = 0,
124 preamble = "InitializeRiven"
125 ] ;
126
127 for i=0 upto 24 :
128 lmt_registerglyph [
129 category = "riven",
130 private = "riven digit " & decimal i,
131 code = "Riven(" & decimal i & ")"
132 tounicode =
133 if i > 9 :
134 { (ASCII "0") (i div 10), (ASCII "0") (i mod 10) }
135 else :
136 (ASCII "0") (i mod 10)
137 fi,
138 ] ;
139 endfor ;
140
141\stopMPcalculation
142
143\unprotect
144
145\permanent\def\rivennumerals#1{\clf_rivennumerals\numexpr#1\relax}
146
147\defineconversion [rivennumerals] [\rivennumerals]
148\defineconversion [R] [\rivennumerals]
149
150\definefontfeature
151 [riven]
152 [metapost=riven]
153
154\protect
155
156\continueifinputfile{metaimpriven.mkxl}
157
158\startbuffer
159
160\definefontfeature
161 [default]
162 [default]
163 [metapost=riven]
164
165\setupbodyfont[dejavu]
166
167\start
168 \showglyphs
169 RIVEN
170 \dostepwiserecurse{0}{24}{1}{\rivennumerals{#1}\space }
171\stop
172
173riven \start
174 \red\glyphxscale 700
175 \dostepwiserecurse{0}{24}{1}{\rivennumerals{#1}\space }
176\stop
177
178\startitemize[packed,R][color=orange,stopper=]
179 \startitem first \stopitem
180 \startitem second \stopitem
181 \startitem third \stopitem
182\stopitemize
183
184RIVEN \start
185 \red \rivennumerals{2023}
186 \green\rivennumerals{4}
187 \blue \rivennumerals{18}
188\stop
189
190\stopbuffer
191
192\starttext
193
194\startTEXpage[offset=1ts,width=3es]
195 \getbuffer
196\stopTEXpage
197
198\setuplayout[tight]
199
200
201
202
203
204\stoptext
205 |