1
2
3
4
5
6
7
8
9
10
11
12
13
14\writestatus{loading}{ConTeXt Spacing Macros Profiling}
15
16
17
18
19
20
21\unprotect
22
23\registerctxluafile{spacprf}{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 {\profileparameter\c!height}
66 depth {\profileparameter\c!depth}
67 distance {\profileparameter\c!distance}
68 factor {\profileparameter\c!factor}
69 lines {\profileparameter\c!lines}
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
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 {#box}
135 height {\profileparameter\c!height}
136 depth {\profileparameter\c!depth}
137 distance {\profileparameter\c!distance}
138 factor {\profileparameter\c!factor}
139 lines {\profileparameter\c!lines}
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
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,
159 \c!paragraph=\v!no,
160 \c!factor=.125]
161
162\def\spac_line_profile_set
163 {\clf_setlineprofile
164 name {\currentlineprofile}
165 step {\lineprofileparameter\c!step}
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
184\to \everyforgetall
185
186\protect \endinput
187 |