summaryrefslogtreecommitdiff
path: root/tex/context/third/cyrillicnumbers/t-cyrillicnumbers.mkiv
blob: 8788c5ec381c7876ce4601971d698c4b2a676d05 (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
%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

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

\registerctxluafile{cyrillicnumbers}

\def\cyrnumsetvariables{%
  \startluacode
    local tc = thirddata.cyrnum
    tc.placetitlo    = "\cyrnumparameter{titlo}"
    tc.titlospan     = "\cyrnumparameter{titlospan}"
    tc.titlolocation = "\cyrnumparameter{titlolocation}"
    tc.drawdots      = "\cyrnumparameter{dots}" == "yes"
    tc.dotsymbol     = "\cyrnumparameter{dotsymbol}"
  \stopluacode%
}

\appendtoks \cyrnumsetvariables \to \everysetupcyrnum

\setupcyrnum[
          titlo=mp,     % font|mp|no
      titlospan=3,      % n|all
  titlolocation=middle, % final|middle -- only effective if span ~= all
           dots=\v!yes, % yes|no
      dotsymbol=·,
       penwidth=3,
      titlomode=5,
]

\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 = .85 ;
  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-.5*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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Interfacing with the Lua functions.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\cyrillicnumerals#1{\ctxcommand{cyrillicnumerals(\number#1)}}
\def\Cyrillicnumerals#1{\ctxcommand{Cyrillicnumerals(\number#1)}}

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

\unprotect \endinput