1
/* FriBidi - Library of BiDi algorithm
2
* Copyright (C) 1999,2000 Dov Grobgeld, and
3
* Copyright (C) 2001,2002 Behdad Esfahbod.
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this library, in a file named COPYING; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
* Boston, MA 02111-1307, USA
20
* For licensing issues, contact <dov@imagic.weizmann.ac.il> and
24
#include "fribidi_config.h"
25
#ifndef FRIBIDI_NO_CHARSETS
32
#define WS FRIBIDI_PROP_TYPE_WS
33
#define BS FRIBIDI_PROP_TYPE_BS
34
#define EO FRIBIDI_PROP_TYPE_EO
35
#define CTL FRIBIDI_PROP_TYPE_CTL
36
#define LRE FRIBIDI_PROP_TYPE_LRE
37
#define RLE FRIBIDI_PROP_TYPE_RLE
38
#define ES FRIBIDI_PROP_TYPE_ES
39
#define LRO FRIBIDI_PROP_TYPE_LRO
40
#define RLO FRIBIDI_PROP_TYPE_RLO
41
#define AL FRIBIDI_PROP_TYPE_AL
42
#define SS FRIBIDI_PROP_TYPE_SS
43
#define ET FRIBIDI_PROP_TYPE_ET
44
#define NSM FRIBIDI_PROP_TYPE_NSM
45
#define LTR FRIBIDI_PROP_TYPE_LTR
46
#define ON FRIBIDI_PROP_TYPE_ON
47
#define AN FRIBIDI_PROP_TYPE_AN
48
#define BN FRIBIDI_PROP_TYPE_BN
49
#define RTL FRIBIDI_PROP_TYPE_RTL
50
#define CS FRIBIDI_PROP_TYPE_CS
51
#define PDF FRIBIDI_PROP_TYPE_PDF
52
#define EN FRIBIDI_PROP_TYPE_EN
54
static FriBidiPropCharType CapRTLCharTypes[] = {
56
ON, ON, ON, ON, LTR,RTL,ON, ON, ON, ON, ON, ON, ON, BS, RLO,RLE, /* 00-0f */
57
LRO,LRE,PDF,WS, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, ON, /* 10-1f */
58
WS, ON, ON, ON, ET, ON, ON, ON, ON, ON, ON, ET, CS, ON, ES, ES, /* 20-2f */
59
EN, EN, EN, EN, EN, EN, AN, AN, AN, AN, CS, ON, ON, ON, ON, ON, /* 30-3f */
60
RTL,AL, AL, AL, AL, AL, AL, RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL, /* 40-4f */
61
RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,RTL,ON, BS, ON, ON, ON, /* 50-5f */
62
NSM,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR, /* 60-6f */
63
LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,LTR,ON, SS, ON, WS, ON, /* 70-7f */
89
#define CAPRTL_CHARS (sizeof CapRTLCharTypes / sizeof CapRTLCharTypes[0])
91
static FriBidiChar *caprtl_to_unicode = NULL;
94
fribidi_unicode_to_cap_rtl_c (FriBidiChar uch)
97
for (i = 0; i < CAPRTL_CHARS; i++)
98
if (uch == caprtl_to_unicode[i])
104
fribidi_cap_rtl_to_unicode (char *s, int len, FriBidiChar *us)
109
for (i = 0; i < len; i++)
149
us[j++] = caprtl_to_unicode[(int) s[i]];
156
fribidi_unicode_to_cap_rtl (FriBidiChar *us, int length, char *s)
161
for (i = 0; i < length; i++)
163
FriBidiChar ch = us[i];
164
if (!FRIBIDI_IS_EXPLICIT (fribidi_get_type (ch)) && ch != '_'
165
&& ch != UNI_LRM && ch != UNI_RLM)
166
s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
199
s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
212
fribidi_char_set_desc_cap_rtl (void)
221
s = (char *) malloc (l);
223
i += snprintf (s + i, l - i,
224
"CapRTL is a character set for testing with the reference\n"
225
"implementation, with explicit marks escape strings, and\n"
226
"the property that contains all unicode character types in\n"
227
"ASCII range 1-127.\n"
229
"Warning: CapRTL character types are subject to change.\n"
230
"\n" "CapRTL's character types:\n");
231
for (j = 0; j < CAPRTL_CHARS; j++)
235
i += snprintf (s + i, l - i, " * 0x%02x %c%c %-3s ", j,
236
j < 0x20 ? '^' : ' ',
237
j < 0x20 ? j + '@' : j < 0x7f ? j : ' ',
238
fribidi_type_name (fribidi_prop_to_type
240
CapRTLCharTypes[j]]));
242
i += snprintf (s + i, l - i,
244
"Escape sequences:\n"
245
" Character `_' is used to escape explicit marks. The list is:\n"
251
" * _R RLO\n" " * _o PDF\n" " * __ `_' itself\n"
257
fribidi_char_set_enter_cap_rtl (void)
259
if (!caprtl_to_unicode)
261
int request[FRIBIDI_TYPES_COUNT + 1];
265
(FriBidiChar *) malloc (CAPRTL_CHARS * sizeof caprtl_to_unicode[0]);
266
for (i = 0; i < FRIBIDI_TYPES_COUNT; i++)
268
for (i = 0; i < CAPRTL_CHARS; i++)
269
if (fribidi_get_mirror_char (i, NULL))
270
caprtl_to_unicode[i] = i;
271
for (count = 0, i = 0; i < CAPRTL_CHARS; i++)
272
if (caprtl_to_unicode[i] == 0)
274
request[(unsigned char) CapRTLCharTypes[i]]++;
277
for (i = 1; i < 0x10000 && count; i++) /* Assign BMP chars to CapRTL entries */
278
if (!fribidi_get_mirror_char (i, NULL))
281
for (j = 0; j < FRIBIDI_TYPES_COUNT; j++)
282
if (fribidi_prop_to_type[j] == fribidi_get_type (i))
284
if (!request[j]) /* Do not need this type */
286
for (k = 0; k < CAPRTL_CHARS; k++)
287
if (!caprtl_to_unicode[k] && j == CapRTLCharTypes[k])
289
if (k < CAPRTL_CHARS)
293
caprtl_to_unicode[k] = i;
302
fribidi_char_set_leave_cap_rtl (void)