| 1 |
% This file is part of babel. For further details see: |
| 2 |
% https://www.ctan.org/pkg/babel |
| 3 |
\ifx\BabelBeforeIni\undefined |
| 4 |
\PackageError{babel}% |
| 5 |
{This file is a component of babel and cannot\MessageBreak |
| 6 |
be loaded directly. I'll stop immediately}% |
| 7 |
{Just use babel as documented.}% |
| 8 |
\stop |
| 9 |
\fi |
| 10 |
\BabelBeforeIni{ug}{% |
| 11 |
} |
| 12 |
|
| 13 |
\ifcase\bbl@engine\or |
| 14 |
|
| 15 |
\newattribute\bblug@disc |
| 16 |
\bblug@disc=-1 |
| 17 |
|
| 18 |
\bbl@luahyphenate |
| 19 |
|
| 20 |
% 1) Store discretionaries just after hyphenation as an attribute of the |
| 21 |
% next glyph, with the value of the disc penalty (assumed positive). Then |
| 22 |
% remove the discretionary. |
| 23 |
% 2) After the shaping, restore the discretionaries. |
| 24 |
|
| 25 |
\directlua{ |
| 26 |
Babel.locale[\the\localeid] = {} |
| 27 |
local ug = Babel.locale[\the\localeid] |
| 28 |
|
| 29 |
function ug.posthyphen(head) |
| 30 |
local UGDISC = luatexbase.registernumber'bblug@disc' |
| 31 |
for item in node.traverse(head) do |
| 32 |
if item.id == 7 and item.subtype == 3 and |
| 33 |
item.next and item.next.id == 29 and |
| 34 |
item.next.lang == \the\l@uyghur\space then |
| 35 |
node.set_attribute(item.next, UGDISC, item.penalty) |
| 36 |
node.remove(head, item) |
| 37 |
end |
| 38 |
end |
| 39 |
end |
| 40 |
|
| 41 |
ug.hyphen_sep = .09 % in em units |
| 42 |
% Note it can be a string, with several characters: |
| 43 |
ug.hyphen = unicode.utf8.char(0x0640) |
| 44 |
|
| 45 |
Babel.linebreaking.add_after(ug.posthyphen) |
| 46 |
|
| 47 |
function ug.hyphenate(head) |
| 48 |
local d, k |
| 49 |
local quad = 655360 |
| 50 |
local UGDISC = luatexbase.registernumber'bblug@disc' |
| 51 |
for item in node.traverse(head) do |
| 52 |
if item.id == 29 and item.lang == \the\l@uyghur\space then |
| 53 |
local ugdisc = node.get_attribute(item, UGDISC) |
| 54 |
if ugdisc >= 0 then |
| 55 |
quad = font.getfont(item.font).size or quad |
| 56 |
k = node.new(13, 1) % (kern, userkern) |
| 57 |
k.kern = ug.hyphen_sep * quad |
| 58 |
d = node.new(7, 3) % (disc, regular) |
| 59 |
d.pre = Babel.str_to_nodes( |
| 60 |
function() return ug.hyphen end, |
| 61 |
nil, item) |
| 62 |
d.pre = node.insert_before(d.pre, d.pre, k) |
| 63 |
d.penalty = ugdisc |
| 64 |
head = node.insert_before(head, item, d) |
| 65 |
end |
| 66 |
end |
| 67 |
end |
| 68 |
return head |
| 69 |
end |
| 70 |
|
| 71 |
luatexbase.add_to_callback("pre_linebreak_filter", |
| 72 |
ug.hyphenate, "Babel.locale.uyghur.hyphenate") |
| 73 |
luatexbase.add_to_callback("hpack_filter", |
| 74 |
ug.hyphenate, "Babel.locale.uyghur.hyphenate") |
| 75 |
} |
| 76 |
|
| 77 |
\fi |
| 78 |
|
| 79 |
\endinput |