page-run.mkiv /size: 8593 b    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=page-run,
3%D        version=2000.10.20,
4%D          title=\CONTEXT\ Page Macros,
5%D       subtitle=Runtime Macros,
6%D         author=Hans Hagen,
7%D           date=\currentdate,
8%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9%C
10%C This module is part of the \CONTEXT\ macro||package and is
11%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12%C details.
13
14\writestatus{loading}{ConTeXt Page Macros / Runtime Macros}
15
16\registerctxluafile{page-run}{}
17
18\unprotect
19
20\unexpanded\gdef\showprint{\dotripleempty\page_layouts_show_print}
21
22\gdef\page_layouts_show_print[#1][#2][#3]% only english
23  {\setbuffer[crap]%
24      \unprotect
25        \definepapersize[X][\c!width=4em, \c!height=6em]
26        \definepapersize[Y][\c!width=12em,\c!height=14em]
27        \setuppapersize[X,#1][Y,#2]
28        \setuplayout[#3]
29        \setuplayout[\v!page]
30        \framed
31          [\c!offset=\v!overlay,\c!strut=\v!no,
32           \c!width=\paperwidth,\c!height=\paperheight]
33          {\ss ABC\par DEF}%
34      \protect
35   \endbuffer
36   \framed[\c!offset=\v!overlay,\c!strut=\v!no]{\typesetbuffer[crap]}}
37
38% \switchtobodyfont[8pt]
39%
40% \startcombination[4*4]
41%   {\showprint}                                      {\strut}
42%   {\showprint[][][location=middle]}                 {\type{location=middle}}
43%   {\showprint[][][location=middle,marking=on]}      {\type{markering=aan}\break\type{location=middle}}
44%   {\showprint[][][location=middle,marking=on,nx=2]} {\type{markering=aan}\break\type{location=middle}\break\type{nx=2}}
45%   {\showprint[][][location=left]}                   {\type{location=left}}
46%   {\showprint[][][location=right]}                  {\type{location=right}}
47%   {\showprint[][][location={left,bottom}]}          {\type{location={left,bottom}}}
48%   {\showprint[][][location={right,bottom}]}         {\type{location={right,bottom}}}
49%   {\showprint[][][nx=2,ny=1]}                       {\type{nx=2,ny=1}}
50%   {\showprint[][][nx=1,ny=2]}                       {\type{nx=1,ny=2}}
51%   {\showprint[][][nx=2,ny=2]}                       {\type{nx=2,ny=2}}
52%   {\showprint[][][nx=2,ny=2,location=middle]}       {\type{nx=2,ny=2}\break\type{location=middle}}
53%   {\showprint[][][backoffset=3pt]}                  {\type{rugoffset=.5cm}}
54%   {\showprint[][][topoffset=3pt]}                   {\type{kopoffset=.5cm}}
55%   {\showprint[][][scale=1.5]}                       {\type{schaal=1.5}}
56%   {\showprint[][][scale=0.8]}                       {\type{schaal=0.8}}
57% \stopcombination
58%
59% \startcombination[3*4]
60%   {\showprint[landscape][]         [location=middle]} {\type{landscape}}
61%   {\showprint[]         [landscape][location=middle]} {\strut\break\type{landscape}}
62%   {\showprint[landscape][landscape][location=middle]} {\type{landscape}\break\type{landscape}}
63%   {\showprint[90]       []         [location=middle]} {\type{90}}
64%   {\showprint[]         [90]       [location=middle]} {\strut\break\type{90}}
65%   {\showprint[90]       [90]       [location=middle]} {\type{90}\break\type{90}}
66%   {\showprint[180]      []         [location=middle]} {\type{180}}
67%   {\showprint[]         [180]      [location=middle]} {\strut\break\type{180}}
68%   {\showprint[180]      [180]      [location=middle]} {\type{180}\break\type{180}}
69%   {\showprint[mirrored] []         [location=middle]} {\type{mirrored}}
70%   {\showprint[]         [mirrored] [location=middle]} {\strut\break\type{mirrored}}
71%   {\showprint[mirrored] [mirrored] [location=middle]} {\type{mirrored}\break\type{mirrored}}
72% \stopcombination
73
74\unexpanded\gdef\showframe {\dodoubleempty\page_layouts_show_frame}
75\unexpanded\gdef\showsetups{\dosingleempty\page_layouts_show_setups}
76\unexpanded\gdef\showlayout{\dosingleempty\page_layouts_show_layout}
77
78\gdef\page_layouts_show_frame[#1][#2]%
79  {\ifsecondargument
80     \setupbackgrounds
81       [\v!page]
82       [\c!frame=\v!on,
83        \c!corner=\v!rectangular,
84        \c!frameoffset=\zeropoint,
85        \c!framedepth=\zeropoint,
86        \c!framecolor=layout:page]
87     \setupbackgrounds
88       [#1][#2]
89       [\c!background=,
90        \c!frame=\v!on,
91        \c!corner=\v!rectangular,
92        \c!frameoffset=\zeropoint,
93        \c!framedepth=\zeropoint,
94        \c!framecolor=]
95   \else\iffirstargument
96     \showframe
97       [\v!header,\v!text,\v!footer]
98       [#1]
99   \else
100     \showframe
101       [\v!top,\v!header,
102        \v!text,
103        \v!footer,\v!bottom]
104       [\v!leftedge,\v!leftmargin,
105        \v!text,
106        \v!rightmargin,\v!rightedge]
107   \fi\fi
108   \setupbackgrounds
109     [\c!state=\v!repeat]}
110
111\gdef\page_layouts_show_setups[#1]%
112  {\ctxcommand{showlayoutvariables("#1")}}
113
114\gdef\page_layouts_show_layout[#1]%
115  {\ctxcommand{showlayout("#1")}}
116
117\unexpanded\gdef\showmargins
118  {\starttabulate
119   \NC asynchrone   \NC \doifelseoddpage     {odd}   {even} \NC \NR
120   \NC synchrone    \NC \doifelserightpage   {right} {left} \NC \NR
121   \NC right margin \NC \the\rightmarginwidth               \NC \NR
122   \NC left margin  \NC \the\leftmarginwidth                \NC \NR
123   \NC outer margin \NC \the\outermarginwidth               \NC \NR
124   \NC inner margin \NC \the\innermarginwidth               \NC \NR
125   \stoptabulate}
126
127%D Page grids:
128
129\newconstant\c_page_grids_location
130\newconstant\c_page_grids_line_mode
131\newconstant\c_page_grids_lineno_mode
132\newconstant\c_page_grids_columns_mode
133
134\unexpanded\gdef\showgrid
135  {\dosingleempty\page_grids_show}
136
137\gdef\page_grids_show[#1]%
138  {\c_page_grids_location    \plusone % downward compatible default
139   \c_page_grids_line_mode   \plusone
140   \c_page_grids_lineno_mode \plusone
141   \c_page_grids_columns_mode\plusone
142   \processallactionsinset
143     [#1]%
144     [   \v!reset=>\c_page_grids_location    \zerocount
145                   \c_page_grids_columns_mode\zerocount,
146        \v!bottom=>\c_page_grids_location    \plusone,
147           \v!top=>\c_page_grids_location    \plustwo,
148          \v!none=>\c_page_grids_line_mode   \zerocount,
149           \v!all=>\c_page_grids_line_mode   \plusone,
150         \v!lines=>\c_page_grids_line_mode   \plustwo,
151         \v!frame=>\c_page_grids_line_mode   \plusthree,
152      \v!nonumber=>\c_page_grids_lineno_mode \zerocount,
153         \v!right=>\c_page_grids_lineno_mode \plusone,
154          \v!left=>\c_page_grids_lineno_mode \plustwo,
155         \v!outer=>\c_page_grids_lineno_mode \plusthree,
156         \v!inner=>\c_page_grids_lineno_mode \plusfour,
157       \v!columns=>\c_page_grids_columns_mode\plusone]% new option
158   \ifcase\c_page_grids_location
159     \let\page_grids_add_to_box\gobbleoneargument
160   \else % 1=bottom 2=top
161     \let\page_grids_add_to_box\page_grids_add_to_box_indeed
162   \fi
163   \ifcase\c_page_grids_columns_mode
164     \let\page_grids_add_to_one\gobbleoneargument
165     \let\page_grids_add_to_mix\gobbleoneargument
166   \else
167     \let\page_grids_add_to_one\page_grids_add_to_one_indeed
168     \let\page_grids_add_to_mix\page_grids_add_to_mix_indeed
169   \fi}
170
171% if really needed for speed we can cache the grid
172
173\glet\page_grids_add_to_box\gobbleoneargument
174\glet\page_grids_add_to_one\gobbleoneargument
175\glet\page_grids_add_to_mix\gobbleoneargument
176
177\gdef\page_grids_add_to_box_indeed#1% to be checked for color and layer ..... use mp
178  {\startcolor[layout:grid]%
179   \resetvisualizers
180   \gridboxlinemode  \c_page_grids_line_mode
181   \gridboxlinenomode\c_page_grids_lineno_mode
182   \setgridbox\scratchbox\makeupwidth\textheight % todo: check color
183   \global\setbox#1\hpack % global ?
184     {\ifcase\c_page_grids_location\or\or\box#1\hskip-\makeupwidth\fi
185      \begingroup % color
186      \ifcase\layoutcolumns\else
187        \gray
188        \setlayoutcomponentattribute{\v!grid:\v!columns}%
189        \hpack \layoutcomponentboxattribute to \makeupwidth
190          {\dorecurse\layoutcolumns
191             {\hskip\layoutcolumnwidth
192              \ifnum\recurselevel<\layoutcolumns
193                \vrule
194                  \s!height\ht\scratchbox
195                  \s!depth \dp\scratchbox
196                  \s!width \layoutcolumndistance
197              \fi}}%
198        \hskip-\makeupwidth
199      \fi
200      \setlayoutcomponentattribute{\v!grid:\v!lines}%
201      \hpack \layoutcomponentboxattribute{\box\scratchbox}%
202      \endgroup
203      \ifcase\c_page_grids_location\or\hskip-\makeupwidth\box#1\fi}%
204   \stopcolor}
205
206\gdef\page_grids_add_to_one_indeed#1%
207  {\begingroup
208   \resetvisualizers
209   \global\setbox#1\vpack{\noindent\backgroundline[layout:one]{\box#1}}%
210   \endgroup}
211
212\gdef\page_grids_add_to_mix_indeed#1%
213  {\begingroup
214   \resetvisualizers
215   \global\setbox#1\vpack{\noindent\backgroundline[layout:mix]{\box#1}}%
216   \endgroup}
217
218\protect \endinput
219