~ubuntu-branches/ubuntu/vivid/fribidi/vivid

« back to all changes in this revision

Viewing changes to fribidi_char_sets_cap_rtl.c

  • Committer: Bazaar Package Importer
  • Author(s): Lior Kaplan
  • Date: 2006-09-16 10:37:10 UTC
  • mfrom: (3.1.3 edgy)
  • Revision ID: james.westby@ubuntu.com-20060916103710-1ktngzyx9azkujhl
Tags: 0.10.7-4
* Fix manual page name section (Closes: #368632)
* debian/control: Upgrade standards version to 3.7.2 (no changes needed).
* debian/copyright: Update Dov Grobgeld's contact address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FriBidi - Library of BiDi algorithm
 
2
 * Copyright (C) 1999,2000 Dov Grobgeld, and
 
3
 * Copyright (C) 2001,2002 Behdad Esfahbod.
 
4
 * 
 
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.
 
9
 * 
 
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.
 
14
 * 
 
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
 
19
 * 
 
20
 * For licensing issues, contact <dov@imagic.weizmann.ac.il> and
 
21
 * <fwpg@sharif.edu>.
 
22
 */
 
23
 
 
24
#include "fribidi_config.h"
 
25
#ifndef FRIBIDI_NO_CHARSETS
 
26
 
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
#include <stdio.h>
 
30
#include "fribidi.h"
 
31
 
 
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
 
53
 
 
54
static FriBidiPropCharType CapRTLCharTypes[] = {
 
55
/* *INDENT-OFF* */
 
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 */
 
64
/* *INDENT-ON* */
 
65
};
 
66
 
 
67
#undef WS
 
68
#undef BS
 
69
#undef EO
 
70
#undef CTL
 
71
#undef LRE
 
72
#undef RLE
 
73
#undef ES
 
74
#undef LRO
 
75
#undef RLO
 
76
#undef AL
 
77
#undef SS
 
78
#undef ET
 
79
#undef NSM
 
80
#undef LTR
 
81
#undef ON
 
82
#undef AN
 
83
#undef BN
 
84
#undef RTL
 
85
#undef CS
 
86
#undef PDF
 
87
#undef EN
 
88
 
 
89
#define CAPRTL_CHARS (sizeof CapRTLCharTypes / sizeof CapRTLCharTypes[0])
 
90
 
 
91
static FriBidiChar *caprtl_to_unicode = NULL;
 
92
 
 
93
char
 
94
fribidi_unicode_to_cap_rtl_c (FriBidiChar uch)
 
95
{
 
96
  int i;
 
97
  for (i = 0; i < CAPRTL_CHARS; i++)
 
98
    if (uch == caprtl_to_unicode[i])
 
99
      return (char) i;
 
100
  return '?';
 
101
}
 
102
 
 
103
int
 
104
fribidi_cap_rtl_to_unicode (char *s, int len, FriBidiChar *us)
 
105
{
 
106
  int i, j;
 
107
 
 
108
  j = 0;
 
109
  for (i = 0; i < len; i++)
 
110
    {
 
111
      char ch;
 
112
 
 
113
      ch = s[i];
 
114
      if (ch == '_')
 
115
        {
 
116
          switch (ch = s[++i])
 
117
            {
 
118
            case '>':
 
119
              us[j++] = UNI_LRM;
 
120
              break;
 
121
            case '<':
 
122
              us[j++] = UNI_RLM;
 
123
              break;
 
124
            case 'l':
 
125
              us[j++] = UNI_LRE;
 
126
              break;
 
127
            case 'r':
 
128
              us[j++] = UNI_RLE;
 
129
              break;
 
130
            case 'o':
 
131
              us[j++] = UNI_PDF;
 
132
              break;
 
133
            case 'L':
 
134
              us[j++] = UNI_LRO;
 
135
              break;
 
136
            case 'R':
 
137
              us[j++] = UNI_RLO;
 
138
              break;
 
139
            case '_':
 
140
              us[j++] = '_';
 
141
              break;
 
142
            default:
 
143
              us[j++] = '_';
 
144
              i--;
 
145
              break;
 
146
            }
 
147
        }
 
148
      else
 
149
        us[j++] = caprtl_to_unicode[(int) s[i]];
 
150
    }
 
151
 
 
152
  return j;
 
153
}
 
154
 
 
155
int
 
156
fribidi_unicode_to_cap_rtl (FriBidiChar *us, int length, char *s)
 
157
{
 
158
  int i, j;
 
159
 
 
160
  j = 0;
 
161
  for (i = 0; i < length; i++)
 
162
    {
 
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);
 
167
      else
 
168
        {
 
169
          s[j++] = '_';
 
170
          switch (ch)
 
171
            {
 
172
            case UNI_LRM:
 
173
              s[j++] = '>';
 
174
              break;
 
175
            case UNI_RLM:
 
176
              s[j++] = '<';
 
177
              break;
 
178
            case UNI_LRE:
 
179
              s[j++] = 'l';
 
180
              break;
 
181
            case UNI_RLE:
 
182
              s[j++] = 'r';
 
183
              break;
 
184
            case UNI_PDF:
 
185
              s[j++] = 'o';
 
186
              break;
 
187
            case UNI_LRO:
 
188
              s[j++] = 'L';
 
189
              break;
 
190
            case UNI_RLO:
 
191
              s[j++] = 'R';
 
192
              break;
 
193
            case '_':
 
194
              s[j++] = '_';
 
195
              break;
 
196
            default:
 
197
              j--;
 
198
              if (ch < 256)
 
199
                s[j++] = fribidi_unicode_to_cap_rtl_c (ch);
 
200
              else
 
201
                s[j++] = '?';
 
202
              break;
 
203
            }
 
204
        }
 
205
    }
 
206
  s[j] = 0;
 
207
 
 
208
  return j;
 
209
}
 
210
 
 
211
char *
 
212
fribidi_char_set_desc_cap_rtl (void)
 
213
{
 
214
  static char *s = 0;
 
215
  int l, i, j;
 
216
 
 
217
  if (s)
 
218
    return s;
 
219
 
 
220
  l = 4000;
 
221
  s = (char *) malloc (l);
 
222
  i = 0;
 
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"
 
228
                 "\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++)
 
232
    {
 
233
      if (j % 4 == 0)
 
234
        s[i++] = '\n';
 
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
 
239
                                        [(unsigned char)
 
240
                                         CapRTLCharTypes[j]]));
 
241
    }
 
242
  i += snprintf (s + i, l - i,
 
243
                 "\n\n"
 
244
                 "Escape sequences:\n"
 
245
                 "  Character `_' is used to escape explicit marks. The list is:\n"
 
246
                 "    * _>  LRM\n"
 
247
                 "    * _<  RLM\n"
 
248
                 "    * _l  LRE\n"
 
249
                 "    * _r  RLE\n"
 
250
                 "    * _L  LRO\n"
 
251
                 "    * _R  RLO\n" "    * _o  PDF\n" "    * __  `_' itself\n"
 
252
                 "\n");
 
253
  return s;
 
254
}
 
255
 
 
256
fribidi_boolean
 
257
fribidi_char_set_enter_cap_rtl (void)
 
258
{
 
259
  if (!caprtl_to_unicode)
 
260
    {
 
261
      int request[FRIBIDI_TYPES_COUNT + 1];
 
262
      int i, count;
 
263
 
 
264
      caprtl_to_unicode =
 
265
        (FriBidiChar *) malloc (CAPRTL_CHARS * sizeof caprtl_to_unicode[0]);
 
266
      for (i = 0; i < FRIBIDI_TYPES_COUNT; i++)
 
267
        request[i] = 0;
 
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)
 
273
          {
 
274
            request[(unsigned char) CapRTLCharTypes[i]]++;
 
275
            count++;
 
276
          }
 
277
      for (i = 1; i < 0x10000 && count; i++)    /* Assign BMP chars to CapRTL entries */
 
278
        if (!fribidi_get_mirror_char (i, NULL))
 
279
          {
 
280
            int j, k;
 
281
            for (j = 0; j < FRIBIDI_TYPES_COUNT; j++)
 
282
              if (fribidi_prop_to_type[j] == fribidi_get_type (i))
 
283
                break;
 
284
            if (!request[j])    /* Do not need this type */
 
285
              continue;
 
286
            for (k = 0; k < CAPRTL_CHARS; k++)
 
287
              if (!caprtl_to_unicode[k] && j == CapRTLCharTypes[k])
 
288
                break;
 
289
            if (k < CAPRTL_CHARS)
 
290
              {
 
291
                request[j]--;
 
292
                count--;
 
293
                caprtl_to_unicode[k] = i;
 
294
              }
 
295
          }
 
296
    }
 
297
 
 
298
  return FRIBIDI_TRUE;
 
299
}
 
300
 
 
301
fribidi_boolean
 
302
fribidi_char_set_leave_cap_rtl (void)
 
303
{
 
304
  return FRIBIDI_TRUE;
 
305
}
 
306
 
 
307
#endif