Add g_unichar_get_mirror_char. (#114749)

2003-09-12  Noah Levitt  <nlevitt@columbia.edu>

	* glib/gen-unicode-tables.pl:
	* glib/gunichartables.h:
	* glib/gunicode.h:
	* glib/guniprop.c: Add g_unichar_get_mirror_char. (#114749)
This commit is contained in:
Noah Levitt 2003-09-12 17:54:43 +00:00 committed by Noah Levitt
parent 2f4c3d8a6d
commit 244a8e5a0a
10 changed files with 463 additions and 2 deletions

View File

@ -1,3 +1,10 @@
2003-09-12 Noah Levitt <nlevitt@columbia.edu>
* glib/gen-unicode-tables.pl:
* glib/gunichartables.h:
* glib/gunicode.h:
* glib/guniprop.c: Add g_unichar_get_mirror_char. (#114749)
Thu Sep 11 20:11:05 2003 Owen Taylor <otaylor@redhat.com>
* glib/gmarkup.c: Add g_markup_printf_escaped(),

View File

@ -1,3 +1,10 @@
2003-09-12 Noah Levitt <nlevitt@columbia.edu>
* glib/gen-unicode-tables.pl:
* glib/gunichartables.h:
* glib/gunicode.h:
* glib/guniprop.c: Add g_unichar_get_mirror_char. (#114749)
Thu Sep 11 20:11:05 2003 Owen Taylor <otaylor@redhat.com>
* glib/gmarkup.c: Add g_markup_printf_escaped(),

View File

@ -1,3 +1,10 @@
2003-09-12 Noah Levitt <nlevitt@columbia.edu>
* glib/gen-unicode-tables.pl:
* glib/gunichartables.h:
* glib/gunicode.h:
* glib/guniprop.c: Add g_unichar_get_mirror_char. (#114749)
Thu Sep 11 20:11:05 2003 Owen Taylor <otaylor@redhat.com>
* glib/gmarkup.c: Add g_markup_printf_escaped(),

View File

@ -1,3 +1,10 @@
2003-09-12 Noah Levitt <nlevitt@columbia.edu>
* glib/gen-unicode-tables.pl:
* glib/gunichartables.h:
* glib/gunicode.h:
* glib/guniprop.c: Add g_unichar_get_mirror_char. (#114749)
Thu Sep 11 20:11:05 2003 Owen Taylor <otaylor@redhat.com>
* glib/gmarkup.c: Add g_markup_printf_escaped(),

View File

@ -1,3 +1,10 @@
2003-09-12 Noah Levitt <nlevitt@columbia.edu>
* glib/gen-unicode-tables.pl:
* glib/gunichartables.h:
* glib/gunicode.h:
* glib/guniprop.c: Add g_unichar_get_mirror_char. (#114749)
Thu Sep 11 20:11:05 2003 Owen Taylor <otaylor@redhat.com>
* glib/gmarkup.c: Add g_markup_printf_escaped(),

View File

@ -1,3 +1,10 @@
2003-09-12 Noah Levitt <nlevitt@columbia.edu>
* glib/gen-unicode-tables.pl:
* glib/gunichartables.h:
* glib/gunicode.h:
* glib/guniprop.c: Add g_unichar_get_mirror_char. (#114749)
Thu Sep 11 20:11:05 2003 Owen Taylor <otaylor@redhat.com>
* glib/gmarkup.c: Add g_markup_printf_escaped(),

View File

@ -167,9 +167,9 @@ elsif (@ARGV && $ARGV[0] eq '-both')
shift @ARGV;
}
if (@ARGV != 6) {
if (@ARGV != 7) {
$0 =~ s@.*/@@;
die "Usage: $0 [-decomp | -both] UNICODE-VERSION UnicodeData.txt LineBreak.txt SpecialCasing.txt CaseFolding.txt CompositionExclusions.txt\n";
die "Usage: $0 [-decomp | -both] UNICODE-VERSION UnicodeData.txt LineBreak.txt SpecialCasing.txt CaseFolding.txt CompositionExclusions.txt BidiMirroring.txt\n";
}
print "Creating decomp table\n" if ($do_decomp);
@ -461,6 +461,23 @@ while (<INPUT>)
close INPUT;
open (INPUT, "< $ARGV[6]") || exit 1;
my @bidimirror;
while (<INPUT>)
{
chomp;
next if /^#/;
next if /^\s*$/;
s/\s*#.*//;
@fields = split ('\s*;\s*', $_, 30);
push @bidimirror, [hex ($fields[0]), hex ($fields[1])];
}
if ($do_props) {
&print_tables ($last_code)
}
@ -637,6 +654,21 @@ sub print_tables
&output_special_case_table (\*OUT);
&output_casefold_table (\*OUT);
print OUT "static const struct {\n";
print OUT " gunichar ch;\n";
print OUT " gunichar mirrored_ch;\n";
print OUT "} bidi_mirroring_table[] =\n";
print OUT "{\n";
$first = 1;
foreach $item (@bidimirror)
{
print OUT ",\n" unless $first;
$first = 0;
printf OUT " { 0x%04x, 0x%04x }", $item->[0], $item->[1];
$bytes_out += 8;
}
print OUT "\n};\n\n";
print OUT "#endif /* CHARTABLES_H */\n";
close (OUT);

View File

@ -10936,4 +10936,329 @@ static const struct {
{ 0xfb17, "\xd5\xb4\xd5\xad" },
};
static const struct {
gunichar ch;
gunichar mirrored_ch;
} bidi_mirroring_table[] =
{
{ 0x0028, 0x0029 },
{ 0x0029, 0x0028 },
{ 0x003c, 0x003e },
{ 0x003e, 0x003c },
{ 0x005b, 0x005d },
{ 0x005d, 0x005b },
{ 0x007b, 0x007d },
{ 0x007d, 0x007b },
{ 0x00ab, 0x00bb },
{ 0x00bb, 0x00ab },
{ 0x2039, 0x203a },
{ 0x203a, 0x2039 },
{ 0x2045, 0x2046 },
{ 0x2046, 0x2045 },
{ 0x207d, 0x207e },
{ 0x207e, 0x207d },
{ 0x208d, 0x208e },
{ 0x208e, 0x208d },
{ 0x2208, 0x220b },
{ 0x2209, 0x220c },
{ 0x220a, 0x220d },
{ 0x220b, 0x2208 },
{ 0x220c, 0x2209 },
{ 0x220d, 0x220a },
{ 0x2215, 0x29f5 },
{ 0x223c, 0x223d },
{ 0x223d, 0x223c },
{ 0x2243, 0x22cd },
{ 0x2252, 0x2253 },
{ 0x2253, 0x2252 },
{ 0x2254, 0x2255 },
{ 0x2255, 0x2254 },
{ 0x2264, 0x2265 },
{ 0x2265, 0x2264 },
{ 0x2266, 0x2267 },
{ 0x2267, 0x2266 },
{ 0x2268, 0x2269 },
{ 0x2269, 0x2268 },
{ 0x226a, 0x226b },
{ 0x226b, 0x226a },
{ 0x226e, 0x226f },
{ 0x226f, 0x226e },
{ 0x2270, 0x2271 },
{ 0x2271, 0x2270 },
{ 0x2272, 0x2273 },
{ 0x2273, 0x2272 },
{ 0x2274, 0x2275 },
{ 0x2275, 0x2274 },
{ 0x2276, 0x2277 },
{ 0x2277, 0x2276 },
{ 0x2278, 0x2279 },
{ 0x2279, 0x2278 },
{ 0x227a, 0x227b },
{ 0x227b, 0x227a },
{ 0x227c, 0x227d },
{ 0x227d, 0x227c },
{ 0x227e, 0x227f },
{ 0x227f, 0x227e },
{ 0x2280, 0x2281 },
{ 0x2281, 0x2280 },
{ 0x2282, 0x2283 },
{ 0x2283, 0x2282 },
{ 0x2284, 0x2285 },
{ 0x2285, 0x2284 },
{ 0x2286, 0x2287 },
{ 0x2287, 0x2286 },
{ 0x2288, 0x2289 },
{ 0x2289, 0x2288 },
{ 0x228a, 0x228b },
{ 0x228b, 0x228a },
{ 0x228f, 0x2290 },
{ 0x2290, 0x228f },
{ 0x2291, 0x2292 },
{ 0x2292, 0x2291 },
{ 0x2298, 0x29b8 },
{ 0x22a2, 0x22a3 },
{ 0x22a3, 0x22a2 },
{ 0x22a6, 0x2ade },
{ 0x22a8, 0x2ae4 },
{ 0x22a9, 0x2ae3 },
{ 0x22ab, 0x2ae5 },
{ 0x22b0, 0x22b1 },
{ 0x22b1, 0x22b0 },
{ 0x22b2, 0x22b3 },
{ 0x22b3, 0x22b2 },
{ 0x22b4, 0x22b5 },
{ 0x22b5, 0x22b4 },
{ 0x22b6, 0x22b7 },
{ 0x22b7, 0x22b6 },
{ 0x22c9, 0x22ca },
{ 0x22ca, 0x22c9 },
{ 0x22cb, 0x22cc },
{ 0x22cc, 0x22cb },
{ 0x22cd, 0x2243 },
{ 0x22d0, 0x22d1 },
{ 0x22d1, 0x22d0 },
{ 0x22d6, 0x22d7 },
{ 0x22d7, 0x22d6 },
{ 0x22d8, 0x22d9 },
{ 0x22d9, 0x22d8 },
{ 0x22da, 0x22db },
{ 0x22db, 0x22da },
{ 0x22dc, 0x22dd },
{ 0x22dd, 0x22dc },
{ 0x22de, 0x22df },
{ 0x22df, 0x22de },
{ 0x22e0, 0x22e1 },
{ 0x22e1, 0x22e0 },
{ 0x22e2, 0x22e3 },
{ 0x22e3, 0x22e2 },
{ 0x22e4, 0x22e5 },
{ 0x22e5, 0x22e4 },
{ 0x22e6, 0x22e7 },
{ 0x22e7, 0x22e6 },
{ 0x22e8, 0x22e9 },
{ 0x22e9, 0x22e8 },
{ 0x22ea, 0x22eb },
{ 0x22eb, 0x22ea },
{ 0x22ec, 0x22ed },
{ 0x22ed, 0x22ec },
{ 0x22f0, 0x22f1 },
{ 0x22f1, 0x22f0 },
{ 0x22f2, 0x22fa },
{ 0x22f3, 0x22fb },
{ 0x22f4, 0x22fc },
{ 0x22f6, 0x22fd },
{ 0x22f7, 0x22fe },
{ 0x22fa, 0x22f2 },
{ 0x22fb, 0x22f3 },
{ 0x22fc, 0x22f4 },
{ 0x22fd, 0x22f6 },
{ 0x22fe, 0x22f7 },
{ 0x2308, 0x2309 },
{ 0x2309, 0x2308 },
{ 0x230a, 0x230b },
{ 0x230b, 0x230a },
{ 0x2329, 0x232a },
{ 0x232a, 0x2329 },
{ 0x2768, 0x2769 },
{ 0x2769, 0x2768 },
{ 0x276a, 0x276b },
{ 0x276b, 0x276a },
{ 0x276c, 0x276d },
{ 0x276d, 0x276c },
{ 0x276e, 0x276f },
{ 0x276f, 0x276e },
{ 0x2770, 0x2771 },
{ 0x2771, 0x2770 },
{ 0x2772, 0x2773 },
{ 0x2773, 0x2772 },
{ 0x2774, 0x2775 },
{ 0x2775, 0x2774 },
{ 0x27d5, 0x27d6 },
{ 0x27d6, 0x27d5 },
{ 0x27dd, 0x27de },
{ 0x27de, 0x27dd },
{ 0x27e2, 0x27e3 },
{ 0x27e3, 0x27e2 },
{ 0x27e4, 0x27e5 },
{ 0x27e5, 0x27e4 },
{ 0x27e6, 0x27e7 },
{ 0x27e7, 0x27e6 },
{ 0x27e8, 0x27e9 },
{ 0x27e9, 0x27e8 },
{ 0x27ea, 0x27eb },
{ 0x27eb, 0x27ea },
{ 0x2983, 0x2984 },
{ 0x2984, 0x2983 },
{ 0x2985, 0x2986 },
{ 0x2986, 0x2985 },
{ 0x2987, 0x2988 },
{ 0x2988, 0x2987 },
{ 0x2989, 0x298a },
{ 0x298a, 0x2989 },
{ 0x298b, 0x298c },
{ 0x298c, 0x298b },
{ 0x298d, 0x2990 },
{ 0x298e, 0x298f },
{ 0x298f, 0x298e },
{ 0x2990, 0x298d },
{ 0x2991, 0x2992 },
{ 0x2992, 0x2991 },
{ 0x2993, 0x2994 },
{ 0x2994, 0x2993 },
{ 0x2995, 0x2996 },
{ 0x2996, 0x2995 },
{ 0x2997, 0x2998 },
{ 0x2998, 0x2997 },
{ 0x29b8, 0x2298 },
{ 0x29c0, 0x29c1 },
{ 0x29c1, 0x29c0 },
{ 0x29c4, 0x29c5 },
{ 0x29c5, 0x29c4 },
{ 0x29cf, 0x29d0 },
{ 0x29d0, 0x29cf },
{ 0x29d1, 0x29d2 },
{ 0x29d2, 0x29d1 },
{ 0x29d4, 0x29d5 },
{ 0x29d5, 0x29d4 },
{ 0x29d8, 0x29d9 },
{ 0x29d9, 0x29d8 },
{ 0x29da, 0x29db },
{ 0x29db, 0x29da },
{ 0x29f5, 0x2215 },
{ 0x29f8, 0x29f9 },
{ 0x29f9, 0x29f8 },
{ 0x29fc, 0x29fd },
{ 0x29fd, 0x29fc },
{ 0x2a2b, 0x2a2c },
{ 0x2a2c, 0x2a2b },
{ 0x2a2d, 0x2a2c },
{ 0x2a2e, 0x2a2d },
{ 0x2a34, 0x2a35 },
{ 0x2a35, 0x2a34 },
{ 0x2a3c, 0x2a3d },
{ 0x2a3d, 0x2a3c },
{ 0x2a64, 0x2a65 },
{ 0x2a65, 0x2a64 },
{ 0x2a79, 0x2a7a },
{ 0x2a7a, 0x2a79 },
{ 0x2a7d, 0x2a7e },
{ 0x2a7e, 0x2a7d },
{ 0x2a7f, 0x2a80 },
{ 0x2a80, 0x2a7f },
{ 0x2a81, 0x2a82 },
{ 0x2a82, 0x2a81 },
{ 0x2a83, 0x2a84 },
{ 0x2a84, 0x2a83 },
{ 0x2a8b, 0x2a8c },
{ 0x2a8c, 0x2a8b },
{ 0x2a91, 0x2a92 },
{ 0x2a92, 0x2a91 },
{ 0x2a93, 0x2a94 },
{ 0x2a94, 0x2a93 },
{ 0x2a95, 0x2a96 },
{ 0x2a96,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 0x300b },
{ 0x300b, 0x300a },
{ 0x300c, 0x300d },
{ 0x300d, 0x300c },
{ 0x300e, 0x300f },
{ 0x300f, 0x300e },
{ 0x3010, 0x3011 },
{ 0x3011, 0x3010 },
{ 0x3014, 0x3015 },
{ 0x3015, 0x3014 },
{ 0x3016, 0x3017 },
{ 0x3017, 0x3016 },
{ 0x3018, 0x3019 },
{ 0x3019, 0x3018 },
{ 0x301a, 0x301b },
{ 0x301b, 0x301a },
{ 0xff08, 0xff09 },
{ 0xff09, 0xff08 },
{ 0xff1c, 0xff1e },
{ 0xff1e, 0xff1c },
{ 0xff3b, 0xff3d },
{ 0xff3d, 0xff3b },
{ 0xff5b, 0xff5d },
{ 0xff5d, 0xff5b },
{ 0xff5f, 0xff60 },
{ 0xff60, 0xff5f },
{ 0xff62, 0xff63 },
{ 0xff63, 0xff62 }
};
#endif /* CHARTABLES_H */

View File

@ -279,6 +279,9 @@ gint g_utf8_collate (const gchar *str1,
gchar *g_utf8_collate_key (const gchar *str,
gssize len);
gboolean g_unichar_get_mirror_char (gunichar ch,
gunichar *mirrored_ch);
G_END_DECLS
#endif /* __G_UNICODE_H__ */

View File

@ -981,3 +981,62 @@ g_utf8_casefold (const gchar *str,
return g_string_free (result, FALSE);
}
/**
* g_unichar_get_mirror_char:
* @ch: a unicode character
* @mirrored_ch: location to store the mirrored character
*
* In Unicode, some characters are <firstterm>mirrored</firstterm>. This
* means that their images are mirrored horizontally in text that is laid
* out from right to left. For instance, "(" would become its mirror image,
* ")", in right-to-left text.
*
* If @ch has the Unicode mirrored property and there is another unicode
* character that typically has a glyph that is the mirror image of @ch's
* glyph, puts that character in the address pointed to by @mirrored_ch.
*
* Return value: %TRUE if @ch has a mirrored character and @mirrored_ch is
* filled in, %FALSE otherwise
**/
/* This code is adapted from FriBidi (http://fribidi.sourceforge.net/).
* FriBidi is: Copyright (C) 1999,2000 Dov Grobgeld, and
* Copyright (C) 2001,2002 Behdad Esfahbod.
*/
gboolean
g_unichar_get_mirror_char (gunichar ch,
gunichar *mirrored_ch)
{
gint pos, step, size;
gboolean found;
size = G_N_ELEMENTS (bidi_mirroring_table);
pos = step = (size / 2) + 1;
while (step > 1)
{
gunichar cmp_ch = bidi_mirroring_table[pos].ch;
step = (step + 1) / 2;
if (cmp_ch < ch)
{
pos += step;
if (pos > size - 1)
pos = size - 1;
}
else if (cmp_ch > ch)
{
pos -= step;
if (pos < 0)
pos = 0;
}
else
break;
}
found = bidi_mirroring_table[pos].ch == ch;
if (mirrored_ch)
*mirrored_ch = found ? bidi_mirroring_table[pos].mirrored_ch : ch;
return found;
}