hybrid-weird.tex /size: 3878 b    last modification: 2023-12-21 09:43
1% language=us
2
3\startcomponent hybrid-backends
4
5\environment hybrid-environment
6
7\startchapter[title={Weird examples}]
8
9\startsection[title={Introduction}]
10
11In this chapter I will collect a couple of weird examples.
12
13\stopsection
14
15\startsection[title=Inter-character spacing]
16
17There was a discussion on the \LUATEX\ (dev) list about inter character spacing
18and ligatures. The discussion involved a mechanism inherited from \PDFTEX\ but in
19\CONTEXT\ we don't use that at all. Actually, support for inter character spacing
20was added in an early stage of \MKIV\ development as an alternative for the
21\MKII\ variant, which used parsing at the \TEX\ end. Personally I never use this
22spacing, unless a design in a project demands it.
23
24In the \MKIV\ method we split ligatures when its components are known. This works
25quite well. It's anyway a good idea to disable ligatures, so it's more a
26fallback. Actually we should create components for hard coded characters like
27\ae\ but as no one ever complained I leave that for a later moment.
28
29As we already had the mechanisms in place, support for selective spacing of
30ligatures was a rather trivial extension. If there is ever a real need for it, I
31will provide control via the normal user interface, but for now using a few hooks
32will do. The following code shows an example of an implementation. \footnote {The
33examples have been adapted to the latest \CONTEXT\ where we use \type
34{\getchar(n)} instead of \type {n.char}.}
35
36\startbuffer
37local utfbyte = utf.byte
38local getchar = nodes.nuts.getchar
39
40local keep = {
41    [0x0132] = true, [0x0133] = true, -- IJ ij
42    [0x00C6] = true, [0x00E6] = true, -- AE ae
43    [0x0152] = true, [0x0153] = true, -- OE oe
44}
45
46function typesetters.kerns.keepligature(n)
47    return keep[getchar(n)]
48end
49
50local together = {
51    [utfbyte("c")] = { [utfbyte("k")] = true },
52    [utfbyte("i")] = { [utfbyte("j")] = true },
53    [utfbyte("I")] = { [utfbyte("J")] = true },
54}
55
56function typesetters.kerns.keeptogether(n1,n2)
57    local k = together[getchar(n1)]
58    return k and k[getchar(n2)]
59end
60\stopbuffer
61
62\ctxluabuffer
63
64\typebuffer
65
66The following also works:
67
68\starttyping
69local lpegmatch = lpeg.match
70local fontdata  = fonts.identifiers
71local getchar   = nodes.nuts.getchar
72local getfont   = nodes.nuts.getfont
73
74local keep = -- start of name
75        lpeg.P("i_j")
76      + lpeg.P("I_J")
77      + lpeg.P("aeligature")
78      + lpeg.P("AEligature")
79      + lpeg.P("oeligature")
80      + lpeg.P("OEligature")
81
82function typesetters.kerns.keepligature(n)
83    local d = fontdata[getfont(n)].descriptions
84    local c = d and d[getchar(n)]
85    local n = c and c.name
86    return n and lpegmatch(keep,n)
87end
88\stoptyping
89
90A more generic solution would be to use the \type {tounicode} information, but it
91would be overkill as we're dealing with a rather predictable set of characters
92that have gotten \UNICODE\ slots assigned. When using basemode most fonts will
93work anyway.
94
95So, is this really worth the effort? Take a look at the following example.
96
97\startbuffer
98\definecharacterkerning [KernMe] [factor=0.25]
99
100\start
101  \setcharacterkerning[KernMe]
102  \definedfont[Serif*default]
103  Ach kijk effe, \ae sop draagt een knickerbocker! \par
104  \definedfont[Serif*smallcaps]
105  Ach kijk effe, \ae sop draagt een knickerbocker! \par
106\stop
107\stopbuffer
108
109\typebuffer
110
111Typeset this (Dutch text) looks like:
112
113\getbuffer
114
115You might wonder why I decided to look into it. Right at the moment when it was
116discussed, I was implementing a style that needed the Calibri font that comes
117with \MSWINDOWS, and I visited the FontShop website to have a look at the font.
118To my surprise it had quite some ligatures, way more than one would expect.
119
120\placefigure
121  {Some of the ligatures in Calibri Regular. Just wonder what
122   intercharacter spacing will do here.}
123  {\externalfigure[calibri-fontshop.png]}
124
125\stopsection
126
127\stopchapter
128
129\stopcomponent
130