summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/tabl-xtb.mkvi
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/tabl-xtb.mkvi')
-rw-r--r--tex/context/base/mkiv/tabl-xtb.mkvi149
1 files changed, 143 insertions, 6 deletions
diff --git a/tex/context/base/mkiv/tabl-xtb.mkvi b/tex/context/base/mkiv/tabl-xtb.mkvi
index dc4a30e2b..148304331 100644
--- a/tex/context/base/mkiv/tabl-xtb.mkvi
+++ b/tex/context/base/mkiv/tabl-xtb.mkvi
@@ -102,6 +102,10 @@
\newcount\c_tabl_x_nesting
\newcount\c_tabl_x_skip_mode % 1 = skip
\newdimen\d_tabl_x_textwidth
+\newcount\c_tabl_x_swapped
+\newcount\c_tabl_x_swapped_max
+
+\let\m_tabl_x_swapped_settings\empty
\let\currentxtablerow \clf_x_table_r
\let\currentxtablecolumn\clf_x_table_c
@@ -112,6 +116,7 @@
\installcorenamespace{xtable}
\installcorenamespace{xtablecheck}
+\installcorenamespace{xtableswap}
\installframedautocommandhandler \??xtable {xtable} \??xtable
@@ -271,6 +276,8 @@
\let\tabl_x_start_cell_nop\relax
\let\tabl_x_stop_cell \relax
+\newtoks\t_table_x_cleanup
+
\unexpanded\def\tabl_x_process
{\begingroup % *
\forgetall % moved here
@@ -296,6 +303,7 @@
% not so nice but needed as we use this in the setup
\linewidth\xtableparameter\c!rulethickness\relax
% so we freeze it
+ \c_tabl_x_swapped_max\zerocount
\begingroup
\let\tabl_x_start_row_yes \tabl_x_start_row_reflow_width_yes
\let\tabl_x_start_row_nop \tabl_x_start_row_reflow_width_nop
@@ -305,6 +313,10 @@
\let\tabl_x_stop_cell \tabl_x_stop_cell_reflow_width
\settrialtypesetting
\tabl_x_get_buffer
+ \ifcase\c_tabl_x_swapped_max
+ \else
+ \tabl_x_flush_swapped
+ \fi
\clf_x_table_reflow_width
\endgroup
\begingroup
@@ -315,7 +327,11 @@
\let\tabl_x_start_cell_nop\tabl_x_start_cell_reflow_height_nop
\let\tabl_x_stop_cell \tabl_x_stop_cell_reflow_height
\settrialtypesetting
- \tabl_x_get_buffer
+ \ifcase\c_tabl_x_swapped_max
+ \tabl_x_get_buffer
+ \else
+ \tabl_x_flush_swapped
+ \fi
\clf_x_table_reflow_height
\endgroup
\begingroup
@@ -325,7 +341,11 @@
\let\tabl_x_start_cell_yes\tabl_x_start_cell_construct_yes
\let\tabl_x_start_cell_nop\tabl_x_start_cell_construct_nop
\let\tabl_x_stop_cell \tabl_x_stop_cell_construct
- \tabl_x_get_buffer
+ \ifcase\c_tabl_x_swapped_max
+ \tabl_x_get_buffer
+ \else
+ \tabl_x_flush_swapped
+ \fi
\clf_x_table_construct
\endgroup
\endgroup % *
@@ -340,6 +360,7 @@
\dostoptagged
\resetbuffer[\tabl_x_current_buffer]%
\resetcharacteralign
+ \the\t_table_x_cleanup
\egroup}
% text flow split modes
@@ -477,10 +498,6 @@
\unexpanded\def\stopxcell
{\tabl_x_stop_cell}
-\unexpanded\def\dummyxcell#1%
- {\tabl_x_start_cell_nop
- \tabl_x_stop_cell}
-
\unexpanded\def\dummyxcell
{\tabl_x_start_cell_nop
\tabl_x_stop_cell}
@@ -879,4 +896,124 @@
\let\NR\tabl_x_nr
\to \everypreparextable
+%D Another bonus, suggested by Taco at the 2018 \CONTEXT\ meeting.
+
+\unexpanded\def\tabl_x_c_cell_start#settings%
+ {\begingroup
+ \tabl_x_set_checked{#settings}%
+ \doifelsenextoptionalcs\tabl_x_start_cell_yes\tabl_x_start_cell_nop}
+
+\unexpanded\def\tabl_x_c_cell_stop
+ {\tabl_x_stop_cell
+ \endgroup}
+
+% \unexpanded\def\dummyxcell
+% {\tabl_x_start_cell_nop
+% \tabl_x_stop_cell}
+
+\def\tabl_x_flush_swapped
+ {\dorecurse\c_tabl_x_swapped_max
+ {\expandafter
+ \startxrow
+ \the\csname\??xtableswap##1\endcsname\relax
+ \stopxrow}}
+
+\def\tabl_x_collect_allocate
+ {\expandafter\newtoks\csname\??xtableswap\number\c_tabl_x_swapped\endcsname
+ \expandafter\let\expandafter\t_tabl_x_swapped\csname\??xtableswap\number\c_tabl_x_swapped\endcsname}
+
+\def\tabl_x_collect_advance
+ {\global\advance\c_tabl_x_swapped\plusone
+ \ifnum\c_tabl_x_swapped>\c_tabl_x_swapped_max
+ \global\c_tabl_x_swapped_max\c_tabl_x_swapped
+ \fi
+ \expandafter\let\expandafter\t_tabl_x_swapped\csname\??xtableswap\number\c_tabl_x_swapped\endcsname
+ \ifx\t_tabl_x_swapped\relax
+ \tabl_x_collect_allocate
+ \fi}
+
+\unexpanded\def\tabl_x_collect_cell_start
+ {\doifelsenextoptionalcs
+ \tabl_x_collect_cell_start_yes
+ \tabl_x_collect_cell_start_nop}
+
+\def\tabl_x_collect_cell_start_nop#content\stopxcell
+ {\tabl_x_collect_advance
+ \ifx\m_tabl_x_swapped_settings\empty
+ \gtoksapp\t_tabl_x_swapped{\tabl_x_c_cell_start{}#content\tabl_x_c_cell_stop}%
+ \else
+ \gtoksapp\t_tabl_x_swapped\expandafter{\expandafter\tabl_x_c_cell_start\expandafter{\m_tabl_x_swapped_settings}#content\tabl_x_c_cell_stop}%
+ \fi}
+
+\def\tabl_x_collect_cell_start_yes[#settings]#content\stopxcell
+ {\tabl_x_collect_advance
+ \ifx\m_tabl_x_swapped_settings\empty
+ \gtoksapp\t_tabl_x_swapped{\tabl_x_c_cell_start{}[#settings]#content\tabl_x_c_cell_stop}%
+ \else
+ \gtoksapp\t_tabl_x_swapped\expandafter{\expandafter\tabl_x_c_cell_start\expandafter{\m_tabl_x_swapped_settings}[#settings]#content\tabl_x_c_cell_stop}%
+ \fi
+ \getdummyparameters[\c!ny=1,#settings]%
+ \scratchcounter\numexpr\dummyparameter\c!ny-\plusone\relax
+ \ifcase\scratchcounter\else
+ \dorecurse\scratchcounter\tabl_x_collect_advance
+ \fi}
+
+\unexpanded\def\startxcolumn % todo: arguments
+ {\begingroup
+ \global\c_tabl_x_swapped\zerocount
+ \let\startxcell\tabl_x_collect_cell_start
+ \let\stopxcell \relax
+ \doifelsenextoptionalcs\tabl_x_start_column_yes\tabl_x_start_column_nop}
+
+\def\tabl_x_start_column_yes[#1]%
+ {\xdef\m_tabl_x_swapped_settings{#1}}
+
+\def\tabl_x_start_column_nop
+ {\glet\m_tabl_x_swapped_settings\empty}
+
+\unexpanded\def\stopxcolumn
+ {\endgroup}
+
+\appendtoks
+ \dorecurse\c_tabl_x_swapped_max
+ {\global\csname\??xtableswap\number#1\endcsname\emptytoks}%
+\to \t_table_x_cleanup
+
+%D \stopbuffer
+%D \setupxtable[one][foregroundcolor=red]
+%D \setupxtable[two][foregroundcolor=blue]
+%D
+%D \startlinecorrection
+%D \startxtable
+%D \startxrow[one]
+%D \startxcell[width=5cm] Row 1, Column 1 \stopxcell
+%D \startxcell Row 1, Column 2 \stopxcell
+%D \startxcell Row 1, Column 3 \stopxcell
+%D \stopxrow
+%D \startxrow[two]
+%D \startxcell Row 2, Column 1 \stopxcell
+%D \startxcell Row 2, Column 2 \stopxcell
+%D \startxcell Row 2, Column 3 \stopxcell
+%D \stopxrow
+%D \stopxtable
+%D \stoplinecorrection
+%D
+%D \startlinecorrection
+%D \startxtable
+%D \startxcolumn[one]
+%D \startxcell[width=5cm] Row 1, Column 1 \stopxcell
+%D \startxcell Row 1, Column 2 \stopxcell
+%D \startxcell Row 1, Column 3 \stopxcell
+%D \stopxcolumn
+%D \startxcolumn[two]
+%D \startxcell Row 2, Column 1 \stopxcell
+%D \startxcell Row 2, Column 2 \stopxcell
+%D \startxcell Row 2, Column 3 \stopxcell
+%D \stopxcolumn
+%D \stopxtable
+%D \stoplinecorrection
+%D \stopbuffer
+%D
+%D \typebuffer \getbuffer
+
\protect \endinput