summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mkxl/pack-box.mkxl
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/context/base/mkxl/pack-box.mkxl')
-rw-r--r--Master/texmf-dist/tex/context/base/mkxl/pack-box.mkxl316
1 files changed, 268 insertions, 48 deletions
diff --git a/Master/texmf-dist/tex/context/base/mkxl/pack-box.mkxl b/Master/texmf-dist/tex/context/base/mkxl/pack-box.mkxl
index 77b0bbc69c8..5a66d394598 100644
--- a/Master/texmf-dist/tex/context/base/mkxl/pack-box.mkxl
+++ b/Master/texmf-dist/tex/context/base/mkxl/pack-box.mkxl
@@ -51,10 +51,10 @@
%
% \anchor[text-1][preset=lefttop][framed settings]{HELLO WORLD}
-\mutable\let\currentanchor\empty
+\mutable\lettonothing\currentanchor
\permanent\tolerant\protected\def\defineanchor[#1]#*[#2]#*[#3]#*[#4]% name targetlayer layersetting framedsetting
- {\setvalue{\??anchor#1}{\pack_anchors_process_defined{#2}{#3}{#4}}}
+ {\defcsname\??anchor#1\endcsname{\pack_anchors_process_defined{#2}{#3}{#4}}}
\let\pack_anchors_process_defined_indeed\gobbletwooptionals
@@ -92,18 +92,18 @@
\def\pack_anchor_notdefined_two #1#2{\dowithnextbox{\pack_anchors_process_finish\currentanchor{#1}{#2}}\vbox}
\def\pack_anchors_process_indeed#1#2#3{\dowithnextbox{\pack_anchors_process_finish {#1}{#2}{#3}}\vbox}
-\newbox \b_pack_anchors
-\newdimen\d_pack_anchors_width
-\newdimen\d_pack_anchors_height
-\newdimen\d_pack_anchors_depth
+\newbox \b_pack_anchors
+\newdimension\d_pack_anchors_width
+\newdimension\d_pack_anchors_height
+\newdimension\d_pack_anchors_depth
% \definelayer[anchor]
-\newcount\c_pack_anchors_n
-\newtoks \t_pack_anchors_flush
+\newinteger\c_pack_anchors_n
+\newtoks \t_pack_anchors_flush
\protected\def\pack_anchors_register#1#2%
- {\global\advance\c_pack_anchors_n\plusone
+ {\global\advanceby\c_pack_anchors_n\plusone
\pagereference[\v!layer:\v!anchor:\number\c_pack_anchors_n]%
\putboxincache\v!anchor{\number\c_pack_anchors_n}\b_pack_anchors
% \xtoksapp\t_pack_anchors_flush{\pack_anchors_flush{\number\c_pack_anchors_n}{#1}{#2}}%
@@ -228,23 +228,23 @@
\installcorenamespace{collectorcorners}
-\setvalue{\??collectorcorners\v!middle}%
+\defcsname\??collectorcorners\v!middle\endcsname
{\ifdim\d_pack_layers_x_size>\zeropoint
- \advance\d_pack_layers_x_position.5\d_pack_layers_x_size
+ \advanceby\d_pack_layers_x_position.5\d_pack_layers_x_size
\fi
\ifdim\d_pack_layers_y_size>\zeropoint
- \advance\d_pack_layers_y_position.5\d_pack_layers_y_size
+ \advanceby\d_pack_layers_y_position.5\d_pack_layers_y_size
\fi}
-\setvalue{\??collectorcorners\v!bottom}%
+\defcsname\??collectorcorners\v!bottom\endcsname
{\ifdim\d_pack_layers_y_size>\zeropoint
- \advance\d_pack_layers_y_position-\d_pack_layers_y_size
+ \advanceby\d_pack_layers_y_position-\d_pack_layers_y_size
\d_pack_layers_y_position-\d_pack_layers_y_position
\fi}
-\setvalue{\??collectorcorners\v!right}%
+\defcsname\??collectorcorners\v!right\endcsname
{\ifdim\d_pack_layers_x_size>\zeropoint
- \advance\d_pack_layers_x_position-\d_pack_layers_x_size
+ \advanceby\d_pack_layers_x_position-\d_pack_layers_x_size
\d_pack_layers_x_position-\d_pack_layers_x_position
\fi}
@@ -271,13 +271,13 @@
\setbox\nextbox\hpack
{\alignedbox[\collectorparameter\c!location]\vpack{\box\nextbox}}%
\boxmaxdepth\zeropoint % really needed, nice example
- \global\advance\boxhdisplacement\d_pack_layers_x_position
+ \global\advanceby\boxhdisplacement\d_pack_layers_x_position
\ifdim\boxhdisplacement<\zeropoint
\global\setbox\b_pack_boxes_collector\hpack
{\kern-\boxhdisplacement
\box\b_pack_boxes_collector}%
\fi
- \global\advance\boxvdisplacement\d_pack_layers_y_position
+ \global\advanceby\boxvdisplacement\d_pack_layers_y_position
\ifdim\boxvdisplacement<\zeropoint
\global\setbox\b_pack_boxes_collector\hpack
{\lower-\boxvdisplacement
@@ -359,8 +359,8 @@
{\box\nextbox}%
\setcollector
[caption][#1]%
- {\letdummyparameter\c!style\empty
- \letdummyparameter\c!color\empty
+ {\resetdummyparameter\c!style
+ \resetdummyparameter\c!color
\getdummyparameters[#2]%
\dousestyleparameter{\directdummyparameter\c!style}%
\setupinterlinespace
@@ -393,8 +393,8 @@
\installsimpleframedcommandhandler \??layeredtext {layeredtext} \??layeredtext
-\newdimen\d_pack_layeredtexts_width
-\newdimen\d_pack_layeredtexts_height
+\newdimension\d_pack_layeredtexts_width
+\newdimension\d_pack_layeredtexts_height
\definelayer % private
[\??layeredtextlayer]
@@ -465,7 +465,7 @@
\permanent\tolerant\protected\def\ornamenttext[#1]#*[#2]% takes another argument
{\bgroup
- \doifelseassignment{#1}
+ \doifelseassignment{#1}%
{\letdummyparameter\c!alternative\v!a
\getdummyparameters[#1]%
\doifelse{\directdummyparameter\c!alternative}\v!a
@@ -509,7 +509,7 @@
%
% \affiliation{drawing}{\externalfigure[hakker][width=3cm]}
-\newcount\c_pack_boxes_bleeds
+\newinteger\c_pack_boxes_bleeds
\installcorenamespace {bleeding}
@@ -535,25 +535,25 @@
\installcorenamespace{bleedinglocation}
-\setvalue{\??bleedinglocation t}{\settrue\c_pack_boxes_t\scratchhoffset\zeropoint}
-\setvalue{\??bleedinglocation b}{\settrue\c_pack_boxes_b\scratchhoffset\zeropoint}
-\setvalue{\??bleedinglocation l}{\settrue\c_pack_boxes_l\scratchvoffset\zeropoint}
-\setvalue{\??bleedinglocation r}{\settrue\c_pack_boxes_r\scratchvoffset\zeropoint}
-\setvalue{\??bleedinglocation bl}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b}
-\setvalue{\??bleedinglocation lb}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b}
-\setvalue{\??bleedinglocation br}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b}
-\setvalue{\??bleedinglocation rb}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b}
-\setvalue{\??bleedinglocation tl}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t}
-\setvalue{\??bleedinglocation lt}{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t}
-\setvalue{\??bleedinglocation tr}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t}
-\setvalue{\??bleedinglocation rt}{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t}
-
-\mutable\let\currentbleedposition\empty
-\mutable\let\currentpageposition \empty
+\defcsname\??bleedinglocation t\endcsname{\settrue\c_pack_boxes_t\scratchhoffset\zeropoint}
+\defcsname\??bleedinglocation b\endcsname{\settrue\c_pack_boxes_b\scratchhoffset\zeropoint}
+\defcsname\??bleedinglocation l\endcsname{\settrue\c_pack_boxes_l\scratchvoffset\zeropoint}
+\defcsname\??bleedinglocation r\endcsname{\settrue\c_pack_boxes_r\scratchvoffset\zeropoint}
+\defcsname\??bleedinglocation bl\endcsname{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b}
+\defcsname\??bleedinglocation lb\endcsname{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_b}
+\defcsname\??bleedinglocation br\endcsname{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b}
+\defcsname\??bleedinglocation rb\endcsname{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_b}
+\defcsname\??bleedinglocation tl\endcsname{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t}
+\defcsname\??bleedinglocation lt\endcsname{\settrue\c_pack_boxes_l\settrue\c_pack_boxes_t}
+\defcsname\??bleedinglocation tr\endcsname{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t}
+\defcsname\??bleedinglocation rt\endcsname{\settrue\c_pack_boxes_r\settrue\c_pack_boxes_t}
+
+\mutable\lettonothing\currentbleedposition
+\mutable\lettonothing\currentpageposition
\permanent\tolerant\protected\def\bleed[#1]%
{\hbox\bgroup
- \global\advance\c_pack_boxes_bleeds\plusone
+ \global\advanceby\c_pack_boxes_bleeds\plusone
%
\enforced\permanent\xdef\bleedwidth {\the\hsize}%
\enforced\permanent\xdef\bleedheight{\the\vsize}%
@@ -694,10 +694,10 @@
\permanent\tolerant\protected\def\setlayertext[#1]#*[#2]#*[#3]%
{\bgroup
- \letdummyparameter\c!align\empty
- \letdummyparameter\c!width\hsize
- \letdummyparameter\c!color\empty
- \letdummyparameter\c!style\empty
+ \resetdummyparameter\c!align
+ \letdummyparameter \c!width\hsize
+ \resetdummyparameter\c!color
+ \resetdummyparameter\c!style
\getdummyparameters[#3]%
\dowithnextboxcontent
{\forgetall
@@ -859,10 +859,10 @@
\pack_boxes_offset_check[#1]%
\dowithnextboxcs\pack_boxes_offsetfinish\hbox}
-\newcount\c_pack_boxes_offset_level
+\newinteger\c_pack_boxes_offset_level
\def\pack_boxes_offset_check
- {\advance\c_pack_boxes_offset_level\plusone
+ {\advanceby\c_pack_boxes_offset_level\plusone
\edef\currentoffsetbox{\the\c_pack_boxes_offset_level}%
\checkoffsetboxparent
\setupcurrentoffsetbox}
@@ -1030,8 +1030,8 @@
\ifcase\scratchcounter
% just one
\else
- \scratchdimen\scratchwidth \divide\scratchdimen\wd\nextbox\scratchnx\scratchdimen\advance\scratchnx\plusone\relax
- \scratchdimen\scratchheight\divide\scratchdimen\ht\nextbox\scratchny\scratchdimen\advance\scratchny\plusone\relax
+ \scratchdimen\scratchwidth \divideby\scratchdimen\wd\nextbox\scratchnx\scratchdimen\advanceby\scratchnx\plusone\relax
+ \scratchdimen\scratchheight\divideby\scratchdimen\ht\nextbox\scratchny\scratchdimen\advanceby\scratchny\plusone\relax
% to be considered: methods
\ifcase\scratchcounter
\or % x and y
@@ -1118,4 +1118,224 @@
[\c!width=\overlaywidth,\c!height=\overlayheight]
{\overlayimage{#1}}}
+%D Here is an end December 2021 experimental feature: anchored boxes.
+
+\installcorenamespace{boxanchor}
+\installcorenamespace{boxanchorid}
+\installcorenamespace{boxanchorbox}
+\installcorenamespace{boxpreset}
+\installcorenamespace{boxanchors}
+
+\installparameterhandler \??boxanchor {boxanchor}
+\installsetuphandler \??boxanchor {boxanchor}
+
+\setupboxanchor
+ [\c!xoffset=\zeropoint,
+ \c!yoffset=\zeropoint]
+
+\newinteger\c_boxes_n_of_anchors
+
+\permanent\protected\def\defineanchorbox[#1]%
+ {\ifcsname\??boxanchorid#1\endcsname
+ \box\lastnamedcs\emptybox
+ \else
+ \global\advanceby\c_boxes_n_of_anchors\plusone
+ \expandafter\integerdef\csname\??boxanchorid #1\endcsname\c_boxes_n_of_anchors
+ \expandafter\newbox \csname\??boxanchorbox#1\endcsname
+ \fi}
+
+\permanent\protected\def\defineanchorboxoverlay[#1]%
+ {\defineanchorbox[#1:\v!background]%
+ \defineanchorbox[#1:\v!foreground]%
+ \defineoverlay[#1:\v!background][\overlayanchorbox{#1:\v!background}]%
+ \defineoverlay[#1:\v!foreground][\overlayanchorbox{#1:\v!foreground}]}
+
+\permanent\def\namedanchorbox#1%
+ {\begincsname\??boxanchorid#1\endcsname} % no checking
+
+\permanent\protected\def\overlayanchorbox#1%
+ {\begingroup
+ \scratchcounter\csname\??boxanchorbox#1\endcsname
+ \ifvoid\scratchcounter\else
+ \boxsource\scratchcounter\namedanchorbox{#1}%
+ \wd\scratchcounter\d_overlay_width
+ \ht\scratchcounter\d_overlay_height
+ \dp\scratchcounter\d_overlay_depth
+ \box\scratchcounter
+ \fi
+ \endgroup}
+
+\permanent\tolerant\protected\def\setanchorbox[#1]#*[#2]%
+ {\begingroup
+ \dowithnextbox
+ {\def\currentanchorbox{#1}%
+ \setupboxanchor[#2]%
+ \scratchcounterone\csname\??boxanchorbox#1\endcsname\relax
+ \scratchxoffset\boxanchorparameter\c!xoffset\relax
+ \scratchyoffset\boxanchorparameter\c!yoffset\relax
+ \boxtarget\nextbox \namedanchorbox {#1}\relax
+ \boxanchors\nextbox
+ % target
+ \numexpr
+ \ifcsname\??boxpreset\boxanchorparameter\c!target\endcsname
+ \lastnamedcs
+ \else
+ \halfwaytotallistanchorcode
+ \fi
+ \relax
+ % source
+ \numexpr
+ \ifcsname\??boxpreset\boxanchorparameter\c!source\endcsname
+ \lastnamedcs
+ \else
+ \halfwaytotallistanchorcode
+ \fi
+ \relax
+ \ifzeropt\scratchxoffset\else
+ \boxxoffset\nextbox\scratchxoffset
+ \fi
+ \ifzeropt\scratchyoffset\else
+ \boxyoffset\nextbox\scratchyoffset
+ \fi
+ \global\setbox\scratchcounterone\hpack\bgroup
+ \unhbox\scratchcounterone
+ \kern-\wd\nextbox
+ \box\nextbox
+ \egroup
+ \endgroup}}
+
+\expandafter\integerdef\csname\??boxpreset\v!left \endcsname\leftoriginlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!left,\v!height \endcsname\leftheightlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!left,\v!top \endcsname\leftheightlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!left,\v!depth \endcsname\leftdepthlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!left,\v!bottom \endcsname\leftdepthlistanchorcode
+
+\expandafter\integerdef\csname\??boxpreset\v!right \endcsname\rightoriginlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!right,\v!height \endcsname\rightheightlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!right,\v!top \endcsname\rightheightlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!right,\v!depth \endcsname\rightdepthlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!right,\v!bottom \endcsname\rightdepthlistanchorcode
+
+\expandafter\integerdef\csname\??boxpreset\v!line \endcsname\centeroriginlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!height \endcsname\centerheightlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!depth \endcsname\centerdepthlistanchorcode
+
+\expandafter\integerdef\csname\??boxpreset\v!middle \endcsname\halfwaytotallistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!middle,\v!height\endcsname\halfwayheightlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!middle,\v!top \endcsname\halfwayheightlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!middle,\v!depth \endcsname\halfwaydepthlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!middle,\v!bottom\endcsname\halfwaydepthlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!middle,\v!left \endcsname\halfwayleftlistanchorcode
+\expandafter\integerdef\csname\??boxpreset\v!middle,\v!right \endcsname\halfwayrightlistanchorcode
+
+% Musical timestamp: 2022-02-07 while listening Hypneurotic from The Blurred Horizon (n times);
+% Jim Matheos with Gavin Harrison; very hypnotic indeed.
+
+\permanent\def\boxanchorpresetcode#1%
+ {\ifcsname\??boxpreset#1\endcsname\lastnamedcs\else\halfwaytotallistanchorcode\fi}
+
+\newinteger\registeredboxanchor
+
+\installmacrostack\boxanchoringclass
+
+\mutable\lettonothing\boxanchoringclass
+
+\newinteger\c_anchor_auto_box_class
+
+\permanent\protected\def\startboxanchoring[#1]% + == auto
+ {\push_macro_boxanchoringclass
+ \iftok{#1}{+}%
+ \global\advanceby\c_anchor_auto_box_class\plusone
+ \edef\boxanchoringclass{\the\c_anchor_auto_box_class::}%
+ \else
+ \edef\boxanchoringclass{#1}
+ \fi}
+
+\permanent\protected\def\stopboxanchoring
+ {\pop_macro_boxanchoringclass}
+
+\permanent\protected\def\registerboxanchor
+ {\global\advanceby\registeredboxanchor\minusone}
+
+\permanent\protected\def\defineboxanchor[#1]%
+ {\registerboxanchor
+ \global\expandafter\integerdef\csname\??boxanchors#1\endcsname\registeredboxanchor}
+
+\permanent\protected\def\doifnotanchorbox#1%
+ {\ifcsname\??boxanchors#1\endcsname
+ \expandafter\gobbleoneargument
+ \else
+ \expandafter\firstofoneargument
+ \fi}
+
+\permanent\def\namedboxanchor#1%
+ {\normalexpanded{\ifcsname\??boxanchors#1\endcsname\lastnamedcs\orelse\ifchknum#1\or#1\else\zerocount\fi}}
+
+\permanent\def\namespacedboxanchor#1%
+ {boxanchor:\number\namedboxanchor{#1}}
+
+\installcorenamespace{boxanchorcontent}
+
+% \installparameterhandler \??boxanchorcontent {boxanchorcontent}
+% \installautosetuphandler \??boxanchorcontent {boxanchorcontent}
+
+\installcommandhandler \??boxanchorcontent {boxanchorcontent} \??boxanchorcontent % no real need but let's have a define too
+
+\setupboxanchorcontent
+ [\c!yoffset=\zeropoint,
+ \c!xoffset=\zeropoint,
+ \c!width=\zeropoint,
+ \c!location=\v!height,
+ \c!corner=\v!depth]
+
+\permanent\tolerant\protected\def\setboxanchor[#1]#*[#2]#*[#3]#*% assumes \defineboxanchor[#1]
+ {\begingroup
+ \dowithnextbox
+ {\ifhastok={#2}%
+ \setupcurrentboxanchorcontent[#2]%
+ \else
+ \def\currentboxanchorcontent{#2}%
+ \setupcurrentboxanchorcontent[#3]%
+ \fi
+ \scratchxoffset\boxanchorcontentparameter\c!xoffset
+ \scratchyoffset\boxanchorcontentparameter\c!yoffset
+ \scratchcounter\namedboxanchor{#1}%
+ \registeranchorbox
+ \scratchcounter
+ \plusone % order
+ \hbox
+ \s!anchors % check order of these:
+ \boxanchorpresetcode{\boxanchorcontentparameter\c!corner}
+ \boxanchorpresetcode{\boxanchorcontentparameter\c!location}
+ \ifzeropt\scratchxoffset\else \s!xoffset \scratchxoffset\fi
+ \ifzeropt\scratchyoffset\else \s!yoffset \scratchyoffset\fi
+ \s!target \scratchcounter
+ {\box\nextbox}%
+ \endgroup}}
+
+%D The name might change:
+
+\permanent\protected\def\mathrowanchored #1{\alignmentwrapsource\namedboxanchor{#1}\relax}
+\permanent\protected\def\mathcellanchored#1{\alignmentcellsource\namedboxanchor{#1}\relax}
+
+%permanent\protected\def\mathboxanchored#1#2{#2\Umathsource\namedboxanchor{#1}\relax}
+
+\permanent\tolerant\protected\def\mathboxanchored[#1]#:#2#3%
+ {#3\Umathsource\iftok{#1}{nucleus}#1\fi\namedboxanchor{\boxanchoringclass:#2}\relax}
+
+% to be used as:
+%
+% \scratchcounter\registeredboxanchor
+%
+% \registeranchorbox
+% \scratchcounter
+% \plusone
+% \ruledhbox{...}
+%
+% \hbox source \scratchcounter
+
+% \negatexlistsigncode
+% \negateylistsigncode
+% \negatelistsigncode
+
\protect \endinput