texdirections.h /size: 4702 b    last modification: 2024-01-16 10:22
1/*
2    See license.txt in the root of this project.
3*/
4
5# ifndef LMT_DIRECTIONS_H
6# define LMT_DIRECTIONS_H
7
8/*tex
9
10    Originally we had quarterwords but some compiler versions then keep complaining about
11    comparisons always being true (something enumeration not being integer or so). Interesting it
12    all worked well and suddenly gcc on openbsd complained. So, in the end I decided to just make
13    these fields halfwords too. It leaves room for growth ... who knows what is needed some day.
14
15    Actually, as we have only two subtypes now, I have considered:
16
17    \starttyping
18    0 = begin l2r   2 = end l2r
19    1 = begin r2l   3 = end r2l
20    \stoptyping
21
22    in which case a regular direction node becomes smaller (no dir_dir any more). But, it come with
23    a change at the \LUA\ end too, so it's a no-go in the end.
24
25    For the moment we keep some geometry values here but these might move to their own file when
26    there is more to it.
27
28*/
29
30# include "luametatex.h"
31
32typedef struct dir_state_info {
33    halfword text_dir_ptr;
34    /* alignment */
35    int      padding;
36} dir_state_info;
37
38extern dir_state_info lmt_dir_state;
39
40typedef enum direction_codes {
41    direction_unknown = 0xFF,
42    direction_l2r     = 0,
43    direction_r2l     = 1
44} direction_codes;
45
46# define direction_def_value   direction_l2r
47# define direction_min_value   direction_l2r
48# define direction_max_value   direction_r2l
49
50# define geometry_def_value    0
51# define geometry_min_value    0
52# define geometry_max_value    0xFF
53
54# define orientation_def_value 0
55# define orientation_min_value 0
56# define orientation_max_value 0x0FFF
57
58# define anchor_def_value      0
59# define anchor_min_value      0
60# define anchor_max_value      0x0FFF
61
62# define orientationonly(t)   (t & 0x000F)
63
64# define valid_direction(d)   ((d >= direction_min_value)   && (d <= direction_max_value))
65# define valid_geometry(g)    ((g >= geometry_min_value)    && (g <= geometry_max_value))
66# define valid_orientation(o) ((o >= orientation_min_value) && (o <= orientation_max_value))
67# define valid_anchor(a)      ((a >= anchor_min_value)      && (a <= anchor_max_value))
68
69# define checked_direction_value(d)   (valid_direction(d)   ? d : direction_def_value)
70# define checked_geometry_value(g)    (valid_geometry(g)    ? g : geometry_def_value)
71# define checked_orientation_value(o) (valid_orientation(o) ? o : orientation_def_value)
72# define checked_anchor_value(a)      (valid_anchor(a)      ? a : anchor_def_value)
73
74# define check_direction_value(d) \
75    if (! valid_direction(d)) { \
76        d = direction_def_value; \
77    }
78
79/* will become texgeometry.h|c and dir also in geometry */
80
81static inline void tex_check_box_geometry(halfword n)
82{
83    if (box_x_offset(n) || box_y_offset(n)) {
84        tex_set_box_geometry(n, offset_geometry);
85    } else {
86        tex_unset_box_geometry(n, offset_geometry);
87    }
88    if (box_w_offset(n) || box_h_offset(n) || box_d_offset(n) || box_orientation(n)) {
89        tex_set_box_geometry(n, orientation_geometry);
90    } else {
91        tex_unset_box_geometry(n, orientation_geometry);
92    }
93    if (box_anchor(n) || box_source_anchor(n) || box_target_anchor(n)) {
94        tex_set_box_geometry(n, anchor_geometry);
95    } else {
96        tex_unset_box_geometry(n, anchor_geometry);
97    }
98}
99
100static inline void tex_set_box_direction(halfword b, halfword v)
101{
102    box_dir(b) = (singleword) checked_direction_value(v);
103}
104
105extern void     tex_initialize_directions (void);
106extern void     tex_cleanup_directions    (void);
107extern halfword tex_new_dir               (quarterword subtype, halfword direction);
108extern void     tex_push_text_dir_ptr     (halfword val);
109extern void     tex_pop_text_dir_ptr      (void);
110extern void     tex_set_text_dir          (halfword d);
111extern void     tex_set_math_dir          (halfword d);
112extern void     tex_set_line_dir          (halfword d);
113extern void     tex_set_par_dir           (halfword d);
114extern void     tex_set_box_dir           (halfword b, singleword d);
115
116# define swap_hang_indent(dir,indentation)           (dir == dir_righttoleft && normalize_line_mode_permitted(normalize_line_mode_par, swap_hangindent_mode) ? (                  - indentation) : indentation)
117# define swap_parshape_indent(dir,indentation,width) (dir == dir_righttoleft && normalize_line_mode_permitted(normalize_line_mode_par, swap_parshape_mode)   ? (hsize_par - width - indentation) : indentation)
118
119extern halfword tex_update_dir_state     (halfword p, halfword initial);
120extern halfword tex_sanitize_dir_state   (halfword first, halfword last, halfword initial);
121extern halfword tex_complement_dir_state (halfword tail);
122extern void     tex_append_dir_state     (void);
123
124# endif
125