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
|
% This file is part of babel. For further details see:
% https://www.ctan.org/pkg/babel
\ifx\BabelBeforeIni\undefined
\PackageError{babel}%
{This file is a component of babel and cannot\MessageBreak
be loaded directly. I'll stop immediately}%
{Just use babel as documented.}%
\stop
\fi
\BabelBeforeIni{ug}{%
}
\newattribute\bblug@disc
\bblug@disc=-1
\bbl@luahyphenate
% 1) Store discretionaries just after hyphenation as an attribute of the
% next glyph, with the value of the disc penalty (assumed positive). Then
% remove the discretionary.
% 2) After the shaping, restore the discretionaries.
\directlua{
Babel.locale[\the\localeid] = {}
local ug = Babel.locale[\the\localeid]
function ug.posthyphen(head)
local UGDISC = luatexbase.registernumber'bblug@disc'
for item in node.traverse(head) do
if item.id == 7 and item.subtype == 3 and
item.next and item.next.id == 29 and
item.next.lang == \the\l@uyghur\space then
node.set_attribute(item.next, UGDISC, item.penalty)
node.remove(head, item)
end
end
end
ug.hyphen_sep = .09 % in em units
% Note it can be a string, with several characters:
ug.hyphen = unicode.utf8.char(0x0640)
Babel.linebreaking.add_after(ug.posthyphen)
function ug.hyphenate(head)
local d, k
local quad = 655360
local UGDISC = luatexbase.registernumber'bblug@disc'
for item in node.traverse(head) do
if item.id == 29 and item.lang == \the\l@uyghur\space then
local ugdisc = node.get_attribute(item, UGDISC)
if ugdisc >= 0 then
quad = font.getfont(item.font).size or quad
k = node.new(13, 1) % (kern, userkern)
k.kern = ug.hyphen_sep * quad
d = node.new(7, 3) % (disc, regular)
d.pre = Babel.str_to_nodes(
function() return ug.hyphen end,
nil, item)
d.pre = node.insert_before(d.pre, d.pre, k)
d.penalty = ugdisc
head = node.insert_before(head, item, d)
end
end
end
return head
end
luatexbase.add_to_callback("pre_linebreak_filter",
ug.hyphenate, "Babel.locale.uyghur.hyphenate")
luatexbase.add_to_callback("hpack_filter",
ug.hyphenate, "Babel.locale.uyghur.hyphenate")
}
\endinput
|