summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/font-tra.mkiv
blob: 89a50c5aeb2635278393baec187903652962cda3 (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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
%D \module
%D   [       file=font-tra,
%D        version=2009.01.02, % or so
%D          title=\CONTEXT\ Font Macros,
%D       subtitle=Tracing,
%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.

\unprotect

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

%D just use fontid

%D \macros
%D   {showbodyfont}
%D
%D One can call for a rather simple overview of a bodyfont and the
%D relations between its alternative fonts.
%D
%D \showsetup{showbodyfont}
%D
%D The current bodyfont (here we omitted the argument) looks like:
%D
%D \showbodyfont
%D
%D The implementation is rather straightforward in using
%D \type{\halign}.

\fetchruntimecommand \showbodyfont  \f!font_run

%D \macros
%D   {showfontstrip, testminimalbaseline, showminimalbaseline}
%D
%D The next command can come in handy when combining
%D different fonts into a collection (typeface) and
%D determining optimal baseline distances.
%D
%D \showfontstrip \blank \showminimalbaseline

\fetchruntimecommand \showfontstrip       \f!font_run
\fetchruntimecommand \testminimalbaseline \f!font_run
\fetchruntimecommand \showminimalbaseline \f!font_run

%D \macros
%D   {showkerning}
%D
%D A goody is:
%D
%D \showkerning{Can you guess what kerning is?}

\fetchruntimecommand \showkerning \f!font_run

%D \macros
%D   {showbodyfontenvironment,showfont,showfontstyle,showligatures}
%D
%D The current bodyfontenvironment is:
%D
%D \showbodyfontenvironment
%D
%D This overview is generated using:
%D
%D \showsetup{showbodyfontenvironment}

\fetchruntimecommand \showbodyfontenvironment \f!font_run

%D
%D The following command generates a fontmap:
%D
%D \startbuffer
%D \showfont[SansBold at 12pt]
%D \stopbuffer
%D
%D \typebuffer
%D \getbuffer

\fetchruntimecommand \showfont           \f!font_run
\fetchruntimecommand \showfontstyle      \f!font_run
\fetchruntimecommand \showligature       \f!font_run
\fetchruntimecommand \showligatures      \f!font_run
\fetchruntimecommand \showcharratio      \f!font_run
\fetchruntimecommand \showfontparameters \f!font_run

\unexpanded\def\showchardata          #1{\ctxcommand{showchardata("#1")}}
\unexpanded\def\showfontdata            {\ctxcommand{showfontparameters()}}

%D \macros
%D   {doiffontpresentelse}
%D
%D \starttyping
%D \doiffontpresentelse{texnansi-lmr10}{YES}{NO}
%D \doiffontpresentelse{adam-lindsay-modern-serif}{YES}{NO}
%D \stoptyping

\unexpanded\def\doifelsefontpresent#1{\clf_doifelsefontpresent{#1}}

\let\doiffontpresentelse\doifelsefontpresent

% experimental, maybe this becomes a module

\newbox\otfcollector

\unexpanded\def\startotfcollecting{\ctxlua{nodes.tracers.steppers.start()}}
\unexpanded\def\stopotfcollecting {\ctxlua{nodes.tracers.steppers.stop()}}
\unexpanded\def\resetotfcollecting{\ctxlua{nodes.tracers.steppers.reset()}}

% Rather experimental:
%
% \page \showotfcomposition{arabtype*arab-default at 48pt}{-1}{الضَّرَّ} \page
% \page \showotfcomposition{arabtype*arab-default at 48pt}{-1}{لِلّٰهِ}   \page

\unexpanded\def\showotfstepglyphs#1%
  {\ctxlua{nodes.tracers.steppers.glyphs(\number\otfcollector,#1)}%
   \unhbox\otfcollector}

\unexpanded\def\otfstepspace
  {\removeunwantedspaces
   \hskip.5\emwidth \s!plus .125\emwidth \s!minus .125\emwidth\relax}

\unexpanded\def\otfstepcharcommand#1#2#3% font char class
  {\otfstepspace
   \doif{#3}{mark}{\underbar}{U+\hexnumber{#2}}:%
   \setbox\scratchbox\hbox{\ctxlua{nodes.tracers.fontchar(#1,#2)}}%
   \ifzeropt\wd\scratchbox
     \scratchwidth.125\onepoint
     \scratchdistance\dimexpr(\emwidth/2-\scratchwidth)\relax
     \kern\scratchdistance
     \ruledhbox to \scratchwidth{\hss\box\scratchbox\hss}%
     \kern-\scratchwidth
     \hskip\scratchdistance
   \else
     \ruledhbox{\box\scratchbox}%
   \fi
   \otfstepspace}

\unexpanded\def\otfstepfontcommand#1#2#3% id font size
  {\begingroup
   \tttf #1: #2 @ \the\dimexpr#3\scaledpoint\relax
   \endgroup}

\unexpanded\def\otfstepmessagecommand#1#2%
  {\begingroup
   \tttf\language\minusone
   \veryraggedright
   \forgetparindent
   \forgeteverypar
   \hangindent\emwidth
   \hangafter\plusone
   \dontleavehmode\detokenize{#1}\removeunwantedspaces
   \doifsomething{#2}{,\space\detokenize{#2}}\endgraf
   \endgroup
   \blank}

\unexpanded\def\showotfstepfont
  {\ctxlua{nodes.tracers.steppers.font("otfstepfontcommand")}}

\unexpanded\def\showotfstepchars#1%
  {\ctxlua{nodes.tracers.steppers.codes(#1,"otfstepcharcommand","otfstepspace")}}

\unexpanded\def\showotfstepmessages#1%
  {\ctxlua{nodes.tracers.steppers.messages(#1,"otfstepmessagecommand",true)}}

\unexpanded\def\showotfstepfeatures
  {\ctxlua{nodes.tracers.steppers.features()}}

\unexpanded\def\otfnoffeaturesteps
  {\ctxlua{nodes.tracers.steppers.nofsteps()}}

% \unexpanded\def\showotfsteps
%   {\begingroup
%    \veryraggedright
%    \forgetparindent
%    \forgeteverypar
%    \dontleavehmode\bgroup\tttf \language\minusone features: \showotfstepfeatures\egroup
%    \blank
%    \dontleavehmode\bgroup\tttf result:\egroup
%    \blank
%    \startlinecorrection
%    \ruledhbox\bgroup\box\otfcompositionbox\egroup
%    \stoplinecorrection
%    \dorecurse\otfnoffeaturesteps
%      {\blank
%       \showotfstepmessages\recurselevel
%       \blank
%       \startlinecorrection
%       \dontleavehmode\bgroup\resetallattributes\lefttoright\tttf\recurselevel: \showotfstepchars\recurselevel\egroup
%       \stoplinecorrection
%       \blank
%       \startlinecorrection
%       \ruledhbox % can be mode
%         \bgroup\resetallattributes\showotfstepglyphs\recurselevel\egroup % reset is new, we don't want additional processing
%       \stoplinecorrection
%       \blank}%
%    \endgroup}

\newconstant\showotfstepsmode  \showotfstepsmode\plusfour

\unexpanded\def\showotfsteps_n
  {\blank
   \begingroup
     \advance\leftskip6\emwidth
     \showotfstepmessages\recurselevel
     \par
   \endgroup
   \blank
   \dontleavehmode
   \hbox to \hsize \bgroup
     \hbox to 6\emwidth \bgroup
       \bf
       \ifnum\recurselevel=\scratchcounter result\else step \recurselevel\fi
       \hss
     \egroup
     \vtop \bgroup
       \hsize\dimexpr\hsize-6\emwidth\relax
       \resetallattributes
       \lefttoright
       \dontleavehmode
       \ifnum\recurselevel=\scratchcounter
         \ruledhbox{\box\otfcompositionbox}%
       \else
         \ruledhbox{\showotfstepglyphs\recurselevel}%
       \fi
       \quad
       \showotfstepchars\recurselevel
       \hfill
       \par
     \egroup
   \egroup
   \blank}

\unexpanded\def\showotfsteps
  {\begingroup
   \veryraggedright
   \forgetparindent
   \forgeteverypar
   \tt
   \lefttoright
   \hbox to \hsize \bgroup
     \hbox to 6\emwidth{\bf font\hss}%
     \vtop \bgroup
       \hsize\dimexpr\hsize-6\emwidth\relax
       \language\minusone
       \bf
       \showotfstepfont
     \egroup
   \egroup
   \blank
   \hbox to \hsize \bgroup
     \hbox to 6\emwidth{\bf features\hss}%
     \vtop \bgroup
       \hsize\dimexpr\hsize-6\emwidth\relax
       \language\minusone
       \showotfstepfeatures
     \egroup
   \egroup
   \blank
   \scratchcounter\otfnoffeaturesteps\relax
   \dorecurse\scratchcounter
     {\ifcase\showotfstepsmode
      \or % 1 = only first
        \ifnum\recurselevel=\plusone
          \showotfsteps_n
        \fi
      \or % 2 = only last
        \ifnum\recurselevel=\scratchcounter
          \showotfsteps_n
        \fi
      \or % 3 = first and last
        \ifnum\recurselevel=\plusone
          \showotfsteps_n
        \else\ifnum\recurselevel=\scratchcounter
          \showotfsteps_n
        \fi\fi
      \else % everything
        \showotfsteps_n
      \fi}%
   \endgroup}

\unexpanded\def\startotfsample
  {\enabletrackers[otf.sample.silent]% beware, kind of global
   \startotfcollecting
   \begingroup
   \veryraggedright
   \forgetparindent
   \forgeteverypar}

\unexpanded\def\stopotfsample
  {\endgroup
   \stopotfcollecting
   \disabletrackers[otf.sample]% beware, kind of global: otf.sample
   \showotfsteps
   \resetotfcollecting}

\newbox\otfcompositionbox

% this should go in spac-ali:

\installcorenamespace{otfcompositiondir}

\letvalue{\??otfcompositiondir  -1}\righttoleft
\letvalue{\??otfcompositiondir r2l}\righttoleft
\letvalue{\??otfcompositiondir l2r}\lefttoright
\letvalue{\??otfcompositiondir  +1}\lefttoright
\letvalue{\??otfcompositiondir   1}\lefttoright

\unexpanded\def\setotfcompositiondirection#1%
 {\begincsname\??otfcompositiondir#1\endcsname}

\unexpanded\def\showotfcomposition#1#2#3% {font*features at size}, rl=-1, text
  {\begingroup
   \forgetparindent
   \forgeteverypar
 % \setupcolors[\c!state=\v!start]%
   \setupalign[\v!verytolerant,\v!flushleft]%
   \startotfsample
   \nohyphens
   \global\setbox\otfcompositionbox\hbox{\definedfont[#1]\relax\setotfcompositiondirection{#2}\relax#3}%
   \stopotfsample
   \endgroup}

%D \startbuffer
%D \startotfcompositionlist{Serif*default @ 11pt}{l2r}%
%D     \showotfcompositionsample{effe}
%D \stopotfcompositionlist
%D \stopbuffer
%D
%D \typebuffer \getbuffer

\unexpanded\def\showotfcompositionlist#1#2#3%
  {\begingroup
   \definedfont[#1]%
   \setbox\scratchbox\hbox\bgroup
     \setotfcompositiondirection{#2}%
     #3%
   \egroup
   \strut
   \def|##1|{\kern\onepoint\string|\kern\onepoint##1\kern\onepoint\string|\kern\onepoint}%
   \cldcontext{nodes.listtoutf(tex.box[\number\scratchbox].list,"{\\kern\\onepoint}",true)}%
   \endgroup}

\unexpanded\def\startotfcompositionlist#1#2#3\stopotfcompositionlist
  {\begingroup
   \unexpanded\def\showotfcompositionsample##1%
     {\NC\type{##1}%
      \NC\showotfcompositionlist{Mono}{#2}{##1}%
      \NC\showotfcompositionlist{#1}{#2}{##1}%
      \NC\definedfont[#1]##1%
      \NC\NR}%
   \starttabulate[|||||]%
     #3%
   \stoptabulate
   \endgroup}

\let\stopotfcompositionlist\relax

% new

\unexpanded\def\savefont[#1]% not yet in i-*.xml
  {\begingroup
   \getdummyparameters[#1]%
   \clf_savefont {
      filename {\dummyparameter\c!file}
      fontname {\dummyparameter\c!name}
      method   {\dummyparameter\c!method}
   }%
   \endgroup}

\protect \endinput