font-tra.mkiv /size: 9 Kb    last modification: 2021-10-28 13:50
1%D \module
2%D   [       file=font-tra,
3%D        version=2009.01.02, % or so
4%D          title=\CONTEXT\ Font Macros,
5%D       subtitle=Tracing,
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\unprotect
15
16\writestatus{loading}{ConTeXt Font Macros / Tracing}
17
18%D just use fontid
19
20%D \macros
21%D   {showbodyfont}
22%D
23%D One can call for a rather simple overview of a bodyfont and the relations between
24%D its alternative fonts.
25%D
26%D \showsetup{showbodyfont}
27%D
28%D The current bodyfont (here we omitted the argument) looks like:
29%D
30%D \showbodyfont
31%D
32%D The implementation is rather straightforward in using
33%D \type{\halign}.
34
35\fetchruntimecommand \showbodyfont  \f!font_run
36
37%D \macros
38%D   {showfontstrip, testminimalbaseline, showminimalbaseline}
39%D
40%D The next command can come in handy when combining different fonts into a
41%D collection (typeface) and determining optimal baseline distances.
42%D
43%D \showfontstrip \blank \showminimalbaseline
44
45\fetchruntimecommand \showfontstrip       \f!font_run
46\fetchruntimecommand \testminimalbaseline \f!font_run
47\fetchruntimecommand \showminimalbaseline \f!font_run
48
49%D \macros
50%D   {showkerning}
51%D
52%D A goody is:
53%D
54%D \showkerning{Can you guess what kerning is?}
55
56\fetchruntimecommand \showkerning \f!font_run
57
58%D \macros
59%D   {showbodyfontenvironment,showfont,showfontstyle,showligatures}
60%D
61%D The current bodyfontenvironment is:
62%D
63%D \showbodyfontenvironment
64%D
65%D This overview is generated using:
66%D
67%D \showsetup{showbodyfontenvironment}
68
69\fetchruntimecommand \showbodyfontenvironment \f!font_run
70
71%D
72%D The following command generates a fontmap:
73%D
74%D \startbuffer
75%D \showfont[SansBold at 12pt]
76%D \stopbuffer
77%D
78%D \typebuffer
79%D \getbuffer
80
81\fetchruntimecommand \showfont           \f!font_run
82\fetchruntimecommand \showfontstyle      \f!font_run
83\fetchruntimecommand \showligature       \f!font_run
84\fetchruntimecommand \showligatures      \f!font_run
85\fetchruntimecommand \showcharratio      \f!font_run
86\fetchruntimecommand \showfontparameters \f!font_run
87
88\unexpanded\def\showchardata          #1{\ctxcommand{showchardata("#1")}}
89\unexpanded\def\showfontdata            {\ctxcommand{showfontparameters()}}
90
91%D \macros
92%D   {doiffontpresentelse}
93%D
94%D \starttyping
95%D \doiffontpresentelse{texnansi-lmr10}{YES}{NO}
96%D \doiffontpresentelse{adam-lindsay-modern-serif}{YES}{NO}
97%D \stoptyping
98
99\unexpanded\def\doifelsefontpresent#1{\clf_doifelsefontpresent{#1}}
100
101\let\doiffontpresentelse\doifelsefontpresent
102
103% experimental, maybe this becomes a module
104
105\newbox\otfcollector
106
107\unexpanded\def\startotfcollecting{\ctxlua{nodes.tracers.steppers.start()}}
108\unexpanded\def\stopotfcollecting {\ctxlua{nodes.tracers.steppers.stop()}}
109\unexpanded\def\resetotfcollecting{\ctxlua{nodes.tracers.steppers.reset()}}
110
111% \page \showotfcomposition{arabtype*arab-default at 48pt}{-1}{الضَّرَّ} \page
112% \page \showotfcomposition{arabtype*arab-default at 48pt}{-1}{لِلّٰهِ} \page
113
114\unexpanded\def\showotfstepglyphs#1%
115  {\ctxlua{nodes.tracers.steppers.glyphs(\number\otfcollector,#1)}%
116   \unhbox\otfcollector}
117
118\unexpanded\def\otfstepspace
119  {\removeunwantedspaces
120   \hskip.5\emwidth \s!plus .125\emwidth \s!minus .125\emwidth\relax}
121
122\unexpanded\def\otfstepcharcommand#1#2#3% font char class
123  {\otfstepspace
124   \doif{#3}{mark}{\underbar}{U+\hexnumber{#2}}:%
125   \setbox\scratchbox\hbox{\ctxlua{nodes.tracers.fontchar(#1,#2)}}%
126   \ifzeropt\wd\scratchbox
127     \scratchwidth.125\onepoint
128     \scratchdistance\dimexpr(\emwidth/2-\scratchwidth)\relax
129     \kern\scratchdistance
130     \ruledhbox to \scratchwidth{\hss\box\scratchbox\hss}%
131     \kern-\scratchwidth
132     \hskip\scratchdistance
133   \else
134     \ruledhbox{\box\scratchbox}%
135   \fi
136   \otfstepspace}
137
138\unexpanded\def\otfstepfontcommand#1#2#3% id font size
139  {\begingroup
140   \tttf #1: #2 @ \the\dimexpr#3\scaledpoint\relax
141   \endgroup}
142
143\unexpanded\def\otfstepmessagecommand#1#2%
144  {\begingroup
145   \tttf\language\minusone
146   \veryraggedright
147   \forgetparindent
148   \forgeteverypar
149   \hangindent\emwidth
150   \hangafter\plusone
151   \dontleavehmode\detokenize{#1}\removeunwantedspaces
152   \doifsomething{#2}{,\space\detokenize{#2}}\endgraf
153   \endgroup
154   \blank}
155
156\unexpanded\def\showotfstepfont
157  {\ctxlua{nodes.tracers.steppers.font("otfstepfontcommand")}}
158
159\unexpanded\def\showotfstepchars#1%
160  {\ctxlua{nodes.tracers.steppers.codes(#1,"otfstepcharcommand","otfstepspace")}}
161
162\unexpanded\def\showotfstepmessages#1%
163  {\ctxlua{nodes.tracers.steppers.messages(#1,"otfstepmessagecommand",true)}}
164
165\unexpanded\def\showotfstepfeatures
166  {\ctxlua{nodes.tracers.steppers.features()}}
167
168\unexpanded\def\otfnoffeaturesteps
169  {\ctxlua{nodes.tracers.steppers.nofsteps()}}
170
171% \unexpanded\def\showotfsteps
172%   {\begingroup
173%    \veryraggedright
174%    \forgetparindent
175%    \forgeteverypar
176%    \dontleavehmode\bgroup\tttf \language\minusone features: \showotfstepfeatures\egroup
177%    \blank
178%    \dontleavehmode\bgroup\tttf result:\egroup
179%    \blank
180%    \startlinecorrection
181%    \ruledhbox\bgroup\box\otfcompositionbox\egroup
182%    \stoplinecorrection
183%    \dorecurse\otfnoffeaturesteps
184%      {\blank
185%       \showotfstepmessages\recurselevel
186%       \blank
187%       \startlinecorrection
188%       \dontleavehmode\bgroup\resetallattributes\lefttoright\tttf\recurselevel: \showotfstepchars\recurselevel\egroup
189%       \stoplinecorrection
190%       \blank
191%       \startlinecorrection
192%       \ruledhbox % can be mode
193%         \bgroup\resetallattributes\showotfstepglyphs\recurselevel\egroup % reset is new, we don't want additional processing
194%       \stoplinecorrection
195%       \blank}%
196%    \endgroup}
197
198\newconstant\showotfstepsmode  \showotfstepsmode\plusfour
199
200\unexpanded\def\showotfsteps_n
201  {\blank
202   \begingroup
203     \advance\leftskip6\emwidth
204     \showotfstepmessages\recurselevel
205     \par
206   \endgroup
207   \blank
208   \dontleavehmode
209   \hbox to \hsize \bgroup
210     \hbox to 6\emwidth \bgroup
211       \bf
212       \ifnum\recurselevel=\scratchcounter result\else step \recurselevel\fi
213       \hss
214     \egroup
215     \vtop \bgroup
216       \hsize\dimexpr\hsize-6\emwidth\relax
217       \resetallattributes
218       \lefttoright
219       \dontleavehmode
220       \ifnum\recurselevel=\scratchcounter
221         \ruledhbox{\box\otfcompositionbox}%
222       \else
223         \ruledhbox{\showotfstepglyphs\recurselevel}%
224       \fi
225       \quad
226       \showotfstepchars\recurselevel
227       \hfill
228       \par
229     \egroup
230   \egroup
231   \blank}
232
233\unexpanded\def\showotfsteps
234  {\begingroup
235   \veryraggedright
236   \forgetparindent
237   \forgeteverypar
238   \tt
239   \lefttoright
240   \hbox to \hsize \bgroup
241     \hbox to 6\emwidth{\bf font\hss}%
242     \vtop \bgroup
243       \hsize\dimexpr\hsize-6\emwidth\relax
244       \language\minusone
245       \bf
246       \showotfstepfont
247     \egroup
248   \egroup
249   \blank
250   \hbox to \hsize \bgroup
251     \hbox to 6\emwidth{\bf features\hss}%
252     \vtop \bgroup
253       \hsize\dimexpr\hsize-6\emwidth\relax
254       \language\minusone
255       \showotfstepfeatures
256     \egroup
257   \egroup
258   \blank
259   \scratchcounter\otfnoffeaturesteps\relax
260   \dorecurse\scratchcounter
261     {\ifcase\showotfstepsmode
262      \or % 1 = only first
263        \ifnum\recurselevel=\plusone
264          \showotfsteps_n
265        \fi
266      \or % 2 = only last
267        \ifnum\recurselevel=\scratchcounter
268          \showotfsteps_n
269        \fi
270      \or % 3 = first and last
271        \ifnum\recurselevel=\plusone
272          \showotfsteps_n
273        \else\ifnum\recurselevel=\scratchcounter
274          \showotfsteps_n
275        \fi\fi
276      \else % everything
277        \showotfsteps_n
278      \fi}%
279   \endgroup}
280
281\unexpanded\def\startotfsample
282  {\enabletrackers[otf.sample.silent]% beware, kind of global
283   \startotfcollecting
284   \begingroup
285   \veryraggedright
286   \forgetparindent
287   \forgeteverypar}
288
289\unexpanded\def\stopotfsample
290  {\endgroup
291   \stopotfcollecting
292   \disabletrackers[otf.sample]% beware, kind of global: otf.sample
293   \showotfsteps
294   \resetotfcollecting}
295
296\newbox\otfcompositionbox
297
298% this should go in spac-ali:
299
300\installcorenamespace{otfcompositiondir}
301
302\letvalue{\??otfcompositiondir  -1}\righttoleft
303\letvalue{\??otfcompositiondir r2l}\righttoleft
304\letvalue{\??otfcompositiondir l2r}\lefttoright
305\letvalue{\??otfcompositiondir  +1}\lefttoright
306\letvalue{\??otfcompositiondir   1}\lefttoright
307
308\unexpanded\def\setotfcompositiondirection#1%
309 {\begincsname\??otfcompositiondir#1\endcsname}
310
311\unexpanded\def\showotfcomposition#1#2#3% {font*features at size}, rl=-1, text
312  {\begingroup
313   \forgetparindent
314   \forgeteverypar
315 % \setupcolors[\c!state=\v!start]%
316   \setupalign[\v!verytolerant,\v!flushleft]%
317   \startotfsample
318   \nohyphens
319   \global\setbox\otfcompositionbox\hbox{\definedfont[#1]\relax\setotfcompositiondirection{#2}\relax#3}%
320   \stopotfsample
321   \endgroup}
322
323%D \startbuffer
324%D \startotfcompositionlist{Serif*default @ 11pt}{l2r}%
325%D     \showotfcompositionsample{effe}
326%D \stopotfcompositionlist
327%D \stopbuffer
328%D
329%D \typebuffer \getbuffer
330
331\unexpanded\def\showotfcompositionlist#1#2#3%
332  {\begingroup
333   \definedfont[#1]%
334   \setbox\scratchbox\hbox\bgroup
335     \setotfcompositiondirection{#2}%
336     #3%
337   \egroup
338   \strut
339   \def|##1|{\kern\onepoint\string|\kern\onepoint##1\kern\onepoint\string|\kern\onepoint}%
340   \cldcontext{nodes.listtoutf(tex.box[\number\scratchbox].list,"{\\kern\\onepoint}",true)}%
341   \endgroup}
342
343\unexpanded\def\startotfcompositionlist#1#2#3\stopotfcompositionlist
344  {\begingroup
345   \unexpanded\def\showotfcompositionsample##1%
346     {\NC\type{##1}%
347      \NC\showotfcompositionlist{Mono}{#2}{##1}%
348      \NC\showotfcompositionlist{#1}{#2}{##1}%
349      \NC\definedfont[#1]##1%
350      \NC\NR}%
351   \starttabulate[|||||]%
352     #3%
353   \stoptabulate
354   \endgroup}
355
356\let\stopotfcompositionlist\relax
357
358% new
359
360\unexpanded\def\savefontdata[#1]% not yet in i-*.xml
361  {\begingroup
362   \getdummyparameters[#1]%
363   \clf_savefont {
364      filename {\dummyparameter\c!file}
365      fontname {\dummyparameter\c!name}
366      method   {\dummyparameter\c!method}
367   }%
368   \endgroup}
369
370\protect \endinput
371