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

-- I need to check what is actually needed, maybe some can become
-- locals.

backends = backends or { }
local backends = backends

local trace_backend = false  trackers.register("backend.initializers", function(v) trace_finalizers = v end)

local report_backends = logs.new("backends")

local function nothing() return nil end

backends.nothing = nothing

backends.nodeinjections = {

    rgbcolor     = nothing,
    cmykcolor    = nothing,
    graycolor    = nothing,
    spotcolor    = nothing,

    transparency = nothing,

    overprint    = nothing,
    knockout     = nothing,

    positive     = nothing,
    negative     = nothing,

    effect       = nothing,

    startlayer   = nothing,
    stoplayer    = nothing,
    switchlayer  = nothing,

    reference    = nothing,
    destination  = nothing,

    addtags      = nothing,

    insertu3d    = nothing,
    insertswf    = nothing,
    insertmovie  = nothing,
    insertsound  = nothing,

}

backends.codeinjections = {

    prerollreference       = nothing,

    presetsymbol           = nothing,
    presetsymbollist       = nothing,
    registersymbol         = nothing,
    registeredsymbol       = nothing,

    registercomment        = nothing,

    embedfile              = nothing,
    attachfile             = nothing,
    attachmentid           = nothing,

    adddocumentinfo        = nothing,
    setupidentity          = nothing,
    setupcanvas            = nothing,

    setpagetransition      = nothing,

    defineviewerlayer      = nothing,

    addbookmarks           = nothing,

    addtransparencygroup   = nothing,

    typesetfield           = nothing,
    doiffieldelse          = nothing,
    doiffieldgroupelse     = nothing,
    doiffieldsetelse       = nothing,
    definefield            = nothing,
    clonefield             = nothing,
    definefieldset         = nothing,
    setfieldcalculationset = nothing,
    getfieldgroup          = nothing,
    getfieldset            = nothing,
    setformsmethod         = nothing,
    getdefaultfieldvalue   = nothing,

    flushpageactions       = nothing,
    flushdocumentactions   = nothing,

    insertrenderingwindow  = nothing,
    processrendering       = nothing,

    setfigurecolorspace    = nothing,
    setfigurealternative   = nothing,

    enabletags             = nothing,
    maptag                 = nothing,
    mapping                = nothing, -- returns table

    mergereferences        = nothing,
    mergeviewerlayers      = nothing,

    setformat              = nothing,
    getformatoption        = nothing,
    supportedformats       = nothing,

    -- called in tex

    finalizepage           = nothing -- will go when we have a hook at the lua end

}

backends.registrations = {

    grayspotcolor  = nothing,
    rgbspotcolor   = nothing,
    cmykspotcolor  = nothing,

    grayindexcolor = nothing,
    rgbindexcolor  = nothing,
    cmykindexcolor = nothing,

    spotcolorname  = nothing,

    transparency   = nothing,

}

local comment = { "comment", "" }

backends.tables = {
    vfspecials = {
        red        = comment,
        green      = comment,
        blue       = comment,
        black      = comment,
        startslant = comment,
        stopslant  = comment,
    }
}

backends.current = "unknown"

function backends.install(what)
    if type(what) == "string" then
        local backend = backends[what]
        if backend then
            if trace_backend then
                report_backends("initializing backend %s (%s)",what,backend.comment or "no comment")
            end
            backends.current = what
            for _, category in next, { "nodeinjections", "codeinjections", "registrations", "tables" } do
                local plugin = backend[category]
                local whereto = backends[category]
                if plugin then
                    for name, meaning in next, whereto do
                        if plugin[name] then
                            whereto[name] = plugin[name]
                        --  report_backends("installing function %s in category %s of %s",name,category,what)
                        elseif trace_backend then
                            report_backends("no function %s in category %s of %s",name,category,what)
                        end
                    end
                elseif trace_backend then
                    report_backends("no category %s in %s",category,what)
                end
                -- extra checks
                for k, v in next, whereto do
                    if not plugin[k] then
                        report_backends("entry %s in %s is not set",k,category)
                    end
                end
                for k, v in next, plugin do
                    if not whereto[k] then
                        report_backends("entry %s in %s is not used",k,category)
                    end
                end
            end
        elseif trace_backend then
            report_backends("no backend named %s",what)
        end
    end
end

statistics.register("used backend", function()
    local bc = backends.current
    if bc ~= "unknown" then
        return string.format("%s (%s)",bc,backends[bc].comment or "no comment")
    else
        return nil
    end
end)