summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/tex/directions.c
blob: 59b2f7dcd8504b184089474e7ce22b7fb3d9cf66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*

directions.w

Copyright 2009-2014 Taco Hoekwater <taco@@luatex.org>

This file is part of LuaTeX.

LuaTeX is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.

LuaTeX is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
License for more details.

You should have received a copy of the GNU General Public License along
with LuaTeX; if not, see <http://www.gnu.org/licenses/>.

*/

#include "ptexlib.h"

void scan_direction(void)
{
    int save_cur_cmd = cur_cmd;
    int save_cur_chr = cur_chr;
    get_x_token();
    if (cur_cmd == assign_dir_cmd) {
        cur_val = eqtb[cur_chr].cint;
        goto EXIT;
    } else {
        back_input();
    }
    if (scan_keyword("tlt")) {
        cur_val = dir_TLT;
    } else if (scan_keyword("trt")) {
        cur_val = dir_TRT;
    } else if (scan_keyword("ltl")) {
        cur_val = dir_LTL;
    } else if (scan_keyword("rtt")) {
        cur_val = dir_RTT;
    } else {
        tex_error("Bad direction", NULL);
        cur_val = 0;
    }
    get_x_token();
    if (cur_cmd != spacer_cmd)
        back_input();
  EXIT:
    cur_cmd = save_cur_cmd;
    cur_chr = save_cur_chr;
}

/*tex

    The next two are used by |postlinebreak.c|:

*/

halfword do_push_dir_node(halfword p, halfword a)
{
    halfword n = copy_node(a);
    vlink(n) = p;
    return n;
}

halfword do_pop_dir_node(halfword p)
{
    halfword n = vlink(p);
    flush_node(p);
    return n;
}

halfword dir_ptr;
halfword text_dir_ptr;

void initialize_directions(void)
{
    /*tex There is no need to do anything here at the moment. */
}

halfword new_dir(int s)
{
    halfword p = new_node(dir_node, 0);
    dir_dir(p) = s;
    dir_level(p) = cur_level;
    return p;
}

const char *dir_strings_par[4] = { [0] =
  "TLT","TRT","LTL","RTT",
};

const char *dir_strings_text_normal[4] = { [0] =
  "+TLT","+TRT","+LTL","+RTT",
};

const char *dir_strings_text_cancel[4] = { [0] =
  "-TLT","-TRT","-LTL","-RTT",
};

void print_dir_par(int d)
{
    tprint(dir_strings_par[d]);
}

void print_dir_text(halfword d)
{
    if (subtype(d) == cancel_dir) {
        tprint(dir_strings_text_cancel[dir_dir(d)]);
    } else {
        tprint(dir_strings_text_normal[dir_dir(d)]);
    }
}

scaled pack_width(int curdir, int pdir, halfword p, boolean isglyph)
{
    scaled wd = 0;
    if (isglyph) {
        if (textdir_parallel(curdir, pdir) == textglyphdir_orthogonal(pdir)) {
            wd = glyph_width(p);
            if (ex_glyph(p) != 0) {
             /* wd = round_xn_over_d(wd, 1000 + ex_glyph(p)/1000, 1000); */
                wd = ext_xn_over_d(wd, 1000000+ex_glyph(p), 1000000);

            }
        } else {
            wd = glyph_depth(p) + glyph_height(p);
        }
    } else {
        if (textdir_parallel(pdir, curdir))
            wd = width(p);
        else
            wd = depth(p) + height(p);
    }
    return wd;
}

scaled_whd pack_width_height_depth(int curdir, int pdir, halfword p, boolean isglyph)
{
    scaled_whd whd = { 0, 0, 0 };
    whd.wd = pack_width(curdir, pdir, p, isglyph);
    if (isglyph) {
        if (is_rotated(curdir)) {
            if (textdir_parallel(curdir, pdir))
                whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2;
            else
                whd.ht = whd.dp = glyph_width(p) / 2;
        } else if (is_rotated(pdir)) {
            if (textdir_parallel(curdir, pdir))
                whd.ht = whd.dp = (glyph_height(p) + glyph_depth(p)) / 2;
            else
                whd.ht = glyph_width(p);
        } else {
            if (glyphdir_eq(curdir, pdir)) {
                whd.ht = glyph_height(p);
                whd.dp = glyph_depth(p);
            } else if (glyphdir_opposite(curdir, pdir)) {
                whd.ht = glyph_depth(p);
                whd.dp = glyph_height(p);
            } else
                whd.ht = glyph_width(p);
        }
    } else {
        if (is_rotated(curdir)) {
            if (textdir_parallel(curdir, pdir))
                whd.ht = whd.dp = (height(p) + depth(p)) / 2;
            else
                whd.ht = whd.dp = width(p) / 2;
        } else if (pardir_eq(curdir, pdir)) {
            whd.ht = height(p);
            whd.dp = depth(p);
        } else if (pardir_opposite(curdir, pdir)) {
            whd.ht = depth(p);
            whd.dp = height(p);
        } else
            whd.ht = width(p);
    }
    return whd;
}

void update_text_dir_ptr(int val)
{
    if (dir_level(text_dir_ptr) == cur_level) {
        /* update */
        dir_dir(text_dir_ptr) = val;
    } else {
        /* addition */
        halfword text_dir_tmp = new_dir(val);
        vlink(text_dir_tmp) = text_dir_ptr;
        text_dir_ptr = text_dir_tmp;
    }
}