blob: 57ce54fb1ff5d8aed08ba736e04315c1c5040070 (
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
|
% language=uk
\environment interaction-style
\startcomponent interaction-javascript
\startchapter[title={JavaScript}]
Annotations can be controlled with \JAVASCRIPT\ but it really depends on the
viewer if it works out well. Using these scripts is a multi||step process where
common functions and data structures can be shared and collected in preambles:
\starttyping
\startJSpreamble {name}
MyCounter = 0 ;
\stopJSpreamble
\stoptyping
The more action oriented scripts are defined as:
\starttyping
\startJScode {increment}
MyCounter = MyCounter + 1 ; // or: ++MyCounter ;
\stopJScode
\stoptyping
This script is executed with:
\starttyping
\goto {advance by one} [JS(increment)]
\stoptyping
Nicer is to define a function:
\starttyping
\startJSpreamble {helpers} used now
function Increment(n) {
MyCounter = MyCounter + n ;
}
\stopJSpreamble
\stoptyping
and then say:
\starttyping
\goto {advance by one} [JS(Increment{5})]
\stoptyping
The distribution contains a collection of scripts that can be preloaded and used
when needed. You can recognize the files by the \type {java-imp-} prefix. To
prevent all preambles ending up in the \PDF\ file, we can say:
\starttyping
\startJSpreamble {something} used later
\stopJSpreamble
\stoptyping
We already saw that one can also say \type {used now} and there's also a way
to filter specific preambles on usage:
\starttyping
\startJScode {mything} uses {something}
\stopJScode
\stoptyping
One should be aware of the fact that there is no decent way to check if every
script is all right! Even worse, the \JAVASCRIPT\ interpreter currently used in
the \ACROBAT\ tools is not reentrant, and breaks down on typos
The full repertoire of commands is:
\showsetup{startJScode}
\showsetup{startJSpreamble}
\showsetup{addtoJSpreamble}
\showsetup{setJSpreamble}
As we're into \LUA\ and because \LUA\ is so lightweight I've wondered several
times now if it would make sense to embed \LUA\ in \PDF\ viewers. After all,
annotations are an extension mechanism. In the early days of \PDF\ this was
actually quite doable because \ACROBAT\ reader (and exchange) had a plugin model.
However, the more functionality ended up in the program, the least interesting
(and popular) the plugins mechanism became. Some open source viewers have an
\API\ so in principle adding the lightweight \LUA\ interpreter (of course with
\LPEG, and quite probably without file \IO) is possible. It has been discussed at
a recent \CONTEXT\ meeting, so who knows \unknown For now we're stuck with
\JAVASCRIPT.
\stopchapter
\stopcomponent
|