3 % Copyright
2009-2014 Taco Hoekwater
<taco@@luatex.org
>
5 % This file is part of LuaTeX.
7 % LuaTeX is free software
; you can redistribute it and
/or modify it under
8 % the terms of the GNU General Public License as published by the Free
9 % Software Foundation
; either version
2 of the License
, or
(at your
10 % option
) any later version.
12 % LuaTeX is distributed in the hope that it will be useful
, but WITHOUT
13 % ANY WARRANTY
; without even the implied warranty of MERCHANTABILITY or
14 % FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15 % License for more details.
17 % You should have received a copy of the GNU General Public License along
18 % with LuaTeX
; if not
, see
<http
://www.gnu.org
/licenses
/>.
25 void scan_direction
(void
)
27 int save_cur_cmd
= cur_cmd
;
28 int save_cur_chr
= cur_chr
;
30 if
(cur_cmd
== assign_dir_cmd
) {
31 cur_val
= eqtb
[cur_chr
].cint
;
36 if
(scan_keyword
("TLT")) {
38 } else if
(scan_keyword
("TRT")) {
40 } else if
(scan_keyword
("LTL")) {
42 } else if
(scan_keyword
("RTT")) {
45 tex_error
("Bad direction", NULL);
49 if
(cur_cmd
!= spacer_cmd
)
52 cur_cmd
= save_cur_cmd
;
53 cur_chr
= save_cur_chr
;
56 @ the next two are used by postlinebreak.c
59 halfword do_push_dir_node
(halfword p
, halfword a
)
61 halfword n
= copy_node
(a
);
66 halfword do_pop_dir_node
(halfword p
)
68 halfword n
= vlink
(p
);
76 halfword text_dir_ptr
;
78 @ There is no need to do anything here at the moment.
80 void initialize_directions
(void
)
85 halfword new_dir
(int s
)
87 halfword p
= new_node
(dir_node
, 0);
90 dir_level
(p
) = cur_level
;
94 @ The global static array variable |dir_strings| is also used
95 by the lua nodelib interface
, so it cannot be static. Putting
96 it here instead of there avoid the nodelib having to know
97 about the actual values of |dir_TRT| etc.
102 const char
*dir_strings
[128] = {
103 "-TLT","???", "???", "???", "-TRT","???", "???", "???",
104 "???", "-LTL","???", "???", "???", "???", "???", "???",
105 "???", "???", "???", "???", "???", "???", "???", "???",
106 "-RTT","???", "???", "???", "???", "???", "???", "???",
107 "???", "???", "???", "???", "???", "???", "???", "???",
108 "???", "???", "???", "???", "???", "???", "???", "???",
109 "???", "???", "???", "???", "???", "???", "???", "???",
110 "???", "???", "???", "???", "???", "???", "???", "???",
111 "+TLT","???", "???", "???", "+TRT","???", "???", "???",
112 "???", "+LTL","???", "???", "???", "???", "???", "???",
113 "???", "???", "???", "???", "???", "???", "???", "???",
114 "+RTT","???", "???", "???", "???", "???", "???", "???",
115 "???", "???", "???", "???", "???", "???", "???", "???",
116 "???", "???", "???", "???", "???", "???", "???", "???",
117 "???", "???", "???", "???", "???", "???", "???", "???",
118 "???", "???", "???", "???", "???", "???", "???", "???"
124 const char
*dir_strings
[8] = {
125 "-TLT","-TRT","-LTL","-RTT",
126 "+TLT","+TRT","+LTL","+RTT",
131 const char
*string_dir
(int d
)
133 return
(dir_strings
[d
+dir_swap
]+1);
137 void print_dir
(int d
)
139 tprint
(string_dir
(d
));
143 scaled pack_width
(int curdir
, int pdir
, halfword p
, boolean isglyph
)
147 if
(textdir_parallel
(curdir
, pdir
) == textglyphdir_orthogonal
(pdir
)) {
149 if
(ex_glyph
(p
) != 0) {
150 /* wd
= round_xn_over_d
(wd
, 1000 + ex_glyph
(p
)/1000, 1000); */
151 wd
= ext_xn_over_d
(wd
, 1000000+ex_glyph
(p
), 1000000);
155 wd
= glyph_depth
(p
) + glyph_height
(p
);
157 } else
{ /* hlist
, vlist
, image
, form
, rule
*/
158 if
(textdir_parallel
(pdir
, curdir
))
161 wd
= depth
(p
) + height
(p
);
167 scaled_whd pack_width_height_depth
(int curdir
, int pdir
, halfword p
,
170 scaled_whd whd
= { 0, 0, 0 };
171 whd.wd
= pack_width
(curdir
, pdir
, p
, isglyph
);
173 if
(is_rotated
(curdir
)) {
174 if
(textdir_parallel
(curdir
, pdir
))
175 whd.ht
= whd.dp
= (glyph_height
(p
) + glyph_depth
(p
)) / 2;
177 whd.ht
= whd.dp
= glyph_width
(p
) / 2;
178 } else if
(is_rotated
(pdir
)) {
179 if
(textdir_parallel
(curdir
, pdir
))
180 whd.ht
= whd.dp
= (glyph_height
(p
) + glyph_depth
(p
)) / 2;
182 whd.ht
= glyph_width
(p
);
184 if
(glyphdir_eq
(curdir
, pdir
)) {
185 whd.ht
= glyph_height
(p
);
186 whd.dp
= glyph_depth
(p
);
187 } else if
(glyphdir_opposite
(curdir
, pdir
)) {
188 whd.ht
= glyph_depth
(p
);
189 whd.dp
= glyph_height
(p
);
191 whd.ht
= glyph_width
(p
);
194 if
(is_rotated
(curdir
)) {
195 if
(textdir_parallel
(curdir
, pdir
))
196 whd.ht
= whd.dp
= (height
(p
) + depth
(p
)) / 2;
198 whd.ht
= whd.dp
= width
(p
) / 2;
199 } else if
(pardir_eq
(curdir
, pdir
)) {
202 } else if
(pardir_opposite
(curdir
, pdir
)) {
212 void update_text_dir_ptr
(int val
)
214 if
(dir_level
(text_dir_ptr
) == cur_level
) {
216 dir_dir
(text_dir_ptr
) = val
;
219 halfword text_dir_tmp
= new_dir
(val
);
220 vlink
(text_dir_tmp
) = text_dir_ptr
;
221 text_dir_ptr
= text_dir_tmp
;