| 1 |
/* |
| 2 |
|
| 3 |
directions.w |
| 4 |
|
| 5 |
Copyright 2009-2014 Taco Hoekwater <taco@@luatex.org> |
| 6 |
|
| 7 |
This file is part of LuaTeX. |
| 8 |
|
| 9 |
LuaTeX is free software; you can redistribute it and/or modify it under |
| 10 |
the terms of the GNU General Public License as published by the Free |
| 11 |
Software Foundation; either version 2 of the License, or (at your |
| 12 |
option) any later version. |
| 13 |
|
| 14 |
LuaTeX is distributed in the hope that it will be useful, but WITHOUT |
| 15 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 16 |
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public |
| 17 |
License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License along |
| 20 |
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
*/ |
| 23 |
|
| 24 |
#include "ptexlib.h" |
| 25 |
|
| 26 |
void scan_direction(void) |
| 27 |
{ |
| 28 |
int save_cur_cmd = cur_cmd; |
| 29 |
int save_cur_chr = cur_chr; |
| 30 |
get_x_token(); |
| 31 |
if (cur_cmd == assign_dir_cmd) { |
| 32 |
cur_val = eqtb[cur_chr].cint; |
| 33 |
goto EXIT; |
| 34 |
} else { |
| 35 |
back_input(); |
| 36 |
} |
| 37 |
if (scan_keyword("tlt")) { |
| 38 |
cur_val = dir_TLT; |
| 39 |
} else if (scan_keyword("trt")) { |
| 40 |
cur_val = dir_TRT; |
| 41 |
} else if (scan_keyword("ltl")) { |
| 42 |
cur_val = dir_LTL; |
| 43 |
} else if (scan_keyword("rtt")) { |
| 44 |
cur_val = dir_RTT; |
| 45 |
} else { |
| 46 |
tex_error("Bad direction", NULL); |
| 47 |
cur_val = 0; |
| 48 |
} |
| 49 |
get_x_token(); |
| 50 |
if (cur_cmd != spacer_cmd) |
| 51 |
back_input(); |
| 52 |
EXIT: |
| 53 |
cur_cmd = save_cur_cmd; |
| 54 |
cur_chr = save_cur_chr; |
| 55 |
} |
| 56 |
|
| 57 |
/*tex |
| 58 |
|
| 59 |
The next two are used by |postlinebreak.c|: |
| 60 |
|
| 61 |
*/ |
| 62 |
|
| 63 |
halfword do_push_dir_node(halfword p, halfword a) |
| 64 |
{ |
| 65 |
halfword n = copy_node(a); |
| 66 |
vlink(n) = p; |
| 67 |
return n; |
| 68 |
} |
| 69 |
|
| 70 |
halfword do_pop_dir_node(halfword p) |
| 71 |
{ |
| 72 |
halfword n = vlink(p); |
| 73 |
flush_node(p); |
| 74 |
return n; |
| 75 |
} |
| 76 |
|
| 77 |
halfword dir_ptr; |
| 78 |
halfword text_dir_ptr; |
| 79 |
|
| 80 |
void initialize_directions(void) |
| 81 |
{ |
| 82 |
/*tex There is no need to do anything here at the moment. */ |
| 83 |
} |
| 84 |
|
| 85 |
halfword new_dir(int s) |
| 86 |
{ |
| 87 |
halfword p = new_node(dir_node, 0); |
| 88 |
dir_dir(p) = s; |
| 89 |
dir_level(p) = cur_level; |
| 90 |
return p; |
| 91 |
} |
| 92 |
|
| 93 |
const char *dir_strings_par[4] = { [0] = |
| 94 |
"TLT","TRT","LTL","RTT", |
| 95 |
}; |
| 96 |
|
| 97 |
const char *dir_strings_text_normal[4] = { [0] = |
| 98 |
"+TLT","+TRT","+LTL","+RTT", |
| 99 |
}; |
| 100 |
|
| 101 |
const char *dir_strings_text_cancel[4] = { [0] = |
| 102 |
"-TLT","-TRT","-LTL","-RTT", |
| 103 |
}; |
| 104 |
|
| 105 |
void print_dir_par(int d) |
| 106 |
{ |
| 107 |
tprint(dir_strings_par[d]); |
| 108 |
} |
| 109 |
|
| 110 |
void print_dir_text(halfword d) |
| 111 |
{ |
| 112 |
if (subtype(d) == cancel_dir) { |
| 113 |
tprint(dir_strings_text_cancel[dir_dir(d)]); |
| 114 |
} else { |
| 115 |
tprint(dir_strings_text_normal[dir_dir(d)]); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
scaled pack_width(int curdir, int pdir, halfword p, boolean isglyph) |
| 120 |
{ |
| 121 |
scaled wd = 0; |
| 122 |
if (isglyph) { |
| 123 |
if (textdir_parallel(curdir, pdir) == textglyphdir_orthogonal(pdir)) { |
| 124 |
wd = glyph_width(p); |
| 125 |
if (ex_glyph(p) != 0) { |
| 126 |
/* wd = round_xn_over_d(wd, 1000 + ex_glyph(p)/1000, 1000); */ |
| 127 |
wd = ext_xn_over_d(wd, 1000000+ex_glyph(p), 1000000); |
| 128 |
|
| 129 |
} |
| 130 |
} else { |
| 131 |
wd = glyph_depth(p) + glyph_height(p); |
| 132 |
} |
| 133 |
} else { |
| 134 |
if (textdir_parallel(pdir, curdir)) |
| 135 |
wd = width(p); |
| 136 |
else |
| 137 |
wd = depth(p) + height(p); |
| 138 |
} |
| 139 |
return wd; |
| 140 |
} |
| 141 |
|
| 142 |
scaled_whd pack_width_height_depth(int curdir, int pdir, halfword p, boolean isglyph) |
| 143 |
{ |
| 144 |
scaled_whd whd = { 0, 0, 0 }; |
| 145 |
whd.wd = pack_width(curdir, pdir, p, isglyph); |
| 146 |
if (isglyph) { |
| 147 |
if (is_rotated(curdir)) { |
| 148 |
if (textdir_parallel(curdir, pdir)) |
| 149 |
whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2; |
| 150 |
else |
| 151 |
whd.ht = whd.dp = glyph_width(p) / 2; |
| 152 |
} else if (is_rotated(pdir)) { |
| 153 |
if (textdir_parallel(curdir, pdir)) |
| 154 |
whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2; |
| 155 |
else |
| 156 |
whd.ht = glyph_width(p); |
| 157 |
} else { |
| 158 |
if (glyphdir_eq(curdir, pdir)) { |
| 159 |
whd.ht = glyph_height(p); |
| 160 |
whd.dp = glyph_depth(p); |
| 161 |
} else if (glyphdir_opposite(curdir, pdir)) { |
| 162 |
whd.ht = glyph_depth(p); |
| 163 |
whd.dp = glyph_height(p); |
| 164 |
} else |
| 165 |
whd.ht = glyph_width(p); |
| 166 |
} |
| 167 |
} else { |
| 168 |
if (is_rotated(curdir)) { |
| 169 |
if (textdir_parallel(curdir, pdir)) |
| 170 |
whd.ht = whd.dp = (height(p) + depth(p)) / 2; |
| 171 |
else |
| 172 |
whd.ht = whd.dp = width(p) / 2; |
| 173 |
} else if (pardir_eq(curdir, pdir)) { |
| 174 |
whd.ht = height(p); |
| 175 |
whd.dp = depth(p); |
| 176 |
} else if (pardir_opposite(curdir, pdir)) { |
| 177 |
whd.ht = depth(p); |
| 178 |
whd.dp = height(p); |
| 179 |
} else |
| 180 |
whd.ht = width(p); |
| 181 |
} |
| 182 |
return whd; |
| 183 |
} |
| 184 |
|
| 185 |
void update_text_dir_ptr(int val) |
| 186 |
{ |
| 187 |
if (dir_level(text_dir_ptr) == cur_level) { |
| 188 |
/* update */ |
| 189 |
dir_dir(text_dir_ptr) = val; |
| 190 |
} else { |
| 191 |
/* addition */ |
| 192 |
halfword text_dir_tmp = new_dir(val); |
| 193 |
vlink(text_dir_tmp) = text_dir_ptr; |
| 194 |
text_dir_ptr = text_dir_tmp; |
| 195 |
} |
| 196 |
} |