Debian Codegraph @

texmf-dist/tex/generic/babel/locale/bo/babel-tibetan.tex

raw
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{bo}{%
11 }
12
13 \ifcase\bbl@engine\or
14
15 \bbl@warning{%
16 Tibetan line breaking and justification are tentative.\\%
17 They might not work as expected and their behavior\\%
18 could change in the future. Feel free to contribute.\\%
19 Reported}%
20
21 \directlua{
22 Babel.tibetan = Babel.tibetan or {}
23 Babel.tibetan.shad = {.5, 0, 0, false}
24 Babel.tibetan.tsheg = {0, .0001, 0, false}
25 Babel.tibetan.intraspace = {0, 0, 0} % TODO
26 }
27
28 \AtBeginDocument{%
29 % (1) Spacing
30 \edef\bbl@tempe{\directlua{
31 tex.print(table.concat(Babel.tibetan.shad, ' ', 1, 3))
32 }}%
33 \babelprehyphenation{tibetan}{[{a}{p}]|}%
34 { {}, {space=\bbl@tempe, data=1 } }%
35 % (2) Line breaking
36 % 0f0d=shad, 0f0e=nyis shad, 0f0b=tsheg
37 \babelprehyphenation{tibetan}{[^^^^0f0d^^^^0f0e]|[^^^^0f0d^^^^0f0e]}%
38 { {}, {insert, penalty=10000}, {}, {} }%
39 \babelprehyphenation{tibetan}{[^^^^0f0d^^^^0f0e][^^^^0f40-^^^^0f6a]}%
40 { {}, {insert, space=0 0 0}, {} }%
41 \edef\bbl@tempe{\directlua{
42 tex.print(table.concat(Babel.tibetan.tsheg, ' ', 1, 3))
43 }}%
44 \babelprehyphenation{tibetan}%
45 {^^^^0f0b[^ ^^^^0f0d^^^^0f0e{)}{]}’”»{007D}^^^^0f3b^^^^0f3d〉〉》」』】〕〗〙〛]}%
46 { {insert, penalty=10000}, {insert, space=\bbl@tempe, data=1}, {},
47 {insert, space=\bbl@tempe, data=1}, {} }%
48 \babelprehyphenation{tibetan}%
49 {^^^^0f0b[{)}{]}’”»{007D}^^^^0f3b^^^^0f3d〉〉》」』】〕〗〙〛]{a}}%
50 { {insert, penalty=10000}, {insert, space=\bbl@tempe, data=1}, {},
51 {}, {insert, space=\bbl@tempe, data=1}, {} }}
52
53 \def\bbl@tibetanjust{%
54 % (3) Justification
55 \directlua{
56 Babel.tibetan = Babel.tibetan or {}
57 %
58 Babel.tibetan.justify_enabled = true
59 Babel.tibetan.justify_factor = 1
60 %
61 function Babel.tibetan.justify(head)
62 if not Babel.tibetan.justify_enabled then return head end
63 for line in node.traverse_id(node.id'hlist', head) do
64 Babel.tibetan.justify_hlist(head, line)
65 end
66 return head
67 end
68 %
69 function Babel.tibetan.justify_hbox(head, gc, size, pack)
70 local has_infte = false
71 if Babel.tibetan.justify_enabled and pack == 'exactly' then
72 for n in node.traverse_id(12, head) do
73 if n.stretch_order > 0 then has_infte = true end
74 end
75 if not has_infte then
76 Babel.tibetan.justify_hlist(head, nil, gc, size, pack)
77 end
78 end
79 return head
80 end
81 %
82 function Babel.tibetan.justify_hlist(head, line, gc, size, pack)
83 local d, new
84 local last_t
85 local width, width_new, full, goal, shift
86 local subst_done = false
87 local GLYPH = node.id'glyph'
88 local LOCALE = Babel.attr_locale
89 %
90 if line == nil then
91 line = {}
92 line.glue_sign = 1
93 line.glue_order = 0
94 line.head = head
95 line.shift = 0
96 line.width = size
97 end
98 %
99 if (line.glue_sign == 1 and line.glue_order == 0) then
100 last_t = nil
101 for n in node.traverse_id(GLYPH, line.head) do
102 if n.char == 0x0f0b then % TSHEG
103 last_t = n
104 else
105 last_t = nil
106 end
107 end
108 %
109 if not last_t then goto next_line end
110 %
111 full = line.width
112 shift = line.shift
113 goal = full * Babel.tibetan.justify_factor % A bit crude
114 width = node.dimensions(line.head) % The 'natural' width
115 %
116 while width < goal do
117 subst_done = true
118 d = node.copy(last_t)
119 line.head, new = node.insert_after(line.head, last_t, d)
120 width_new = node.dimensions(line.head)
121 if width_new > goal or width == width_new then
122 node.remove(line.head, new) % Better compute before
123 break
124 end
125 width = width_new
126 end
127 % Must take into account marks and ins, see luatex manual.
128 % Have to be executed only if there are changes. Investigate
129 % what's going on exactly.
130 if subst_done and not gc then
131 d = node.hpack(line.head, full, 'exactly')
132 d.shift = shift
133 node.insert_before(head, line, d)
134 node.remove(head, line)
135 end
136 ::next_line::
137 end % if process line
138 end
139 %
140 luatexbase.add_to_callback('post_linebreak_filter',
141 Babel.tibetan.justify, 'Babel.tibetan.justify')
142 luatexbase.add_to_callback('hpack_filter',
143 Babel.tibetan.justify_hbox, 'Babel.tibetan.justify_hbox')
144 }}
145
146 \fi
147
148 \endinput