1 /* -*- c-basic-offset:2; tab-width:2; indent-tabs-mode:nil -*- */
2 
3 #ifndef __VT_CHAR_H__
4 #define __VT_CHAR_H__
5 
6 #include <pobl/bl_types.h>
7 #include <pobl/bl_def.h>     /* WORDS_BIGENDIAN */
8 #include <mef/ef_charset.h> /* ef_charset_t */
9 
10 #include "vt_font.h"
11 #include "vt_color.h"
12 
13 #define MAX_COMB_SIZE 7 /* Used in vt_shape.c,x_screen.c,vt_screen.c */
14 #define UTF_MAX_SIZE 6  /* see skk/dict.c */
15                         /*
16                          * XXX
17                          * char prefixes are max 4 bytes.
18                          * additional 3 bytes + cs name len ("viscii1.1-1" is max 11 bytes) =
19                          * 14 bytes for iso2022 extension.
20                          * char length is max 2 bytes.
21                          * (total 20 bytes)
22                          */
23 #define XCT_MAX_SIZE 20
24 #define VTCHAR_UTF_MAX_SIZE (UTF_MAX_SIZE * (MAX_COMB_SIZE + 1))
25 #define VTCHAR_XCT_MAX_SIZE (XCT_MAX_SIZE * (MAX_COMB_SIZE + 1))
26 
27 /* For inline pictures (see x_picture.c) */
28 #define PICTURE_CHARSET 0x1ff
29 #define PICTURE_ID_BITS 9   /* fg or bg color */
30 #define PICTURE_POS_BITS 23 /* code (Can be shrunk to 21 bits) */
31 
32 #define LS_UNDERLINE (LS_UNDERLINE_SINGLE|LS_UNDERLINE_DOUBLE)
33 
34 /*
35  * If a new entry is added, check if the size of vt_storable_states_t::line_style
36  * is sufficient or not.
37  */
38 typedef enum {
39   LS_NOLINE = 0x0,
40   LS_UNDERLINE_SINGLE = 0x1,
41   LS_UNDERLINE_DOUBLE = 0x2,
42   LS_OVERLINE = 0x4,
43   LS_CROSSED_OUT = 0x8,
44 } vt_line_style_t;
45 
46 /*
47  * This object size should be kept as small as possible.
48  * (ILP32: 64bit) (LP64: 64bit)
49  *
50  * If LSB of vt_char_t.u.ch.attr is 0,
51  * vt_char_t.u.ch is invalid.
52  * vt_char_t.u.multi_ch -> vt_char_t [main char]
53  *                      -> vt_char_t [first combining char]
54  *                      -> vt_char_t [second combining char]
55  *                      .....
56  */
57 typedef struct vt_char {
58   union {
59     struct {
60 /*
61  * attr member contents.
62  * Total 23 bit
63  * 4 bit : vt_char_attr_line_style_t                     -+
64  * 1 bit : is_blinking(0 or 1)                            |__\ or advance (for OT Layout)
65  * 1 bit : is_reversed(0 or 1) ... used for X Selection   |
66  * 1 bit : is_protected(0 or 1)                          -+
67  * 1 bit : is unicode area cs(0 or 1)
68  * 1 bit : is_italic(0 or 1)       -+
69  * 1 bit : is_bold(0 or 1)          |__\ vt_font_t
70  * 1 bit : is_fullwidth(0 or 1)     |
71  * 9 bit : charset(0x0 - 0x1ff) or -+
72  *         1 bit: CS_REVISION_1(ISO10646_UCS4_1_V(*))
73  *         8 bit: unicode area id
74  * 1 bit : is_comb(0 or 1)
75  * 1 bit : is_comb_trailing(0 or 1)
76  * ---
77  * 1 bit : is_single_ch(0 or 1)
78  *
79  * (*) ISO10646_UCS4_1_V is set during being shaped.
80  *     (See vt_shape.c and vt_char_set_cs())
81  *
82  * attr2 member contents.
83  * Total 2 bit
84  * 1 bit : is_awidth(0 or 1)
85  * 1 bit : is_zerowidth(0 or 1)
86  */
87 #ifdef WORDS_BIGENDIAN
88       u_int code : 21;
89       u_int attr2 : 2;
90       u_int fg_color : 9;
91       u_int bg_color : 9;
92       u_int attr : 23;
93 #else
94       u_int attr : 23;
95       u_int fg_color : 9;
96       u_int bg_color : 9;
97       u_int attr2 : 2;
98       u_int code : 21;
99 #endif
100     } ch;
101 
102     /*
103      * 32 bits(on ILP32) or 64 bits(on LP64).
104      * LSB(used for is_single_ch) is considered 0.
105      */
106     struct vt_char *multi_ch;
107 
108   } u;
109 
110 } vt_char_t;
111 
112 void vt_set_use_multi_col_char(int use_it);
113 
114 int vt_get_unicode_area(vt_font_t font, int *min, int *max);
115 
116 vt_font_t vt_get_unicode_area_font(u_int32_t min, u_int32_t max);
117 
118 void vt_set_blink_chars_visible(int visible);
119 
120 void vt_char_init(vt_char_t *ch);
121 
122 void vt_char_final(vt_char_t *ch);
123 
124 void vt_char_set(vt_char_t *ch, u_int32_t code, ef_charset_t cs, int is_fullwidth,
125                  int is_awidth, int is_comb, vt_color_t fg_color, vt_color_t bg_color,
126                  int is_bold, int is_italic, int line_style, int is_blinking, int is_protected);
127 
128 void vt_char_change_attr(vt_char_t *ch, int is_bold, int is_italic, int underline_style,
129                          int is_blinking, int is_reversed, int crossed_out, int is_overlined);
130 
131 void vt_char_reverse_attr(vt_char_t *ch, int bold, int italic, int underline_style,
132                           int blinking, int reversed, int crossed_out, int overlined);
133 
134 vt_char_t *vt_char_combine(vt_char_t *ch, u_int32_t code, ef_charset_t cs, int is_fullwidth,
135                            int is_awidth, int is_comb, vt_color_t fg_color, vt_color_t bg_color,
136                            int is_bold, int is_italic, int line_style, int is_blinking,
137                            int is_protected);
138 
139 /* set both fg and bg colors for reversing. */
140 #define vt_char_combine_picture(ch, id, pos) \
141   vt_char_combine(ch, pos, PICTURE_CHARSET, 0, 0, 0, id, id, 0, 0, 0, 0, 0)
142 
143 vt_char_t *vt_char_combine_simple(vt_char_t *ch, vt_char_t *comb);
144 
145 /* This doesn't check if src is a zero width character or not. (See new_comb()) */
146 vt_char_t *vt_char_combine_forcibly(vt_char_t *ch, vt_char_t *src);
147 
148 vt_char_t *vt_get_base_char(vt_char_t *ch);
149 
150 vt_char_t *vt_get_combining_chars(vt_char_t *ch, u_int *size);
151 
152 vt_char_t *vt_get_picture_char(vt_char_t *ch);
153 
154 #if 0
155 /*
156  * Not used for now.
157  */
158 int vt_char_move(vt_char_t *dst, vt_char_t *src);
159 #endif
160 
161 int vt_char_copy(vt_char_t *dst, vt_char_t *src);
162 
163 u_int32_t vt_char_code(vt_char_t *ch);
164 
165 void vt_char_set_code(vt_char_t *ch, u_int32_t code);
166 
167 ef_charset_t vt_char_cs(vt_char_t *ch);
168 
169 int vt_char_set_cs(vt_char_t *ch, ef_charset_t cs);
170 
171 int vt_char_is_comb(vt_char_t *ch);
172 
173 vt_font_t vt_char_font(vt_char_t *ch);
174 
175 u_int vt_char_cols(vt_char_t *ch);
176 
177 int vt_char_is_fullwidth(vt_char_t *ch);
178 
179 int vt_char_is_zerowidth(vt_char_t *ch);
180 
181 int vt_char_is_awidth(vt_char_t *ch);
182 
183 vt_color_t vt_char_fg_color(vt_char_t *ch);
184 
185 void vt_char_set_fg_color(vt_char_t *ch, vt_color_t color);
186 
187 #define vt_char_picture_id(ch) vt_char_fg_color(ch)
188 #define vt_char_set_picture_id(ch, idx) vt_char_set_fg_color(ch, idx)
189 
190 vt_color_t vt_char_bg_color(vt_char_t *ch);
191 
192 void vt_char_set_bg_color(vt_char_t *ch, vt_color_t color);
193 
194 int vt_char_get_xoffset(vt_char_t *ch);
195 
196 int vt_char_get_yoffset(vt_char_t *ch);
197 
198 u_int vt_char_get_advance(vt_char_t *ch);
199 
200 int vt_char_set_position(vt_char_t *ch, u_int8_t xoffset, u_int8_t yoffset, u_int8_t advance);
201 
202 int vt_char_line_style(vt_char_t *ch);
203 
204 int vt_char_is_blinking(vt_char_t *ch);
205 
206 int vt_char_is_protected(vt_char_t *ch);
207 
208 int vt_char_reverse_color(vt_char_t *ch);
209 
210 int vt_char_restore_color(vt_char_t *ch);
211 
212 int vt_char_is_null(vt_char_t *ch);
213 
214 int vt_char_equal(vt_char_t *ch1, vt_char_t *ch2);
215 
216 int vt_char_code_is(vt_char_t *ch, u_int32_t code, ef_charset_t cs);
217 
218 int vt_char_code_equal(vt_char_t *ch1, vt_char_t *ch2);
219 
220 vt_char_t *vt_sp_ch(void);
221 
222 vt_char_t *vt_nl_ch(void);
223 
224 #ifdef DEBUG
225 
226 void vt_char_dump(vt_char_t *ch);
227 
228 #endif
229 
230 #endif
231