s-typesetting-kerning.mkiv /size: 6330 b    last modification: 2020-07-01 14:35
1%D \module
2%D   [      file=s-typesetting-kerning,
3%D        version=2014.12.14,
4%D          title=\CONTEXT\ Style File,
5%D       subtitle=Show Character Kerning,
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\unprotect
15
16\definecharacterkerning
17  [typesetting-kerning-demo]
18  [factor=.5]
19
20\startbuffer[showcharacterkerning:boxes]
21    \starttextrule{boxes}
22        \showfontkerns
23        \dontcomplain
24        \startlines
25            test \hbox{!} test
26            test\hbox{!} test
27            test \hbox{!}test
28            test:$x$ test
29            \setcharacterkerning[typesetting-kerning-demo]
30            test \hbox{!} test
31            test\hbox{!} test
32            test \hbox{!}test
33            test:$x$ test
34        \stoplines
35    \stoptextrule
36\stopbuffer
37
38\startbuffer[showcharacterkerning:ligatures]
39    \starttextrule{ligatures}
40        \dontcomplain
41        \startlines
42            effe flink effectief efficient fietsen
43            \blank
44            \setcharacterkerning[typesetting-kerning-demo]
45            effe flink effectief efficient fietsen
46            \blank \hsize\zeropoint
47            effe
48            flink
49            effectief
50            efficient
51            fietsen
52        \stoplines
53    \stoptextrule
54\stopbuffer
55
56\startbuffer[showcharacterkerning:discretionaries]
57    \starttextrule{discretionary}
58        \dontcomplain
59        \startlines
60            \hbox{\samplediscretionary}
61            \hbox{xxx\samplediscretionary}
62            \hbox{\samplediscretionary xxx}
63            \hbox{xxx\samplediscretionary xxx}
64            \blank
65            \setcharacterkerning[typesetting-kerning-demo]
66            \hbox{\samplediscretionary}
67            \hbox{xxx\samplediscretionary}
68            \hbox{\samplediscretionary xxx}
69            \hbox{xxx\samplediscretionary xxx}
70            \blank \hsize\zeropoint
71            \samplediscretionary
72            xxx\samplediscretionary
73            \samplediscretionary xxx
74            xxx\samplediscretionary xxx
75        \stoplines
76    \stoptextrule
77\stopbuffer
78
79\startbuffer[showcharacterkerning:explicits]
80    \starttextrule{explicits}
81        \exhyphenchar    \hyphenasciicode
82        \preexhyphenchar \lessthanasciicode
83        \postexhyphenchar\morethanasciicode
84        \def\TestDisc
85          {\discretionary
86             {\kern\emwidth<}%
87             {>\kern\emwidth}%
88             {\kern\emwidth=\kern\emwidth}%
89          }
90        \dontcomplain
91        \startlines
92            \hbox{super-charged}
93            \hbox{super\-charged}
94            \hbox{super\TestDisc charged}
95            \hbox{super\discretionary{[}{]}{[]}charged}
96            \blank
97            \setcharacterkerning[typesetting-kerning-demo]
98            \hbox{super-charged}
99            \hbox{super\-charged}
100            \hbox{super\TestDisc charged}
101            \hbox{super\discretionary{[}{]}{[]}charged}
102            \blank \hsize\zeropoint
103            super-charged
104            super\-charged
105            super\TestDisc charged
106            super\discretionary{[}{]}{[]}charged
107        \stoplines
108    \stoptextrule
109\stopbuffer
110
111\starttexdefinition unexpanded showcharacterkerning
112    \getbuffer[showcharacterkerning:boxes]
113    \getbuffer[showcharacterkerning:ligatures]
114    \getbuffer[showcharacterkerning:discretionaries]
115    \getbuffer[showcharacterkerning:explicits]
116\stoptexdefinition
117
118
119\starttexdefinition showcharacterkerningstepscompared #1
120    \definecharacterkerning[crap][factor=\KerningStepFactor]%
121    \setbox0=\ruledhbox{\color[color-1]{#1}\hss}
122    \setbox2=\ruledhbox{\setcharacterkerning[crap]\color[color-2]{#1}}
123    \setbox4=\ruledhbox{\setcharacterkerning[crap]\showfontkerns\showglyphs#1}
124    \xdef\KerningStepPercentage{\ctxlua{context("\letterpercent 0.2f",(1-\number\wd0/\number\wd2)*100)}}
125    \scratchwidth\wd0
126    \vtop\bgroup
127        \hbox{\box0\hskip-\scratchwidth\box2}
128        \par
129        \box4
130    \egroup
131\stoptexdefinition
132
133\starttexdefinition showcharacterkerningsteps [#1]
134
135    \start
136
137    \getdummyparameters
138      [\s!font=Regular,
139       \c!sample={Wat een bende, rommelen met het font design!},
140       \c!text={rommelen},
141       \c!first=00,
142       \c!last=95,
143       \c!step=05,
144       \c!option=, % \v!page
145       #1]
146
147    \doif{\dummyparameter\c!option}\v!page {
148        \startTEXpage[\c!offset=1ex]
149    }
150
151        \definecolor[color-1][r=1,t=.5,a=1]
152        \definecolor[color-2][b=1,t=.5,a=1]
153
154        \definedfont[\dummyparameter\s!font*default sa 1]
155
156        \doif {\dummyparameter\c!option}\v!page {
157            \begingroup
158                \tttf \dummyparameter\s!font\space @ default
159            \endgroup
160            \blank
161        }
162
163        \starttabulate[|cT|l|cT|l|cT|]
164
165        \NC \tt\bf factor \NC \tt\bf sample \NC \tt\bf \letterpercent \NC \tt\bf text \NC \tt\bf \letterpercent \NC \NR \HL
166
167        \dostepwiserecurse {\dummyparameter\c!first} {\dummyparameter\c!last} {\dummyparameter\c!step} {
168            \NC
169                \xdef\KerningStepFactor{\ctxlua{context("\letterpercent 0.3f",####1/1000)}}
170                \KerningStepFactor
171            \NC
172                \showcharacterkerningstepscompared{\dummyparameter\c!sample}
173            \NC
174                \KerningStepPercentage
175            \NC
176                \showcharacterkerningstepscompared{\dummyparameter\c!text}
177            \NC
178                \KerningStepPercentage
179            \NC \NR
180        }
181
182        \stoptabulate
183
184    \doif{\dummyparameter\c!option}\v!page {
185        \stopTEXpage
186    }
187
188    \stop
189
190\stoptexdefinition
191
192\protect
193
194\continueifinputfile{s-typesetting-kerning.mkiv}
195
196\starttext
197
198  % \showcharacterkerning
199
200    \showcharacterkerningsteps[font=file:FuturaStd-Book.otf,option=page]
201    \showcharacterkerningsteps[font=file:FuturaStd-Medium.otf,option=page]
202    \showcharacterkerningsteps[font=file:FuturaStd-Bold.otf,option=page]
203    \showcharacterkerningsteps[font=file:FuturaStd-heavy.otf,option=page]
204
205\stoptext
206
207% {\hsize1mm efficient\discretionary{\kern1pt!\kern1pt}{\kern1pt!\kern1pt}{\kern1pt!\kern1pt}efficient\par}
208% {\hsize1mm\definedfont[Regular]\setcharacterkerning[typesetting-kerning-demo]efficient\-efficient\par}
209
210