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