Imported Upstream version 0.19.4
[platform/upstream/fribidi.git] / lib / fribidi-joining-types.c
1 /* FriBidi
2  * fribidi-joining-types.c - character joining types
3  *
4  * $Id: fribidi-joining-types.c,v 1.5 2006-01-31 03:23:13 behdad Exp $
5  * $Author: behdad $
6  * $Date: 2006-01-31 03:23:13 $
7  * $Revision: 1.5 $
8  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-joining-types.c,v $
9  *
10  * Authors:
11  *   Behdad Esfahbod, 2001, 2002, 2004
12  *
13  * Copyright (C) 2004 Sharif FarsiWeb, Inc.
14  * Copyright (C) 2001,2002 Behdad Esfahbod
15  * 
16  * This library is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU Lesser General Public
18  * License as published by the Free Software Foundation; either
19  * version 2.1 of the License, or (at your option) any later version.
20  * 
21  * This library is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24  * Lesser General Public License for more details.
25  * 
26  * You should have received a copy of the GNU Lesser General Public License
27  * along with this library, in a file named COPYING; if not, write to the
28  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
29  * Boston, MA 02111-1307, USA
30  *
31  * For licensing issues, contact <license@farsiweb.info>.
32  */
33
34 #include "common.h"
35
36 #include <fribidi-joining-types.h>
37
38 #include "joining-types.h"
39
40 enum FriBidiJoiningTypeShortEnum
41 {
42 # define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) TYPE = FRIBIDI_JOINING_TYPE_##TYPE,
43 # include "fribidi-joining-types-list.h"
44 # undef _FRIBIDI_ADD_TYPE
45   _FRIBIDI_NUM_TYPES
46 };
47
48 #include "joining-type.tab.i"
49
50 FRIBIDI_ENTRY FriBidiJoiningType
51 fribidi_get_joining_type (
52   /* input */
53   FriBidiChar ch
54 )
55 {
56   return FRIBIDI_GET_JOINING_TYPE (ch);
57 }
58
59 FRIBIDI_ENTRY void
60 fribidi_get_joining_types (
61   /* input */
62   const FriBidiChar *str,
63   const FriBidiStrIndex len,
64   /* output */
65   FriBidiJoiningType *jtypes
66 )
67 {
68   register FriBidiStrIndex i = len;
69   for (; i; i--)
70     {
71       *jtypes++ = FRIBIDI_GET_JOINING_TYPE (*str);
72       str++;
73     }
74 }
75
76 FRIBIDI_ENTRY const char *
77 fribidi_get_joining_type_name (
78   /* input */
79   FriBidiJoiningType j
80 )
81 {
82   switch (j)
83     {
84 #   define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL) case FRIBIDI_JOINING_TYPE_##TYPE: return STRINGIZE(TYPE);
85 #   include "fribidi-joining-types-list.h"
86 #   undef _FRIBIDI_ADD_TYPE
87     default:
88       return "?";
89     }
90 }
91
92 #if DEBUG+0
93
94 char
95 fribidi_char_from_joining_type (
96   /* input */
97   FriBidiJoiningType j,
98   fribidi_boolean visual
99 )
100 {
101   /* switch left and right if on visual run */
102   if (visual & ((FRIBIDI_JOINS_RIGHT (j) && !FRIBIDI_JOINS_LEFT (j)) |
103                 (!FRIBIDI_JOINS_RIGHT (j) && FRIBIDI_JOINS_LEFT (j))))
104     j ^= FRIBIDI_MASK_JOINS_RIGHT | FRIBIDI_MASK_JOINS_LEFT;
105
106 #   define _FRIBIDI_ADD_TYPE(TYPE,SYMBOL)       \
107         if (FRIBIDI_IS_JOINING_TYPE_##TYPE(j)) return SYMBOL;
108 #   include "fribidi-joining-types-list.h"
109 #   undef _FRIBIDI_ADD_TYPE
110
111   return '?';
112 }
113
114 #endif /* DEBUG */
115
116 /* Editor directions:
117  * vim:textwidth=78:tabstop=8:shiftwidth=2:autoindent:cindent
118  */