spac-prf.mklx /size: 5346 b    last modification: 2023-12-21 09:44
1%D \module
2%D   [       file=spac-prf,
3%D        version=2015.11.16, % moved from test module mathplus
4%D          title=\CONTEXT\ Spacing Macros,
5%D       subtitle=Profiling,
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 Spacing Macros / Profiling}
15
16%D This is experimental code that we need for a project. The interface and details
17%D can change. I moved it into the core because that way we can use it on servers.
18
19% framed: first reflow then profile
20
21\unprotect
22
23\registerctxluafile{spac-prf}{autosuffix}
24
25\definesystemattribute[profilemethod][public]
26
27\installcorenamespace {profile}
28\installcorenamespace {profiles}
29
30\installcommandhandler \??profile {profile} \??profile
31
32\setupprofile
33  [\c!height=\strutht,
34   \c!depth=\strutdp,
35   \c!distance=\normallineskip,
36   \c!lines=\zerocount,
37   \c!factor=\plusone]
38
39\defineprofile
40  [\v!strict]
41  [\c!method=\v!strict]
42
43\defineprofile
44  [\v!fixed]
45  [\c!method=\v!fixed]
46
47\defineprofile
48  [\v!none]
49  [\c!method=\v!none,
50   \c!height=\zeropoint,
51   \c!depth=\zeropoint,
52   \c!distance=\zeropoint,
53   \c!factor=\plusone]
54
55\appendtoks
56    \ifcstok{\profileparameter\c!define}\v!yes
57        \frozen\protected\edefcsname\e!start\currentprofile\endcsname{\spac_profile_start{\currentprofile}}%
58        \frozen\protected\defcsname \e!stop \currentprofile\endcsname{\spac_profile_stop}%
59    \fi
60\to \everydefineprofile
61
62\def\spac_profile_set
63  {\clf_setprofile
64      name      {\currentprofile}%
65      height    \dimexpr\profileparameter\c!height\relax
66      depth     \dimexpr\profileparameter\c!depth\relax
67      distance  \dimexpr\profileparameter\c!distance\relax
68      factor    \numexpr\profileparameter\c!factor\relax
69      lines     \numexpr\profileparameter\c!lines\relax
70      method    {\profileparameter\c!method}%
71   \relax}
72
73\tolerant\protected\def\spac_profile_start#profile#spacer[#S#settings]%
74  {\begingroup
75   \ifparameter#settings\or
76     \cdef\currentprofile{#profile}%
77     \setupcurrentprofile[#settings]%
78   \orelse\ifhastok={#profile}%
79      \let\currentprofile\v!none
80      \setupcurrentprofile[#profile]%
81   \else
82      \cdef\currentprofile{#profile}%
83   \fi
84   \spac_profile_set
85   \profileparameter\c!before}
86
87\protected\def\spac_profile_stop
88  {\par % otherwise not applied
89   \profileparameter\c!after
90   \endgroup}
91
92\permanent\protected\def\startprofile[#S#profile]%
93  {\spac_profile_start{#profile}}
94
95\permanent\protected\def\stopprofile
96  {\spac_profile_stop}
97
98\permanent\protected\def\setprofile[#profile]%
99  {\cdef\currentprofile{#profile}%
100   \spac_profile_set}
101
102\permanent\protected\def\resetprofile
103  {\c_attr_profilemethod\attributeunsetvalue}
104
105\permanent\protected\def\useprofileparameter#getparameter%
106  {\edef\m_spac_profile_asked{#getparameter\c!profile}%
107   \ifempty\m_spac_profile_asked
108     \resetprofile
109   \else
110     \setprofile[\m_spac_profile_asked]%
111   \fi}
112
113\permanent\tolerant\protected\def\profiledbox[#S#profile]#spacer[#S#settings]%
114  {\vbox\bgroup
115   \ifparameter#settings\or
116     \cdef\currentprofile{#profile}%
117     \setupcurrentprofile[#settings]%
118   \orelse\ifhastok={#profile}%
119      \let\currentprofile\v!none
120      \setupcurrentprofile[#profile]%
121   \else
122      \cdef\currentprofile{#profile}%
123   \fi
124   \dowithnextbox
125     {\profilegivenbox\currentprofile\nextbox
126      \unvbox\nextbox
127      \egroup}%
128     \vbox}
129
130\permanent\protected\def\profilegivenbox#profile#box%
131  {\begingroup
132   \cdef\currentprofile{#profile}%
133   \clf_profilebox
134      box      \numexpr#box\relax
135      height   \dimexpr\profileparameter\c!height\relax
136      depth    \dimexpr\profileparameter\c!depth\relax
137      distance \dimexpr\profileparameter\c!distance\relax
138      factor   \numexpr\profileparameter\c!factor\relax
139      lines    \numexpr\profileparameter\c!lines\relax
140      method   {\profileparameter\c!method}%
141    \relax
142    \endgroup}
143
144\defineprofile[halffixed]   [\v!fixed][\c!factor=\plustwo]
145\defineprofile[quarterfixed][\v!fixed][\c!factor=\plusfour]
146\defineprofile[eightsfixed] [\v!fixed][\c!factor=\pluseight]
147
148% Finally some follow up on this experiment:
149
150\definesystemattribute[lineprofile]  [public]
151
152\installcorenamespace {lineprofile}
153
154\installcommandhandler \??lineprofile {lineprofile} \??lineprofile
155
156\setuplineprofile
157  [\c!method=\v!a,
158   \c!step=.5\emwidth, % maybe 2pt
159   \c!paragraph=\v!no,
160   \c!factor=.125]     % maybe 0.250
161
162\def\spac_line_profile_set
163  {\clf_setlineprofile
164      name      {\currentlineprofile}%
165      step      \dimexpr\lineprofileparameter\c!step\relax
166      factor    {\lineprofileparameter\c!factor}%
167      method    {\lineprofileparameter\c!method}%
168      paragraph {\lineprofileparameter\c!paragraph}%
169   \relax}
170
171\permanent\tolerant\protected\def\setlineprofile[#profile]%
172  {\cdef\currentlineprofile{#profile}%
173   \spac_line_profile_set}
174
175\permanent\protected\def\resetlineprofile
176  {\c_attr_lineprofile\attributeunsetvalue}
177
178\permanent\protected\def\setmainlineprofile
179  {\lettonothing\currentlineprofile
180   \spac_line_profile_set}
181
182\appendtoks
183    \c_attr_lineprofile\attributeunsetvalue % or in general resetter
184\to \everyforgetall
185
186\protect \endinput
187