1if not modules then modules = { } end modules ['layo-ini'] = {
2 version = 1.001,
3 comment = "companion to layo-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
10
11
12local texgetcount = tex.getcount
13local conditionals = tex.conditionals
14
15local c_realpageno = tex.iscount("realpageno")
16local c_pagenoshift = tex.iscount("pagenoshift")
17
18layouts = {
19 status = { },
20}
21
22local status = layouts.status
23
24function status.leftorrightpageaction(left,right)
25 if left == nil then
26 left, right = false, true
27 end
28 if not conditionals.layoutisdoublesided then
29 return left, right
30 elseif conditionals.layoutissinglesided then
31 return left, right
32 elseif texgetcount(c_pagenoshift) % 2 == 0 then
33 if texgetcount(c_realpageno) % 2 == 0 then
34 return right, left
35 else
36 return left, right
37 end
38 else
39 if texgetcount(c_realpageno) % 2 == 0 then
40 return left, right
41 else
42 return right, left
43 end
44 end
45end
46
47function status.isleftpage(r)
48 if not conditionals.layoutisdoublesided then
49 return false
50 elseif conditionals.layoutissinglesided then
51 return false
52 elseif texgetcount(c_pagenoshift) % 2 == 0 then
53 return (r or texgetcount(c_realpageno)) % 2 == 0
54 else
55 return not (r or texgetcount(c_realpageno)) % 2 == 0
56 end
57end
58
59
60
61
62local canvas = {
63 pagespec = "default",
64 paperwidth = 0,
65 paperheight = 0,
66 topoffset = 0,
67 leftoffset = 0,
68 height = 0,
69 width = 0,
70 cropoffset = 0,
71 bleedoffset = 0,
72 trimoffset = 0,
73 artoffset = 0,
74 doublesided = false,
75 marked = false,
76 copies = false,
77}
78
79function layouts.setupcanvas(specification)
80 local paperheight = specification.paperheight or canvas.paperheight
81 local paperwidth = specification.paperwidth or canvas.paperwidth
82 local cropoffset = specification.cropoffset or 0
83 local trimoffset = cropoffset - (specification.trimoffset or 0)
84 local bleedoffset = trimoffset - (specification.bleedoffset or 0)
85 local artoffset = bleedoffset - (specification.artoffset or 0)
86
87 canvas.paperheight = paperheight
88 canvas.paperwidth = paperwidth
89 canvas.cropoffset = cropoffset
90 canvas.trimoffset = trimoffset
91 canvas.bleedoffset = bleedoffset
92 canvas.artoffset = artoffset
93
94 canvas.pagespec = specification.mode or pagespec
95 canvas.topoffset = specification.topoffset or 0
96 canvas.leftoffset = specification.leftoffset or 0
97 canvas.height = specification.height or paperheight
98 canvas.width = specification.width or paperwidth
99 canvas.marked = specification.print
100
101 local copies = specification.copies
102 if type(copies) == "number" then
103 if copies < 2 then
104 canvas.copies = false
105 else
106 canvas.copies = copies
107 end
108 end
109
110 local doublesided = specification.doublesided
111 if doublesided ~= nil then
112 canvas.doublesided = doublesided
113 end
114end
115
116function layouts.getpagedimensions()
117 return canvas.paperwidth, canvas.paperheight
118end
119
120function layouts.getcanvas()
121 return canvas
122end
123 |