1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16\writestatus{loading}{ConTeXt Spacing Macros Grid Snapping}
17
18\unprotect
19
20
21
22
23\installcorenamespace{lastnodepusher}
24
25\let\poplastnode\relax
26
27\unexpanded\def\pushlastnode
28 {\csname\??lastnodepusher
29 \ifcsname\??lastnodepusher\the\lastnodetype\endcsname
30 \the\lastnodetype
31 \else
32 \s!unknown
33 \fi
34 \endcsname}
35
36\setvalue{\??lastnodepusher\number\kernnodecode}
37 {\unexpanded\edef\poplastnode{\kern\the\lastkern\relax}
38 \kern\lastkern}
39
40\setvalue{\??lastnodepusher\number\gluenodecode}
41 {\unexpanded\edef\poplastnode{\vskip\the\lastskip\relax}
42 \vskip\lastskip}
43
44\setvalue{\??lastnodepusher\number\penaltynodecode}
45 {\unexpanded\edef\poplastnode{\penalty\the\lastpenalty\relax}
46 \nobreak}
47
48\setvalue{\??lastnodepusher\s!unknown}
49 {\let\poplastnode\relax}
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104\newdimen\d_spac_lines_correction_before
105\newdimen\d_spac_lines_correction_after
106
107\newbox \b_spac_lines_correction_before
108\newbox \b_spac_lines_correction_after
109
110\def\spac_lines_initialize_corrections
111 {\setbox\b_spac_lines_correction_before\hpack{\setstrut\strut}
112 \setbox\b_spac_lines_correction_after \hbox {(}
113 \d_spac_lines_correction_before\dimexpr\ht\b_spac_lines_correction_before\ht\b_spac_lines_correction_after\relax
114 \d_spac_lines_correction_after \dimexpr\dp\b_spac_lines_correction_before\dp\b_spac_lines_correction_after\relax
115 \ifdim\d_spac_lines_correction_before<\zeropoint\d_spac_lines_correction_before\zeropoint\fi
116 \ifdim\d_spac_lines_correction_after <\zeropoint\d_spac_lines_correction_after \zeropoint\fi}
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139\unexpanded\def\dotopbaselinecorrection{\expandafter\blank\expandafter[\the\d_spac_lines_correction_before]}
140\unexpanded\def\dobotbaselinecorrection{\expandafter\blank\expandafter[\the\d_spac_lines_correction_after ]}
141
142\def\showbaselinecorrection
143 {\def\dobaselinecorrection
144 {\bgroup
145 \ifdim\prevdepth>\zeropoint
146 \kern\prevdepth
147 \fi
148 \setbox\scratchbox\emptyhbox
149 \wd\scratchbox\hsize
150 \dp\scratchbox\strutdp
151 \nointerlineskip
152 \forgetall
153 \ruledvpack{\box\scratchbox}
154 \egroup
155 \prevdepth\strutdp}
156 \def\dotopbaselinecorrection
157 {\hrule\s!height\d_spac_lines_correction_before}
158 \def\dobotbaselinecorrection
159 {\hrule\s!height\d_spac_lines_correction_after}}
160
161\def\dobaselinecorrection
162 {\ifdim\prevdepth>\zeropoint\kern\prevdepth\fi
163 \kern\strutdp
164 \prevdepth\strutdp}
165
166\def\baselinecorrection
167 {\endgraf
168 \ifvmode
169 \ifdim\prevdepth<\maxdimen
170 \ifdim\prevdepth<\zeropoint \else
171 \ifdim\prevdepth<\strutdepth \relax
172 \pushlastnode
173 \dobaselinecorrection
174 \poplastnode
175 \fi
176 \fi
177 \fi
178 \fi}
179
180\def\pagebaselinecorrection
181 {\ifdim\pagegoal<\maxdimen
182 \ifdim\pagetotal>\lineheight
183 \scratchdimen\pagetotal
184 \advance\scratchdimen\lineheight
185 \ifdim\scratchdimen<\pagegoal
186 \baselinecorrection
187 \fi
188 \fi
189 \fi}
190
191\unexpanded\def\startbaselinecorrection
192 {\bgroup
193 \let\stopbaselinecorrection\egroup
194 \ifcase\baselinecorrectionmode
195 \or
196 \baselinecorrection
197 \ifvmode
198 \setbox\scratchbox\vbox\bgroup\ignorespaces
199 \let\stopbaselinecorrection\donormalstopbaselinecorrection
200 \fi
201 \or
202 \or
203 \baselinecorrection
204 \ifvmode
205 \setbox\scratchbox\vbox\bgroup\ignorespaces
206 \let\stopbaselinecorrection\doforcedstopbaselinecorrection
207 \fi
208 \fi}
209
210\let\stopbaselinecorrection\relax
211
212\def\donormalstopbaselinecorrection
213 {\egroup
214 \topbaselinecorrection
215 \box\scratchbox
216 \botbaselinecorrection
217 \egroup}
218
219\def\doforcedstopbaselinecorrection
220 {\egroup
221 \forcedtopbaselinecorrection
222 \box\scratchbox
223 \forcedbotbaselinecorrection
224 \egroup}
225
226
227
228
229
230\setnewconstant\baselinecorrectionmode\plusone
231
232\def\onbaselinecorrection {\baselinecorrectionmode\plusone }
233\def\offbaselinecorrection {\baselinecorrectionmode\plustwo }
234\def\forcebaselinecorrection{\baselinecorrectionmode\plusthree}
235
236
237
238
239
240
241\def\topbaselinecorrection
242 {\ifvmode \ifdim\pagegoal<\maxdimen
243 \forcedtopbaselinecorrection
244 \fi \fi}
245
246\def\forcedtopbaselinecorrection
247 {\ifvmode
248 \bgroup
249 \spac_lines_initialize_corrections
250 \whitespace
251 \nointerlineskip
252 \dotopbaselinecorrection
253 \egroup
254 \fi}
255
256\def\botbaselinecorrection
257 {\ifvmode
258 \bgroup
259 \spac_lines_initialize_corrections
260 \dobotbaselinecorrection
261 \allowbreak
262 \prevdepth\strutdp
263 \egroup
264 \fi}
265
266\let\forcedbotbaselinecorrection\botbaselinecorrection
267
268
269
270
271
272
273
274
275\def\forcedtopbaselinecorrection
276 {\ifvmode
277 \bgroup
278 \spac_lines_initialize_corrections
279 \vspacing[\v!white]
280
281 \dotopbaselinecorrection
282 \egroup
283\fi}
284
285\def\dobaselinecorrection
286 {\ifdim\prevdepth>\zeropoint
287 \vspacing[\the\dimexpr\prevdepth\strutdp\relax]
288 \else
289 \vspacing[\the\dimexpr\strutdp\relax]
290 \fi
291 \prevdepth\strutdp}
292
293\let\normalstartbaselinecorrection\startbaselinecorrection
294
295\unexpanded\def\startbaselinecorrection
296 {\ifgridsnapping
297 \snaptogrid[\v!normal]\vbox\bgroup
298 \let\stopbaselinecorrection\egroup
299 \else
300 \normalstartbaselinecorrection
301 \fi}
302
303
304
305
306
307
308
309\let\checkprevdepth\baselinecorrection
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343\protect \endinput
344 |