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
|
if not modules then modules = { } end modules ['page-blk'] = {
version = 1.001,
comment = "companion to page-blk.mkiv",
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local context = context
local implement = interfaces.implement
local texgetcount = tex.getcount
local blocks = { }
local block = false
implement {
name = "startpageblock",
arguments = "string",
actions = function(s)
local p = texgetcount("realpageno")
block = { p, p }
blocks[s] = block
end,
}
implement {
name = "stoppageblock",
actions = function()
local p = texgetcount("realpageno") - 1
block[2] = p
end,
}
implement {
name = "pageblockrealpage",
arguments = "string",
actions = function(name)
local b = blocks[name]
context(b and b[1] or 0)
end,
}
implement {
name = "flushpageblocks",
arguments = "string",
actions = function(list)
local count = 0
local order = utilities.parsers.settings_to_array(list)
local pages = { }
for i=1,#order do
local name = order[i]
local block = blocks[name]
if block then
for i=block[1],block[2] do
count = count + 1
pages[count] = i
end
end
end
-- if count ~= nofpages then
-- end
-- inspect(blocks)
-- inspect(pages)
if lpdf.setpageorder then
lpdf.setpageorder(pages) -- ,count)
end
end
}
-- maybe intercept nesting with error
local currentpreroll = false
local prerolled = { }
implement {
name = "startprerollpageblock",
arguments = "string",
actions = function(name)
currentrealpage = texgetcount("realpageno")
currentpreroll = name
end
}
implement {
name = "stopprerollpageblock",
actions = function()
prerolled[currentpreroll] = texgetcount("realpageno") - currentrealpage
currentpreroll = false
end
}
implement {
name = "prerolledpages",
arguments = "string",
actions = function(name)
context(prerolled[name] or 0)
end
}
|