fix getsup (HH)
[luatex.git] / source / texk / web2c / luatexdir / tex / directions.w
blob20d46606d6adbe698d2a6ebe5b7c8c1f4c21d419
1 % directions.w
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/>.
20 @ @c
22 #include "ptexlib.h"
24 @ @c
25 void scan_direction(void)
27 int save_cur_cmd = cur_cmd;
28 int save_cur_chr = cur_chr;
29 get_x_token();
30 if (cur_cmd == assign_dir_cmd) {
31 cur_val = eqtb[cur_chr].cint;
32 goto EXIT;
33 } else {
34 back_input();
36 if (scan_keyword("TLT")) {
37 cur_val = dir_TLT;
38 } else if (scan_keyword("TRT")) {
39 cur_val = dir_TRT;
40 } else if (scan_keyword("LTL")) {
41 cur_val = dir_LTL;
42 } else if (scan_keyword("RTT")) {
43 cur_val = dir_RTT;
44 } else {
45 tex_error("Bad direction", NULL);
46 cur_val = 0;
48 get_x_token();
49 if (cur_cmd != spacer_cmd)
50 back_input();
51 EXIT:
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);
62 vlink(n) = p;
63 return n;
66 halfword do_pop_dir_node(halfword p)
68 halfword n = vlink(p);
69 flush_node(p);
70 return n;
73 @ @c
74 halfword dir_ptr;
76 halfword text_dir_ptr;
78 @ There is no need to do anything here at the moment.
80 void initialize_directions(void)
84 @ @c
85 halfword new_dir(int s)
87 halfword p = new_node(dir_node, 0);
88 dir_dir(p) = s;
89 dir_level(p) = cur_level;
90 return p;
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 "???", "???", "???", "???", "???", "???", "???", "???"
120 int dir_swap = 64;
123 const char *dir_strings[8] = {
124 "-TLT","-TRT","-LTL","-RTT",
125 "+TLT","+TRT","+LTL","+RTT",
128 int dir_swap = 4;
130 const char *string_dir(int d)
132 return (dir_strings[d+dir_swap]+1);
135 @ @c
136 void print_dir(int d)
138 tprint(string_dir(d));
141 @ @c
142 scaled pack_width(int curdir, int pdir, halfword p, boolean isglyph)
144 scaled wd = 0;
145 if (isglyph) {
146 if (textdir_parallel(curdir, pdir) == textglyphdir_orthogonal(pdir)) {
147 wd = glyph_width(p);
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);
153 } else {
154 wd = glyph_depth(p) + glyph_height(p);
156 /* experimental */
157 wd += x_advance(p);
158 } else { /* hlist, vlist, image, form, rule */
159 if (textdir_parallel(pdir, curdir))
160 wd = width(p);
161 else
162 wd = depth(p) + height(p);
164 return wd;
167 @ @c
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);
172 if (isglyph) {
173 if (is_rotated(curdir)) {
174 if (textdir_parallel(curdir, pdir))
175 whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2;
176 else
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;
181 else
182 whd.ht = glyph_width(p);
183 } else {
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);
190 } else
191 whd.ht = glyph_width(p);
193 } else {
194 if (is_rotated(curdir)) {
195 if (textdir_parallel(curdir, pdir))
196 whd.ht = whd.dp = (height(p) + depth(p)) / 2;
197 else
198 whd.ht = whd.dp = width(p) / 2;
199 } else if (pardir_eq(curdir, pdir)) {
200 whd.ht = height(p);
201 whd.dp = depth(p);
202 } else if (pardir_opposite(curdir, pdir)) {
203 whd.ht = depth(p);
204 whd.dp = height(p);
205 } else
206 whd.ht = width(p);
208 return whd;
211 @ @c
212 void update_text_dir_ptr(int val)
214 if (dir_level(text_dir_ptr) == cur_level) {
215 /* update */
216 dir_dir(text_dir_ptr) = val;
217 } else {
218 /* addition */
219 halfword text_dir_tmp = new_dir(val);
220 vlink(text_dir_tmp) = text_dir_ptr;
221 text_dir_ptr = text_dir_tmp;