summaryrefslogtreecommitdiff
path: root/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv
blob: 24e7b560e314724d57888347ebb5e6b6fc344e63 (plain)
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
%D \module
%D   [     file=t-cyrillicnumbers,
%D      version=2011-11-29 09:58:48+0100,
%D        title=\CONTEXT\ User Module,
%D     subtitle=Cyrillic Number Module,
%D       author=Philipp Gesang,
%D         date=\currentdate,
%D    copyright=Philipp Gesang,
%D      license=2-clause BSD,
%D        email={gesang at stud dot uni-heidelberg dot de}]
%D This module is licensed under the conditions of the BSD license with 
%D two clauses. There is a copy in a file named "COPYING" in the
%D t-cyrillicnumbers source tree.

\writestatus{loading}{Cyrillic Number Support for ConTeXt}

\unprotect

\startinterface all
  \setinterfacevariable {cyrillicnumerals} {cyrillicnumerals}
  \setinterfacevariable {Cyrillicnumerals} {Cyrillicnumerals}
  \setinterfacevariable           {cyrnum} {cyrnum}
  \setinterfacevariable             {dots} {dots}
  \setinterfacevariable        {dotsymbol} {dotsymbol}
  \setinterfacevariable         {penwidth} {penwidth}
  \setinterfacevariable   {preferhundredk} {preferhundredk}
  \setinterfacevariable    {titlolocation} {titlolocation}
  \setinterfacevariable        {titlomode} {titlomode}
  \setinterfacevariable        {titlospan} {titlospan}
  \setinterfacevariable            {titlo} {titlo}
\stopinterface

\definenamespace [cyrnum] [
    command=\v!yes,
    comment=cyrillic numbers,
    \s!name=\v!cyrnum,
  \s!parent=\v!cyrnum,
      setup=\v!list,
      style=\v!no,
       type=module,
    version=hg-tip,
]

\registerctxluafile{cyrillicnumbers}

\def\cyrnumsetvariables{%
  \startluacode
    local tc = thirddata.cyrnum
    tc.placetitlo    = "\cyrnumparameter{\v!titlo}"
    tc.titlolocation = tc.position_synonyms["\cyrnumparameter{\v!titlolocation}"]   or "f"
    tc.prefer100k    = tc.     yes_synonyms["\cyrnumparameter{\v!preferhundredk}"]  or false
    tc.drawdots      = tc.     yes_synonyms["\cyrnumparameter{\v!dots}"]            or false
    tc.dotsymbol     = "\cyrnumparameter{\v!dotsymbol}"

    local span   = "\cyrnumparameter{\v!titlospan}"
    local num = tonumber(span)
    if num then
      tc.titlotype = true
      tc.titlospan = num
    elseif span == "all" then
      tc.titlotype = false
    end
  \stopluacode%
}

\appendtoks \setuevalue{\currentcyrnum}{\do_cyrnum[\currentcyrnum]} \to \everydefinecyrnum
\appendtoks \cyrnumsetvariables                                     \to \everysetupcyrnum

\startmoduletestsection
  \ctxlua{thirddata.cyrnum.debug = true}
\stopmoduletestsection

\startuniqueMPgraphic{cyrnum-titlo1}
  path titlo ;
  save High, Low ;
  save Vfactor ; Vfactor = .15 ;
  save Hfactor ; Hfactor = .90 ;
  titlo := ( 0.00,    -Vfactor) ..
           ( 0.05,  .4*Vfactor) ..
           ( 0.95, -.4*Vfactor) ..
           ( 1.00,     Vfactor) ;
  pickup pensquare yscaled \cyrnumparameter{penwidth} xscaled 1 rotated -30 ;
  draw titlo
       xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight)
       shifted (.5*(OverlayWidth-Hfactor*OverlayWidth),OverlayHeight-Vfactor*OverlayHeight) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{cyrnum-titlo2}
  path titlo ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .15 ;
  save Hfactor ; Hfactor = .80 ;
  titlo := ( 0.05,    -Vfactor) --
           ( 0.07,  .7*Vfactor) ..
           ( 0.09,  .8*Vfactor) ..
           ( 0.91, -.8*Vfactor) ..
           ( 0.93, -.7*Vfactor) --
           ( 0.95,     Vfactor) ;
  pickup pensquare yscaled penwidth xscaled 1 rotated 70 ;
  draw titlo
       xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight)
       shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{cyrnum-titlo3}
  path titlo ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .15 ;
  save Hfactor ; Hfactor = .80 ;
  titlo := ( 0.05,      -Vfactor) --
           ( 0.07,  0.70*Vfactor) ..
           ( 0.09,  0.90*Vfactor) .. { dir 00 }
           ( 0.49, -0.00*Vfactor) --
           ( 0.49, -0.90*Vfactor) --
           ( 0.51,  0.90*Vfactor) --
           ( 0.51,  0.00*Vfactor) { dir 00 } ..
           ( 0.91, -0.90*Vfactor) ..
           ( 0.93, -0.70*Vfactor) --
           ( 0.95,       Vfactor) ;
  pickup pensquare yscaled penwidth xscaled 1 rotated 70 ;
  draw titlo
       xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight)
       shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

%%% Same as 2 with inner vertical stroke
\startuniqueMPgraphic{cyrnum-titlo4}
  path titlo, stroke ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .15 ;
  save Hfactor ; Hfactor = .80 ;
  titlo = ( 0.05, -1.00*Vfactor) --
          ( 0.07,  0.70*Vfactor) ..
          ( 0.09,  0.90*Vfactor) { dir 00 } .. { dir 00 }
          ( 0.91, -0.90*Vfactor) ..
          ( 0.93, -0.70*Vfactor) --
          ( 0.95,  1.00*Vfactor) ;
  stroke = ( 0.49*Hfactor*OverlayWidth+.5*penwidth, -0.30*Vfactor*OverlayHeight ) -- %% this is a mess
           ( 0.51*Hfactor*OverlayWidth+.5*penwidth,  0.50*Vfactor*OverlayHeight ) ;
  pickup pensquare yscaled penwidth xscaled 1 rotated 80 ;
  draw titlo
       xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight)
       shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) ;
  draw stroke
       % xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight) %% doesn’t work as expected somehow
       shifted (.5*(OverlayWidth-Hfactor*OverlayWidth)-.5*penwidth,OverlayHeight-Vfactor*OverlayHeight) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{cyrnum-titlo5}
  path titlo ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .20 ;
  save Hfactor ; Hfactor = .75 ;
  titlo := ( 0.00, -0.8*Vfactor) {dir 90} .. {dir 90}
           ( 1.00,  1.2*Vfactor) ;
  pickup pensquare yscaled penwidth xscaled 2 rotated 85 ;
  draw titlo
       xysized (Hfactor*OverlayWidth-penwidth,Vfactor*OverlayHeight)
       shifted (.5*(OverlayWidth-Hfactor*OverlayWidth),OverlayHeight-Vfactor*OverlayHeight) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{cyrnum-titlo6}
  path titlo ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .20 ;
  save Hfactor ; Hfactor = .85 ;
  titlo := ( 0.03, -0.80*Vfactor) --
           ( 0.03,  0.15*Vfactor) --
           ( 0.00,  0.20*Vfactor) {right} .. {right}
           ( 1.00, -0.20*Vfactor) --
           ( 0.97, -0.15*Vfactor) --
           ( 0.97,  0.80*Vfactor) ;
  pickup pensquare yscaled penwidth xscaled sqrt(2) rotated 90 ;
  draw titlo
       xysized (Hfactor*OverlayWidth-.5*penwidth,Vfactor*OverlayHeight)
       shifted (.5*(OverlayWidth-Hfactor*OverlayWidth),OverlayHeight-(0.5*Vfactor*OverlayHeight)) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{cyrnum-titlo7}
  path titlo ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .20 ;
  save Hfactor ; Hfactor = .85 ;
  titlo := ( 0.05, -0.80*Vfactor) --
           ( 0.05, -0.30*Vfactor) {up} .. {right}
           ( 0.07, -0.00*Vfactor) --
           ( 0.93,  0.00*Vfactor) {right} .. {up}
           ( 0.95,  0.30*Vfactor) --
           ( 0.95,  0.80*Vfactor) ;
  pickup pensquare yscaled (0.66*penwidth) xscaled penwidth ;
  draw titlo
       xysized (Hfactor*OverlayWidth-2*penwidth,Vfactor*OverlayHeight)
       shifted ((.5*penwidth+.5*(OverlayWidth-Hfactor*OverlayWidth)),
                (OverlayHeight-(0.7*Vfactor*OverlayHeight))) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{cyrnum-titlo8}
  path titlo, stroke ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .20 ;
  save Hfactor ; Hfactor = .85 ;
  titlo := ( 0.15, -0.10*Vfactor) {dir 25} ..% tension 8 ..
            controls (0.40, 0.50) and (0.00, 0.35) ..
           ( 0.00, -0.00*Vfactor) {down} .. 
            controls (0.00, -0.30) and (0.10, -0.25) ..
           % ( 0.10, -0.20*Vfactor) {right} .. tension 4 .. {dir -120}
           ( 0.30, -0.90*Vfactor) ..
           controls
            ( 0.70,  0.20*Vfactor) and
            ( 0.97,  0.08*Vfactor) ..
           ( 0.97, -0.30*Vfactor) .. tension 6 .. {dir -140}
           ( 0.95, -0.90*Vfactor) ;
  stroke := ((0.45*Hfactor*OverlayWidth),-0.20*Vfactor*OverlayHeight) ..
            ((0.54*Hfactor*OverlayWidth), 0.35*Vfactor*OverlayHeight) ---
            ((0.65*Hfactor*OverlayWidth), 0.90*Vfactor*OverlayHeight) {dir -120} .. {dir 30}
            % ((0.54*Hfactor*OverlayWidth), 0.35*Vfactor*OverlayHeight) ..
            ((0.45*Hfactor*OverlayWidth), 0.90*Vfactor*OverlayHeight)
            ;
  pickup pensquare yscaled 2 xscaled (0.5*penwidth) rotated 10;
  % pickup pensquare yscaled 1 xscaled 2 ;
  draw titlo
       xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight)
       shifted ((.5*(OverlayWidth-Hfactor*OverlayWidth)),
                (OverlayHeight-(0.7*Vfactor*OverlayHeight))) ;
  pickup pensquare yscaled 2 xscaled (0.5*penwidth) rotated 70;
  draw stroke
       % xysized (Hfactor*OverlayWidth,Vfactor*OverlayHeight)
       shifted ((.6*(OverlayWidth-Hfactor*OverlayWidth)),
                (OverlayHeight-Vfactor*OverlayHeight))
       ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\startuniqueMPgraphic{cyrnum-titlo9}
  path titlo ;
  save penwidth ; penwidth = \cyrnumparameter{penwidth} ;
  save High, Low ;
  save Vfactor ; Vfactor = .10 ;
  save Hfactor ; Hfactor = .85 ;
  titlo := ( 0.05, -0.40*Vfactor) --
           ( 0.05,  0.00*Vfactor) --
           ( 0.95,  0.00*Vfactor) --
           ( 0.95, -0.40*Vfactor) ;
  pickup pensquare yscaled (2*penwidth/3) xscaled penwidth ;
  draw titlo
       xysized (Hfactor*OverlayWidth-2*penwidth,Vfactor*OverlayHeight)
       shifted ((.5*penwidth+.5*(OverlayWidth-Hfactor*OverlayWidth)),
                (OverlayHeight-(0.7*Vfactor*OverlayHeight))) ;
  setbounds currentpicture to boundingbox OverlayBox ;
\stopuniqueMPgraphic

\defineoverlay[cyrnum-titlo-overlay1][\uniqueMPgraphic{cyrnum-titlo1}]
\defineoverlay[cyrnum-titlo-overlay2][\uniqueMPgraphic{cyrnum-titlo2}]
\defineoverlay[cyrnum-titlo-overlay3][\uniqueMPgraphic{cyrnum-titlo3}]
\defineoverlay[cyrnum-titlo-overlay4][\uniqueMPgraphic{cyrnum-titlo4}]
\defineoverlay[cyrnum-titlo-overlay5][\uniqueMPgraphic{cyrnum-titlo5}]
\defineoverlay[cyrnum-titlo-overlay6][\uniqueMPgraphic{cyrnum-titlo6}]
\defineoverlay[cyrnum-titlo-overlay7][\uniqueMPgraphic{cyrnum-titlo7}]
\defineoverlay[cyrnum-titlo-overlay8][\uniqueMPgraphic{cyrnum-titlo8}]
\defineoverlay[cyrnum-titlo-overlay9][\uniqueMPgraphic{cyrnum-titlo9}]

\defineframed[cyrnum_titloframe][
    location=low,
       frame=off,
  background=cyrnum-titlo-overlay\cyrnumparameter{titlomode},
]

\def\Titlo{\dontleavehmode\cyrnum_titloframe}

\let\cyrnumdrawtitlo\cyrnum_titloframe %% for protected context

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%D \subject{Interfacing with the Lua functions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%D \macros
%D   {definecyrnum}
%D 
%D User interface to the main conversion routines. The definition
%D macro autogenerates the primary user-level macro, which in turn
%D relies \type{\setupcyrnum} for argument processing (see above on
%D \at{Page}[setupdef]).
%D 
%D Example usage:
%D
%D \starttyping
%D   \definecyrnum[titlofree]
%D   \setupcyrnum [titlofree][titlo=no]
%D   \starttext
%D     \titlofree{42}
%D   \stoptext
%D \stoptyping

\unexpanded\def\do_cyrnum[#1]{%
  \edef\currentcyrnum{#1}%
  \dosingleempty\dodo_cyrnum%
}

\def\dodo_cyrnum[#1]{%
  \iffirstargument
    \doifassignmentelse{#1}{\setupcyrnum[\currentcyrnum][#1]}\relax
  \else
    \setupcyrnum
  \fi
  \dododo_cyrnum%
}

\def\dododo_cyrnum#1{%
  \ctxcommand{cyrillicnumerals(\number#1)}%
}

%D \macros
%D    {setupcyrnum}
%D 
%D The \type{\setupcyrnum} and \type{\definecyrnum} macros are
%D autogenerated via the namespace.

\setupcyrnum[
            \v!dots=\v!yes, % yes|no
       \v!dotsymbol=·,
        \v!penwidth=.66pt,
  \v!preferhundredk=no,
   \v!titlolocation=\v!middle, % final|middle -- only effective if using the font’s titlo
       \v!titlomode=5,
       \v!titlospan=3,      % n|all
           \v!titlo=\v!mp,     % font|mp|no
]

%D \macros
%D   {cyrillicnumerals,Cyrillicnumerals}
%D 
%D Conforming to the standard \CONTEXT\ naming scheme as employed
%D with number conversion macros, we define two macros for use with
%D conversions. As there is no definition for uppercase conversion,
%D the macro \type{\Cyrillicnumerals} exists only for compatibility
%D reasons.
%D 
%D Also, we setup two corresponding conversions \type{cyr} and
%D \type{Cyr} for use with e.g.  enumerations, headings, counters
%D {\italic\letterampersand}c.

\definecyrnum[\v!cyrillicnumerals]
\definecyrnum[\v!Cyrillicnumerals]

\defineconversion[cyrillicnumerals][\cyrillicnumerals]
\defineconversion[Cyrillicnumerals][\Cyrillicnumerals]
\defineconversion[cyr]             [\cyrillicnumerals]
\defineconversion[Cyr]             [\Cyrillicnumerals]

%D \macros
%D   {cyrnum}
%D 
%D The default user macro is defined as \type{\cyrnum}.

\definecyrnum[\v!cyrnum]

\unprotect \endinput

%   vi:ft=context:fo=co:ts=2:expandtab:sw=2