2 * fribidi-char-sets-cap-rtl.c - CapRTL character set conversion routines
4 * $Id: fribidi-char-sets-cap-rtl.c,v 1.12 2006-01-22 10:12:17 behdad Exp $
6 * $Date: 2006-01-22 10:12:17 $
8 * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/charset/fribidi-char-sets-cap-rtl.c,v $
11 * Behdad Esfahbod, 2001, 2002, 2004
12 * Dov Grobgeld, 1999, 2000
14 * Copyright (C) 2004 Sharif FarsiWeb, Inc
15 * Copyright (C) 2001,2002 Behdad Esfahbod
16 * Copyright (C) 1999,2000 Dov Grobgeld
18 * This library is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU Lesser General Public
20 * License as published by the Free Software Foundation; either
21 * version 2.1 of the License, or (at your option) any later version.
23 * This library is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 * Lesser General Public License for more details.
28 * You should have received a copy of the GNU Lesser General Public License
29 * along with this library, in a file named COPYING; if not, write to the
30 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
31 * Boston, MA 02110-1301, USA
33 * For licensing issues, contact <license@farsiweb.info>.
38 #include <fribidi-char-sets-cap-rtl.h>
40 #include <fribidi-unicode.h>
41 #include <fribidi-mirroring.h>
42 #include <fribidi-bidi-types.h>
44 #include <bidi-types.h>
50 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE = FRIBIDI_TYPE_##TYPE,
51 # include "fribidi-bidi-types-list.h"
52 # undef _FRIBIDI_ADD_TYPE
53 _FRIBIDI_MAX_TYPES_VALUE
58 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) DUMMY_##TYPE,
59 # include "fribidi-bidi-types-list.h"
60 # undef _FRIBIDI_ADD_TYPE
64 static FriBidiCharType CapRTLCharTypes[] = {
66 ON, ON, ON, ON, LTR,RTL,ON, ON, ON, ON, ON, ON, ON, BS, RLO,RLE, /* 00-0f */
67 LRO,LRE,PDF,WS, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, /* 10-1f */
68 WS, ON, ON, ON, ET, ON, ON, ON, ON, ON, ON, ET, CS, ON, ES, ES, /* 20-2f */
69 EN, EN, EN, EN, EN, EN, AN, AN, AN, AN, CS, ON, ON, ON, ON, ON, /* 30-3f */
70 RTL,AL, AL, AL, AL, AL, AL, RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL, /* 40-4f */
71 RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,ON, BS, ON, BN, ON, /* 50-5f */
72 NSM,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR, /* 60-6f */
73 LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,ON, SS, ON, WS, ON, /* 70-7f */
77 #define CAPRTL_CHARS (int)(sizeof CapRTLCharTypes / sizeof CapRTLCharTypes[0])
79 static FriBidiChar *caprtl_to_unicode = NULL;
86 int request[_FRIBIDI_NUM_TYPES];
87 FriBidiCharType to_type[_FRIBIDI_NUM_TYPES];
88 int num_types = 0, count = 0;
90 char mark[CAPRTL_CHARS];
93 (FriBidiChar *) fribidi_malloc (CAPRTL_CHARS *
94 sizeof caprtl_to_unicode[0]);
95 for (i = 0; i < CAPRTL_CHARS; i++)
96 if (CapRTLCharTypes[i] == fribidi_get_bidi_type (i))
98 caprtl_to_unicode[i] = i;
105 caprtl_to_unicode[i] = FRIBIDI_UNICODE_CHARS;
107 if (fribidi_get_mirror_char (i, NULL))
109 DBG ("warning: I could not map mirroring character map to itself in CapRTL");
112 for (j = 0; j < num_types; j++)
113 if (to_type[j] == CapRTLCharTypes[i])
118 to_type[j] = CapRTLCharTypes[i];
124 for (i = 0; i < 0x10000 && count; i++) /* Assign BMP chars to CapRTL entries */
125 if (!fribidi_get_mirror_char (i, NULL) && !(i < CAPRTL_CHARS && mark[i]))
128 FriBidiCharType t = fribidi_get_bidi_type (i);
129 for (j = 0; j < num_types; j++)
132 if (!request[j]) /* Do not need this type */
134 for (k = 0; k < CAPRTL_CHARS; k++)
135 if (caprtl_to_unicode[k] == FRIBIDI_UNICODE_CHARS
136 && to_type[j] == CapRTLCharTypes[k])
140 caprtl_to_unicode[k] = i;
148 DBG ("warning: could not find a mapping for CapRTL to Unicode:");
149 for (j = 0; j < num_types; j++)
152 DBG2 (" need this type: %s", fribidi_get_bidi_type_name (to_type[j]));
158 fribidi_unicode_to_cap_rtl_c (
165 if (!caprtl_to_unicode)
168 for (i = 0; i < CAPRTL_CHARS; i++)
169 if (uch == caprtl_to_unicode[i])
170 return (unsigned char) i;
175 fribidi_cap_rtl_to_unicode (
183 FriBidiStrIndex i, j;
185 if (!caprtl_to_unicode)
189 for (i = 0; i < len; i++)
199 us[j++] = FRIBIDI_CHAR_LRM;
202 us[j++] = FRIBIDI_CHAR_RLM;
205 us[j++] = FRIBIDI_CHAR_LRE;
208 us[j++] = FRIBIDI_CHAR_RLE;
211 us[j++] = FRIBIDI_CHAR_PDF;
214 us[j++] = FRIBIDI_CHAR_LRO;
217 us[j++] = FRIBIDI_CHAR_RLO;
229 us[j++] = caprtl_to_unicode[(int) s[i]];
236 fribidi_unicode_to_cap_rtl (
238 const FriBidiChar *us,
248 for (i = 0; i < len; i++)
250 FriBidiChar ch = us[i];
251 if (!FRIBIDI_IS_EXPLICIT (fribidi_get_bidi_type (ch)) && ch != '_'
252 && ch != FRIBIDI_CHAR_LRM && ch != FRIBIDI_CHAR_RLM)
253 s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
259 case FRIBIDI_CHAR_LRM:
262 case FRIBIDI_CHAR_RLM:
265 case FRIBIDI_CHAR_LRE:
268 case FRIBIDI_CHAR_RLE:
271 case FRIBIDI_CHAR_PDF:
274 case FRIBIDI_CHAR_LRO:
277 case FRIBIDI_CHAR_RLO:
286 s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
299 fribidi_char_set_desc_cap_rtl (
310 s = (char *) fribidi_malloc (l);
312 i += sprintf (s + i, /*l - i, */
313 "CapRTL is a character set for testing with the reference\n"
314 "implementation, with explicit marks escape strings, and\n"
315 "the property that contains all unicode character types in\n"
316 "ASCII range 1-127.\n"
318 "Warning: CapRTL character types are subject to change.\n"
319 "\n" "CapRTL's character types:\n");
320 for (j = 0; j < CAPRTL_CHARS; j++)
324 i += sprintf (s + i, /*l - i, */ " * 0x%02x %c%c %-3s ", j,
325 j < 0x20 ? '^' : ' ',
326 j < 0x20 ? j + '@' : j < 0x7f ? j : ' ',
327 fribidi_get_bidi_type_name (CapRTLCharTypes[j]));
329 i += sprintf (s + i, /*l - i, */
331 "Escape sequences:\n"
332 " Character `_' is used to escape explicit marks. The list is:\n"
333 " * _> LRM\n" " * _< RLM\n"
334 " * _l LRE\n" " * _r RLE\n"
335 " * _L LRO\n" " * _R RLO\n"
336 " * _o PDF\n" " * __ `_' itself\n" "\n");
340 /* Editor directions:
341 * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent