summaryrefslogtreecommitdiff
path: root/tex/context/base/mkxl/typo-ada.mkxl
blob: 6b7ce39021dfeabbba3ffa27c800dcb31d27f0c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
%D \module
%D   [       file=typo-ada,
%D        version=2022.04.04,
%D          title=\CONTEXT\ Typesetting Macros,
%D       subtitle=Adaptive,
%D         author=Hans Hagen,
%D           date=\currentdate,
%D      copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.

\writestatus{loading}{ConTeXt Typesetting Macros / Adaptive}

\registerctxluafile{typo-ada}{autosuffix}

% Musical timestamp: the postponed by COVID concert of Gazpacho in Zwolle NL: a joy
% to see dedicated and talented musicians perform their work in perfection and as a
% well balanced and equiped team.

\unprotect

\newdimen\d_adaptive_width
\newdimen\d_adaptive_height
\newdimen\d_adaptive_depth
\newdimen\d_adaptive_line

\mutable\let\m_adaptive_color\empty

\newbox\b_adaptive_box

\aliased\let\usedadaptivewidth    \d_adaptive_width
\aliased\let\usedadaptiveheight   \d_adaptive_height
\aliased\let\usedadaptivedepth    \d_adaptive_depth
\aliased\let\usedadaptivelinewidth\d_adaptive_linewidth
\aliased\let\usedadaptivebox      \b_adaptive_box

\definesystemattribute[adaptive][public]

\installcorenamespace{adaptive}

\installcommandhandler \??adaptive {adaptive} \??adaptive

% \appendtoks
%     %
% \to \everydefineadaptive

\setupadaptive
  [\c!foregroundstyle=,
   \c!foregroundcolor=,
   \c!color=gray,
   \c!rulethickness=\linewidth,
   \c!method=1,
   \c!stretch=,
   \c!shrink=,
  %\c!strut=\v!no,
   \c!margin=2\emwidth]

\permanent\tolerant\protected\def\adaptivebox[#1]#*[#2]%
   {\dontleavehmode
    \begingroup
    \ifhastok={#1}%
      \let\currentadaptive\empty
      \setupcurrentadaptive[#1]%
    \else
      \edef\currentadaptive{#1}%
      \setupcurrentadaptive[#2]%
    \fi
    \edef\p_setups{\adaptiveparameter\c!setups}%
    \dowithnextboxcontent
      {\useadaptivestyleandcolor\c!foregroundstyle\c!foregroundcolor
       \ifcstok{\adaptiveparameter\c!strut}\v!yes\strut\fi % for now
      }
      {\ifempty\p_setups
         % there is no need for postprocessing
       \else
         \clf_setadaptive {
           method         \adaptiveparameter\c!method
           setups        {\p_setups}%
           color         {\adaptiveparameter\c!color}%
           rulethickness  \adaptiveparameter\c!rulethickness
         }%
       \fi
       \scratchdimen\adaptiveparameter\c!margin\relax
       \edef\p_stretch{\adaptiveparameter\c!stretch}%
       \edef\p_shrink {\adaptiveparameter\c!shrink}%
       \uleaders
         \hbox
           \s!spread \scratchdimen
         \bgroup
           \hss\box\nextbox\hss
         \egroup
         \hskip
           \zeropoint
           \s!plus  \ifempty\p_stretch\scratchdimen\else\p_stretch\fi
           \s!minus \ifempty\p_shrink \scratchdimen\else\p_shrink \fi
         \endgroup}%
    \hbox}

%D Here is a test case, expect more:
%D
%D \starttyping
%D \startMPdefinitions
%D     def TickTock =
%D         interim linecap := squared;
%D         save p ; path p ; p := fullsquare xysized(AdaptiveWidth,.9(AdaptiveHeight+AdaptiveDepth)) ;
%D         fill p withcolor AdaptiveColor ;
%D         draw bottomboundary (p enlarged (-AdaptiveThickness) )
%D             withdashes (3*AdaptiveThickness)
%D             withpen pencircle scaled AdaptiveThickness
%D             withcolor white ;
%D     enddef ;
%D \stopMPdefinitions
%D
%D \startsetups adaptive:test
%D     \setbox\usedadaptivebox\hbox to \usedadaptivewidth yoffset -.9\usedadaptivedepth \bgroup
%D         \hss
%D         \startMPcode
%D             TickTock ;
%D         \stopMPcode
%D         \hss
%D    \egroup
%D \stopsetups
%D
%D \definecolor[adaptive:tick][.25(blue,green)]
%D \definecolor[adaptive:tock][.75(blue,green)]
%D
%D \defineadaptive
%D   [tick]
%D   [setups=adaptive:test,
%D    color=adaptive:tick,
%D    foregroundcolor=white,
%D    foregroundstyle=\infofont,
%D    strut=yes]
%D
%D \defineadaptive
%D   [tock]
%D   [tick]
%D   [color=adaptive:tock]
%D
%D \dorecurse{5}{
%D     \dostepwiserecurse{1}{150}{1}{%
%D         this~#1.##1 is~#1.##1 test~#1.##1
%D         \ifodd##1\relax
%D             \adaptivebox[tick]{\hss tick #1.##1\hss}
%D         \else
%D             \adaptivebox[tock]{\hss tock #1.##1\hss}
%D         \fi
%D     }
%D     \blank
%D }
%D
%D \setupexternalfigures
%D   [location={default,global}]
%D
%D \startsetups adaptive:test
%D     \setbox\usedadaptivebox\hbox to \usedadaptivewidth yoffset -\usedadaptivedepth \bgroup
%D         \externalfigure
%D           [cow.pdf]
%D           [width=\usedadaptivewidth,
%D            height=\dimexpr\usedadaptiveheight+\usedadaptivedepth\relax]%
%D    \egroup
%D \stopsetups
%D
%D \dorecurse{5}{
%D     \dostepwiserecurse{1}{150}{1}{%
%D         this~#1.##1 is~#1.##1 test~#1.##1
%D         {\adaptivebox[strut=yes,setups=adaptive:test]{}}
%D     }
%D     \blank
%D }
%D \stoptyping

\protect