1
4
5# ifndef LMT_DIRECTIONS_H
6# define LMT_DIRECTIONS_H
7
8
29
30# include "luametatex.h"
31
32typedef struct dir_state_info {
33 halfword text_dir_ptr;
34
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
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 |