1if not modules then modules = { } end modules ['page-blk'] = {
2 version = 1.001,
3 comment = "companion to page-blk.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 context = context
10local implement = interfaces.implement
11local texgetcount = tex.getcount
12
13local c_realpageno = tex.iscount("realpageno")
14
15local blocks = { }
16local block = false
17
18implement {
19 name = "startpageblock",
20 arguments = "string",
21 actions = function(s)
22 local p = texgetcount(c_realpageno)
23 block = { p, p }
24 blocks[s] = block
25 end,
26}
27
28implement {
29 name = "stoppageblock",
30 actions = function()
31 local p = texgetcount(c_realpageno) - 1
32 block[2] = p
33 end,
34}
35
36implement {
37 name = "pageblockrealpage",
38 arguments = "string",
39 actions = function(name)
40 local b = blocks[name]
41 context(b and b[1] or 0)
42 end,
43}
44
45implement {
46 name = "flushpageblocks",
47 arguments = "string",
48 actions = function(list)
49 local count = 0
50 local order = utilities.parsers.settings_to_array(list)
51 local pages = { }
52 for i=1,#order do
53 local name = order[i]
54 local block = blocks[name]
55 if block then
56 for i=block[1],block[2] do
57 count = count + 1
58 pages[count] = i
59 end
60 end
61 end
62
63
64
65
66 if lpdf.setpageorder then
67 lpdf.setpageorder(pages)
68 end
69 end
70}
71
72
73
74local currentpreroll = false
75local prerolled = { }
76
77implement {
78 name = "startprerollpageblock",
79 arguments = "string",
80 actions = function(name)
81 currentrealpage = texgetcount(c_realpageno)
82 currentpreroll = name
83 end
84}
85
86implement {
87 name = "stopprerollpageblock",
88 actions = function()
89 prerolled[currentpreroll] = texgetcount(c_realpageno) - currentrealpage
90 currentpreroll = false
91 end
92}
93
94implement {
95 name = "prerolledpages",
96 arguments = "string",
97 actions = function(name)
98 context(prerolled[name] or 0)
99 end
100}
101 |