page-cst.mkiv /size: 25 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=page-cst,
3
%D version=2016.12.15,
4
%D title=\CONTEXT\ Page Macros,
5
%D subtitle=Page Grids (aka Column Sets),
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
% todo : markings per column
15 16
%D This module is work in progress and in due time it will replace
17
%D columnsets.
18 19
\writestatus
{
loading
}{
ConTeXt
Page
Macros
/
Page
Grids
}
20 21
\registerctxluafile
{
page
-
cst
}{}
22 23
\unprotect
24 25
% maybe some protected def ([esc])
26 27
%D Columnsets are kind of special. They are mostly meant for special products with
28
%D magazine like properties. They are normally not mixed with single column layouts
29
%D and not all features of \CONTEXT\ might cooperate well with a mechanism like
30
%D this. We use the name page grid because (as with other reimplementations of
31
%D \MKII\ features in \MKIV, we need another namespace in order to migrate stepwise.
32
%D
33
%D This implementation is not neccessarily better than the previous one but it might
34
%D be easier to extend it. It should be a bit more efficient.
35
%D
36
%D When writing this code I occasionally needed a motivational musical time||out and
37
%D watching the latest Snarky Puppy DVD brought me the musically and visually videos
38
%D of Jacob Collier (Piano, voice, anything) on YouTube (and yes, music keeps amazing
39
%D me). It's definitely more fun to watch that than to write code like this.
40 41
\definesystemconstant
{
pagegrid
}
42 43
\installcorenamespace
{
pagegrid
}
44 45
\installframedcommandhandler
\??pagegrid
{
pagegrid
}
\??pagegrid
46 47
\setuppagegrid
48
[
\c!distance
=
1
.
5
\bodyfontsize
,
49
\c!n
=
\plustwo
,
50
\c!nleft
=
\pagegridparameter
\c!n
,
51
\c!nright
=
\pagegridparameter
\c!n
,
52
%\c!align=, % inherit
53
%\c!separator=\v!none,
54
%\c!setups=,
55
\c!lines
=
\layoutparameter
\c!lines
,
56
\c!frame
=
\v!off
,
57
\c!strut
=
\v!no
,
58
\c!offset
=
\v!overlay
,
59
\c!alternative
=
\v!local
,
60
\c!width
=
\v!auto
,
61
\c!page
=
,
62
\c!direction
=
\v!normal
,
% todo
63
\c!maxheight
=
\textheight
,
64
\c!maxwidth
=
\makeupwidth
]
65 66
\appendtoks
% could become an option
67
\setuevalue
{
\e!start
\currentpagegrid
}{
\startpagegrid
[
\currentpagegrid
]
}
%
68
\setuevalue
{
\e!stop
\currentpagegrid
}{
\stoppagegrid
}
%
69
\clf_definecolumnset
{
70
name
{
\currentpagegrid
}
%
71
}
%
72
\to
\everydefinepagegrid
73 74
\newdimen
\d_page_grd_column_width
75
\newdimen
\d_page_grd_max_height
76
\newdimen
\d_page_grd_max_width
77
\newdimen
\d_page_grd_distance
78 79
\newdimen
\d_page_grd_reserved_height
80
\newdimen
\d_page_grd_reserved_width
81
\newcount
\c_page_grd_reserved_state
82 83
\newdimen
\d_page_grd_gap_height
84 85
\newcount
\c_page_grd_n_of_left
86
\newcount
\c_page_grd_n_of_right
87
\newcount
\c_page_grd_n_of_rows
88
\newcount
\c_page_grd_first_column
89
\newcount
\c_page_grd_last_column
90 91
\newbox
\b_page_grd_collected
92
\newbox
\b_page_grd_column_rest
93
\newbox
\b_page_grd_column
94 95
\unexpanded
\def
\setuppagegridlines
{
\doquadrupleempty
\page_grd_setup_lines
}
96
\unexpanded
\def
\setuppagegridstart
{
\doquadrupleempty
\page_grd_setup_start
}
97 98
\def
\page_grd_setup_lines
[#
1
][#
2
][#
3
][#
4
]
% id page col value
99
{
\clf_setcolumnsetlines
{
name
{
#
1
}
page
#
2
column
#
3
value
#
4
}}
100 101
\def
\page_grd_setup_start
[#
1
][#
2
][#
3
][#
4
]
% id page col value
102
{
\clf_setcolumnsetstart
{
name
{
#
1
}
page
#
2
column
#
3
value
#
4
}}
103 104
\unexpanded
\def
\page_grd_check
105
{
\dorecurse
{
\numexpr
\pagegridparameter
\c!nleft
+
\pagegridparameter
\c!nright
}
106
{
\page_grd_check_column
{
##
1
}}}
107 108
\unexpanded
\def
\page_grd_check_column
#
1
%
109
{
\chaintocurrentpagegrid
{
\currentpagegrid
:
#
1
}
%
110
\edef
\p_distance
{
\namedpagegridparameter
{
\currentpagegrid
:
#
1
}
\c!distance
}
%
111
\edef
\p_width
{
\namedpagegridparameter
{
\currentpagegrid
:
#
1
}
\c!width
}
%
112
\clf_setcolumnsetproperties
{
%
113
name
{
\currentpagegrid
}
114
column
\numexpr
#
1
\relax
115
\ifx
\p_distance
\empty
\else
116
distance
\p_distance
117
\fi
118
\ifx
\p_width
\empty
\else\ifx
\p_width
\v!auto
\else
119
width
\p_width
120
\fi\fi
121
}}
122 123
\appendtoks
124
\dorecurse
{
\numexpr
\pagegridparameter
\c!nleft
+
\pagegridparameter
\c!nright
}
125
{
\chaintocurrentpagegrid
{
\currentpagegrid
:
#
1
}}
%
126
\to
\everydefinepagegrid
127 128
\unexpanded
\def
\startpagegrid
129
{
\bgroup
130
\dodoubleempty
\page_grd_start
}
131 132
\def
\page_grd_start_dummy
[#
1
][#
2
]
%
133
{
\let
\page_grd_stop
\egroup
}
134 135
\def
\page_grd_start
[#
1
][#
2
]
%
136
{
\let
\page_grd_start
\page_grd_start_dummy
137
\ifsecondargument
138
\edef
\currentpagegrid
{
#
1
}
%
139
\setupcurrentpagegrid
[#
2
]
%
140
\else
\iffirstargument
141
\doifassignmentelse
{
#
1
}
142
{
\let
\currentpagegrid
\empty
143
\setupcurrentpagegrid
[#
1
]
}
%
144
{
\def
\currentpagegrid
{
#
1
}}
%
145
\else
146
\let
\currentpagegrid
\empty
147
\fi\fi
148
\usepageparameter
\pagegridparameter
149
\c_page_grd_n_of_left
\pagegridparameter
\c!nleft
\relax
150
\c_page_grd_n_of_right
\pagegridparameter
\c!nright
\relax
151
\c_page_grd_n_of_rows
\pagegridparameter
\c!lines
\relax
152
\d_page_grd_max_width
\pagegridparameter
\c!maxwidth
\relax
153
\d_page_grd_max_height
\pagegridparameter
\c!maxheight
\relax
154
\d_page_grd_distance
\pagegridparameter
\c!distance
\relax
155
%
156
\ifcase
\c_page_grd_n_of_rows
157
\getrawnoflines
{
\dimexpr
\d_page_grd_max_height
-
\strutheight
+
\topskip\relax
}
%
158
\c_page_grd_n_of_rows
\noflines
159
\fi
160
\edef
\p_width
{
\pagegridparameter
\c!width
}
%
161
\insidecolumnstrue
% will be different flag in addition
162
\clf_resetcolumnset
{
163
name
{
\currentpagegrid
}
164
nofrows
\c_page_grd_n_of_rows
165
nofleft
\c_page_grd_n_of_left
166
nofright
\c_page_grd_n_of_right
167
lineheight
\strutht
168
linedepth
\strutdp
169
\ifx
\p_width
\v!auto
170
% sets \d_page_grd_column_width
171
\else
172
width
\p_width
173
\fi
174
distance
\d_page_grd_distance
175
maxwidth
\d_page_grd_max_width
176
}
%
177
%
178
\page_grd_check
179
%
180
\clf_flushcolumnsetareas
{
\currentpagegrid
}
\relax
181
\setupoutputroutine
[
\s!pagegrid
]
%
182
\page_grd_command_set_hsize
183
\page_grd_command_set_vsize
184
%
185
\columnwidth
\d_page_grd_column_width
186
\columndistance
\d_page_grd_distance
187
\nofcolumns
\c_page_grd_n_of_left
% not always ok
188
\textwidth
\d_page_grd_column_width
% kind of redundant but we had it so ...
189
%
190
}
%\begingroup}
191 192
\unexpanded
\def
\stoppagegrid
193
{
\page_grd_stop
}
194 195
\def
\page_grd_stop
196
{
\endgraf
% needed, else wrong vsize in one par case
197
\vfill
% otherwise weird \placenotes[endnotes]
198
\page_grd_command_set_vsize
% needed
199
\penalty
\c_page_otr_eject_penalty
200
\page_grd_command_flush_page
201
\page_otr_fill_and_eject_page
202
\page_grd_command_set_vsize
% why here
203
\egroup
204
\page_otr_command_set_vsize
205
\page_otr_command_set_hsize
}
206 207
\unexpanded
\def
\reservepagegrid
[#
1
]
%
208
{
\begingroup
209
\letdummyparameter
\c!c
\plusone
210
\letdummyparameter
\c!r
\plusone
211
\letdummyparameter
\c!nc
\plusone
212
\letdummyparameter
\c!nr
\plusone
213
\getdummyparameters
[#
1
]
%
214
\clf_blockcolumnset
{
215
name
{
\currentpagegrid
}
216
c
\dummyparameter
\c!c
217
r
\dummyparameter
\c!r
218
nc
\dummyparameter
\c!nc
219
nr
\dummyparameter
\c!nr
220
}
%
221
\endgroup
}
222 223
\unexpanded
\def
\setpagegrid
224
{
\dosingleempty
\page_grd_set
}
225 226
\unexpanded
\def
\page_grd_set
[#
1
]
%
227
{
\begingroup
228
\letdummyparameter
\c!c
\zerocount
229
\letdummyparameter
\c!r
\zerocount
230
\letdummyparameter
\c!method\v!here
231
\letdummyparameter
\c!option\v!none
232
\getdummyparameters
[#
1
]
%
233
\dowithnextboxcs
\page_grd_set_indeed
\hbox
}
234 235
\def
\page_grd_set_indeed
236
{
\clf_checkcolumnset
{
237
name
{
\currentpagegrid
}
238
c
\dummyparameter
\c!c
239
r
\dummyparameter
\c!r
240
box
\nextbox
241
method
{
\dummyparameter
\c!method
}
242
option
{
\dummyparameter
\c!option
}
243
}
%
244
\ifcase
\c_page_grd_reserved_state
245
\setbox
\nextbox
\vpack
to
\d_page_grd_reserved_height
\bgroup
246
\vss
247
\hpack
to
\d_page_grd_reserved_width
\bgroup
248
\box
\nextbox
249
\hss
250
\egroup
251
\vss
252
\egroup
253
\wd
\nextbox
\d_page_grd_reserved_width
254
\clf_putincolumnset
{
255
name
{
\currentpagegrid
}
256
box
\nextbox
257
}
%
258
\fi
259
\endgroup
}
260 261 262
\unexpanded
\def
\page_grd_command_set_vsize
263
{
\clf_setvsizecolumnset
{
\currentpagegrid
}
%
264
\ifdim
\d_page_grd_gap_height
<
\lineheight
265
\page_grd_command_flush_page
266
\page_otr_fill_and_eject_page
267
\fi
268
\global\vsize
\d_page_grd_gap_height
269
\pagegoal\vsize
}
270 271
\unexpanded
\def
\page_grd_command_set_hsize
272
{
\clf_sethsizecolumnset
{
\currentpagegrid
}
%
273
\hsize
\d_page_grd_column_width
274
\textwidth
\d_page_grd_column_width
}
275 276
\unexpanded
\def
\page_grd_command_routine
277
{
\ifvoid
\normalpagebox
\else
278
\clf_addtocolumnset
{
\currentpagegrid
}
\normalpagebox
279
\fi
280
\page_grd_command_set_vsize
281
\page_grd_command_flush_saved_floats
282
\page_grd_command_set_vsize
283
\ifdim
\d_page_grd_gap_height
<
\lineheight
284
\page_grd_command_flush_page
285
\fi
286
\page_grd_command_set_vsize
287
\clf_flushcolumnsetrest
{
\currentpagegrid
}
\normalpagebox
288
\ifvoid
\normalpagebox
\else
289
\unvbox
\normalpagebox
290
\fi
}
291 292
\installoutputroutine
\synchronizepagegrid
293
{
\ifvoid
\normalpagebox
\else
294
\clf_addtocolumnset
{
\currentpagegrid
}
\normalpagebox
295
\page_grd_command_set_vsize
296
\clf_flushcolumnsetrest
{
\currentpagegrid
}
\normalpagebox
297
\ifvoid
\normalpagebox
\else
298
\unvbox
\normalpagebox
299
\fi
300
\fi
}
301 302
% todo line numbers and marks
303 304
\unexpanded
\def
\page_grd_command_flush_page_column
#
1
%
305
{
\privatescratchcounter
#
1
\relax
% or just currentcolumn as in page-col.mkiv
306
\clf_flushcolumnsetcolumn
{
\currentpagegrid
}
\privatescratchcounter
307
\anch_mark_column_box
\b_page_grd_column
\privatescratchcounter
308
\page_marks_synchronize_column
\c_page_grd_first_column
\c_page_grd_last_column
\privatescratchcounter
\b_page_grd_column
309
\ifnum
\privatescratchcounter
>
\c_page_grd_n_of_left
310
\advance
\privatescratchcounter
-
\c_page_grd_n_of_left
311
\page_lines_add_numbers_to_box
\b_page_grd_column
\privatescratchcounter
\c_page_grd_n_of_right
\plustwo
312
\else
313
\page_lines_add_numbers_to_box
\b_page_grd_column
\privatescratchcounter
\c_page_grd_n_of_left
\plustwo
314
\fi
315
\begingroup
316
\edef
\currentpagegrid
{
\currentpagegrid
:
#
1
}
%
317
\inheritedpagegridframedbox
\box
\b_page_grd_column
318
\endgroup
}
319 320
\unexpanded
\def
\page_grd_command_flush_page
321
{
\deactivatecolor
% puzzling, try ungrouped color \red or so
322
\setbox
\b_page_grd_collected
\hpack
\bgroup
323
\clf_preparecolumnsetflush
{
\currentpagegrid
}
%
324
\letpagegridparameter
\c!region
\currentpagegrid
325
\doifelse
{
\pagegridparameter
\c!direction
}
\v!reverse
326
{
\dostepwiserecurse
\c_page_grd_last_column
\c_page_grd_first_column
\minusone
327
{
\page_grd_command_flush_page_column
{
##
1
}
%
328
\ifnum
##
1
>
\plusone
329
\kern
\namedpagegridparameter
{
\currentpagegrid
:
##
1
}
\c!distance
\relax
330
\fi
}}
%
331
{
\dostepwiserecurse
\c_page_grd_first_column
\c_page_grd_last_column
\plusone
332
{
\page_grd_command_flush_page_column
{
##
1
}
%
333
\ifnum
##
1
<
\c_page_grd_last_column
334
\kern
\namedpagegridparameter
{
\currentpagegrid
:
##
1
}
\c!distance
\relax
335
\fi
}}
%
336
\clf_finishcolumnsetflush
{
\currentpagegrid
}
%
337
\egroup
338
\page_otr_construct_and_shipout
\box
\b_page_grd_collected
\zerocount
% three arguments
339
\clf_flushcolumnsetareas
{
\currentpagegrid
}
\relax
340
\page_grd_command_flush_saved_floats
}
341 342
% slow but robust
343 344
\unexpanded
\def
\page_grd_command_next_progress
345
{
\strut
346
\page_grd_command_flush_all_floats
347
\page_otr_eject_page
348
\ifcase
\clf_columnsetnoto
\else
349
\expandafter
\page_grd_command_next_progress
350
\fi
}
351 352
\unexpanded
\def
\page_grd_command_handle_column
353
{
\ifcase
\clf_columnsetgoto
{
\currentpagegrid
}{
\page_breaks_columns_current_option
}
\relax\else
354
\expandafter
\page_grd_command_next_progress
355
\fi
}
356 357
\installcolumnbreakmethod
\s!pagegrid\s!unknown
{
\page_grd_command_handle_column
}
358
\installcolumnbreakmethod
\s!pagegrid\v!yes
{
\page_grd_command_handle_column
}
359 360
\unexpanded
\def
\page_grd_command_next_page
361
{
\ifcase
\clf_columnsetgoto
{
\currentpagegrid
}{
\v!page
}
\relax\else
362
\page_grd_command_flush_page
363
\fi
}
364 365
\unexpanded
\def
\page_grd_command_next_page_and_inserts
366
{
\page_grd_command_flush_all_floats
367
\page_grd_command_next_page
}
368 369
\let
\page_grd_command_flush_all_floats
\page_one_command_flush_all_floats
370
\let
\page_grd_command_package_contents
\page_one_command_package_contents
371 372
\unexpanded
\def
\page_grd_command_flush_saved_floats
373
{
\ifconditional
\c_page_floats_flushing
\else
374
\ifconditional
\c_page_floats_some_waiting
375
\page_grd_command_flush_saved_floats_indeed
376
\fi
377
\fi
}
378 379
\unexpanded
\def
\page_grd_command_flush_saved_floats_indeed
380
{
\page_floats_flush
\s!text
\plusone
381
\clf_checkcolumnset
{
382
name
{
\currentpagegrid
}
383
method
{
\floatmethod
}
384
width
\wd
\floatbox
385
height
\ht
\floatbox
386
}
%
387
\ifcase
\c_page_grd_reserved_state
388
\page_grd_place_float_here_indeed
389
\page_grd_command_set_vsize
% needed
390
\ifconditional
\c_page_floats_some_waiting
391
\doubleexpandafter
\page_grd_command_flush_saved_floats_indeed
392
\fi
393
\else
394
\page_floats_resave
\s!text
395
\fi
}
396 397
% needs checking
398 399
\unexpanded
\def
\page_grd_command_flush_floats
400
{
\wait
\global
\settrue
\c_page_floats_flushing
401
\ifconditional
\c_page_floats_some_waiting
402
\par
403
\page_grd_command_flush_floats_indeed
404
\fi
405
\global
\savednoffloats
\zerocount
406
\global
\setfalse
\c_page_floats_some_waiting
407
\global
\setfalse
\c_page_floats_flushing
}
408 409
\def
\page_grd_command_flush_floats_indeed
% much in common with OTRSET
410
{
\ifconditional
\c_page_floats_some_waiting
411
\ifconditional
\c_page_floats_compress_flushed
412
\page_floats_collect
\s!text
\hsize
\d_page_floats_compress_distance
413
\ifcase
\nofcollectedfloats
414
\page_floats_get
415
% \or
416
% \page_floats_get
417
\else
418
\setfalse
\c_page_floats_center_box
% not needed as we do call directly
419
\global\setbox
\floatbox
\hbox
to
\hsize
420
{
\hfil
421
\dorecurse
\nofcollectedfloats
422
{
\ifcase
\columndirection
% nog document wide
423
\page_floats_flush
\s!text
\plusone
424
\else
425
\page_floats_flush
\s!text
{
\the\numexpr
\nofcollectedfloats
-
\recurselevel
+
1
\relax
}
%
426
\fi
427
\ifdim
\wd
\floatbox
>
\makeupwidth
% \hsize
428
\hbox
to
\makeupwidth
{
\hss\box
\floatbox
\hss
}
%
429
\else
430
\box
\floatbox
431
\fi
432
\ifnum
\recurselevel
<
\nofcollectedfloats
433
\hfil
434
\fi
}
%
435
\hfil
}
%
436
\fi
437
\else
438
\page_floats_get
439
\fi
440
\doplacefloatbox
441
\expandafter
\page_grd_command_flush_floats_indeed
442
\fi
}
443 444
% so far
445 446
\unexpanded
\def
\page_grd_command_check_if_float_fits
447
{
\clf_checkcolumnset
{
448
name
{
\currentpagegrid
}
449
method
{
\floatmethod
}
450
% c \zerocount
451
% r \zerocount
452
box
\floatbox
453
}
%
454
\ifcase
\c_page_grd_reserved_state
455
\global
\settrue
\c_page_floats_room
456
\else
457
\global
\setfalse
\c_page_floats_room
458
\fi
}
459 460
\unexpanded
\def
\page_grd_place_float_here_indeed
461
{
\setbox
\floatbox
\vpack
to
\d_page_grd_reserved_height
\bgroup
462
\vss
463
\hpack
to
\d_page_grd_reserved_width
\bgroup
464
% \hss % no
465
\box
\floatbox
466
\hss
467
\egroup
468
\vss
469
\egroup
470
\clf_putincolumnset
{
471
name
{
\currentpagegrid
}
472
box
\floatbox
473
}}
474 475
\def
\page_grd_place_float_slot
476
{
% safeguard
477
\ifx
\floatmethod
\empty
478
\let
\floatmethod
\v!here
479
\fi
480
% synchronize
481
\penalty
\c_page_otr_eject_penalty
482
% push
483
\setbox
\savedfloatbox
\box
\floatbox
484
\page_grd_command_flush_saved_floats
485
\setbox
\floatbox
\box
\savedfloatbox
486
% pop
487
\ifconditional
\c_page_floats_some_waiting
488
\page_floats_save
\s!text
489
\nonoindentation
490
\else
491
\clf_checkcolumnset
{
492
name
{
\currentpagegrid
}
493
method
{
\floatmethod
}
494
\ifx
\floatcolumn
\empty
\else
495
c
\floatcolumn
496
\fi
497
\ifx
\floatrow
\empty
\else
498
r
\floatrow
499
\fi
500
box
\floatbox
501
}
%
502
\ifcase
\c_page_grd_reserved_state
503
\page_grd_place_float_here_indeed
504
\else
505
\page_floats_save
\s!text
506
\nonoindentation
507
\fi
508
\fi
}
509 510
\def
\page_grd_place_float_fixed
% todo: fallback on here
511
{
\ifx
\floatcolumn
\empty
512
\let
\floatmethod
\v!here
513
\else\ifx
\floatrow
\empty
514
\let
\floatmethod
\v!here
515
\else
516
\let
\floatmethod
\v!fixed
517
\fi\fi
518
\page_grd_place_float_slot
}
519 520
\def
\page_grd_place_float_force
521
{
% synchronize
522
\penalty
\c_page_otr_eject_penalty
523
\clf_checkcolumnset
{
524
name
{
\currentpagegrid
}
525
method
{
\floatmethod
}
526
box
\floatbox
527
}
%
528
\ifcase
\c_page_grd_reserved_state
529
\page_grd_place_float_here_indeed
530
\else
531
\page_floats_save
\s!text
532
\nonoindentation
533
\fi
}
534 535
\def
\page_grd_place_float_page
{
\page_grd_place_float_slot
}
% todo: fallback on here
536 537
\def
\page_grd_place_float_here
{
\let
\floatmethod
\v!here
\page_grd_place_float_slot
}
538
\def
\page_grd_place_float_top
{
\page_grd_place_float_slot
}
539
\def
\page_grd_place_float_bottom
{
\page_grd_place_float_slot
}
540 541
\installfloatmethod
\s!pagegrid
\v!here
\page_grd_place_float_here
542
\installfloatmethod
\s!pagegrid
\v!force
\page_grd_place_float_force
% todo
543
%installfloatmethod \s!pagegrid \v!left
544
%installfloatmethod \s!pagegrid \v!right
545
%installfloatmethod \s!pagegrid \v!text
546
\installfloatmethod
\s!pagegrid
\v!top
\page_grd_place_float_top
547
\installfloatmethod
\s!pagegrid
\v!bottom
\page_grd_place_float_bottom
548
%installfloatmethod \s!pagegrid \v!auto
549
%installfloatmethod \s!pagegrid \v!margin
550
%installfloatmethod \s!pagegrid \v!opposite
551
\installfloatmethod
\s!pagegrid
\v!page
\page_grd_place_float_page
552
%installfloatmethod \s!pagegrid \v!leftpage
553
%installfloatmethod \s!pagegrid \v!rightpage
554
%installfloatmethod \s!pagegrid \v!inmargin
555
%installfloatmethod \s!pagegrid \v!inleft
556
%installfloatmethod \s!pagegrid \v!inright
557
%installfloatmethod \s!pagegrid \v!leftmargin
558
%installfloatmethod \s!pagegrid \v!rightmargin
559
%installfloatmethod \s!pagegrid \v!leftedge
560
%installfloatmethod \s!pagegrid \v!rightedge
561
%installfloatmethod \s!pagegrid \v!somewhere
562
%installfloatmethod \s!pagegrid \v!backspace
563
%installfloatmethod \s!pagegrid \v!cutspace
564
\installfloatmethod
\s!pagegrid
\s!tblr
\page_grd_place_float_slot
565
\installfloatmethod
\s!pagegrid
\s!lrtb
\page_grd_place_float_slot
566
\installfloatmethod
\s!pagegrid
\s!tbrl
\page_grd_place_float_slot
567
\installfloatmethod
\s!pagegrid
\s!rltb
\page_grd_place_float_slot
568
\installfloatmethod
\s!pagegrid
\s!fxtb
\page_grd_place_float_slot
569
\installfloatmethod
\s!pagegrid
\s!btlr
\page_grd_place_float_slot
570
\installfloatmethod
\s!pagegrid
\s!lrbt
\page_grd_place_float_slot
571
\installfloatmethod
\s!pagegrid
\s!btrl
\page_grd_place_float_slot
572
\installfloatmethod
\s!pagegrid
\s!rlbt
\page_grd_place_float_slot
573
\installfloatmethod
\s!pagegrid
\s!fxbt
\page_grd_place_float_slot
574
\installfloatmethod
\s!pagegrid
\s!fixd
\page_grd_place_float_fixed
575 576
%
577 578
\unexpanded
\def
\page_grd_command_side_float_output
579
{}
% nothing, reset anyway
580 581
\unexpanded
\def
\page_grd_command_flush_side_floats
582
{
\page_sides_forget_floats
}
583 584
\unexpanded
\def
\page_grd_command_synchronize_side_floats
585
{
\page_sides_forget_floats
}
586 587
\unexpanded
\def
\page_grd_command_synchronize_hsize
588
{
\page_grd_command_set_hsize
}
589 590
\unexpanded
\def
\page_grd_command_flush_all_floats
591
{
\page_one_command_flush_all_floats
}
592 593
\defineoutputroutine
594
[
\s!pagegrid
]
595
[
\s!page_otr_command_routine
=
\page_grd_command_routine
,
596
\s!page_otr_command_package_contents
=
\page_grd_command_package_contents
,
597
\s!page_otr_command_set_vsize
=
\page_grd_command_set_vsize
,
598
\s!page_otr_command_set_hsize
=
\page_grd_command_set_hsize
,
% tricky, goes wrong
599
\s!page_otr_command_synchronize_hsize
=
\page_grd_command_synchronize_hsize
,
600
\s!page_otr_command_next_page
=
\page_grd_command_next_page
,
601
\s!page_otr_command_next_page_and_inserts
=
\page_grd_command_next_page_and_inserts
,
602
% \s!page_otr_command_set_top_insertions =\page_grd_command_set_top_insertions,
603
% \s!page_otr_command_set_bottom_insertions =\page_grd_command_set_bottom_insertions,
604
% \s!page_otr_command_flush_top_insertions =\page_grd_command_flush_top_insertions,
605
% \s!page_otr_command_flush_bottom_insertions =\page_grd_command_flush_bottom_insertions,
606
\s!page_otr_command_check_if_float_fits
=
\page_grd_command_check_if_float_fits
,
607
% \s!page_otr_command_set_float_hsize =\page_grd_command_set_float_hsize,
608
% \s!page_otr_command_flush_float_box =\page_grd_command_flush_float_box,
609
\s!page_otr_command_synchronize_side_floats
=
\page_grd_command_synchronize_side_floats
,
610
\s!page_otr_command_side_float_output
=
\page_grd_command_side_float_output
,
611
\s!page_otr_command_flush_floats
=
\page_grd_command_flush_floats
,
612
\s!page_otr_command_flush_side_floats
=
\page_grd_command_flush_side_floats
,
613
\s!page_otr_command_flush_saved_floats
=
\page_grd_command_flush_saved_floats
,
614
\s!page_otr_command_flush_all_floats
=
\page_grd_command_flush_all_floats
,
615
% \s!page_otr_command_flush_margin_blocks =\page_grd_command_flush_margin_blocks, % not used
616
]
617 618
% spans
619 620
\installcorenamespace
{
pagegridspan
}
621 622
\installframedcommandhandler
\??pagegridspan
{
pagegridspan
}
\??pagegridspan
623 624
\setuppagegridspan
625
[
\c!frame
=
\v!off
,
626
\c!before
=
,
627
\c!after
=
,
628
\c!offset
=
\v!overlay
,
629
\c!location
=
\v!left
,
630
\c!linecorrection
=
\v!off
,
631
\c!depthcorrection
=
\v!off
,
632
\c!n
=
\plustwo
,
633
\c!nlines
=
\zerocount
,
634
\c!align
=
\v!normal
,
635
\c!width
=
\d_page_grd_span_width
,
636
\c!indenting
=
,
637
\c!indentnext
=
\v!yes
,
638
\c!default
=
\v!here
,
639
\c!alternative
=
\v!a
]
640 641
\newdimen
\d_page_grd_span_width
642 643
\unexpanded
\def
\startpagegridspan
644
{
\dotripleempty
\page_grd_span_start
}
645 646
\def
\page_grd_span_start
[#
1
][#
2
][#
3
]
% [#3] gobbles space
647
{
\endgraf
% else rubish output if forgotten
648
\synchronizepagegrid
649
\bgroup
650
\forgetall
651
\edef
\currentpagegridspan
{
#
1
}
%
652
\clf_sethsizecolumnspan
{
\currentpagegrid
}
\pagegridspanparameter
\c!n
\relax
653
\setbox
\scratchbox
\hbox
\bgroup
\inheritedpagegridspanframed
\bgroup
654
\def
\page_grd_span_stop
{
\page_grd_span_stop_indeed
{
#
2
}}
%
655
\usepagegridspanstyleandcolor
\c!style\c!color
656
\pagegridspanparameter
\c!before
657
\ignorespaces
}
658 659
\unexpanded
\def
\page_grd_span_stop_indeed
#
1
%
660
{
\removeunwantedspaces
661
\par
662
\verticalstrut
663
\kern
-
2
\struttotal
664
\verticalstrut
665
\endgraf
666
\pagegridspanparameter
\c!after
667
\egroup\egroup
668
\setpagegrid
[#
1
]
{
\box
\scratchbox
}
%
669
% todo: push into slot
670
\egroup
671
\endgraf
}
672 673
\unexpanded
\def
\stoppagegridspan
% indirectness permits aliasing
674
{
\page_grd_span_stop
}
675 676
\def
\pagegridspanwidth
#
1
% assumes equal distances
677
{
\the\dimexpr
678
#
1
\d_page_grd_column_width
679
+
#
1
\d_page_grd_distance
680
-
\d_page_grd_distance
681
\relax
}
682 683
% areas
684 685
\installcorenamespace
{
pagegridarea
}
686 687
\installframedcommandhandler
\??pagegridarea
{
pagegridarea
}
\??pagegridarea
688 689
\setuppagegridarea
690
[
\c!x
=
\plusone
,
691
\c!y
=
\plusone
,
692
\c!nx
=
\plusone
,
693
\c!ny
=
\plusone
,
694
\c!clipoffset
=
2
\lineheight
,
695
\c!leftoffset
=
\zeropoint
,
696
\c!rightoffset
=
\zeropoint
,
697
\c!offset
=
\v!overlay
,
698
\c!strut
=
\v!no
,
699
\c!frame
=
\v!off
,
700
%\c!type=\v!next,
701
\c!align
=
\v!normal
,
702
\c!page
=
\plusone
,
703
\c!state
=
\v!stop
]
704 705
% type: both fixed left right next (not now), then better
706
% lefttext and righttext or so
707 708
\appendtoks
709
% \edef\p_type{}%
710
% \ifx\p_type\v!next
711
% \doifelseoddpage
712
% {\letpagegridareaparameter\c!type\v!right}%
713
% {\letpagegridareaparameter\c!type\v!left}%
714
% \fi
715
\clf_registercolumnsetarea
{
716
name
{
\currentpagegridarea
}
717
% type {\p_type}
718
% page \pagegridareaparameter\c!page
719
state
{
\pagegridareaparameter
\c!state
}
720
c
\pagegridareaparameter
\c!x
721
r
\pagegridareaparameter
\c!y
722
nc
\pagegridareaparameter
\c!nx
723
nr
\pagegridareaparameter
\c!ny
724
}
%
725
\to
\everydefinepagegridarea
726 727
\unexpanded
\def
\setuppagegridareatext
728
{
\dodoubleargument
\page_grd_set_area_text
}
729 730
\def
\page_grd_set_area_text
[#
1
][#
2
]
%
731
{
\edef
\currentpagegridarea
{
#
1
}
%
732
\setpagegridareaparameter
\c!text
{
#
2
}}
733 734
% maybe move the left/right correction to the tex end or the offset to lua
735 736
\unexpanded
\def
\page_grd_set_area
#
1
#
2
#
3
#
4
#
5
#
6
#
7
#
8
% can be optimized
737
{
\begingroup
738
\edef
\currentpagegridarea
{
#
2
}
%
739
\setpagegridareaparameter
\c!width
{
#
5
\scaledpoint
}
%
740
\setpagegridareaparameter
\c!height
{
#
6
\scaledpoint
}
%
741
\setbox
\nextbox
\hpack
\bgroup
\inheritedpagegridareaframed
\bgroup
742
\usepagegridareastyleandcolor
\c!style\c!color
743
\ignorespaces
744
\pagegridareaparameter
\c!text
745
\egroup\egroup
746
%
747
\scratchdimen
#
8
\scaledpoint
748
\ifdim
\scratchdimen
>
\zeropoint
749
\setbox
\scratchbox
\vbox
\bgroup
750
\clip
751
[
\c!offset
=
\pagegridareaparameter
\c!clipoffset
,
%
752
\c!rightoffset
=
\pagegridareaparameter
\c!rightoffset
,
%
753
\c!width
=
\scratchdimen
,
%
754
% \c!height=
755
]
%
756
{
\copy
\nextbox
}
%
757
\egroup
758
\clf_setcolumnsetarea
{
name
{
#
1
}
box
\scratchbox
c
#
3
r
#
4
}
%
759
\setbox
\scratchbox
\vbox
\bgroup
760
\hskip
-
\layoutparameter
\c!backspace
% todo: #9
761
\clip
762
[
\c!offset
=
\pagegridareaparameter
\c!clipoffset
,
%
763
\c!leftoffset
=
\pagegridareaparameter
\c!rightoffset
,
%
764
\c!hoffset
=
\scratchdimen
,
%
765
\c!width
=
\dimexpr\wd
\nextbox
-
\scratchdimen
\relax
,
%
766
% \c!height=
767
]
%
768
{
\box
\nextbox
}
%
769
\egroup
770
\clf_setcolumnsetarea
{
name
{
#
1
}
box
\scratchbox
c
#
7
r
#
4
}
%
771
\else
772
\setbox
\scratchbox
\vbox
\bgroup
773
\box
\nextbox
% wrapping needed
774
\egroup
775
\clf_setcolumnsetarea
{
name
{
#
1
}
box
\scratchbox
c
#
3
r
#
4
}
%
776
\fi
777
\endgroup
}
778 779
\let
\setpagegridarea
\page_grd_set_area
780 781
% state start | repeat
782 783
%D The old one:
784 785
\let
\definecolumnset
\definepagegrid
786
\let
\setupcolumnset
\setuppagegrid
787
\let
\setupcolumnsetlines
\setuppagegridlines
788
\let
\setupcolumnsetstart
\setuppagegridstart
789
\let
\startcolumnset
\startpagegrid
790
\let
\stopcolumnset
\stoppagegrid
791
\let
\definecolumnsetspan
\definepagegridspan
792
\let
\setupcolumnsetspan
\setuppagegridspan
793
\let
\startcolumnsetspan
\startpagegridspan
794
\let
\stopcolumnsetspan
\stoppagegridspan
795
\let
\columnsetspanwidth
\pagegridspanwidth
796
\let
\definecolumnsetarea
\definepagegridarea
797
\let
\setupcolumnsetarea
\setuppagegridarea
798
\let
\setupcolumnsetareatext
\setuppagegridareatext
799 800
%D It ends here.
801 802
\protect
\endinput
803