Fix cross compilation (e.g. on Darwin). Following changes to make.tmpl,
[AROS.git] / arch / all-pc / boot / grub2-aros / include / grub / unicode.h
bloba0403e91f9af8f9e463f1fd1e873acf3212276ae
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2010 Free Software Foundation, Inc.
5 * GRUB is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GRUB is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef GRUB_BIDI_HEADER
20 #define GRUB_BIDI_HEADER 1
22 #include <grub/types.h>
23 #include <grub/mm.h>
24 #include <grub/misc.h>
26 struct grub_unicode_bidi_pair
28 grub_uint32_t key;
29 grub_uint32_t replace;
32 struct grub_unicode_compact_range
34 unsigned start:21;
35 unsigned len:9;
36 unsigned bidi_type:5;
37 unsigned comb_type:8;
38 unsigned bidi_mirror:1;
39 unsigned join_type:3;
40 } GRUB_PACKED;
42 /* Old-style Arabic shaping. Used for "visual UTF-8" and
43 in grub-mkfont to find variant glyphs in absence of GPOS tables. */
44 struct grub_unicode_arabic_shape
46 grub_uint32_t code;
47 grub_uint32_t isolated;
48 grub_uint32_t right_linked;
49 grub_uint32_t both_linked;
50 grub_uint32_t left_linked;
53 extern struct grub_unicode_arabic_shape grub_unicode_arabic_shapes[];
55 enum grub_bidi_type
57 GRUB_BIDI_TYPE_L = 0,
58 GRUB_BIDI_TYPE_LRE,
59 GRUB_BIDI_TYPE_LRO,
60 GRUB_BIDI_TYPE_R,
61 GRUB_BIDI_TYPE_AL,
62 GRUB_BIDI_TYPE_RLE,
63 GRUB_BIDI_TYPE_RLO,
64 GRUB_BIDI_TYPE_PDF,
65 GRUB_BIDI_TYPE_EN,
66 GRUB_BIDI_TYPE_ES,
67 GRUB_BIDI_TYPE_ET,
68 GRUB_BIDI_TYPE_AN,
69 GRUB_BIDI_TYPE_CS,
70 GRUB_BIDI_TYPE_NSM,
71 GRUB_BIDI_TYPE_BN,
72 GRUB_BIDI_TYPE_B,
73 GRUB_BIDI_TYPE_S,
74 GRUB_BIDI_TYPE_WS,
75 GRUB_BIDI_TYPE_ON
78 enum grub_join_type
80 GRUB_JOIN_TYPE_NONJOINING = 0,
81 GRUB_JOIN_TYPE_LEFT = 1,
82 GRUB_JOIN_TYPE_RIGHT = 2,
83 GRUB_JOIN_TYPE_DUAL = 3,
84 GRUB_JOIN_TYPE_CAUSING = 4,
85 GRUB_JOIN_TYPE_TRANSPARENT = 5
88 enum grub_comb_type
90 GRUB_UNICODE_COMB_NONE = 0,
91 GRUB_UNICODE_COMB_OVERLAY = 1,
92 GRUB_UNICODE_COMB_HEBREW_SHEVA = 10,
93 GRUB_UNICODE_COMB_HEBREW_HATAF_SEGOL = 11,
94 GRUB_UNICODE_COMB_HEBREW_HATAF_PATAH = 12,
95 GRUB_UNICODE_COMB_HEBREW_HATAF_QAMATS = 13,
96 GRUB_UNICODE_COMB_HEBREW_HIRIQ = 14,
97 GRUB_UNICODE_COMB_HEBREW_TSERE = 15,
98 GRUB_UNICODE_COMB_HEBREW_SEGOL = 16,
99 GRUB_UNICODE_COMB_HEBREW_PATAH = 17,
100 GRUB_UNICODE_COMB_HEBREW_QAMATS = 18,
101 GRUB_UNICODE_COMB_HEBREW_HOLAM = 19,
102 GRUB_UNICODE_COMB_HEBREW_QUBUTS = 20,
103 GRUB_UNICODE_COMB_HEBREW_DAGESH = 21,
104 GRUB_UNICODE_COMB_HEBREW_METEG = 22,
105 GRUB_UNICODE_COMB_HEBREW_RAFE = 23,
106 GRUB_UNICODE_COMB_HEBREW_SHIN_DOT = 24,
107 GRUB_UNICODE_COMB_HEBREW_SIN_DOT = 25,
108 GRUB_UNICODE_COMB_HEBREW_VARIKA = 26,
109 GRUB_UNICODE_COMB_ARABIC_FATHATAN = 27,
110 GRUB_UNICODE_COMB_ARABIC_DAMMATAN = 28,
111 GRUB_UNICODE_COMB_ARABIC_KASRATAN = 29,
112 GRUB_UNICODE_COMB_ARABIC_FATHAH = 30,
113 GRUB_UNICODE_COMB_ARABIC_DAMMAH = 31,
114 GRUB_UNICODE_COMB_ARABIC_KASRA = 32,
115 GRUB_UNICODE_COMB_ARABIC_SHADDA = 33,
116 GRUB_UNICODE_COMB_ARABIC_SUKUN = 34,
117 GRUB_UNICODE_COMB_ARABIC_SUPERSCRIPT_ALIF = 35,
118 GRUB_UNICODE_COMB_SYRIAC_SUPERSCRIPT_ALAPH = 36,
119 GRUB_UNICODE_STACK_ATTACHED_BELOW = 202,
120 GRUB_UNICODE_STACK_ATTACHED_ABOVE = 214,
121 GRUB_UNICODE_COMB_ATTACHED_ABOVE_RIGHT = 216,
122 GRUB_UNICODE_STACK_BELOW = 220,
123 GRUB_UNICODE_COMB_BELOW_RIGHT = 222,
124 GRUB_UNICODE_COMB_ABOVE_LEFT = 228,
125 GRUB_UNICODE_STACK_ABOVE = 230,
126 GRUB_UNICODE_COMB_ABOVE_RIGHT = 232,
127 GRUB_UNICODE_COMB_YPOGEGRAMMENI = 240,
128 /* If combining nature is indicated only by class and
129 not "combining type". */
130 GRUB_UNICODE_COMB_ME = 253,
131 GRUB_UNICODE_COMB_MC = 254,
132 GRUB_UNICODE_COMB_MN = 255,
135 struct grub_unicode_combining
137 grub_uint32_t code:21;
138 enum grub_comb_type type:8;
140 /* This structure describes a glyph as opposed to character. */
141 struct grub_unicode_glyph
143 grub_uint32_t base:23; /* minimum: 21 */
144 grub_uint16_t variant:9; /* minimum: 9 */
146 grub_uint8_t attributes:5; /* minimum: 5 */
147 grub_uint8_t bidi_level:6; /* minimum: 6 */
148 enum grub_bidi_type bidi_type:5; /* minimum: :5 */
150 unsigned ncomb:8;
151 /* Hint by unicode subsystem how wide this character usually is.
152 Real width is determined by font. Set only in UTF-8 stream. */
153 int estimated_width:8;
155 grub_size_t orig_pos;
156 union
158 struct grub_unicode_combining combining_inline[sizeof (void *)
159 / sizeof (struct grub_unicode_combining)];
160 struct grub_unicode_combining *combining_ptr;
164 #define GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR 0x1
165 #define GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN_LEFT_TO_RIGHT_SHIFT 1
166 #define GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED 0x2
167 #define GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED \
168 (GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED \
169 << GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN_LEFT_TO_RIGHT_SHIFT)
170 /* Set iff the corresponding joining flags come from ZWJ or ZWNJ. */
171 #define GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED_EXPLICIT 0x8
172 #define GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED_EXPLICIT \
173 (GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED_EXPLICIT \
174 << GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN_LEFT_TO_RIGHT_SHIFT)
175 #define GRUB_UNICODE_GLYPH_ATTRIBUTES_JOIN \
176 (GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED \
177 | GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED \
178 | GRUB_UNICODE_GLYPH_ATTRIBUTE_LEFT_JOINED_EXPLICIT \
179 | GRUB_UNICODE_GLYPH_ATTRIBUTE_RIGHT_JOINED_EXPLICIT)
181 enum
183 GRUB_UNICODE_DOTLESS_LOWERCASE_I = 0x0131,
184 GRUB_UNICODE_DOTLESS_LOWERCASE_J = 0x0237,
185 GRUB_UNICODE_COMBINING_GRAPHEME_JOINER = 0x034f,
186 GRUB_UNICODE_HEBREW_WAW = 0x05d5,
187 GRUB_UNICODE_ARABIC_START = 0x0600,
188 GRUB_UNICODE_ARABIC_END = 0x0700,
189 GRUB_UNICODE_THAANA_ABAFILI = 0x07a6,
190 GRUB_UNICODE_THAANA_AABAAFILI = 0x07a7,
191 GRUB_UNICODE_THAANA_IBIFILI = 0x07a8,
192 GRUB_UNICODE_THAANA_EEBEEFILI = 0x07a9,
193 GRUB_UNICODE_THAANA_UBUFILI = 0x07aa,
194 GRUB_UNICODE_THAANA_OOBOOFILI = 0x07ab,
195 GRUB_UNICODE_THAANA_EBEFILI = 0x07ac,
196 GRUB_UNICODE_THAANA_EYBEYFILI = 0x07ad,
197 GRUB_UNICODE_THAANA_OBOFILI = 0x07ae,
198 GRUB_UNICODE_THAANA_OABOAFILI = 0x07af,
199 GRUB_UNICODE_THAANA_SUKUN = 0x07b0,
200 GRUB_UNICODE_ZWNJ = 0x200c,
201 GRUB_UNICODE_ZWJ = 0x200d,
202 GRUB_UNICODE_LRM = 0x200e,
203 GRUB_UNICODE_RLM = 0x200f,
204 GRUB_UNICODE_LRE = 0x202a,
205 GRUB_UNICODE_RLE = 0x202b,
206 GRUB_UNICODE_PDF = 0x202c,
207 GRUB_UNICODE_LRO = 0x202d,
208 GRUB_UNICODE_RLO = 0x202e,
209 GRUB_UNICODE_LEFTARROW = 0x2190,
210 GRUB_UNICODE_UPARROW = 0x2191,
211 GRUB_UNICODE_RIGHTARROW = 0x2192,
212 GRUB_UNICODE_DOWNARROW = 0x2193,
213 GRUB_UNICODE_UPDOWNARROW = 0x2195,
214 GRUB_UNICODE_LIGHT_HLINE = 0x2500,
215 GRUB_UNICODE_HLINE = 0x2501,
216 GRUB_UNICODE_LIGHT_VLINE = 0x2502,
217 GRUB_UNICODE_VLINE = 0x2503,
218 GRUB_UNICODE_LIGHT_CORNER_UL = 0x250c,
219 GRUB_UNICODE_CORNER_UL = 0x250f,
220 GRUB_UNICODE_LIGHT_CORNER_UR = 0x2510,
221 GRUB_UNICODE_CORNER_UR = 0x2513,
222 GRUB_UNICODE_LIGHT_CORNER_LL = 0x2514,
223 GRUB_UNICODE_CORNER_LL = 0x2517,
224 GRUB_UNICODE_LIGHT_CORNER_LR = 0x2518,
225 GRUB_UNICODE_CORNER_LR = 0x251b,
226 GRUB_UNICODE_BLACK_UP_TRIANGLE = 0x25b2,
227 GRUB_UNICODE_BLACK_RIGHT_TRIANGLE = 0x25ba,
228 GRUB_UNICODE_BLACK_DOWN_TRIANGLE = 0x25bc,
229 GRUB_UNICODE_BLACK_LEFT_TRIANGLE = 0x25c4,
230 GRUB_UNICODE_VARIATION_SELECTOR_1 = 0xfe00,
231 GRUB_UNICODE_VARIATION_SELECTOR_16 = 0xfe0f,
232 GRUB_UNICODE_TAG_START = 0xe0000,
233 GRUB_UNICODE_TAG_END = 0xe007f,
234 GRUB_UNICODE_VARIATION_SELECTOR_17 = 0xe0100,
235 GRUB_UNICODE_VARIATION_SELECTOR_256 = 0xe01ef,
236 GRUB_UNICODE_LAST_VALID = 0x10ffff
239 extern struct grub_unicode_compact_range grub_unicode_compact[];
240 extern struct grub_unicode_bidi_pair grub_unicode_bidi_pairs[];
242 #define GRUB_UNICODE_MAX_CACHED_CHAR 0x20000
243 /* Unicode mandates an arbitrary limit. */
244 #define GRUB_BIDI_MAX_EXPLICIT_LEVEL 61
246 struct grub_term_pos
248 unsigned valid:1;
249 unsigned x:15, y:16;
252 grub_ssize_t
253 grub_bidi_logical_to_visual (const grub_uint32_t *logical,
254 grub_size_t logical_len,
255 struct grub_unicode_glyph **visual_out,
256 grub_size_t (*getcharwidth) (const struct grub_unicode_glyph *visual, void *getcharwidth_arg),
257 void *getcharwidth_arg,
258 grub_size_t max_width,
259 grub_size_t start_width, grub_uint32_t codechar,
260 struct grub_term_pos *pos,
261 int primitive_wrap);
263 enum grub_comb_type
264 grub_unicode_get_comb_type (grub_uint32_t c);
265 grub_size_t
266 grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen,
267 struct grub_unicode_glyph *out);
269 static inline const struct grub_unicode_combining *
270 grub_unicode_get_comb (const struct grub_unicode_glyph *in)
272 if (in->ncomb == 0)
273 return NULL;
274 if (in->ncomb > ARRAY_SIZE (in->combining_inline))
275 return in->combining_ptr;
276 return in->combining_inline;
279 static inline void
280 grub_unicode_destroy_glyph (struct grub_unicode_glyph *glyph)
282 if (glyph->ncomb > ARRAY_SIZE (glyph->combining_inline))
283 grub_free (glyph->combining_ptr);
284 glyph->ncomb = 0;
287 static inline struct grub_unicode_glyph *
288 grub_unicode_glyph_dup (const struct grub_unicode_glyph *in)
290 struct grub_unicode_glyph *out = grub_malloc (sizeof (*out));
291 if (!out)
292 return NULL;
293 grub_memcpy (out, in, sizeof (*in));
294 if (in->ncomb > ARRAY_SIZE (out->combining_inline))
296 out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0]));
297 if (!out->combining_ptr)
299 grub_free (out);
300 return NULL;
302 grub_memcpy (out->combining_ptr, in->combining_ptr,
303 in->ncomb * sizeof (out->combining_ptr[0]));
305 else
306 grub_memcpy (&out->combining_inline, &in->combining_inline,
307 sizeof (out->combining_inline));
308 return out;
311 static inline void
312 grub_unicode_set_glyph (struct grub_unicode_glyph *out,
313 const struct grub_unicode_glyph *in)
315 grub_memcpy (out, in, sizeof (*in));
316 if (in->ncomb > ARRAY_SIZE (out->combining_inline))
318 out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0]));
319 if (!out->combining_ptr)
320 return;
321 grub_memcpy (out->combining_ptr, in->combining_ptr,
322 in->ncomb * sizeof (out->combining_ptr[0]));
324 else
325 grub_memcpy (&out->combining_inline, &in->combining_inline,
326 sizeof (out->combining_inline));
329 static inline struct grub_unicode_glyph *
330 grub_unicode_glyph_from_code (grub_uint32_t code)
332 struct grub_unicode_glyph *ret;
333 ret = grub_zalloc (sizeof (*ret));
334 if (!ret)
335 return NULL;
337 ret->base = code;
339 return ret;
342 static inline void
343 grub_unicode_set_glyph_from_code (struct grub_unicode_glyph *glyph,
344 grub_uint32_t code)
346 grub_memset (glyph, 0, sizeof (*glyph));
348 glyph->base = code;
351 grub_uint32_t
352 grub_unicode_mirror_code (grub_uint32_t in);
353 grub_uint32_t
354 grub_unicode_shape_code (grub_uint32_t in, grub_uint8_t attr);
356 const grub_uint32_t *
357 grub_unicode_get_comb_end (const grub_uint32_t *end,
358 const grub_uint32_t *cur);
360 #endif