2 * fribidi-char-sets-cap-rtl.c - CapRTL character set conversion routines
5 * Behdad Esfahbod, 2001, 2002, 2004
6 * Dov Grobgeld, 1999, 2000
8 * Copyright (C) 2004 Sharif FarsiWeb, Inc
9 * Copyright (C) 2001,2002 Behdad Esfahbod
10 * Copyright (C) 1999,2000 Dov Grobgeld
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with this library, in a file named COPYING; if not, write to the
24 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 * Boston, MA 02110-1301, USA
27 * For licensing issues, contact <fribidi.license@gmail.com>.
32 #include <fribidi-char-sets-cap-rtl.h>
34 #include <fribidi-unicode.h>
35 #include <fribidi-mirroring.h>
36 #include <fribidi-bidi-types.h>
38 #include <bidi-types.h>
44 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE = FRIBIDI_TYPE_##TYPE,
45 # include "fribidi-bidi-types-list.h"
46 # undef _FRIBIDI_ADD_TYPE
47 _FRIBIDI_MAX_TYPES_VALUE
52 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) DUMMY_##TYPE,
53 # include "fribidi-bidi-types-list.h"
54 # undef _FRIBIDI_ADD_TYPE
58 static FriBidiCharType CapRTLCharTypes[] = {
60 ON, ON, ON, ON, LTR,RTL,ON, ON, ON, ON, ON, ON, ON, BS, RLO,RLE, /* 00-0f */
61 LRO,LRE,PDF,WS, LRI, RLI, FSI, PDI, ON, ON, ON, ON, ON, ON, ON, ON, /* 10-1f */
62 WS, ON, ON, ON, ET, ON, ON, ON, ON, ON, ON, ET, CS, ON, ES, ES, /* 20-2f */
63 EN, EN, EN, EN, EN, EN, AN, AN, AN, AN, CS, ON, ON, ON, ON, ON, /* 30-3f */
64 RTL,AL, AL, AL, AL, AL, AL, RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL, /* 40-4f */
65 RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,ON, BS, ON, BN, ON, /* 50-5f */
66 NSM,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR, /* 60-6f */
67 LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,ON, SS, ON, WS, ON, /* 70-7f */
71 #define CAPRTL_CHARS (int)(sizeof CapRTLCharTypes / sizeof CapRTLCharTypes[0])
73 static FriBidiChar *caprtl_to_unicode = NULL;
80 int request[_FRIBIDI_NUM_TYPES];
81 FriBidiCharType to_type[_FRIBIDI_NUM_TYPES];
82 int num_types = 0, count = 0;
84 char mark[CAPRTL_CHARS];
87 (FriBidiChar *) fribidi_malloc (CAPRTL_CHARS *
88 sizeof caprtl_to_unicode[0]);
89 for (i = 0; i < CAPRTL_CHARS; i++)
90 if (CapRTLCharTypes[i] == fribidi_get_bidi_type (i))
92 caprtl_to_unicode[i] = i;
99 caprtl_to_unicode[i] = FRIBIDI_UNICODE_CHARS;
101 if (fribidi_get_mirror_char (i, NULL))
103 DBG ("warning: I could not map mirroring character map to itself in CapRTL");
106 for (j = 0; j < num_types; j++)
107 if (to_type[j] == CapRTLCharTypes[i])
112 to_type[j] = CapRTLCharTypes[i];
118 for (i = 0; i < 0x10000 && count; i++) /* Assign BMP chars to CapRTL entries */
119 if (!fribidi_get_mirror_char (i, NULL) && !(i < CAPRTL_CHARS && mark[i]))
122 FriBidiCharType t = fribidi_get_bidi_type (i);
123 for (j = 0; j < num_types; j++)
126 if (!request[j]) /* Do not need this type */
128 for (k = 0; k < CAPRTL_CHARS; k++)
129 if (caprtl_to_unicode[k] == FRIBIDI_UNICODE_CHARS
130 && to_type[j] == CapRTLCharTypes[k])
134 caprtl_to_unicode[k] = i;
142 DBG ("warning: could not find a mapping for CapRTL to Unicode:");
143 for (j = 0; j < num_types; j++)
146 DBG2 (" need this type: %s", fribidi_get_bidi_type_name (to_type[j]));
152 fribidi_unicode_to_cap_rtl_c (
159 if (!caprtl_to_unicode)
162 for (i = 0; i < CAPRTL_CHARS; i++)
163 if (uch == caprtl_to_unicode[i])
164 return (unsigned char) i;
169 fribidi_cap_rtl_to_unicode (
177 FriBidiStrIndex i, j;
179 if (!caprtl_to_unicode)
183 for (i = 0; i < len; i++)
193 us[j++] = FRIBIDI_CHAR_LRM;
196 us[j++] = FRIBIDI_CHAR_RLM;
199 us[j++] = FRIBIDI_CHAR_LRE;
202 us[j++] = FRIBIDI_CHAR_RLE;
205 us[j++] = FRIBIDI_CHAR_PDF;
208 us[j++] = FRIBIDI_CHAR_LRO;
211 us[j++] = FRIBIDI_CHAR_RLO;
214 us[j++] = FRIBIDI_CHAR_LRI;
217 us[j++] = FRIBIDI_CHAR_RLI;
220 us[j++] = FRIBIDI_CHAR_FSI;
223 us[j++] = FRIBIDI_CHAR_PDI;
235 us[j++] = caprtl_to_unicode[(int) s[i]];
242 fribidi_unicode_to_cap_rtl (
244 const FriBidiChar *us,
254 for (i = 0; i < len; i++)
256 FriBidiChar ch = us[i];
257 if (!FRIBIDI_IS_EXPLICIT (fribidi_get_bidi_type (ch))
258 && !FRIBIDI_IS_ISOLATE (fribidi_get_bidi_type (ch))
259 && ch != '_' && ch != FRIBIDI_CHAR_LRM && ch != FRIBIDI_CHAR_RLM)
260 s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
266 case FRIBIDI_CHAR_LRM:
269 case FRIBIDI_CHAR_RLM:
272 case FRIBIDI_CHAR_LRE:
275 case FRIBIDI_CHAR_RLE:
278 case FRIBIDI_CHAR_PDF:
281 case FRIBIDI_CHAR_LRO:
284 case FRIBIDI_CHAR_RLO:
287 case FRIBIDI_CHAR_LRI:
290 case FRIBIDI_CHAR_RLI:
293 case FRIBIDI_CHAR_FSI:
296 case FRIBIDI_CHAR_PDI:
305 s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
318 fribidi_char_set_desc_cap_rtl (
329 s = (char *) fribidi_malloc (l);
331 i += sprintf (s + i, /*l - i, */
332 "CapRTL is a character set for testing with the reference\n"
333 "implementation, with explicit marks escape strings, and\n"
334 "the property that contains all unicode character types in\n"
335 "ASCII range 1-127.\n"
337 "Warning: CapRTL character types are subject to change.\n"
338 "\n" "CapRTL's character types:\n");
339 for (j = 0; j < CAPRTL_CHARS; j++)
343 i += sprintf (s + i, /*l - i, */ " * 0x%02x %c%c %-3s ", j,
344 j < 0x20 ? '^' : ' ',
345 j < 0x20 ? j + '@' : j < 0x7f ? j : ' ',
346 fribidi_get_bidi_type_name (CapRTLCharTypes[j]));
348 i += sprintf (s + i, /*l - i, */
350 "Escape sequences:\n"
351 " Character `_' is used to escape explicit marks. The list is:\n"
352 " * _> LRM\n" " * _< RLM\n"
353 " * _l LRE\n" " * _r RLE\n"
354 " * _L LRO\n" " * _R RLO\n"
355 " * _o PDF\n" " * _i LRI\n"
356 " * _y RLI\n" " * _f FSI\n"
357 " * _I PDI\n" " * __ `_' itself\n"
362 /* Editor directions:
363 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent