summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/trac-vis.mkiv
blob: 570e6a7c730c9241fc255559f8b9f8d7e0acb701 (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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
%D \module
%D   [       file=trac-vis, % replaces supp-vis plus some s-* modules
%D        version=2012.06.23, % 1996.10.21,
%D          title=\CONTEXT\ Tracing Macros,
%D       subtitle=Visualization,
%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.

%D The old visual debugger dates from 1996 and started out as joke. In practice
%D it's not used that often although the \type {\ruledhbox} cum suis macros come
%D in handy when writing code. In the process of luafication some additional
%D tracing options were tested, for instance showing font kerns. As part of the
%D \MKIV\ cleanup the decision was made to reimplement, reintegrate and reconsider
%D all these features. The old code is gone and the new code will get extended
%D when needed. We still provide placeholders for some old visualization commands
%D but they might go away.
%D
%D Control over what gets visualized happens with the tracker command:
%D
%D \enabletrackers[visualizers.*]
%D
%D Possible values are: \type {fontkern}, \type {kern}, \type {glue}, \type
%D {penalty}, \type {hbox}, \type {vbox}, \type {all}, \type {reset}, \type
%D {makeup}, \type {whatsit}, \type{glyph}.
%D
%D In due time some special visualzation of math will move here as well.

\writestatus{loading}{ConTeXt Tracing Macros / Visualization}

\registerctxluafile{trac-vis}{optimize}

\unprotect

\newconstant\c_syst_visualizers_state
\newtoks    \t_syst_visualizers_optimize

% \definesystemattribute[visual][public,global] % already defined

% no, but can become an option:
%
% \appendtoks
%     \attribute\visualattribute\attributeunsetvalue
% \to \everybeforepagebody

%D We only provide box visualizers as they can come in handy for testing
%D macros. In due time we will move some of the m-visual code here too.

\let\syst_visualizers_hbox\hbox
\let\syst_visualizers_vbox\vbox
\let\syst_visualizers_vtop\vtop

\let\syst_visualizers_hpack\hpack
\let\syst_visualizers_vpack\vpack
\let\syst_visualizers_tpack\tpack

\unexpanded\def\ruledhbox{\syst_visualizers_hbox attr \visualattribute \clf_getvisual{simplehbox} }
\unexpanded\def\ruledvbox{\syst_visualizers_vbox attr \visualattribute \clf_getvisual{simplevbox} }
\unexpanded\def\ruledvtop{\syst_visualizers_vtop attr \visualattribute \clf_getvisual{simplevtop} } % special case
\unexpanded\def\ruledtopv{\syst_visualizers_vtop attr \visualattribute \clf_getvisual{vtop}       }

\unexpanded\def\ruledhpack{\syst_visualizers_hpack attr \visualattribute \clf_getvisual{simplehbox} }
\unexpanded\def\ruledvpack{\syst_visualizers_vpack attr \visualattribute \clf_getvisual{simplevbox} }
\unexpanded\def\ruledtpack{\syst_visualizers_tpack attr \visualattribute \clf_getvisual{simplevtop} } % special case

\unexpanded\def\ruledmbox#1{\ruledhbox{\startimath#1\stopimath}}

\appendtoks
    \ifcase\c_syst_visualizers_state\else
        \syst_visualizers_speedup
    \fi
\to \everyshipout

\appendtoks
    \glet\syst_visualizers_speedup\relax
\to \t_syst_visualizers_optimize

\def\syst_visualizers_speedup{\the\t_syst_visualizers_optimize}

\appendtoks
    \normalexpanded {%
        \unexpanded\xdef\ruledhbox\expandafter{\ruledhbox}%
        \unexpanded\xdef\ruledvbox\expandafter{\ruledvbox}%
        \unexpanded\xdef\ruledvtop\expandafter{\ruledvtop}%
        \unexpanded\xdef\ruledtopv\expandafter{\ruledtopv}%
    }%
\to \t_syst_visualizers_optimize

\unexpanded\def\showmakeup
  {\dosingleempty\syst_visualizers_makeup}

\unexpanded\def\syst_visualizers_makeup[#1]%
  {\iffirstargument
     \clf_setvisual{#1}%
   \else
     \clf_setvisual{makeup}%
     \let\normalvtop\ruledtopv
     \let\vtop      \ruledtopv
   \fi}

\unexpanded\def\showallmakeup
  {\clf_setvisual{all}%
   \let\normalvtop\ruledtopv
   \let\vtop      \ruledtopv
   \showstruts}

\unexpanded\def\showboxes
  {\clf_setvisual{boxes}%
   \let\normalvtop\ruledtopv
   \let\vtop      \ruledtopv}

\unexpanded\def\showglyphs
  {\clf_setvisual{glyph}}

\unexpanded\def\showfontkerns
  {\clf_setvisual{fontkern}}

\unexpanded\def\showfontitalics
  {\clf_setvisual{italic}}

\unexpanded\def\showglyphdata
  {\showglyphs
   \showfontkerns
   \showfontitalics}

\unexpanded\def\showfontexpansion
  {\clf_setvisual{expansion}}

\unexpanded\def\setvisualizerfont
  {\dosingleempty\syst_visualizers_setfont}

\def\syst_visualizers_setfont[#1]% somename at 4pt
  {\begingroup
   \doifelsenothing{#1}{\definedfont[Mono at 4pt]}{\definedfont[#1]}%
   \clf_setvisualfont\fontid\font
   \endgroup}

\unexpanded\def\resetvisualizers
  {\attribute\visualattribute\attributeunsetvalue}

%D New (these might also be a visualizers):

% \definecolor[f:r:t][a=1,t=.25,r=1]
% \definecolor[f:g:t][a=1,t=.25,g=1]
% \definecolor[f:b:t][a=1,t=.25,b=1]
% \definecolor[f:c:t][a=1,t=.25,c=1]
% \definecolor[f:m:t][a=1,t=.25,m=1]
% \definecolor[f:y:t][a=1,t=.25,y=1]
% \definecolor[f:k:t][a=1,t=.25,s=0]

\unexpanded\def\filledhboxr{\node_backgrounds_boxes_add\hbox[f:r:t]}
\unexpanded\def\filledhboxg{\node_backgrounds_boxes_add\hbox[f:g:t]}
\unexpanded\def\filledhboxb{\node_backgrounds_boxes_add\hbox[f:b:t]}
\unexpanded\def\filledhboxc{\node_backgrounds_boxes_add\hbox[f:c:t]}
\unexpanded\def\filledhboxm{\node_backgrounds_boxes_add\hbox[f:m:t]}
\unexpanded\def\filledhboxy{\node_backgrounds_boxes_add\hbox[f:y:t]}
\unexpanded\def\filledhboxk{\node_backgrounds_boxes_add\hbox[f:k:t]}

%D Overload:

% \def\spac_struts_vide_hbox
%   {\hbox attr \visualattribute \clf_getvisual{strut} }
%
% \def\spac_struts_vide_hbox
%   {\xdef\spac_struts_vide_hbox{\hbox attr \visualattribute \clf_getvisual{strut} }%
%    \spac_struts_vide_hbox}

\unexpanded\def\spac_struts_vide_hbox
  {\hbox attr \visualattribute \clf_getvisual{strut} }

\appendtoks
    \normalexpanded{\unexpanded\xdef\spac_struts_vide_hbox\expandafter{\spac_struts_vide_hbox}}%
\to \t_syst_visualizers_optimize

%D For manuals:

\unexpanded\def\markfonts#1%
  {\dontleavehmode
   \begingroup
   \setbox\scratchbox\hbox{\getbuffer}%
   \clf_markvisualfonts\scratchbox
   \unhbox\scratchbox
   \endgroup}

% As demo:
%
% \startbuffer
%     \hbox {\raise1cm\hbox{raised} normal \lower1cm\hbox{lowered}}
%     \blank
%     \moveleft1cm\hbox{left}
%     \blank
%     \hbox{normal}
%     \blank
%     \moveright1cm\hbox{right}
%     \blank
% \stopbuffer
%
% \start \showboxes \getbuffer \stop \blank[4*big] \getbuffer
%
% \startbuffer
%     \moveleft1cm\vbox{left}
%     \blank
%     \vbox{normal}
%     \blank
%     \moveright1cm\vbox{right}
%     \blank
% \stopbuffer
%
% \start \showboxes \getbuffer \stop \blank[4*big] \getbuffer

%D We keep this one:

\unexpanded\def\dontinterfere
  {\reseteverypar
   \parindent\zeropoint
   \parskip  \zeropoint
   \leftskip \zeropoint
   \rightskip\zeropoint
   \relax}

%D We keep these for a while:

\let\ruledvcenter   \vcenter
\let\ruledhss       \hss
\let\ruledhfil      \hfil
\let\ruledhfill     \hfill
\let\ruledhfilll    \hfilll
\let\ruledhfilneg   \hfilneg
\let\ruledhfillneg  \hfillneg
\let\ruledhfilllneg \hfilllneg
\let\ruledvss       \vss
\let\ruledvfil      \vfil
\let\ruledvfill     \vfill
\let\ruledvfilll    \vfilll
\let\ruledvfilneg   \vfilneg
\let\ruledvfillneg  \vfillneg
\let\ruledvfilllneg \vfilllneg
\let\ruledhskip     \hskip
\let\ruledvskip     \vskip
\let\ruledkern      \kern
\let\ruledhglue     \hglue
\let\ruledvglue     \vglue
\let\ruledmkern     \mkern
\let\ruledmskip     \mskip
\let\ruledpenalty   \penalty

\protect \endinput