]> git.proxmox.com Git - grub2.git/blob - include/grub/unicode.h
e7f176d0f0443e2574a9ea0b22fcf8be142aa6a4
[grub2.git] / include / grub / unicode.h
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 2010 Free Software Foundation, Inc.
4 *
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.
9 *
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.
14 *
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/>.
17 */
18
19 #ifndef GRUB_BIDI_HEADER
20 #define GRUB_BIDI_HEADER 1
21
22 #include <grub/types.h>
23 #include <grub/mm.h>
24 #include <grub/misc.h>
25
26 struct grub_unicode_compact_range
27 {
28 grub_uint32_t start:21;
29 grub_uint32_t end:21;
30 grub_uint8_t bidi_type:5;
31 grub_uint8_t comb_type;
32 grub_uint8_t bidi_mirror:1;
33 } __attribute__ ((packed));
34
35 enum grub_bidi_type
36 {
37 GRUB_BIDI_TYPE_L = 0,
38 GRUB_BIDI_TYPE_LRE,
39 GRUB_BIDI_TYPE_LRO,
40 GRUB_BIDI_TYPE_R,
41 GRUB_BIDI_TYPE_AL,
42 GRUB_BIDI_TYPE_RLE,
43 GRUB_BIDI_TYPE_RLO,
44 GRUB_BIDI_TYPE_PDF,
45 GRUB_BIDI_TYPE_EN,
46 GRUB_BIDI_TYPE_ES,
47 GRUB_BIDI_TYPE_ET,
48 GRUB_BIDI_TYPE_AN,
49 GRUB_BIDI_TYPE_CS,
50 GRUB_BIDI_TYPE_NSM,
51 GRUB_BIDI_TYPE_BN,
52 GRUB_BIDI_TYPE_B,
53 GRUB_BIDI_TYPE_S,
54 GRUB_BIDI_TYPE_WS,
55 GRUB_BIDI_TYPE_ON
56 };
57
58 enum grub_comb_type
59 {
60 GRUB_UNICODE_COMB_NONE = 0,
61 GRUB_UNICODE_COMB_OVERLAY = 1,
62 GRUB_UNICODE_STACK_ATTACHED_BELOW = 202,
63 GRUB_UNICODE_STACK_ATTACHED_ABOVE = 214,
64 GRUB_UNICODE_COMB_ATTACHED_ABOVE_RIGHT = 216,
65 GRUB_UNICODE_STACK_BELOW = 220,
66 GRUB_UNICODE_STACK_ABOVE = 230,
67 GRUB_UNICODE_COMB_ABOVE_RIGHT = 232,
68 GRUB_UNICODE_COMB_YPOGEGRAMMENI = 240,
69 /* If combining nature is indicated only by class and
70 not "combining type". */
71 GRUB_UNICODE_COMB_ME = 253,
72 GRUB_UNICODE_COMB_MC = 254,
73 GRUB_UNICODE_COMB_MN = 255,
74 };
75
76 /* This structure describes a glyph as opposed to character. */
77 struct grub_unicode_glyph
78 {
79 grub_uint32_t base;
80 grub_uint16_t variant:9;
81 grub_uint8_t attributes:1;
82 grub_size_t ncomb;
83 struct grub_unicode_combining {
84 grub_uint32_t code;
85 enum grub_comb_type type;
86 } *combining;
87 };
88
89 #define GRUB_UNICODE_GLYPH_ATTRIBUTE_MIRROR 0x1
90 #define GRUB_UNICODE_COMBINING_GRAPHEME_JOINER 0x34f
91 #define GRUB_UNICODE_VARIATION_SELECTOR_1 0xfe00
92 #define GRUB_UNICODE_VARIATION_SELECTOR_16 0xfe0f
93 #define GRUB_UNICODE_VARIATION_SELECTOR_17 0xe0100
94 #define GRUB_UNICODE_VARIATION_SELECTOR_256 0xe01ef
95
96 extern struct grub_unicode_compact_range grub_unicode_compact[];
97
98 #define GRUB_UNICODE_MAX_CACHED_CHAR 0x20000
99 /* Unicode mandates an arbitrary limit. */
100 #define GRUB_BIDI_MAX_EXPLICIT_LEVEL 61
101
102 grub_ssize_t
103 grub_bidi_logical_to_visual (const grub_uint32_t *logical,
104 grub_size_t logical_len,
105 struct grub_unicode_glyph **visual_out,
106 grub_ssize_t (*getcharwidth) (const struct grub_unicode_glyph *visual),
107 grub_size_t max_width,
108 grub_size_t start_width);
109
110 enum grub_comb_type
111 grub_unicode_get_comb_type (grub_uint32_t c);
112 grub_size_t
113 grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen,
114 struct grub_unicode_glyph *out);
115
116 static inline struct grub_unicode_glyph *
117 grub_unicode_glyph_dup (const struct grub_unicode_glyph *in)
118 {
119 struct grub_unicode_glyph *out = grub_malloc (sizeof (*out));
120 if (!out)
121 return NULL;
122 grub_memcpy (out, in, sizeof (*in));
123 out->combining = grub_malloc (in->ncomb * sizeof (*in));
124 if (!out->combining)
125 {
126 grub_free (out);
127 return NULL;
128 }
129 grub_memcpy (out->combining, in->combining, in->ncomb * sizeof (*in));
130 return out;
131 }
132
133 static inline struct grub_unicode_glyph *
134 grub_unicode_glyph_from_code (grub_uint32_t code)
135 {
136 struct grub_unicode_glyph *ret;
137 ret = grub_malloc (sizeof (*ret));
138 if (!ret)
139 return NULL;
140
141 ret->base = code;
142 ret->variant = 0;
143 ret->attributes = 0;
144 ret->ncomb = 0;
145 ret->combining = 0;
146
147 return ret;
148 }
149
150 #endif