summaryrefslogtreecommitdiff
path: root/tex/context/base/s-typesetting-kerning.mkiv
blob: 48d81ce360239fbc52e7861a5832bdb509486e17 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
%D \module
%D   [      file=s-typesetting-kerning,
%D        version=2014.12.14,
%D          title=\CONTEXT\ Style File,
%D       subtitle=Show Character Kerning,
%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.

\unprotect

\definecharacterkerning
  [typesetting-kerning-demo]
  [factor=.5]

\startbuffer[showcharacterkerning:boxes]
    \starttextrule{boxes}
        \showfontkerns
        \dontcomplain
        \startlines
            test \hbox{!} test
            test\hbox{!} test
            test \hbox{!}test
            test:$x$ test
            \setcharacterkerning[typesetting-kerning-demo]
            test \hbox{!} test
            test\hbox{!} test
            test \hbox{!}test
            test:$x$ test
        \stoplines
    \stoptextrule
\stopbuffer

\startbuffer[showcharacterkerning:ligatures]
    \starttextrule{ligatures}
        \dontcomplain
        \startlines
            effe flink effectief efficient fietsen
            \blank
            \setcharacterkerning[typesetting-kerning-demo]
            effe flink effectief efficient fietsen
            \blank \hsize\zeropoint
            effe
            flink
            effectief
            efficient
            fietsen
        \stoplines
    \stoptextrule
\stopbuffer

\startbuffer[showcharacterkerning:discretionaries]
    \starttextrule{discretionary}
        \dontcomplain
        \startlines
            \hbox{\samplediscretionary}
            \hbox{xxx\samplediscretionary}
            \hbox{\samplediscretionary xxx}
            \hbox{xxx\samplediscretionary xxx}
            \blank
            \setcharacterkerning[typesetting-kerning-demo]
            \hbox{\samplediscretionary}
            \hbox{xxx\samplediscretionary}
            \hbox{\samplediscretionary xxx}
            \hbox{xxx\samplediscretionary xxx}
            \blank \hsize\zeropoint
            \samplediscretionary
            xxx\samplediscretionary
            \samplediscretionary xxx
            xxx\samplediscretionary xxx
        \stoplines
    \stoptextrule
\stopbuffer

\startbuffer[showcharacterkerning:explicits]
    \starttextrule{explicits}
        \exhyphenchar    \hyphenasciicode
        \preexhyphenchar \lessthanasciicode
        \postexhyphenchar\morethanasciicode
        \def\TestDisc
          {\discretionary
             {\kern\emwidth<}%
             {>\kern\emwidth}%
             {\kern\emwidth=\kern\emwidth}%
          }
        \dontcomplain
        \startlines
            \hbox{super-charged}
            \hbox{super\-charged}
            \hbox{super\TestDisc charged}
            \hbox{super\discretionary{[}{]}{[]}charged}
            \blank
            \setcharacterkerning[typesetting-kerning-demo]
            \hbox{super-charged}
            \hbox{super\-charged}
            \hbox{super\TestDisc charged}
            \hbox{super\discretionary{[}{]}{[]}charged}
            \blank \hsize\zeropoint
            super-charged
            super\-charged
            super\TestDisc charged
            super\discretionary{[}{]}{[]}charged
        \stoplines
    \stoptextrule
\stopbuffer

\starttexdefinition unexpanded showcharacterkerning
    \getbuffer[showcharacterkerning:boxes]
    \getbuffer[showcharacterkerning:ligatures]
    \getbuffer[showcharacterkerning:discretionaries]
    \getbuffer[showcharacterkerning:explicits]
\stoptexdefinition


\starttexdefinition showcharacterkerningstepscompared #1
    \definecharacterkerning[crap][factor=\KerningStepFactor]%
    \setbox0=\ruledhbox{\color[color-1]{#1}\hss}
    \setbox2=\ruledhbox{\setcharacterkerning[crap]\color[color-2]{#1}}
    \setbox4=\ruledhbox{\setcharacterkerning[crap]\showfontkerns\showglyphs#1}
    \xdef\KerningStepPercentage{\ctxlua{context("\letterpercent 0.2f",(1-\number\wd0/\number\wd2)*100)}}
    \scratchwidth\wd0
    \vtop\bgroup
        \hbox{\box0\hskip-\scratchwidth\box2}
        \par
        \box4
    \egroup
\stoptexdefinition

\starttexdefinition showcharacterkerningsteps [#1]

    \start

    \getdummyparameters
      [\s!font=Regular,
       \c!sample={Wat een bende, rommelen met het font design!},
       \c!text={rommelen},
       \c!first=00,
       \c!last=95,
       \c!step=05,
       \c!option=, % \v!page
       #1]

    \doif{\dummyparameter\c!option}\v!page {
        \startTEXpage[\c!offset=1ex]
    }

        \definecolor[color-1][r=1,t=.5,a=1]
        \definecolor[color-2][b=1,t=.5,a=1]

        \definedfont[\dummyparameter\s!font*default sa 1]

        \doif {\dummyparameter\c!option}\v!page {
            \begingroup
                \tttf \dummyparameter\s!font\space @ default
            \endgroup
            \blank
        }

        \starttabulate[|cT|l|cT|l|cT|]

        \NC \tt\bf factor \NC \tt\bf sample \NC \tt\bf \letterpercent \NC \tt\bf text \NC \tt\bf \letterpercent \NC \NR \HL

        \dostepwiserecurse {\dummyparameter\c!first} {\dummyparameter\c!last} {\dummyparameter\c!step} {
            \NC
                \xdef\KerningStepFactor{\ctxlua{context("\letterpercent 0.3f",####1/1000)}}
                \KerningStepFactor
            \NC
                \showcharacterkerningstepscompared{\dummyparameter\c!sample}
            \NC
                \KerningStepPercentage
            \NC
                \showcharacterkerningstepscompared{\dummyparameter\c!text}
            \NC
                \KerningStepPercentage
            \NC \NR
        }

        \stoptabulate

    \doif{\dummyparameter\c!option}\v!page {
        \stopTEXpage
    }

    \stop

\stoptexdefinition

\protect

\continueifinputfile{s-typesetting-kerning.mkiv}

\starttext

  % \showcharacterkerning

    \showcharacterkerningsteps[font=file:FuturaStd-Book.otf,option=page]
    \showcharacterkerningsteps[font=file:FuturaStd-Medium.otf,option=page]
    \showcharacterkerningsteps[font=file:FuturaStd-Bold.otf,option=page]
    \showcharacterkerningsteps[font=file:FuturaStd-heavy.otf,option=page]

\stoptext

% {\hsize1mm efficient\discretionary{\kern1pt!\kern1pt}{\kern1pt!\kern1pt}{\kern1pt!\kern1pt}efficient\par}
% {\hsize1mm\definedfont[Regular]\setcharacterkerning[typesetting-kerning-demo]efficient\-efficient\par}