tabl-frm.mkiv /size: 7763 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=tabl-frm,
3
%D version=2017.04.11,
4
%D title=\CONTEXT\ Table Macros,
5
%D subtitle=Framed Tables,
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
%D For Thomas Schmitz who needed 3000 pages long tables.
15 16
\unprotect
17 18
\writestatus
{
loading
}{
ConTeXt
Table
Macros
/
Framed
Tables
}
19 20
\installcorenamespace
{
framedtable
}
21
\installcorenamespace
{
framedtablerow
}
22
\installcorenamespace
{
framedtablecolumn
}
23 24
\newcount
\c_tabl_framed_c
25
\newcount
\c_tabl_framed_r
26
\newdimen
\d_tabl_framed_h
27
\newdimen
\d_tabl_framed_d
28
\newdimen
\b_tabl_framed
29 30
\initializeboxstack
\??framedtable
31 32
\defineframed
[
\??framedtable
]
33
\defineframed
[
\??framedtablerow
][
\??framedtable
]
34
\defineframed
[
\??framedtablecolumn
][
\??framedtable
]
35 36
\setupframed
37
[
\??framedtable
]
38
[
\c!distance
=
\zeropoint
,
39
\c!before
=
,
40
\c!after
=
,
41
\c!inbetween
=]
42 43
\setupframed
44
[
\??framedtablerow
]
45
[
\c!strut
=
\v!no
,
46
\c!offset
=
\v!overlay
]
47 48
% \defineframedtable[foo]
49
% \defineframedtable[bar][foo]
50 51
\unexpanded
\def
\defineframedtable
52
{
\dodoubleempty
\tabl_framed_define
}
53 54
\def
\tabl_framed_define
[#
1
][#
2
]
%
55
{
\ifsecondargument
56
\defineframed
[
\??framedtable
#
1
][
\??framedtable
#
2
]
%
57
\else
\iffirstargument
58
\defineframed
[
\??framedtable
#
1
][
\??framedtable
]
%
59
\fi\fi
}
60 61
% \setupframedtable[foo][...]
62 63
\unexpanded
\def
\setupframedtable
64
{
\dodoubleempty
\tabl_framed_setup
}
65 66
\def
\tabl_framed_setup
[#
1
][#
2
]
%
67
{
\ifsecondargument
68
\ifcsname
\??framed
:
\??framedtable
#
1
\endcsname
\else
69
\defineframed
[
\??framedtable
#
1
][
\??framedtable
]
%
70
\fi
71
\setupframed
[
\??framedtable
#
1
][#
2
]
%
72
\else
73
\setupframed
[
\??framedtable
][#
1
]
%
74
\fi
}
75 76
% \setupframedtable[1][...]
77
% \setupframedtable[foo][1][...]
78 79
\unexpanded
\def
\setupframedtablerow
80
{
\dotripleempty
\tabl_framed_setup_row
}
81 82
\def
\tabl_framed_setup_row
[#
1
][#
2
][#
3
]
%
83
{
\ifthirdargument
84
\ifcsname
\??framed
:
\??framedtable
#
1
\endcsname
\else
85
\defineframed
[
\??framedtable
#
1
][
\??framedtable
]
%
86
\fi
87
\ifcsname
\??framed
:
\??framedtablerow
#
1
:
#
2
\endcsname
\else
88
\defineframed
[
\??framedtablerow
#
1
:
#
2
][
\??framedtable
#
1
]
%
89
\fi
90
\setupframed
[
\??framedtablerow
#
1
:
#
2
][#
3
]
%
91
\else
\ifsecondargument
92
\ifcsname
\??framed
:
\??framedtablerow
:
#
1
\endcsname
\else
93
\defineframed
[
\??framedtablerow
:
#
1
][
\??framedtable
]
%
94
\fi
95
\setupframed
[
\??framedtablerow
:
#
1
][#
2
]
%
96
\fi\fi
}
97 98
\unexpanded
\def
\setupframedtablecolumn
99
{
\dotripleempty
\tabl_framed_setup_column
}
100 101
\def
\tabl_framed_setup_column
[#
1
][#
2
][#
3
]
%
102
{
\ifthirdargument
103
\ifcsname
\??framed
:
\??framedtable
#
1
\endcsname
\else
104
\defineframed
[
\??framedtable
#
1
][
\??framedtable
]
%
105
\fi
106
\ifcsname
\??framed
:
\??framedtablecolumn
#
1
:
#
2
\endcsname
\else
107
\defineframed
[
\??framedtablecolumn
#
1
:
#
2
][
\??framedtable
#
1
]
%
108
\fi
109
\setupframed
[
\??framedtablecolumn
#
1
:
#
2
][#
3
]
%
110
\else
\ifsecondargument
111
\ifcsname
\??framed
:
\??framedtablecolumn
:
#
1
\endcsname
\else
112
\defineframed
[
\??framedtablecolumn
:
#
1
][
\??framedtable
]
%
113
\fi
114
\setupframed
[
\??framedtablecolumn
:
#
1
][#
2
]
%
115
\fi\fi
}
116 117
\unexpanded
\def
\startframedtable
118
{
\dodoubleempty
\tabl_framed_start
}
119 120
\unexpanded
\def
\tabl_framed_start
[#
1
][#
2
]
%
121
{
\begingroup
122
\forgetall
123
\doifelseassignment
{
#
1
}
%
124
{
\let
\currentframedtable
\empty
125
\setupframed
[
\??framedtable
][#
1
]
}
%
126
{
\edef
\currentframedtable
{
#
1
}
%
127
\setupframed
[
\??framedtable
][#
2
]
}
%
128
\edef
\currentframed
{
\??framedtable
\currentframedtable
}
%
129
\c_tabl_framed_r
\zerocount
130
\d_tabl_framed_d
\framedparameter
\c!distance
131
\framedparameter
\c!before
}
132 133
\unexpanded
\def
\stopframedtable
134
{
\framedparameter
\c!after
135
\endgroup
}
136 137
% a two pass variant that deals with the height .. so no catcode changes here
138 139
\unexpanded
\def
\startframedrow
140
{
\advance
\c_tabl_framed_r
\plusone
141
\c_tabl_framed_c
\zerocount
142
\d_tabl_framed_h
\zeropoint
143
\bgroup
144
\edef
\currentframed
{
\number
\c_tabl_framed_r
}
%
145
\edef
\currentframed
146
{
\??framedtablerow
\currentframedtable
147
\ifcsname
\??framedtablerow
\currentframedtable
:
\currentframed
\endcsname
148
:
\currentframed
149
\else\ifcsname
\??framedtablerow
\currentframedtable
:
\v!each
\endcsname
150
:
\v!each
151
\fi\fi
}
%
152
\dosingleempty
\pack_framed_start_framed_nop_indeed
}
153 154
\unexpanded
\def
\stopframedrow
155
{
\dofastloopcs
\c_tabl_framed_c
\tabl_framed_flush_row
156
\stopframed
157
\nointerlineskip
158
\vskip
\zeropoint
\relax
159
\framedparameter
\c!inbetween
}
160 161
\unexpanded
\def
\tabl_framed_flush_row
162
{
\vpack
to
\d_tabl_framed_h
{
\flushbox
\??framedtable
{
\number
\fastloopindex
}
\vfill
}
%
163
\ifzeropt
\d_tabl_framed_d
\else\kern
\d_tabl_framed_d
\fi
}
164 165
\newcount
\c_tabl_framed_pass
166 167
\let
\stopframedrow
\relax
168 169
\unexpanded
\def
\startframedrow
#
1
\stopframedrow
170
{
\advance
\c_tabl_framed_r
\plusone
171
\startframedrow_one
#
1
\stopframedrow_one
172
\startframedrow_two
#
1
\stopframedrow_two
}
173 174
\def
\startframedrow_one
175
{
\bgroup
176
\c_tabl_framed_pass
\plusone
177
\c_tabl_framed_c
\zerocount
178
\d_tabl_framed_h
\zeropoint
179
\settrialtypesetting
180
\gobblesingleempty
}
181 182
\unexpanded
\def
\stopframedrow_one
183
{
\normalexpanded
{
\egroup
\d_tabl_framed_h
\the
\d_tabl_framed_h
\relax
}}
184 185
\def
\startframedrow_two
186
{
\bgroup
187
\c_tabl_framed_c
\zerocount
188
\c_tabl_framed_pass
\plustwo
189
\edef
\currentframed
{
\number
\c_tabl_framed_r
}
%
190
\edef
\currentframed
191
{
\??framedtablerow
\currentframedtable
192
\ifcsname
\??framedtablerow
\currentframedtable
:
\currentframed
\endcsname
193
:
\currentframed
194
\else\ifcsname
\??framedtablerow
\currentframedtable
:
\v!each
\endcsname
195
:
\v!each
196
\fi\fi
}
%
197
\dosingleempty
\pack_framed_start_framed_nop_indeed
}
198 199
\unexpanded
\def
\stopframedrow_two
200
{
\dofastloopcs
\c_tabl_framed_c
\tabl_framed_flush_row
201
\stopframed
202
\nointerlineskip
203
\vskip
\zeropoint
\relax
204
\framedparameter
\c!inbetween
}
205 206
\unexpanded
\def
\tabl_framed_flush_row_two
207
{
\vpack
to
\d_tabl_framed_h
{
\flushbox
\??framedtable
{
\number
\fastloopindex
}
\vfill
}
%
208
\ifzeropt
\d_tabl_framed_d
\else\kern
\d_tabl_framed_d
\fi
}
209 210 211
\unexpanded
\def
\startframedcell
212
{
\advance
\c_tabl_framed_c
\plusone
213
\setbox
\b_tabl_framed
\hpack
\bgroup
214
%\bgroup
215
\edef
\currentframed
{
\number
\c_tabl_framed_c
}
%
216
\edef
\currentframed
217
{
\??framedtablecolumn
\currentframedtable
218
\ifcsname
\??framedtablecolumn
\currentframedtable
:
\currentframed
\endcsname
219
:
\currentframed
220
\else\ifcsname
\??framedtablecolumn
\currentframedtable
:
\v!each
\endcsname
221
:
\v!each
222
\fi\fi
}
%
223
\ifcase
\c_tabl_framed_pass
224
\or
225
\letframedparameter
\c!background
\empty
226
\letframedparameter
\c!frame\v!off
227
\or
228
\letframedparameter
\c!height
\d_tabl_framed_h
229
\fi
230
\dosingleempty
\pack_framed_start_framed_nop_indeed
}
231 232
\unexpanded
\def
\stopframedcell
233
{
\stopframed
234
%\egroup
235
\ifcase
\c_tabl_framed_pass
236
\or
237
\ifdim
\ht
\b_tabl_framed
>
\d_tabl_framed_h
238
\d_tabl_framed_h
\ht
\b_tabl_framed
239
\fi
240
\else
241
\savebox
\??framedtable
{
\number
\c_tabl_framed_c
}{
\box
\b_tabl_framed
}
%
242
\fi
}
243 244
\protect
\endinput
245 246
\starttext
247 248
\setupframedtablecolumn
[
1
]
[
width
=
3
cm
,
background
=
color
,
backgroundcolor
=
red
]
249
\setupframedtablecolumn
[
2
]
[
width
=
4
cm
,
background
=
color
,
backgroundcolor
=
green
,
align
=
normal
]
250
% \setupframedtablerow [each] [background=color,backgroundcolor=blue,strut=no]
251
% \setupframedtablerow [each] [strut=no,offset=overlay]
252 253
\startframedtable
[
inbetween
=
\kern
-
0
.
4
pt
,
distance
=
-
0
.
4
pt
]
254 255
\testfeatureonce
{
1
0
0
0
0
}{
256
% \testfeatureonce{10}{
257
\startframedrow
258
\startframedcell
%[backgroundcolor=yellow]
259
test
260
\stopframedcell
261
\startframedcell
262
test
\par
test
263
\stopframedcell
264
\stopframedrow
265
}
266
\stopframedtable
267 268
\stoptext
269