1if not modules then modules = { } end modules ['back-ini'] = {
2 version = 1.001,
3 comment = "companion to back-ini.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
9local next, type = next, type
10local format = string.format
11
12backends = backends or { }
13local backends = backends
14
15local context = context
16
17local trace = false trackers.register("backend", function(v) trace = v end)
18local report = logs.reporter("backend")
19
20local allocate = utilities.storage.allocate
21local setmetatableindex = table.setmetatableindex
22local setaction = nodes.tasks.setaction
23
24local implement = interfaces.implement
25local variables = interfaces.variables
26
27local texset = tex.set
28
29local nodeinjections = { }
30local codeinjections = { }
31local registrations = { }
32local tables = allocate()
33
34local function nothing()
35 return nil
36end
37
38backends.nothing = nothing
39
40local function donothing(t,k)
41 t[k] = nothing
42 return nothing
43end
44
45setmetatableindex(nodeinjections, donothing)
46setmetatableindex(codeinjections, donothing)
47setmetatableindex(registrations, donothing)
48
49local defaults = {
50 nodeinjections = nodeinjections,
51 codeinjections = codeinjections,
52 registrations = registrations,
53 tables = tables,
54}
55
56backends.defaults = defaults
57
58backends.nodeinjections = { } setmetatableindex(backends.nodeinjections, nodeinjections)
59backends.codeinjections = { } setmetatableindex(backends.codeinjections, codeinjections)
60backends.registrations = { } setmetatableindex(backends.registrations, registrations)
61backends.tables = { } setmetatableindex(backends.tables, tables)
62
63backends.current = "unknown"
64
65function backends.install(what)
66 if type(what) == "string" then
67 local backend = backends[what]
68 if backend then
69 if trace then
70 if backend.comment then
71 report("initializing backend %a, %a",what,backend.comment)
72 else
73 report("initializing backend %a",what)
74 end
75 end
76 backends.current = what
77 for category, default in next, defaults do
78 local target = backends[category]
79 local plugin = backend [category]
80 setmetatableindex(plugin, default)
81 setmetatableindex(target, plugin)
82 end
83 elseif trace then
84 report("no backend named %a",what)
85 end
86 end
87end
88
89statistics.register("used backend", function()
90 local bc = backends.current
91 if bc ~= "unknown" then
92 return format("%s (%s)",bc,backends[bc].comment or "no comment")
93 else
94 return nil
95 end
96end)
97
98local comment = { "comment", "" }
99
100tables.vfspecials = allocate {
101 red = comment,
102 green = comment,
103 blue = comment,
104 black = comment,
105 startslant = comment,
106 stopslant = comment,
107}
108
109
110
111interfaces.implement {
112 name = "setrealspaces",
113 arguments = "string",
114 actions = function(v)
115 setaction("shipouts","nodes.handlers.accessibility",v == variables.yes)
116 end
117}
118
119
120
121local included = table.setmetatableindex( {
122 context = true,
123 id = true,
124 metadata = true,
125 date = true,
126 id = true,
127 pdf = true,
128}, function(t,k)
129 return true
130end)
131
132backends.included = included
133
134function backends.timestamp()
135 return os.date("%Y-%m-%dT%X") .. os.timezone()
136end
137
138
139
140local paper_width = 0
141local paper_height = 0
142
143function codeinjections.setpagedimensions(paperwidth,paperheight)
144 if paperwidth then
145 paper_width = paperwidth
146 end
147 if paperheight then
148 paper_height = paperheight
149 end
150 texset("global","pageheight",paper_height)
151 texset("global","pagewidth", paper_width)
152 return paper_width, paper_height
153end
154
155function codeinjections.getpagedimensions()
156 return paper_width, paper_height
157end
158
159implement {
160 name = "shipoutoffset",
161 actions = function()
162 context("-1in")
163 end
164}
165
166local page_x_origin = 0
167local page_y_origin = 0
168
169function codeinjections.setpageorigin(x,y)
170 page_x_origin = x
171 page_y_origin = y
172end
173
174function codeinjections.getpageorigin()
175 local x = page_x_origin
176 local y = page_y_origin
177 page_x_origin = 0
178 page_y_origin = 0
179 return x, y, (x ~= 0 or y ~= 0)
180end
181
182implement {
183 name = "setpageorigin",
184 arguments = { "dimension", "dimension" },
185 actions = codeinjections.setpageorigin,
186}
187
188
189
190function backends.getcallbackstate()
191 return { count = status.late_callbacks or 0 }
192end
193 |