gpforge
An advanced bitmap font editor
Loading...
Searching...
No Matches
unicode_blocks.c
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*
3 * Copyright (C) 2026 Cyril Hrubis <metan@ucw.cz>
4 */
5/*
6 * The block table is generated from the Unicode Blocks.txt, do not edit it.
7 *
8 * sed/awk equivalent: Start..End; Name, the BMP only, coverage 0.
9 *
10 * The preview samples and the functions below it are hand written.
11 */
12
13#include <string.h>
14
15#include <utils/gp_vec.h>
16
17#include "unicode_blocks.h"
18
19const struct gpf_ucode_block gpf_ucode_blocks[] = {
20 {0x0000, 0x007f, "Basic Latin", 0},
21 {0x0080, 0x00ff, "Latin-1 Supplement", 0},
22 {0x0100, 0x017f, "Latin Extended-A", 0},
23 {0x0180, 0x024f, "Latin Extended-B", 0},
24 {0x0250, 0x02af, "IPA Extensions", 0},
25 {0x02b0, 0x02ff, "Spacing Modifier Letters", 0},
26 {0x0300, 0x036f, "Combining Diacritical Marks", 0},
27 {0x0370, 0x03ff, "Greek and Coptic", 0},
28 {0x0400, 0x04ff, "Cyrillic", 0},
29 {0x0500, 0x052f, "Cyrillic Supplement", 0},
30 {0x0530, 0x058f, "Armenian", 0},
31 {0x0590, 0x05ff, "Hebrew", 0},
32 {0x0600, 0x06ff, "Arabic", 0},
33 {0x0700, 0x074f, "Syriac", 0},
34 {0x0750, 0x077f, "Arabic Supplement", 0},
35 {0x0780, 0x07bf, "Thaana", 0},
36 {0x07c0, 0x07ff, "NKo", 0},
37 {0x0800, 0x083f, "Samaritan", 0},
38 {0x0840, 0x085f, "Mandaic", 0},
39 {0x0860, 0x086f, "Syriac Supplement", 0},
40 {0x0870, 0x089f, "Arabic Extended-B", 0},
41 {0x08a0, 0x08ff, "Arabic Extended-A", 0},
42 {0x0900, 0x097f, "Devanagari", 0},
43 {0x0980, 0x09ff, "Bengali", 0},
44 {0x0a00, 0x0a7f, "Gurmukhi", 0},
45 {0x0a80, 0x0aff, "Gujarati", 0},
46 {0x0b00, 0x0b7f, "Oriya", 0},
47 {0x0b80, 0x0bff, "Tamil", 0},
48 {0x0c00, 0x0c7f, "Telugu", 0},
49 {0x0c80, 0x0cff, "Kannada", 0},
50 {0x0d00, 0x0d7f, "Malayalam", 0},
51 {0x0d80, 0x0dff, "Sinhala", 0},
52 {0x0e00, 0x0e7f, "Thai", 0},
53 {0x0e80, 0x0eff, "Lao", 0},
54 {0x0f00, 0x0fff, "Tibetan", 0},
55 {0x1000, 0x109f, "Myanmar", 0},
56 {0x10a0, 0x10ff, "Georgian", 0},
57 {0x1100, 0x11ff, "Hangul Jamo", 0},
58 {0x1200, 0x137f, "Ethiopic", 0},
59 {0x1380, 0x139f, "Ethiopic Supplement", 0},
60 {0x13a0, 0x13ff, "Cherokee", 0},
61 {0x1400, 0x167f, "Unified Canadian Aboriginal Syllabics", 0},
62 {0x1680, 0x169f, "Ogham", 0},
63 {0x16a0, 0x16ff, "Runic", 0},
64 {0x1700, 0x171f, "Tagalog", 0},
65 {0x1720, 0x173f, "Hanunoo", 0},
66 {0x1740, 0x175f, "Buhid", 0},
67 {0x1760, 0x177f, "Tagbanwa", 0},
68 {0x1780, 0x17ff, "Khmer", 0},
69 {0x1800, 0x18af, "Mongolian", 0},
70 {0x18b0, 0x18ff, "Unified Canadian Aboriginal Syllabics Extended", 0},
71 {0x1900, 0x194f, "Limbu", 0},
72 {0x1950, 0x197f, "Tai Le", 0},
73 {0x1980, 0x19df, "New Tai Lue", 0},
74 {0x19e0, 0x19ff, "Khmer Symbols", 0},
75 {0x1a00, 0x1a1f, "Buginese", 0},
76 {0x1a20, 0x1aaf, "Tai Tham", 0},
77 {0x1ab0, 0x1aff, "Combining Diacritical Marks Extended", 0},
78 {0x1b00, 0x1b7f, "Balinese", 0},
79 {0x1b80, 0x1bbf, "Sundanese", 0},
80 {0x1bc0, 0x1bff, "Batak", 0},
81 {0x1c00, 0x1c4f, "Lepcha", 0},
82 {0x1c50, 0x1c7f, "Ol Chiki", 0},
83 {0x1c80, 0x1c8f, "Cyrillic Extended-C", 0},
84 {0x1c90, 0x1cbf, "Georgian Extended", 0},
85 {0x1cc0, 0x1ccf, "Sundanese Supplement", 0},
86 {0x1cd0, 0x1cff, "Vedic Extensions", 0},
87 {0x1d00, 0x1d7f, "Phonetic Extensions", 0},
88 {0x1d80, 0x1dbf, "Phonetic Extensions Supplement", 0},
89 {0x1dc0, 0x1dff, "Combining Diacritical Marks Supplement", 0},
90 {0x1e00, 0x1eff, "Latin Extended Additional", 0},
91 {0x1f00, 0x1fff, "Greek Extended", 0},
92 {0x2000, 0x206f, "General Punctuation", 0},
93 {0x2070, 0x209f, "Superscripts and Subscripts", 0},
94 {0x20a0, 0x20cf, "Currency Symbols", 0},
95 {0x20d0, 0x20ff, "Combining Diacritical Marks for Symbols", 0},
96 {0x2100, 0x214f, "Letterlike Symbols", 0},
97 {0x2150, 0x218f, "Number Forms", 0},
98 {0x2190, 0x21ff, "Arrows", 0},
99 {0x2200, 0x22ff, "Mathematical Operators", 0},
100 {0x2300, 0x23ff, "Miscellaneous Technical", 0},
101 {0x2400, 0x243f, "Control Pictures", 0},
102 {0x2440, 0x245f, "Optical Character Recognition", 0},
103 {0x2460, 0x24ff, "Enclosed Alphanumerics", 0},
104 {0x2500, 0x257f, "Box Drawing", 0},
105 {0x2580, 0x259f, "Block Elements", 0},
106 {0x25a0, 0x25ff, "Geometric Shapes", 0},
107 {0x2600, 0x26ff, "Miscellaneous Symbols", 0},
108 {0x2700, 0x27bf, "Dingbats", 0},
109 {0x27c0, 0x27ef, "Miscellaneous Mathematical Symbols-A", 0},
110 {0x27f0, 0x27ff, "Supplemental Arrows-A", 0},
111 {0x2800, 0x28ff, "Braille Patterns", 0},
112 {0x2900, 0x297f, "Supplemental Arrows-B", 0},
113 {0x2980, 0x29ff, "Miscellaneous Mathematical Symbols-B", 0},
114 {0x2a00, 0x2aff, "Supplemental Mathematical Operators", 0},
115 {0x2b00, 0x2bff, "Miscellaneous Symbols and Arrows", 0},
116 {0x2c00, 0x2c5f, "Glagolitic", 0},
117 {0x2c60, 0x2c7f, "Latin Extended-C", 0},
118 {0x2c80, 0x2cff, "Coptic", 0},
119 {0x2d00, 0x2d2f, "Georgian Supplement", 0},
120 {0x2d30, 0x2d7f, "Tifinagh", 0},
121 {0x2d80, 0x2ddf, "Ethiopic Extended", 0},
122 {0x2de0, 0x2dff, "Cyrillic Extended-A", 0},
123 {0x2e00, 0x2e7f, "Supplemental Punctuation", 0},
124 {0x2e80, 0x2eff, "CJK Radicals Supplement", 0},
125 {0x2f00, 0x2fdf, "Kangxi Radicals", 0},
126 {0x2ff0, 0x2fff, "Ideographic Description Characters", 0},
127 {0x3000, 0x303f, "CJK Symbols and Punctuation", 0},
128 {0x3040, 0x309f, "Hiragana", 0},
129 {0x30a0, 0x30ff, "Katakana", 0},
130 {0x3100, 0x312f, "Bopomofo", 0},
131 {0x3130, 0x318f, "Hangul Compatibility Jamo", 0},
132 {0x3190, 0x319f, "Kanbun", 0},
133 {0x31a0, 0x31bf, "Bopomofo Extended", 0},
134 {0x31c0, 0x31ef, "CJK Strokes", 0},
135 {0x31f0, 0x31ff, "Katakana Phonetic Extensions", 0},
136 {0x3200, 0x32ff, "Enclosed CJK Letters and Months", 0},
137 {0x3300, 0x33ff, "CJK Compatibility", 0},
138 {0x3400, 0x4dbf, "CJK Unified Ideographs Extension A", 0},
139 {0x4dc0, 0x4dff, "Yijing Hexagram Symbols", 0},
140 {0x4e00, 0x9fff, "CJK Unified Ideographs", 0},
141 {0xa000, 0xa48f, "Yi Syllables", 0},
142 {0xa490, 0xa4cf, "Yi Radicals", 0},
143 {0xa4d0, 0xa4ff, "Lisu", 0},
144 {0xa500, 0xa63f, "Vai", 0},
145 {0xa640, 0xa69f, "Cyrillic Extended-B", 0},
146 {0xa6a0, 0xa6ff, "Bamum", 0},
147 {0xa700, 0xa71f, "Modifier Tone Letters", 0},
148 {0xa720, 0xa7ff, "Latin Extended-D", 0},
149 {0xa800, 0xa82f, "Syloti Nagri", 0},
150 {0xa830, 0xa83f, "Common Indic Number Forms", 0},
151 {0xa840, 0xa87f, "Phags-pa", 0},
152 {0xa880, 0xa8df, "Saurashtra", 0},
153 {0xa8e0, 0xa8ff, "Devanagari Extended", 0},
154 {0xa900, 0xa92f, "Kayah Li", 0},
155 {0xa930, 0xa95f, "Rejang", 0},
156 {0xa960, 0xa97f, "Hangul Jamo Extended-A", 0},
157 {0xa980, 0xa9df, "Javanese", 0},
158 {0xa9e0, 0xa9ff, "Myanmar Extended-B", 0},
159 {0xaa00, 0xaa5f, "Cham", 0},
160 {0xaa60, 0xaa7f, "Myanmar Extended-A", 0},
161 {0xaa80, 0xaadf, "Tai Viet", 0},
162 {0xaae0, 0xaaff, "Meetei Mayek Extensions", 0},
163 {0xab00, 0xab2f, "Ethiopic Extended-A", 0},
164 {0xab30, 0xab6f, "Latin Extended-E", 0},
165 {0xab70, 0xabbf, "Cherokee Supplement", 0},
166 {0xabc0, 0xabff, "Meetei Mayek", 0},
167 {0xac00, 0xd7af, "Hangul Syllables", 0},
168 {0xd7b0, 0xd7ff, "Hangul Jamo Extended-B", 0},
169 {0xd800, 0xdb7f, "High Surrogates", 0},
170 {0xdb80, 0xdbff, "High Private Use Surrogates", 0},
171 {0xdc00, 0xdfff, "Low Surrogates", 0},
172 {0xe000, 0xf8ff, "Private Use Area", 0},
173 {0xf900, 0xfaff, "CJK Compatibility Ideographs", 0},
174 {0xfb00, 0xfb4f, "Alphabetic Presentation Forms", 0},
175 {0xfb50, 0xfdff, "Arabic Presentation Forms-A", 0},
176 {0xfe00, 0xfe0f, "Variation Selectors", 0},
177 {0xfe10, 0xfe1f, "Vertical Forms", 0},
178 {0xfe20, 0xfe2f, "Combining Half Marks", 0},
179 {0xfe30, 0xfe4f, "CJK Compatibility Forms", 0},
180 {0xfe50, 0xfe6f, "Small Form Variants", 0},
181 {0xfe70, 0xfeff, "Arabic Presentation Forms-B", 0},
182 {0xff00, 0xffef, "Halfwidth and Fullwidth Forms", 0},
183 {0xfff0, 0xffff, "Specials", 0},
184 {}
185};
186
187/*
188 * Sample text per unicode block, so that the preview shows the glyphs being
189 * worked on.
190 *
191 * Right to left scripts and scripts that need shaping or combining marks are
192 * left out on purpose, gp_text() draws a string glyph by glyph, left to right,
193 * so a sample would show them wrong. Those blocks fall back to the font's own
194 * glyphs in the preview.
195 */
196static const struct {
197 const char *block;
198 const char *sample;
199} samples[] = {
200 {"Basic Latin",
201 "Sphinx of black quartz, judge my vow. 0123456789 #&@?!"},
202 {"Latin-1 Supplement",
203 "Příliš žluťoučký kůň úpěl ódy §±¼½¾ ÀÉÎÕÜ àéîõü"},
204 {"Latin Extended-A",
205 "Příliš žluťoučký kůň úpěl ďábelské ódy ŁŒŠŽ łœšž"},
206 {"Latin Extended-B",
207 "Ș ș Ț ț Ǎ ǎ Ǐ ǐ Ǒ ǒ Ǔ ǔ Ǖ ǖ ƒ Ơ ơ Ư ư Ʒ ǯ"},
208 {"IPA Extensions",
209 "ðə kwɪk bɹaʊn fɒks dʒʌmps ˈoʊvɚ ðə ˈleɪzi dɔɡ"},
210 {"Spacing Modifier Letters",
211 "ʰ ʲ ʷ ˀ ˈ ˌ ː ˑ ˆ ˇ ˘ ˙ ˚ ˛ ˜ ˝"},
212 {"Greek and Coptic",
213 "Ξεσκεπάζω την ψυχοφθόρα βδελυγμία"},
214 {"Cyrillic",
215 "Съешь же ещё этих мягких французских булок"},
216 {"Cyrillic Supplement",
217 "Ԁ ԁ Ԃ ԃ Ԑ ԑ Ԛ ԛ Ԝ ԝ Ԥ ԥ Ԯ ԯ"},
218 {"Armenian",
219 "Հայերեն այբուբեն Աա Բբ Գգ Դդ Եե"},
220 {"Georgian",
221 "ქართული ენა აბგდევზთიკლმნოპ"},
222 {"Latin Extended Additional",
223 "Tiếng Việt có dấu Ẩ ẩ Ặ ặ Ố ố Ự ự Ỹ ỹ Ḍ ḍ Ẁ ẁ"},
224 {"Greek Extended",
225 "Ἀρχὴ ἥμισυ παντός ἄ ἒ ἢ ἶ ὂ ὖ ὦ ᾳ ῃ ῳ"},
226 {"General Punctuation",
227 "‘single’ “double” – — † ‡ • ‰ ′ ″ ‹ › …"},
228 {"Superscripts and Subscripts",
229 "H₂O x⁴ ⁽ⁿ⁺¹⁾ ₍ₐ₋ₓ₎ ⁰⁴⁵⁶⁷⁸⁹ ₀₁₂₃₄₅₆₇₈₉"},
230 {"Currency Symbols",
231 "₠ ₡ ₢ ₣ ₤ ₦ ₧ ₨ ₩ ₪ ₫ € ₭ ₮ ₱ ₲ ₴ ₵ ₹ ₺ ₽ ₿"},
232 {"Letterlike Symbols",
233 "℃ ℉ ℓ № ℗ ℞ ℠ ™ Ω ℧ K Å ℮ ℵ"},
234 {"Number Forms",
235 "⅓ ⅔ ⅕ ⅛ ⅜ ⅝ ⅞ Ⅰ Ⅱ Ⅲ Ⅳ Ⅴ Ⅹ Ⅼ Ⅽ Ⅾ Ⅿ ⅰ ⅱ ⅲ ⅳ"},
236 {"Arrows",
237 "← ↑ → ↓ ↔ ↕ ↖ ↗ ↘ ↙ ⇐ ⇑ ⇒ ⇓ ⇔ ⇕"},
238 {"Mathematical Operators",
239 "∀x ∃y: x ∈ A ∩ B ⊆ C ∑ ∏ √ ∞ ≈ ≠ ≤ ≥ ∂ ∇ ∫"},
240 {"Miscellaneous Technical",
241 "⌀ ⌂ ⌘ ⌚ ⌛ ⌈ ⌉ ⌊ ⌋ ⌠ ⌡ ⎡ ⎤ ⏎ ⏏ ⏻"},
242 {"Box Drawing",
243 "┌──┬──┐ ├──┼──┤ └──┴──┘ ╔══╦══╗ ╠══╬══╣ ╚══╩══╝"},
244 {"Block Elements",
245 "░▒▓█ ▀▄▌▐ ▁▂▃▄▅▆▇█"},
246 {"Geometric Shapes",
247 "■ □ ▪ ▫ ▲ △ ► ▶ ▼ ▽ ◀ ◆ ◇ ○ ◎ ● ◐ ◑ ◢ ◣"},
248 {"Miscellaneous Symbols",
249 "☀ ☁ ☂ ☃ ★ ☆ ☎ ☐ ☑ ☒ ☺ ☹ ♀ ♂ ♠ ♣ ♥ ♦ ♪ ♫ ⚠ ⚡"},
250 {"Dingbats",
251 "✁ ✂ ✈ ✉ ✎ ✓ ✔ ✗ ✘ ✚ ✦ ✱ ❄ ❤ ➔ ➜ ➤"},
252 {"Braille Patterns",
253 "⠓⠑⠇⠇⠕ ⠺⠕⠗⠇⠙ ⣿⣶⣤⣀"},
254 {"CJK Symbols and Punctuation",
255 "、。〃々〆〇〈〉《》「」『』【】〒〔〕"},
256 {"Hiragana",
257 "いろはにほへと ちりぬるを わかよたれそ"},
258 {"Katakana",
259 "イロハニホヘト チリヌルヲ ワカヨタレソ"},
260 {"Halfwidth and Fullwidth Forms",
261 "Fullwidth 0123 カタカナ ワカヨタレソ"},
262 {}
263};
264
265const char *gpf_ucode_block_sample(const char *name)
266{
267 unsigned int i;
268
269 for (i = 0; samples[i].block; i++) {
270 if (!strcmp(samples[i].block, name))
271 return samples[i].sample;
272 }
273
274 return NULL;
275}
276
278{
279 struct gpf_ucode_block *vec = gp_vec_new(0, sizeof(struct gpf_ucode_block));
280 uint32_t *codes = gpf_font_codes(font);
281 unsigned int i;
282 size_t j = 0;
283
284 if (!vec || !codes) {
285 gp_vec_free(vec);
286 gp_vec_free(codes);
287 return NULL;
288 }
289
290 /* both are sorted by the codepoint, so this is a merge */
291 for (i = 0; gpf_ucode_blocks[i].name; i++) {
292 const struct gpf_ucode_block *ub = &gpf_ucode_blocks[i];
293 struct gpf_ucode_block block = *ub;
294
295 while (j < gp_vec_len(codes) && codes[j] < ub->min)
296 j++;
297
298 while (j < gp_vec_len(codes) && codes[j] <= ub->max) {
299 block.coverage++;
300 j++;
301 }
302
303 if (!block.coverage && !gpf_font_block_declared(font, ub->min))
304 continue;
305
306 if (!GP_VEC_APPEND(vec, block)) {
307 gp_vec_free(vec);
308 gp_vec_free(codes);
309 return NULL;
310 }
311 }
312
313 gp_vec_free(codes);
314
315 /* an empty font starts with Basic Latin, it has to start somewhere */
316 if (!gp_vec_len(vec)) {
317 if (!GP_VEC_APPEND(vec, gpf_ucode_blocks[0])) {
318 gp_vec_free(vec);
319 return NULL;
320 }
321 }
322
323 return vec;
324}
325
326int gpf_blocks_find(const struct gpf_ucode_block *blocks, uint32_t code)
327{
328 size_t i;
329
330 for (i = 0; i < gp_vec_len(blocks); i++) {
331 if (code >= blocks[i].min && code <= blocks[i].max)
332 return i;
333 }
334
335 return -1;
336}
A font family.
Definition font.h:274
A unicode block description.
uint32_t max
Last code point in the block.
uint32_t min
First code point in the block.
The BMP part of unicode block table and the blocks of a font.
int gpf_blocks_find(const struct gpf_ucode_block *blocks, uint32_t code)
Looks up a block by a codepoint.
struct gpf_ucode_block * gpf_blocks_build(struct gpf_font *font)
Builds a list of blocks for a font.