node-bck.mkiv /size: 3490 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=node-bck,
3%D        version=2009.06.08,
4%D          title=\CONTEXT\ Node Macros,
5%D       subtitle=Backgrounds,
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\writestatus{loading}{ConTeXt Node Support / Backgrounds}
15
16%D This is first attempt to replacing backgrounds in a few tables
17%D mechanisms. When used more frequently, we can store the color
18%D spec in the attribute.
19
20\unprotect
21
22\registerctxluafile{node-bck}{optimize}
23
24% \backgroundvbox[green] {\input tufte } \par
25% \backgroundvbox[blue]  {\input ward } \par
26% \backgroundvbox[red]   {\input knuth } \par
27% \backgroundhbox[yellow]{\rotate[rotation=45]{hello world}} \par
28
29\def\colorattr#1%
30  {\ifcsname\??colorattribute\currentcolorprefix#1\endcsname
31     \node_backgrounds_thecolorattr{\currentcolorprefix#1}%
32   \else\ifcsname\??colorattribute#1\endcsname
33     \node_backgrounds_thecolorattr{#1}%
34   \fi\fi}
35
36\def\node_backgrounds_thecolorattr#1%
37  {attr \colormodelattribute   \c_attr_colormodel
38   attr \colorattribute        \lastnamedcs
39   attr \transparencyattribute \thetransparencyattribute{#1} } % can be optimized
40
41\def\thecolorattr#1%
42  {attr \colormodelattribute   \c_attr_colormodel
43   attr \colorattribute        \csname\??colorattribute#1\endcsname
44   attr \transparencyattribute \thetransparencyattribute{#1} } % can be optimized
45
46\def\backgroundcolorattr#1%
47  {\ifcsname\??colorattribute\currentcolorprefix#1\endcsname
48     \node_backgrounds_thebackgroundcolorattr{\currentcolorprefix#1}%
49   \else\ifcsname\??colorattribute#1\endcsname
50     \node_backgrounds_thebackgroundcolorattr{#1}%
51   \fi\fi}
52
53\def\thebackgroundcolorattr#1%
54  {attr \backgroundattribute      \plusone
55   attr \colormodelattribute      \c_attr_colormodel
56   attr \colorattribute           \csname\??colorattribute#1\endcsname
57   attr \transparencyattribute    \thetransparencyattribute{#1} } % can be optimized
58
59\def\node_backgrounds_thebackgroundcolorattr#1%
60  {attr \backgroundattribute      \plusone
61   attr \colormodelattribute      \c_attr_colormodel
62   attr \colorattribute           \lastnamedcs
63   attr \transparencyattribute    \thetransparencyattribute{#1} } % can be optimized
64
65\def\thealignbackgroundcolorattr#1%
66  {attr \alignbackgroundattribute \plusone
67   attr \colormodelattribute      \c_attr_colormodel
68   attr \colorattribute           \csname\??colorattribute#1\endcsname
69   attr \transparencyattribute    \thetransparencyattribute{#1} } % can be optimized
70
71\unexpanded\def\backgroundhbox{\node_backgrounds_boxes_add\hbox}
72\unexpanded\def\backgroundvbox{\node_backgrounds_boxes_add\vbox}
73\unexpanded\def\backgroundvtop{\node_backgrounds_boxes_add\vtop}
74
75\unexpanded\def\backgroundline{\dontleavehmode
76                               \node_backgrounds_boxes_add\hbox}
77
78% \def\node_backgrounds_boxes_add#1[#2]%
79%   {\begingroup
80%    \clf_enablebackgroundboxes
81%    \dousecolorparameter{#2}%
82%    \normalexpanded{\endgroup#1
83%      attr \backgroundattribute   \plusone
84%      attr \colormodelattribute   \the\c_attr_colormodel
85%      attr \colorattribute        \the\c_attr_color
86%      attr \transparencyattribute \the\c_attr_transparency}}
87%
88% more efficient:
89
90\def\node_backgrounds_boxes_add#1[#2]%
91  {\clf_enablebackgroundboxes
92   #1\backgroundcolorattr{#2}}
93
94\protect \endinput
95