font-sol.mkvi /size: 4135 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [       file=font-sol,
3%D        version=2009.05.19,
4%D          title=\CONTEXT\ Font Macros,
5%D       subtitle=Solutions,
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 / Splitters}
15
16% todo: pass color for tracing
17
18%D This module is specially made for the oriental \TEX\ project. The working is as
19%D follows (and tuned for fonts like Idris' Husayni. The following method came to
20%D my mind after a couple of Skype sessions with Idris while working on the rough
21%D edges of the Husayni font and playing with font dynamics.
22%D
23%D \startitemize[packed]
24%D
25%D \item We define a couple of features sets, some can have stylistics variants
26%D       that result in the same words getting a different width. Normally this
27%D       happens in a goodies file.
28%D
29%D \item We group such features in a solution set. A solutionset can be enabled
30%D       by setting an attribute.
31%D
32%D \item For each paragraph we identify words that get this set applied. We replace
33%D       these words by a user node that refers to the original.
34%D
35%D \item For each word we apply the features to a copy that we associate with this
36%D       original word.
37%D
38%D \item At the end we have a paragraph (node list) with user nodes that point to a
39%D       cache that has originals and processed variants.
40%D
41%D \item When the paragraph is broken into lines we optimize the spacing by
42%D       substituting variants.
43%D
44%D \stopitemize
45%D
46%D This approach permits us to use a dedicated paragraph builder, one that treats
47%D the user nodes special and takes the alternatives into account.
48%D
49%D Currently we assume only one solution being active. Maybe some day I'll support
50%D a mixture. This is only one way of optimizing and after several experiments this
51%D one was chosen as testcase. It took quite some experiments (and time) to get thus
52%D far.
53%D
54%D The is experimental code for the Oriental \TEX\ project and aspects of it might
55%D change.
56%D
57%D \starttyping
58%D \setupfontsolutions[method={random,preroll},criterium=1,randomseed=101]
59%D
60%D \definefontsolution % actually only the last run needs to be done this way
61%D   [FancyHusayni]
62%D   [goodies=husayni,
63%D    solution=experimental]
64%D
65%D \definedfont[husayni*husayni-default at 24pt]
66%D \setupinterlinespace[line=36pt]
67%D \righttoleft
68%D \enabletrackers[parbuilders.solutions.splitters.colors]
69%D \setfontsolution[FancyHusayni]
70%D alb alb alb \par
71%D \resetfontsolution
72%D \disabletrackers[parbuilders.solutions.splitters.colors]
73%D \stoptyping
74
75\registerctxluafile{font-sol}{}
76
77\unprotect
78
79\definesystemattribute[splitter][public]
80
81\installcorenamespace{fontsolution}
82
83\installcommandhandler \??fontsolution {fontsolution} \??fontsolution
84
85\let\setupfontsolutions\setupfontsolution
86
87\appendtoks
88    \clf_definefontsolution
89      {\currentfontsolution}%
90      {% these are frozen
91        goodies  {\fontsolutionparameter\s!goodies}%
92        solution {\fontsolutionparameter\c!solution}%
93        less     {\fontsolutionparameter\c!less}%
94        more     {\fontsolutionparameter\c!more}%
95      }%
96    \relax
97\to \everydefinefontsolution
98
99\unexpanded\def\setfontsolution[#solution]% just one
100  {\edef\currentfontsolution{#solution}%
101   \clf_setfontsolution
102     {\currentfontsolution}%
103     {%
104        method     {\fontsolutionparameter\c!method}%
105        criterium  {\fontsolutionparameter\c!criterium}%
106      % randomseed {\fontsolutionparameter\c!random}%
107     }%
108   \relax}
109
110\unexpanded\def\resetfontsolution % resets all
111  {\clf_resetfontsolution
112   \let\currentfontsolution\empty}
113
114\unexpanded\def\startfontsolution % [#1]
115  {\pushmacro\currentfontsolution
116   \setfontsolution}
117
118\unexpanded\def\stopfontsolution
119  {\ifhmode\par\fi
120   \clf_stopfontsolution
121   \popmacro\currentfontsolution}
122
123% We initialize this module at the \LUA\ end.
124%
125% \setupfontsolutions
126%   [\c!method={\v!normal,preroll},
127%    \c!criterium=0]
128
129\protect
130