summaryrefslogtreecommitdiff
path: root/tex/context/base/scrn-int.lua
blob: d01669aa462dd8015f04bd8eae70fc9610830889 (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
if not modules then modules = { } end modules ['scrn-int'] = {
    version   = 1.001,
    comment   = "companion to scrn-int.mkiv",
    author    = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
    copyright = "PRAGMA ADE / ConTeXt Development Team",
    license   = "see context related readme files"
}

local format = string.format
local texsprint, texcount, ctxcatcodes = tex.sprint, tex.count, tex.ctxcatcodes

interactions       = interactions or { }
local interactions = interactions

interactions.attachments = interactions.attachments or { }
interactions.soundclips  = interactions.soundclips  or { }
interactions.renderings  = interactions.renderings  or { }
interactions.linkedlists = interactions.linkedlists or { }

local attachments = interactions.attachments
local soundclips  = interactions.soundclips
local renderings  = interactions.renderings
local linkedlists = interactions.linkedlists

local jobpasses   = job.passes

function attachments.register(specification)
    if specification.label then
        specification.filename = specification.filename or specification.label
        specification.newname = specification.newname or specification.filename
        specification.title = specification.title or specification.filename
        specification.newname = file.addsuffix(specification.newname,file.extname(specification.filename))
        attachments[specification.label] = specification
        return specification
    end
end

function attachments.attachment(label)
    local at = attachments[label]
    if not at then
        interfaces.showmessage("interactions",6,label)
        return attachments.register { label = label }
    else
        return at
    end
end

function attachments.var(label,key)
    local at = attachments[label]
    texsprint(ctxcatcodes,at and at[key] or "")
end

function soundclips.register(specification)
    if specification.label then
        specification.filename = specification.filename or specification.label
        soundclips[specification.label] = specification
        return specification
    end
end

function soundclips.soundclip(label)
    local sc = soundclips[label]
    if not sc then
        -- todo: message
        return soundclips.register { label = label }
    else
        return sc
    end
end

function renderings.register(specification)
    if specification.label then
        renderings[specification.label] = specification
        return specification
    end
end

function renderings.rendering(label)
    local rn = renderings[label]
    if not rn then
        -- todo: message
        return renderings.register { label = label }
    else
        return rn
    end
end

function renderings.var(label,key)
    local rn = renderings[label]
    texsprint(ctxcatcodes,rn and rn[key] or "")
end

-- linked lists

function linkedlists.define(name)
    -- no need
end

function linkedlists.add(name)
    local tobesaved   = jobpasses.gettobesaved(name)
    local collected   = jobpasses.getcollected(name) or { }
    local currentlink = #tobesaved + 1
    local noflinks    = #collected
    tobesaved[currentlink] = 0
    local f = collected[1] or 0
    local l = collected[noflinks] or 0
    local p = collected[currentlink-1] or f
    local n = collected[currentlink+1] or l
    texsprint(ctxcatcodes,format("\\setlinkproperties{%s}{%s}{%s}{%s}{%s}{%s}",currentlink,noflinks,f,p,n,l))
end

function linkedlists.enhance(name,n)
    local ll = jobpasses.gettobesaved(name)
    if ll then
        ll[n] = texcount.realpageno
    end
end