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