Imported Upstream version 0.19.4
[platform/upstream/fribidi.git] / lib / fribidi-mirroring.c
1 /* fribidi-mirroring.c - get mirrored character
2  *
3  * Copyright (C) 2004  Sharif FarsiWeb, Inc
4  * Copyright (C) 2001, 2002, 2004  Behdad Esfahbod
5  * Copyright (C) 1999, 2000  Dov Grobgeld
6  *
7  * This file is part of GNU FriBidi.
8  * 
9  * GNU FriBidi is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  * 
14  * GNU FriBidi is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with GNU FriBidi; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  * 
23  * For licensing issues, contact <license@farsiweb.info> or write to
24  * Sharif FarsiWeb, Inc., PO Box 13445-389, Tehran, Iran.
25  */
26 /* $Id: fribidi-mirroring.c,v 1.15 2005-11-03 01:39:01 behdad Exp $
27  * $Author: behdad $
28  * $Date: 2005-11-03 01:39:01 $
29  * $Revision: 1.15 $
30  * $Source: /home/behdad/src/fdo/fribidi/togit/git/../fribidi/fribidi2/lib/fribidi-mirroring.c,v $
31  *
32  * Author(s):
33  *   Behdad Esfahbod, 2001, 2002, 2004
34  *   Dov Grobgeld, 1999, 2000
35  */
36
37 #include "common.h"
38
39 #include <fribidi-mirroring.h>
40
41 #include "mirroring.tab.i"
42
43 FRIBIDI_ENTRY fribidi_boolean
44 fribidi_get_mirror_char (
45   /* input */
46   FriBidiChar ch,
47   /* output */
48   FriBidiChar *mirrored_ch
49 )
50 {
51   register FriBidiChar result;
52   result = FRIBIDI_GET_MIRRORING (ch);
53   if (mirrored_ch)
54     *mirrored_ch = result;
55   return ch != result ? true : false;
56 }
57
58
59 FRIBIDI_ENTRY void
60 fribidi_shape_mirroring (
61   /* input */
62   const FriBidiLevel *embedding_levels,
63   const FriBidiStrIndex len,
64   /* input and output */
65   FriBidiChar *str
66 )
67 {
68   register FriBidiStrIndex i;
69
70   DBG ("in fribidi_shape_mirroring");
71
72   if UNLIKELY
73     (len == 0 || !str) return;
74
75   fribidi_assert (embedding_levels);
76
77   /* L4. Mirror all characters that are in odd levels and have mirrors. */
78   for (i = len - 1; i >= 0; i--)
79     if (FRIBIDI_LEVEL_IS_RTL (embedding_levels[i]))
80       {
81         FriBidiChar mirrored_ch;
82
83         if (fribidi_get_mirror_char (str[i], &mirrored_ch))
84           str[i] = mirrored_ch;
85       }
86 }
87
88 /* Editor directions:
89  * Local Variables:
90  *   mode: c
91  *   c-basic-offset: 2
92  *   indent-tabs-mode: t
93  *   tab-width: 8
94  * End:
95  * vim: textwidth=78: autoindent: cindent: shiftwidth=2: tabstop=8:
96  */