1if not modules then modules = { } end modules [ ' page-run ' ] = {
2 version = 1 . 001 ,
3 comment = " companion to page-run.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 format , concat = string . format , table . concat
10local todimen = number . todimen
11local texdimen = tex . dimen
12
13local function asdimen ( name , unit )
14 return todimen ( texdimen [ name ] , unit , " %0.4f " )
15end
16
17local function checkedoptions ( options )
18 if type ( options ) = = " table " then
19 return options
20 elseif not options or options = = " " then
21 options = " pt,cm "
22 end
23 options = utilities . parsers . settings_to_hash ( options )
24 local n = 4
25 for k , v in table . sortedhash ( options ) do
26 local m = tonumber ( k )
27 if m then
28 n = m
29 end
30 end
31 options . n = n
32 return options
33end
34
35function commands . showlayoutvariables ( options )
36
37 options = checkedoptions ( options )
38
39 local dimensions = { " pt " , " bp " , " cm " , " mm " , " dd " , " cc " , " pc " , " nd " , " nc " , " sp " , " in " }
40
41 local n = 0
42 for i = 1 , # dimensions do
43 if options [ dimensions [ i ] ] then
44 n = n + 1
45 end
46 end
47
48 if n = = 0 then
49 options . pt = true
50 n = 1
51 end
52
53 local function showdimension ( name )
54 context . NC ( )
55 context . tex ( interfaces . interfacedcommand ( name ) )
56 context . NC ( )
57 for i = 1 , # dimensions do
58 local d = dimensions [ i ]
59 if options [ d ] then
60 context ( " %s%s " , asdimen ( name , d ) , d )
61 context . NC ( )
62 end
63 end
64 context . NR ( )
65 end
66
67 local function showmacro ( name )
68 context . NC ( )
69 context . tex ( interfaces . interfacedcommand ( name ) )
70 context . NC ( )
71 context . getvalue ( name )
72 context . NC ( )
73 context . NR ( )
74 end
75
76 local function reportdimension ( name )
77 local result = { }
78 for i = 1 , # dimensions do
79 local d = dimensions [ i ]
80 if options [ d ] then
81 result [ # result + 1 ] = format ( " %12s%s " , asdimen ( name , d ) , d )
82 end
83 end
84 commands . writestatus ( " layout " , format ( " %-24s %s " , interfaces . interfacedcommand ( name ) , concat ( result , " " ) ) )
85 end
86
87 if tex . count . textlevel = = 0 then
88
89
90
91 reportdimension ( " paperheight " )
92 reportdimension ( " paperwidth " )
93 reportdimension ( " printpaperheight " )
94 reportdimension ( " printpaperwidth " )
95 reportdimension ( " topspace " )
96 reportdimension ( " backspace " )
97 reportdimension ( " makeupheight " )
98 reportdimension ( " makeupwidth " )
99 reportdimension ( " topheight " )
100 reportdimension ( " topdistance " )
101 reportdimension ( " headerheight " )
102 reportdimension ( " headerdistance " )
103 reportdimension ( " textheight " )
104 reportdimension ( " footerdistance " )
105 reportdimension ( " footerheight " )
106 reportdimension ( " bottomdistance " )
107 reportdimension ( " bottomheight " )
108 reportdimension ( " leftedgewidth " )
109 reportdimension ( " leftedgedistance " )
110 reportdimension ( " leftmarginwidth " )
111 reportdimension ( " leftmargindistance " )
112 reportdimension ( " textwidth " )
113 reportdimension ( " rightmargindistance " )
114 reportdimension ( " rightmarginwidth " )
115 reportdimension ( " rightedgedistance " )
116 reportdimension ( " rightedgewidth " )
117 reportdimension ( " bodyfontsize " )
118 reportdimension ( " lineheight " )
119
120 else
121
122 context . starttabulate { " |l| " . . string . rep ( " Tr| " , n ) }
123
124 showdimension ( " paperheight " )
125 showdimension ( " paperwidth " )
126 showdimension ( " printpaperheight " )
127 showdimension ( " printpaperwidth " )
128 showdimension ( " topspace " )
129 showdimension ( " backspace " )
130 showdimension ( " makeupheight " )
131 showdimension ( " makeupwidth " )
132 showdimension ( " topheight " )
133 showdimension ( " topdistance " )
134 showdimension ( " headerheight " )
135 showdimension ( " headerdistance " )
136 showdimension ( " textheight " )
137 showdimension ( " footerdistance " )
138 showdimension ( " footerheight " )
139 showdimension ( " bottomdistance " )
140 showdimension ( " bottomheight " )
141 showdimension ( " leftedgewidth " )
142 showdimension ( " leftedgedistance " )
143 showdimension ( " leftmarginwidth " )
144 showdimension ( " leftmargindistance " )
145 showdimension ( " textwidth " )
146 showdimension ( " rightmargindistance " )
147 showdimension ( " rightmarginwidth " )
148 showdimension ( " rightedgedistance " )
149 showdimension ( " rightedgewidth " )
150 context . NR ( )
151 showdimension ( " bodyfontsize " )
152 showdimension ( " lineheight " )
153 context . NR ( )
154 showmacro ( " strutheightfactor " )
155 showmacro ( " strutdepthfactor " )
156 showmacro ( " topskipfactor " )
157 showmacro ( " maxdepthfactor " )
158
159 context . stoptabulate ( )
160
161 end
162
163end
164
165function commands . showlayout ( options )
166
167 options = checkedoptions ( options )
168
169 if tex . count . textlevel = = 0 then
170
171 commands . showlayoutvariables ( options )
172
173 else
174
175 context . page ( )
176 context . bgroup ( )
177 context . showframe ( )
178 context . setuplayout { marking = interfaces . variables . on }
179 for i = 1 , ( options . n or 4 ) do
180 commands . showlayoutvariables ( options )
181 context . page ( )
182 end
183 context . egroup ( )
184
185 end
186
187end
188
189local report = logs . reporter ( " usage " )
190
191function commands . showusage ( )
192 report ( " " )
193 report ( " status after shipping out page %s " , tex . getcount ( " realpageno " ) )
194 report ( " " )
195 report ( " filename : %s " , status . filename )
196 report ( " inputid : %s " , status . inputid )
197 report ( " linenumber : %s " , status . linenumber )
198 report ( " input pointer : %s " , status . input_ptr )
199 report ( " " )
200 report ( " string pointer : %s of %s " , status . str_ptr , status . max_strings + status . init_str_ptr )
201 report ( " pool size : %s " , status . pool_size )
202 report ( " " )
203 report ( " node memory usage : %s of %s " , status . var_used , status . var_mem_max )
204 report ( " token memory usage : %s of %s " , status . dyn_used , status . fix_mem_max )
205 report ( " " )
206 report ( " cs count : %s of %s " , status . cs_count , status . hash_size + status . hash_extra )
207 report ( " " )
208 report ( " stack size : %s of %s " , status . max_in_stack , status . stack_size )
209 report ( " nest size : %s of %s " , status . max_nest_stack , status . nest_size )
210 report ( " parameter size : %s of %s " , status . max_param_stack , status . param_size )
211 report ( " buffer size : %s of %s " , status . max_buf_stack , status . buf_size )
212 report ( " save size : %s of %s " , status . max_save_stack , status . save_size )
213 report ( " " )
214 report ( " luabytecode bytes : %s in %s registers " , status . luabytecode_bytes , status . luabytecodes )
215 report ( " luastate bytes : %s of %s " , status . luastate_bytes , status . luastate_bytes_max or " unknown " )
216 report ( " " )
217 report ( " callbacks : %s " , status . callbacks )
218 report ( " indirect callbacks : %s " , status . indirect_callbacks )
219 report ( " saved callbacks : %s " , status . saved_callbacks )
220 report ( " direct callbacks : %s " , status . direct_callbacks )
221 report ( " function callbacks : %s " , status . function_callbacks )
222 report ( " " )
223end
224 |