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
/>.
26 void scan_direction
(void
)
28 int save_cur_cmd
= cur_cmd
;
29 int save_cur_chr
= cur_chr
;
31 if
(cur_cmd
== assign_dir_cmd
) {
32 cur_val
= eqtb
[cur_chr
].cint
;
37 if
(scan_keyword
("TLT")) {
39 } else if
(scan_keyword
("TRT")) {
41 } else if
(scan_keyword
("LTL")) {
43 } else if
(scan_keyword
("RTT")) {
46 tex_error
("Bad direction", NULL);
50 if
(cur_cmd
!= spacer_cmd
)
53 cur_cmd
= save_cur_cmd
;
54 cur_chr
= save_cur_chr
;
57 @ the next two are used by postlinebreak.c
60 halfword do_push_dir_node
(halfword p
, halfword a
)
68 halfword do_pop_dir_node
(halfword p
)
70 halfword n
= vlink
(p
);
78 halfword text_dir_ptr
;
80 @ There is no need to do anything here at the moment.
82 void initialize_directions
(void
)
87 halfword new_dir
(int s
)
89 halfword p
; /* the new node
*/
90 p
= new_node
(whatsit_node
, dir_node
);
93 dir_level
(p
) = cur_level
;
97 @ The global static array variable |dir_strings| is also used
98 by the lua nodelib interface
, so it cannot be static. Putting
99 it here instead of there avoid the nodelib having to know
100 about the actual values of |dir_TRT| etc.
103 const char
*dir_strings
[128] = {
104 "-TLT","???", "???", "???", "-TRT","???", "???", "???",
105 "???", "-LTL","???", "???", "???", "???", "???", "???",
106 "???", "???", "???", "???", "???", "???", "???", "???",
107 "-RTT","???", "???", "???", "???", "???", "???", "???",
108 "???", "???", "???", "???", "???", "???", "???", "???",
109 "???", "???", "???", "???", "???", "???", "???", "???",
110 "???", "???", "???", "???", "???", "???", "???", "???",
111 "???", "???", "???", "???", "???", "???", "???", "???",
112 "+TLT","???", "???", "???", "+TRT","???", "???", "???",
113 "???", "+LTL","???", "???", "???", "???", "???", "???",
114 "???", "???", "???", "???", "???", "???", "???", "???",
115 "+RTT","???", "???", "???", "???", "???", "???", "???",
116 "???", "???", "???", "???", "???", "???", "???", "???",
117 "???", "???", "???", "???", "???", "???", "???", "???",
118 "???", "???", "???", "???", "???", "???", "???", "???",
119 "???", "???", "???", "???", "???", "???", "???", "???" };
121 const char
*string_dir
(int d
)
123 return
(dir_strings
[d
+64]+1);
128 void print_dir
(int d
)
130 /* hh-ls
: todo
: just fetch the string pt from the registry ... then the above can go
*/
132 tprint
(string_dir
(d
));
136 scaled pack_width
(int curdir
, int pdir
, halfword p
, boolean isglyph
)
140 if
(textdir_parallel
(curdir
, pdir
) == textglyphdir_orthogonal
(pdir
)) {
142 if
(ex_glyph
(p
) != 0) {
143 //wd
= round_xn_over_d
(wd
, 1000 + ex_glyph
(p
)/1000, 1000);
144 wd
= ext_xn_over_d
(wd
, 1000000+ex_glyph
(p
), 1000000);
148 wd
= glyph_depth
(p
) + glyph_height
(p
);
150 } else
{ /* hlist
, vlist
, image
, form
, rule
*/
151 if
(textdir_parallel
(pdir
, curdir
))
154 wd
= depth
(p
) + height
(p
);
160 scaled_whd pack_width_height_depth
(int curdir
, int pdir
, halfword p
,
163 scaled_whd whd
= { 0, 0, 0 };
164 whd.wd
= pack_width
(curdir
, pdir
, p
, isglyph
);
166 if
(is_rotated
(curdir
)) {
167 if
(textdir_parallel
(curdir
, pdir
))
168 whd.ht
= whd.dp
= (glyph_height
(p
) + glyph_depth
(p
)) / 2;
170 whd.ht
= whd.dp
= glyph_width
(p
) / 2;
172 if
(is_rotated
(pdir
)) {
173 if
(textdir_parallel
(curdir
, pdir
))
174 whd.ht
= whd.dp
= (glyph_height
(p
) + glyph_depth
(p
)) / 2;
176 whd.ht
= glyph_width
(p
);
178 if
(glyphdir_eq
(curdir
, pdir
)) {
179 whd.ht
= glyph_height
(p
);
180 whd.dp
= glyph_depth
(p
);
181 } else if
(glyphdir_opposite
(curdir
, pdir
)) {
182 whd.ht
= glyph_depth
(p
);
183 whd.dp
= glyph_height
(p
);
185 whd.ht
= glyph_width
(p
);
189 if
(is_rotated
(curdir
)) {
190 if
(textdir_parallel
(curdir
, pdir
))
191 whd.ht
= whd.dp
= (height
(p
) + depth
(p
)) / 2;
193 whd.ht
= whd.dp
= width
(p
) / 2;
195 if
(pardir_eq
(curdir
, pdir
)) {
198 } else if
(pardir_opposite
(curdir
, pdir
)) {
209 void update_text_dir_ptr
(int val
)
211 if
(dir_level
(text_dir_ptr
) == cur_level
) {
213 dir_dir
(text_dir_ptr
) = val
;
216 halfword text_dir_tmp
= new_dir
(val
);
217 vlink
(text_dir_tmp
) = text_dir_ptr
;
218 text_dir_ptr
= text_dir_tmp
;