1 /*	$NetBSD: ucpgba.h,v 1.1.1.3 2010/12/12 15:21:58 adam Exp $	*/
2 
3 /* OpenLDAP: pkg/ldap/libraries/liblunicode/ucdata/ucpgba.h,v 1.8.2.5 2010/04/13 20:23:04 kurt Exp */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2010 The OpenLDAP Foundation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* Copyright 1999 Computing Research Labs, New Mexico State University
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining a
20  * copy of this software and associated documentation files (the "Software"),
21  * to deal in the Software without restriction, including without limitation
22  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
23  * and/or sell copies of the Software, and to permit persons to whom the
24  * Software is furnished to do so, subject to the following conditions:
25  *
26  * The above copyright notice and this permission notice shall be included in
27  * all copies or substantial portions of the Software.
28  *
29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
32  * THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
33  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
34  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
35  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36  */
37 /* Id: ucpgba.h,v 1.4 1999/11/19 15:24:30 mleisher Exp */
38 
39 #ifndef _h_ucpgba
40 #define _h_ucpgba
41 
42 #include "portable.h"
43 
44 LDAP_BEGIN_DECL
45 
46 /***************************************************************************
47  *
48  * Macros and types.
49  *
50  ***************************************************************************/
51 
52 /*
53  * These are the direction values that can appear in render runs and render
54  * strings.
55  */
56 #define UCPGBA_LTR 0
57 #define UCPGBA_RTL 1
58 
59 /*
60  * These are the flags for cursor motion.
61  */
62 #define UCPGBA_CURSOR_VISUAL  0
63 #define UCPGBA_CURSOR_LOGICAL 1
64 
65 /*
66  * This structure is used to contain runs of text in a particular direction.
67  */
68 typedef struct _ucrun_t {
69     struct _ucrun_t *visual_prev;  /* Pointer to the previous visual run.    */
70     struct _ucrun_t *visual_next;  /* Pointer to the next visual run.        */
71 
72     struct _ucrun_t *logical_prev; /* Pointer to the previous logical run.   */
73     struct _ucrun_t *logical_next; /* Pointer to the next logical run.       */
74 
75     int direction;                 /* Direction of the run.                  */
76 
77     long cursor;                   /* Position of "cursor" in the string.    */
78 
79     unsigned long *chars;          /* List of characters for the run.        */
80     unsigned long *positions;      /* List of original positions in source.  */
81 
82     unsigned long *source;         /* The source string.                     */
83     unsigned long start;           /* Beginning offset in the source string. */
84     unsigned long end;             /* Ending offset in the source string.    */
85 } ucrun_t;
86 
87 /*
88  * This represents a string of runs rendered up to a point that is not
89  * platform specific.
90  */
91 typedef struct _ucstring_t {
92     int direction;                /* Overall direction of the string.       */
93 
94     int cursor_motion;            /* Logical or visual cursor motion flag.  */
95 
96     ucrun_t *cursor;              /* The run containing the "cursor."       */
97 
98     ucrun_t *logical_first;       /* First run in the logical order.        */
99     ucrun_t *logical_last;        /* Last run in the logical order.         */
100 
101     ucrun_t *visual_first;        /* First run in the visual order.         */
102     ucrun_t *visual_last;         /* Last run in the visual order.          */
103 
104     unsigned long *source;        /* The source string.                     */
105     unsigned long start;          /* The beginning offset in the source.    */
106     unsigned long end;            /* The ending offset in the source.       */
107 } ucstring_t;
108 
109 /***************************************************************************
110  *
111  * API
112  *
113  ***************************************************************************/
114 
115 /*
116  * This creates and reorders the specified substring using the
117  * "Pretty Good Bidi Algorithm."  A default direction is provided for cases
118  * of a string containing no strong direction characters and the default
119  * cursor motion should be provided.
120  */
121 LDAP_LUNICODE_F (ucstring_t *)
122 ucstring_create LDAP_P((unsigned long *source,
123 		        unsigned long start,
124 		        unsigned long end,
125 		        int default_direction,
126 		        int cursor_motion));
127 /*
128  * This releases the string.
129  */
130 LDAP_LUNICODE_F (void) ucstring_free LDAP_P((ucstring_t *string));
131 
132 /*
133  * This changes the cursor motion flag for the string.
134  */
135 LDAP_LUNICODE_F (int)
136 ucstring_set_cursor_motion LDAP_P((ucstring_t *string,
137 				   int cursor_motion));
138 
139 /*
140  * This function will move the cursor to the right depending on the
141  * type of cursor motion that was specified for the string.
142  *
143  * A 0 is returned if no cursor motion is performed, otherwise a
144  * 1 is returned.
145  */
146 LDAP_LUNICODE_F (int)
147 ucstring_cursor_right LDAP_P((ucstring_t *string, int count));
148 
149 /*
150  * This function will move the cursor to the left depending on the
151  * type of cursor motion that was specified for the string.
152  *
153  * A 0 is returned if no cursor motion is performed, otherwise a
154  * 1 is returned.
155  */
156 LDAP_LUNICODE_F (int)
157 ucstring_cursor_left LDAP_P((ucstring_t *string, int count));
158 
159 /*
160  * This routine retrieves the direction of the run containing the cursor
161  * and the actual position in the original text string.
162  */
163 LDAP_LUNICODE_F (void)
164 ucstring_cursor_info LDAP_P((ucstring_t *string, int *direction,
165 			     unsigned long *position));
166 
167 LDAP_END_DECL
168 
169 #endif /* _h_ucpgba */
170