scrn-wid.lua /size: 10 Kb    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
scrn-wid
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to scrn-wid.mkiv
"
,
4
author
=
"
Hans Hagen, PRAGMA-ADE, Hasselt NL
"
,
5
copyright
=
"
PRAGMA ADE / ConTeXt Development Team
"
,
6
license
=
"
see context related readme files
"
7
}
8 9
-- Support for interactive features is handled elsewhere. Now that is some mess! In
10
-- the early days one had media features like sound and movies that were easy to set
11
-- up. Then at some point renditions came around which were more work and somewhat
12
-- unreliable. Now, both mechanism are obsolete and replaced by rich media which is
13
-- a huge mess and has no real concept of what media are supported. There's flash
14
-- cq. shockwave (basically obsolete too), and for instance mp4 needs to be handled
15
-- by a swf player, and there's u3d which somehow has its own specification. One
16
-- would expect native support for video and audio to be en-par with browsers but
17
-- alas ... pdf has lost the battle with html here due to a few decades of
18
-- unstability and changing support. So far we could catch on and even were ahead
19
-- but I wonder if we should keep doing that. As we can't trust support for media we
20
-- can better not embed anything and just use a hyperlink to an external resource. No
21
-- sane person will create media rich pdf's as long as it's that unpredictable. Just
22
-- look at the specification and viewer preferences and decide.
23 24
local
next
=
next
25 26
interactions
=
interactions
or
{
}
27
local
interactions
=
interactions
28 29
local
context
=
context
30
local
implement
=
interfaces
.
implement
31 32
local
allocate
=
utilities
.
storage
.
allocate
33 34
local
attachments
=
allocate
(
)
35
local
comments
=
allocate
(
)
36
local
soundclips
=
allocate
(
)
37
local
renderings
=
allocate
(
)
38
local
linkedlists
=
allocate
(
)
39 40
interactions
.
attachments
=
attachments
41
interactions
.
soundclips
=
soundclips
42
interactions
.
renderings
=
renderings
43
interactions
.
linkedlists
=
linkedlists
44 45
local
texsetbox
=
tex
.
setbox
46 47
local
jobpasses
=
job
.
passes
48 49
local
texgetcount
=
tex
.
getcount
50 51
local
codeinjections
=
backends
.
codeinjections
52
local
nodeinjections
=
backends
.
nodeinjections
53 54
local
variables
=
interfaces
.
variables
55
local
v_auto
=
variables
.
auto
56 57
local
trace_attachments
=
false
trackers
.
register
(
"
widgets.attachments
"
,
function
(
v
)
trace_attachments
=
v
end
)
58 59
local
report_attachments
=
logs
.
reporter
(
"
widgets
"
,
"
attachments
"
)
60 61
-- Symbols
62 63
implement
{
64
name
=
"
presetsymbollist
"
,
65
arguments
=
"
string
"
,
66
actions
=
function
(
list
)
67
codeinjections
.
presetsymbollist
(
list
)
68
end
69
}
70 71
-- Attachments
72
--
73
-- registered : unique id
74
-- tag : used at the tex end
75
-- file : name that the file has on the filesystem
76
-- name : name that the file will get in the output
77
-- title : up to the backend
78
-- subtitle : up to the backend
79
-- author : up to the backend
80
-- method : up to the backend (hidden == no rendering)
81 82
local
nofautoattachments
,
lastregistered
=
0
,
nil
83 84
local
function
checkregistered
(
specification
)
85
local
registered
=
specification
.
registered
86
if
not
registered
or
registered
=
=
"
"
or
registered
=
=
v_auto
then
87
nofautoattachments
=
nofautoattachments
+
1
88
lastregistered
=
"
attachment-
"
.
.
nofautoattachments
89
specification
.
registered
=
lastregistered
90
return
lastregistered
91
else
92
return
registered
93
end
94
end
95 96
local
function
checkbuffer
(
specification
)
97
local
buffer
=
specification
.
buffer
98
if
buffer
~
=
"
"
then
99
specification
.
data
=
buffers
.
getcontent
(
buffer
)
or
"
<no data>
"
100
end
101
end
102 103
function
attachments
.
register
(
specification
)
-- beware of tag/registered mixup(tag is namespace)
104
local
registered
=
checkregistered
(
specification
)
105
checkbuffer
(
specification
)
106
attachments
[
registered
]
=
specification
107
if
trace_attachments
then
108
report_attachments
(
"
registering %a
"
,
registered
)
109
end
110
return
specification
111
end
112 113
function
attachments
.
insert
(
specification
)
114
local
registered
=
checkregistered
(
specification
)
115
local
r
=
attachments
[
registered
]
116
if
r
then
117
if
trace_attachments
then
118
report_attachments
(
"
including registered %a
"
,
registered
)
119
end
120
for
k
,
v
in
next
,
r
do
121
local
s
=
specification
[
k
]
122
if
s
=
=
"
"
then
123
specification
[
k
]
=
v
124
end
125
end
126
elseif
trace_attachments
then
127
report_attachments
(
"
including unregistered %a
"
,
registered
)
128
end
129
checkbuffer
(
specification
)
130
return
nodeinjections
.
attachfile
(
specification
)
131
end
132 133
implement
{
134
name
=
"
registerattachment
"
,
135
actions
=
attachments
.
register
,
136
arguments
=
{
137
{
138
{
"
tag
"
}
,
139
{
"
registered
"
}
,
140
{
"
title
"
}
,
141
{
"
subtitle
"
}
,
142
{
"
author
"
}
,
143
{
"
file
"
}
,
144
{
"
name
"
}
,
145
{
"
buffer
"
}
,
146
{
"
mimetype
"
}
,
147
}
148
}
149
}
150 151
implement
{
152
name
=
"
insertattachment
"
,
153
actions
=
function
(
specification
)
154
texsetbox
(
"
b_scrn_attachment_link
"
,
(
attachments
.
insert
(
specification
)
)
)
155
end
,
156
arguments
=
{
157
{
158
{
"
tag
"
}
,
159
{
"
registered
"
}
,
160
{
"
method
"
}
,
161
{
"
width
"
,
"
dimen
"
}
,
162
{
"
height
"
,
"
dimen
"
}
,
163
{
"
depth
"
,
"
dimen
"
}
,
164
{
"
colormodel
"
,
"
integer
"
}
,
165
{
"
colorvalue
"
,
"
integer
"
}
,
166
{
"
color
"
}
,
167
{
"
transparencyvalue
"
,
"
integer
"
}
,
168
{
"
symbol
"
}
,
169
{
"
layer
"
}
,
170
{
"
title
"
}
,
171
{
"
subtitle
"
}
,
172
{
"
author
"
}
,
173
{
"
file
"
}
,
174
{
"
name
"
}
,
175
{
"
buffer
"
}
,
176
{
"
mimetype
"
}
,
177
}
178
}
179
}
180 181
-- Comment
182 183
function
comments
.
insert
(
specification
)
184
local
buffer
=
specification
.
buffer
185
if
buffer
~
=
"
"
then
186
specification
.
data
=
buffers
.
getcontent
(
buffer
)
or
"
"
187
end
188
return
nodeinjections
.
comment
(
specification
)
189
end
190 191
implement
{
192
name
=
"
insertcomment
"
,
193
actions
=
function
(
specification
)
194
texsetbox
(
"
b_scrn_comment_link
"
,
(
comments
.
insert
(
specification
)
)
)
195
end
,
196
arguments
=
{
197
{
198
{
"
tag
"
}
,
199
{
"
title
"
}
,
200
{
"
subtitle
"
}
,
201
{
"
author
"
}
,
202
{
"
width
"
,
"
dimen
"
}
,
203
{
"
height
"
,
"
dimen
"
}
,
204
{
"
depth
"
,
"
dimen
"
}
,
205
{
"
nx
"
}
,
206
{
"
ny
"
}
,
207
{
"
colormodel
"
,
"
integer
"
}
,
208
{
"
colorvalue
"
,
"
integer
"
}
,
209
{
"
transparencyvalue
"
,
"
integer
"
}
,
210
{
"
option
"
}
,
211
{
"
symbol
"
}
,
212
{
"
buffer
"
}
,
213
{
"
layer
"
}
,
214
{
"
space
"
}
,
215
}
216
}
217
}
218 219
-- Soundclips
220 221
function
soundclips
.
register
(
specification
)
222
local
tag
=
specification
.
tag
223
if
tag
and
tag
~
=
"
"
then
224
local
filename
=
specification
.
file
225
if
not
filename
or
filename
=
=
"
"
then
226
filename
=
tag
227
specification
.
file
=
filename
228
end
229
soundclips
[
tag
]
=
specification
230
return
specification
231
end
232
end
233 234
function
soundclips
.
insert
(
tag
)
235
local
sc
=
soundclips
[
tag
]
236
if
not
sc
then
237
-- todo: message
238
return
soundclips
.
register
{
tag
=
tag
}
239
else
240
return
sc
241
end
242
end
243 244
implement
{
245
name
=
"
registersoundclip
"
,
246
actions
=
soundclips
.
register
,
247
arguments
=
{
248
{
249
{
"
tag
"
}
,
250
{
"
file
"
}
251
}
252
}
253
}
254 255
implement
{
256
name
=
"
insertsoundclip
"
,
257
actions
=
soundclips
.
insert
,
258
arguments
=
{
259
{
260
{
"
tag
"
}
,
261
{
"
repeat
"
}
262
}
263
}
264
}
265 266
-- Renderings
267 268
function
renderings
.
register
(
specification
)
269
if
specification
.
label
then
270
renderings
[
specification
.
label
]
=
specification
271
return
specification
272
end
273
end
274 275
function
renderings
.
rendering
(
label
)
276
local
rn
=
renderings
[
label
]
277
if
not
rn
then
278
-- todo: message
279
return
renderings
.
register
{
label
=
label
}
280
else
281
return
rn
282
end
283
end
284 285
function
renderings
.
var
(
label
,
key
)
286
local
rn
=
renderings
[
label
]
287
return
rn
and
rn
[
key
]
or
"
"
288
end
289 290
implement
{
291
name
=
"
renderingvar
"
,
292
actions
=
{
renderings
.
var
,
context
}
,
293
arguments
=
"
2 strings
"
,
294
}
295 296
implement
{
297
name
=
"
registerrendering
"
,
298
actions
=
renderings
.
register
,
299
arguments
=
{
300
{
301
{
"
type
"
}
,
302
{
"
label
"
}
,
303
{
"
mime
"
}
,
304
{
"
filename
"
}
,
305
{
"
option
"
}
,
306
}
307
}
308
}
309 310
-- Rendering:
311 312
implement
{
313
name
=
"
insertrenderingwindow
"
,
314
actions
=
function
(
specification
)
315
codeinjections
.
insertrenderingwindow
(
specification
)
316
end
,
317
arguments
=
{
318
{
319
{
"
label
"
}
,
320
{
"
width
"
,
"
dimen
"
}
,
321
{
"
height
"
,
"
dimen
"
}
,
322
{
"
option
"
}
,
323
{
"
page
"
,
"
integer
"
}
,
324
}
325
}
326
}
327 328
-- Linkedlists (only a context interface)
329 330
implement
{
331
name
=
"
definelinkedlist
"
,
332
arguments
=
"
string
"
,
333
actions
=
function
(
tag
)
334
-- no need
335
end
336
}
337 338
implement
{
339
name
=
"
enhancelinkedlist
"
,
340
arguments
=
{
"
string
"
,
"
integer
"
}
,
341
actions
=
function
(
tag
,
n
)
342
local
ll
=
jobpasses
.
gettobesaved
(
tag
)
343
if
ll
then
344
ll
[
n
]
=
texgetcount
(
"
realpageno
"
)
345
end
346
end
347
}
348 349
implement
{
350
name
=
"
addlinklistelement
"
,
351
arguments
=
"
string
"
,
352
actions
=
function
(
tag
)
353
local
tobesaved
=
jobpasses
.
gettobesaved
(
tag
)
354
local
collected
=
jobpasses
.
getcollected
(
tag
)
or
{
}
355
local
currentlink
=
#
tobesaved
+
1
356
local
noflinks
=
#
collected
357
tobesaved
[
currentlink
]
=
0
358
local
f
=
collected
[
1
]
or
0
359
local
l
=
collected
[
noflinks
]
or
0
360
local
p
=
collected
[
currentlink
-1
]
or
f
361
local
n
=
collected
[
currentlink
+
1
]
or
l
362
context
.
setlinkedlistproperties
(
currentlink
,
noflinks
,
f
,
p
,
n
,
l
)
363
-- context.ctxlatelua(function() commands.enhancelinkedlist(tag,currentlink) end)
364
end
365
}
366