back-pdp.lua /size: 8263 b    last modification: 2020-07-01 14:35
1
if
not
modules
then
modules
=
{
}
end
modules
[
'
back-pdp
'
]
=
{
2
version
=
1
.
001
,
3
comment
=
"
companion to lpdf-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
-- This is temporary ... awaiting a better test .. basically we can
10
-- always use this: pdf primitives.
11 12
local
context
=
context
13
local
lpdf
=
lpdf
14 15
local
lpdfreserveobject
=
lpdf
.
reserveobject
16
local
lpdfcompresslevel
=
lpdf
.
compresslevel
17
local
lpdfobj
=
lpdf
.
obj
18
local
lpdfpagereference
=
lpdf
.
pagereference
19
local
lpdfxformname
=
lpdf
.
xformname
20 21
local
tokenscanners
=
tokens
.
scanners
22
local
scanword
=
tokenscanners
.
word
23
local
scankeyword
=
tokenscanners
.
keyword
24
local
scanstring
=
tokenscanners
.
string
25
local
scaninteger
=
tokenscanners
.
integer
26
local
scanwhd
=
tokenscanners
.
whd
27 28
local
trace
=
false
trackers
.
register
(
"
backend
"
,
function
(
v
)
trace
=
v
end
)
29
local
report
=
logs
.
reporter
(
"
backend
"
)
30 31
local
nodepool
=
nodes
.
pool
32
local
newliteral
=
nodepool
.
literal
33
local
newsave
=
nodepool
.
save
34
local
newrestore
=
nodepool
.
restore
35
local
newsetmatrix
=
nodepool
.
setmatrix
36 37
local
implement
=
interfaces
.
implement
38
local
constants
=
interfaces
.
constants
39
local
variables
=
interfaces
.
variables
40 41
-- literals
42 43
local
function
pdfliteral
(
)
44
context
(
newliteral
(
scanword
(
)
or
"
origin
"
,
scanstring
(
)
)
)
45
end
46 47
-- objects
48 49
local
lastobjnum
=
0
50 51
local
function
pdfobj
(
)
52
if
scankeyword
(
"
reserveobjnum
"
)
then
53
lastobjnum
=
lpdfreserveobject
(
)
54
if
trace
then
55
report
(
"
\\pdfobj reserveobjnum: object %i
"
,
lastobjnum
)
56
end
57
else
58
local
immediate
=
true
59
local
objnum
=
scankeyword
(
"
useobjnum
"
)
and
scaninteger
(
)
or
lpdfreserveobject
(
)
60
local
uncompress
=
scankeyword
(
"
uncompressed
"
)
or
lpdfcompresslevel
(
)
=
=
0
61
local
streamobject
=
scankeyword
(
"
stream
"
)
62
local
attributes
=
scankeyword
(
"
attr
"
)
and
scanstring
(
)
or
nil
63
local
fileobject
=
scankeyword
(
"
file
"
)
64
local
content
=
scanstring
(
)
65
local
object
=
streamobject
and
{
66
type
=
"
stream
"
,
67
objnum
=
objnum
,
68
immediate
=
immediate
,
69
attr
=
attributes
,
70
compresslevel
=
uncompress
and
0
or
nil
,
71
}
or
{
72
type
=
"
raw
"
,
73
objnum
=
objnum
,
74
immediate
=
immediate
,
75
}
76
if
fileobject
then
77
object
.
filename
=
content
78
else
79
object
.
string
=
content
80
end
81
lpdfobj
(
object
)
82
lastobjnum
=
objnum
83
if
trace
then
84
report
(
"
\\pdfobj: object %i
"
,
lastobjnum
)
85
end
86
end
87
end
88 89
local
function
pdflastobj
(
)
90
context
(
"
%i
"
,
lastobjnum
)
91
if
trace
then
92
report
(
"
\\lastobj: object %i
"
,
lastobjnum
)
93
end
94
end
95 96
local
function
pdfrefobj
(
)
97
local
objnum
=
scaninteger
(
)
98
if
trace
then
99
report
(
"
\\refobj: object %i (todo)
"
,
objnum
)
100
end
101
end
102 103
-- annotations
104 105
local
lastobjnum
=
0
106 107
local
function
pdfannot
(
)
108
if
scankeyword
(
"
reserveobjnum
"
)
then
109
lastobjnum
=
lpdfreserveobject
(
)
110
if
trace
then
111
report
(
"
\\pdfannot reserveobjnum: object %i
"
,
lastobjnum
)
112
end
113
else
114
local
width
=
false
115
local
height
=
false
116
local
depth
=
false
117
local
data
=
false
118
local
object
=
false
119
local
attr
=
false
120
--
121
if
scankeyword
(
"
useobjnum
"
)
then
122
object
=
scancount
(
)
123
report
(
"
\\pdfannot useobjectnum is not (yet) supported
"
)
124
end
125
local
width
,
height
,
depth
=
scanwhd
(
)
126
if
scankeyword
(
"
attr
"
)
then
127
attr
=
scanstring
(
)
128
end
129
data
=
scanstring
(
)
130
context
(
backends
.
nodeinjections
.
annotation
(
width
or
0
,
height
or
0
,
depth
or
0
,
data
or
"
"
)
)
131
end
132
end
133 134
local
function
pdfdest
(
)
135
local
name
=
false
136
local
zoom
=
false
137
local
view
=
false
138
local
width
=
false
139
local
height
=
false
140
local
depth
=
false
141
if
scankeyword
(
"
num
"
)
then
142
report
(
"
\\pdfdest num is not (yet) supported
"
)
143
elseif
scankeyword
(
"
name
"
)
then
144
name
=
scanstring
(
)
145
end
146
if
scankeyword
(
"
xyz
"
)
then
147
view
=
"
xyz
"
148
if
scankeyword
(
"
zoom
"
)
then
149
report
(
"
\\pdfdest zoom is ignored
"
)
150
zoom
=
scancount
(
)
-- will be divided by 1000 in the backend
151
end
152
elseif
scankeyword
(
"
fitbh
"
)
then
153
view
=
"
fitbh
"
154
elseif
scankeyword
(
"
fitbv
"
)
then
155
view
=
"
fitbv
"
156
elseif
scankeyword
(
"
fitb
"
)
then
157
view
=
"
fitb
"
158
elseif
scankeyword
(
"
fith
"
)
then
159
view
=
"
fith
"
160
elseif
scankeyword
(
"
fitv
"
)
then
161
view
=
"
fitv
"
162
elseif
scankeyword
(
"
fitr
"
)
then
163
view
=
"
fitr
"
164
width
,
height
,
depth
=
scanwhd
(
)
165
elseif
scankeyword
(
"
fit
"
)
then
166
view
=
"
fit
"
167
end
168
context
(
backends
.
nodeinjections
.
destination
(
width
or
0
,
height
or
0
,
depth
or
0
,
{
name
or
"
"
}
,
view
or
"
fit
"
)
)
169
end
170 171
-- management
172 173
local
function
pdfsave
(
)
174
context
(
newsave
(
)
)
175
end
176 177
local
function
pdfrestore
(
)
178
context
(
newrestore
(
)
)
179
end
180 181
local
function
pdfsetmatrix
(
)
182
context
(
newsetmatrix
(
scanstring
(
)
)
)
183
end
184 185
-- extras
186 187
local
function
pdfpageref
(
)
188
context
(
lpdfpagereference
(
)
)
189
end
190 191
local
function
pdfxformname
(
)
192
context
(
lpdfxformname
(
)
)
193
end
194 195
-- extensions: literal dest annot save restore setmatrix obj refobj colorstack
196
-- startlink endlink startthread endthread thread outline glyphtounicode fontattr
197
-- mapfile mapline includechars catalog info names trailer
198 199
local
extensions
=
{
200
literal
=
pdfliteral
,
201
obj
=
pdfobj
,
202
refobj
=
pdfrefobj
,
203
dest
=
pdfdest
,
204
annot
=
pdfannot
,
205
save
=
pdfsave
,
206
restore
=
pdfrestore
,
207
setmatrix
=
pdfsetmatrix
,
208
}
209 210
local
function
pdfextension
(
)
211
local
w
=
scanword
(
)
212
if
w
then
213
local
e
=
extensions
[
w
]
214
if
e
then
215
e
(
)
216
else
217
report
(
"
\\pdfextension: unknown %a
"
,
w
)
218
end
219
end
220
end
221 222
-- feedbacks: colorstackinit creationdate fontname fontobjnum fontsize lastannot
223
-- lastlink lastobj pageref retval revision version xformname
224 225
local
feedbacks
=
{
226
lastobj
=
pdflastobj
,
227
pageref
=
pdfpageref
,
228
xformname
=
pdfxformname
,
229
}
230 231
local
function
pdffeedback
(
)
232
local
w
=
scanword
(
)
233
if
w
then
234
local
f
=
feedbacks
[
w
]
235
if
f
then
236
f
(
)
237
else
238
report
(
"
\\pdffeedback: unknown %a
"
,
w
)
239
end
240
end
241
end
242 243
-- variables: (integers:) compresslevel decimaldigits gamma gentounicode
244
-- ignoreunknownimages imageaddfilename imageapplygamma imagegamma imagehicolor
245
-- imageresolution inclusioncopyfonts inclusionerrorlevel majorversion minorversion
246
-- objcompresslevel omitcharset omitcidset pagebox pkfixeddpi pkresolution
247
-- recompress suppressoptionalinfo uniqueresname (dimensions:) destmargin horigin
248
-- linkmargin threadmargin vorigin xformmargin (tokenlists:) pageattr pageresources
249
-- pagesattr pkmode trailerid xformattr xformresources
250 251
-- local variables = {
252
-- }
253
--
254
-- local function pdfvariable()
255
-- local w = scanword()
256
-- if w then
257
-- local f = variables[w]
258
-- if f then
259
-- f()
260
-- else
261
-- print("invalid variable",w)
262
-- end
263
-- else
264
-- print("missing variable")
265
-- end
266
-- end
267 268
-- kept:
269 270
implement
{
name
=
"
pdfextension
"
,
actions
=
pdfextension
}
271
implement
{
name
=
"
pdffeedback
"
,
actions
=
pdffeedback
}
272
--------- { name = "pdfvariable", actions = pdfvariable }
273 274
-- for the moment (tikz)
275 276
implement
{
name
=
"
pdfliteral
"
,
actions
=
pdfliteral
}
277
implement
{
name
=
"
pdfobj
"
,
actions
=
pdfobj
}
278
implement
{
name
=
"
pdflastobj
"
,
actions
=
pdflastobj
}
279
implement
{
name
=
"
pdfrefobj
"
,
actions
=
pdfrefobj
}
280
--------- { name = "pdfannot", actions = pdfannot }
281
--------- { name = "pdfdest", actions = pdfdest }
282
--------- { name = "pdfsave", actions = pdfsave }
283
--------- { name = "pdfrestore", actions = pdfrestore }
284
--------- { name = "pdfsetmatrix", actions = pdfsetmatrix }
285