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);
89 dir_level
(p
) = cur_level
;
93 @ The global static array variable |dir_strings| is also used
94 by the lua nodelib interface
, so it cannot be static. Putting
95 it here instead of there avoid the nodelib having to know
96 about the actual values of |dir_TRT| etc.
101 const char
*dir_strings
[128] = {
102 "-TLT","???", "???", "???", "-TRT","???", "???", "???",
103 "???", "-LTL","???", "???", "???", "???", "???", "???",
104 "???", "???", "???", "???", "???", "???", "???", "???",
105 "-RTT","???", "???", "???", "???", "???", "???", "???",
106 "???", "???", "???", "???", "???", "???", "???", "???",
107 "???", "???", "???", "???", "???", "???", "???", "???",
108 "???", "???", "???", "???", "???", "???", "???", "???",
109 "???", "???", "???", "???", "???", "???", "???", "???",
110 "+TLT","???", "???", "???", "+TRT","???", "???", "???",
111 "???", "+LTL","???", "???", "???", "???", "???", "???",
112 "???", "???", "???", "???", "???", "???", "???", "???",
113 "+RTT","???", "???", "???", "???", "???", "???", "???",
114 "???", "???", "???", "???", "???", "???", "???", "???",
115 "???", "???", "???", "???", "???", "???", "???", "???",
116 "???", "???", "???", "???", "???", "???", "???", "???",
117 "???", "???", "???", "???", "???", "???", "???", "???"
123 const char
*dir_strings
[8] = {
124 "-TLT","-TRT","-LTL","-RTT",
125 "+TLT","+TRT","+LTL","+RTT",
130 const char
*string_dir
(int d
)
132 return
(dir_strings
[d
+dir_swap
]+1);
136 void print_dir
(int d
)
138 tprint
(string_dir
(d
));
142 scaled pack_width
(int curdir
, int pdir
, halfword p
, boolean isglyph
)
146 if
(textdir_parallel
(curdir
, pdir
) == textglyphdir_orthogonal
(pdir
)) {
148 if
(ex_glyph
(p
) != 0) {
149 /* wd
= round_xn_over_d
(wd
, 1000 + ex_glyph
(p
)/1000, 1000); */
150 wd
= ext_xn_over_d
(wd
, 1000000+ex_glyph
(p
), 1000000);
154 wd
= glyph_depth
(p
) + glyph_height
(p
);
158 } else
{ /* hlist
, vlist
, image
, form
, rule
*/
159 if
(textdir_parallel
(pdir
, curdir
))
162 wd
= depth
(p
) + height
(p
);
168 scaled_whd pack_width_height_depth
(int curdir
, int pdir
, halfword p
, boolean isglyph
)
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
;