summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/node-spl.mkiv
blob: 3630212af3bde6356035bfee4b2b2de1fd9e92f2 (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
%D \module
%D   [       file=node-spl,
%D        version=2009.05.19,
%D          title=\CONTEXT\ Node Macros,
%D       subtitle=Splitters,
%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 Node Support / Splitters}

\registerctxluafile{node-spl}{1.001}

\definesystemattribute[splitter][public]

%D This module is specially made for the oriental \TEX\ project. The working is as
%D follows (and tuned for fonts like Idris' Husayni. The following method came to
%D my mind after a couple of Skype sessions with Idris while working on the rough
%D edges of the Husayni font and playing with font dynamics.
%D
%D \startitemize[packed]
%D
%D \item We define a couple of features sets, some can have stylistics variants
%D       that result in the same words getting a different width. Normally this
%D       happens in a goodies file.
%D
%D \item We group such features in a solution set. A solutionset can be enabled
%D       by setting an attribute.
%D
%D \item For each paragraph we identify words that get this set applied. We replace
%D       these words by a user node that refers to the original.
%D
%D \item For each word we apply the features to a copy that we associate with this
%D       original word.
%D
%D \item At the end we have a paragraph (node list) with user nodes that point to a
%D       cache that has originals and processed variants.
%D
%D \item When the paragraph is broken into lines we optimize the spacing by
%D       substituting variants.
%D
%D \stopitemize
%D
%D This approach permits us to use a dedicated paragraph builder, one that treats
%D the user nodes special and takes the alternatives into account.
%D
%D Currently we assume only one solution being active. Maybe some day I'll support
%D a mixture. This is only one way of optimizing and after several experiments this
%D one was chosen as testcase. It took quite some experiments (and time) to get thus
%D far.
%D
%D The is experimental code for the Oriental \TEX\ project and aspects of it might
%D change.
%D
%D \starttyping
%D \setupfontsolutions[method={random,preroll},criterium=1,randomseed=101]
%D
%D \definefontsolution % actually only the last run needs to be done this way
%D   [FancyHusayni]
%D   [goodies=husayni,
%D    solution=experimental]
%D
%D \definedfont[husayni*husayni-default at 24pt]
%D \setupinterlinespace[line=36pt]
%D \righttoleft
%D \enabletrackers[parbuilders.solutions.splitters.colors]
%D \setfontsolution[FancyHusayni]
%D alb alb alb \par
%D \resetfontsolution
%D \disabletrackers[parbuilders.solutions.splitters.colors]
%D \stoptyping

\unprotect

\newtoks\everysetupfontsolutions

\unexpanded\def\definefontsolution
  {\dodoubleargument\dodefinefontsolution}

\def\dodefinefontsolution[#1][#2]% we could set the attribute at the lua end
  {\setxvalue{\??fu:#1}{\attribute\splitterattribute\ctxlua{builders.paragraphs.solutions.splitters.define("#1","#2")}\relax}}

\unexpanded\def\setfontsolution[#1]%
  {\ctxlua{builders.paragraphs.solutions.splitters.enable()}%
   \csname\??fu:#1\endcsname}

\unexpanded\def\resetfontsolution
  {\ctxlua{builders.paragraphs.solutions.splitters.disable()}%
   \attribute\splitterattribute\attributeunsetvalue}

\letvalue{\??fu:\v!reset}\resetfontsolution

\unexpanded\def\setupfontsolutions[#1]%
  {\getparameters[\??fu][#1]%
   \the\everysetupfontsolutions}

\appendtoks
    \ctxlua{builders.paragraphs.solutions.splitters.setup {
        method    = "\@@fumethod",
        criterium = "\@@fucriterium",
    }}%
\to \everysetupfontsolutions

% We initialize this module at the \LUA\ end.
%
% \setupfontsolutions
%   [\c!method={\v!normal,preroll},
%    \c!criterium=0]

\protect