1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
|
/*
* libzvbi test
*
* Copyright (C) 2000, 2001, 2008 Michael H. Schimek
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
/* $Id: unicode.c,v 1.13 2008-09-11 02:47:12 mschimek Exp $ */
#undef NDEBUG
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <assert.h>
#include <limits.h>
#include "src/lang.h"
#include "src/misc.h"
static void
putwchar_local (unsigned int c)
{
if (c < 0x80) {
putchar (c);
} else if (c < 0x800) {
putchar (0xC0 | (c >> 6));
putchar (0x80 | (c & 0x3F));
} else if (c < 0x10000) {
putchar (0xE0 | (c >> 12));
putchar (0x80 | ((c >> 6) & 0x3F));
putchar (0x80 | (c & 0x3F));
} else if (c < 0x200000) {
putchar (0xF0 | (c >> 18));
putchar (0x80 | ((c >> 12) & 0x3F));
putchar (0x80 | ((c >> 6) & 0x3F));
putchar (0x80 | (c & 0x3F));
}
}
#undef putwchar
#define putwchar putwchar_local
static void
putwstr (const char * s)
{
for (; *s; s++)
putwchar (*s);
}
static const unsigned int
national [] = {
0x23, 0x24, 0x40, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
0x60, 0x7B, 0x7C, 0x7D, 0x7E
};
static void
print_set (const char * name,
unsigned int s)
{
unsigned int i, j;
putwstr (name);
putwchar ('\n');
for (i = 0; i < 16; ++i) {
for (j = 2; j < 8; ++j) {
putwchar (vbi_teletext_unicode (s, 0, j * 16 + i));
putwchar (' ');
}
putwchar ('\n');
}
putwchar ('\n');
}
static void
teletext_composed (vbi_bool upper_case)
{
unsigned int offs;
unsigned int i, j;
offs = upper_case ? 0x00 : 0x20;
putwstr ("Teletext composed glyphs\n\n ");
for (i = 0x40; i < 0x60; ++i)
putwchar (vbi_teletext_unicode (1, 0, i | offs));
putwstr ("\n\n");
for (i = 0; i < 16; ++i) {
putwchar (vbi_teletext_unicode (2, 0, 0x40 + i));
putwstr (" ");
for (j = 0x40; j < 0x60; ++j) {
unsigned int c;
c = vbi_teletext_composed_unicode (i, j | offs);
putwchar ((0 == c) ? '-' : c);
}
putwchar ('\n');
}
putwchar ('\n');
}
static int
is_teletext_composed (unsigned int uc)
{
unsigned int i, j;
for (i = 0; i < 16; ++i) {
for (j = 0x20; j < 0x80; ++j) {
if (uc == vbi_teletext_composed_unicode (i, j))
return TRUE;
}
}
return FALSE;
}
static void
teletext_composed_inv (void)
{
unsigned int i, j;
putwstr ("Teletext composed glyphs (Unicode U+0080 ... U+00FF)\n\n");
for (i = 0; i < 16; ++i) {
for (j = 0x080; j < 0x100; j += 0x10) {
putwchar (is_teletext_composed (i + j) ? i + j : '-');
putwchar (' ');
}
putwchar ('\n');
}
putwchar ('\n');
putwstr ("Teletext composed glyphs (Unicode U+0100 ... U+017F)\n\n");
for (i = 0; i < 16; ++i) {
for (j = 0x100; j < 0x180; j += 0x10) {
putwchar (is_teletext_composed (i + j) ? i + j : '-');
putwchar (' ');
}
putwchar ('\n');
}
putwchar ('\n');
}
int
main (int argc,
char ** argv)
{
unsigned int i, j;
argc = argc; /* unused */
argv = argv;
putwstr ("libzvbi unicode test -*- coding: utf-8 -*-\n\n");
putwstr ("ETS 300 706 Table 36: Latin National Option Sub-sets\n\n");
for (i = 1; i < 14; ++i) {
for (j = 0; j < N_ELEMENTS (national); ++j) {
putwchar (vbi_teletext_unicode (1, i, national[j]));
putwchar (' ');
}
putwchar ('\n');
}
putwchar ('\n');
print_set ("ETS 300 706 Table 35: Latin G0 Primary Set\n", 1);
print_set ("ETS 300 706 Table 37: Latin G2 Supplementary Set\n", 2);
print_set ("ETS 300 706 Table 38: Cyrillic G0 Primary Set "
"- Option 1 - Serbian/Croatian\n", 3);
print_set ("ETS 300 706 Table 39: Cyrillic G0 Primary Set "
"- Option 2 - Russian/Bulgarian\n", 4);
print_set ("ETS 300 706 Table 40: Cyrillic G0 Primary Set "
"- Option 3 - Ukrainian\n", 5);
print_set ("ETS 300 706 Table 41: Cyrillic G2 Supplementary Set\n", 6);
print_set ("ETS 300 706 Table 42: Greek G0 Primary Set\n", 7);
print_set ("ETS 300 706 Table 43: Greek G2 Supplementary Set\n", 8);
print_set ("ETS 300 706 Table 44: Arabic G0 Primary Set\n", 9);
print_set ("ETS 300 706 Table 45: Arabic G2 Supplementary Set\n", 10);
print_set ("ETS 300 706 Table 46: Hebrew G0 Primary Set\n", 11);
putwstr ("ETS 300 706 Table 47: G1 Block Mosaics Set\n\n");
for (i = 0; i < 16; ++i) {
for (j = 2; j < 8; ++j) {
if (j == 4 || j == 5)
putwchar (' ');
else
putwchar (vbi_teletext_unicode
(12, 0, j * 16 + i));
putwchar (' ');
}
putwchar ('\n');
}
putwchar ('\n');
print_set ("ETS 300 706 Table 48: G3 Smooth Mosaics and "
"Line Drawing Set\n", 13);
teletext_composed (/* upper_case */ TRUE);
teletext_composed (/* upper_case */ FALSE);
teletext_composed_inv ();
putwstr ("\nEIA 608 Closed Caption Basic Character Set\n\n");
for (i = 0; i < 8; ++i) {
for (j = 0x20; j < 0x80; j += 8) {
putwchar (vbi_caption_unicode (j + i, FALSE));
putwchar (' ');
}
putwstr (" ");
for (j = 0x20; j < 0x80; j += 8) {
putwchar (vbi_caption_unicode (j + i, TRUE));
putwchar (' ');
}
putwchar ('\n');
}
putwstr ("\n\nEIA 608 Closed Caption "
"Special Characters (0x1130+n)\n\n");
for (i = 0; i < 16; ++i)
putwchar (vbi_caption_unicode (0x1130 + i, FALSE));
putwchar ('\n');
for (i = 0; i < 16; ++i)
putwchar (vbi_caption_unicode (0x1130 + i, TRUE));
putwstr ("\n\nEIA 608 Closed Caption "
"Extended Characters (0x1220+n)\n\n");
for (i = 0; i < 32; ++i)
putwchar (vbi_caption_unicode (0x1220 + i, FALSE));
putwchar ('\n');
for (i = 0; i < 32; ++i)
putwchar (vbi_caption_unicode (0x1220 + i, TRUE));
putwstr ("\n\nEIA 608 Closed Caption "
"Extended Characters (0x1320+n)\n\n");
for (i = 0; i < 32; ++i)
putwchar (vbi_caption_unicode (0x1320 + i, FALSE));
putwchar ('\n');
for (i = 0; i < 32; ++i)
putwchar (vbi_caption_unicode (0x1320 + i, TRUE));
putwchar ('\n');
assert ('a' == vbi_caption_unicode ('a', FALSE));
assert ('A' == vbi_caption_unicode ('a', TRUE));
assert ('A' == vbi_caption_unicode ('a', -1));
assert ('A' == vbi_caption_unicode ('a', INT_MAX));
for (i = 0; i < 2; ++i) {
assert (0 == vbi_caption_unicode (-1, i));
assert (0 == vbi_caption_unicode (0x80, i));
assert (0 == vbi_caption_unicode (0x1130 - 1, i));
assert (0 == vbi_caption_unicode (0x1130 + 16, i));
assert (0 == vbi_caption_unicode (0x1220 - 1, i));
assert (0 == vbi_caption_unicode (0x1220 + 32, i));
assert (0 == vbi_caption_unicode (0x1320 - 1, i));
assert (0 == vbi_caption_unicode (0x1320 + 32, i));
assert (0 == vbi_caption_unicode (INT_MAX, i));
}
exit (EXIT_SUCCESS);
}
|