1 /* $NetBSD: ucpgba.h,v 1.3 2021/08/14 16:14:57 christos Exp $ */ 2 3 /* $OpenLDAP$ */ 4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>. 5 * 6 * Copyright 1998-2021 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 <sys/cdefs.h> 43 __RCSID("$NetBSD: ucpgba.h,v 1.3 2021/08/14 16:14:57 christos Exp $"); 44 45 #include "portable.h" 46 47 LDAP_BEGIN_DECL 48 49 /*************************************************************************** 50 * 51 * Macros and types. 52 * 53 ***************************************************************************/ 54 55 /* 56 * These are the direction values that can appear in render runs and render 57 * strings. 58 */ 59 #define UCPGBA_LTR 0 60 #define UCPGBA_RTL 1 61 62 /* 63 * These are the flags for cursor motion. 64 */ 65 #define UCPGBA_CURSOR_VISUAL 0 66 #define UCPGBA_CURSOR_LOGICAL 1 67 68 /* 69 * This structure is used to contain runs of text in a particular direction. 70 */ 71 typedef struct _ucrun_t { 72 struct _ucrun_t *visual_prev; /* Pointer to the previous visual run. */ 73 struct _ucrun_t *visual_next; /* Pointer to the next visual run. */ 74 75 struct _ucrun_t *logical_prev; /* Pointer to the previous logical run. */ 76 struct _ucrun_t *logical_next; /* Pointer to the next logical run. */ 77 78 int direction; /* Direction of the run. */ 79 80 long cursor; /* Position of "cursor" in the string. */ 81 82 unsigned long *chars; /* List of characters for the run. */ 83 unsigned long *positions; /* List of original positions in source. */ 84 85 unsigned long *source; /* The source string. */ 86 unsigned long start; /* Beginning offset in the source string. */ 87 unsigned long end; /* Ending offset in the source string. */ 88 } ucrun_t; 89 90 /* 91 * This represents a string of runs rendered up to a point that is not 92 * platform specific. 93 */ 94 typedef struct _ucstring_t { 95 int direction; /* Overall direction of the string. */ 96 97 int cursor_motion; /* Logical or visual cursor motion flag. */ 98 99 ucrun_t *cursor; /* The run containing the "cursor." */ 100 101 ucrun_t *logical_first; /* First run in the logical order. */ 102 ucrun_t *logical_last; /* Last run in the logical order. */ 103 104 ucrun_t *visual_first; /* First run in the visual order. */ 105 ucrun_t *visual_last; /* Last run in the visual order. */ 106 107 unsigned long *source; /* The source string. */ 108 unsigned long start; /* The beginning offset in the source. */ 109 unsigned long end; /* The ending offset in the source. */ 110 } ucstring_t; 111 112 /*************************************************************************** 113 * 114 * API 115 * 116 ***************************************************************************/ 117 118 /* 119 * This creates and reorders the specified substring using the 120 * "Pretty Good Bidi Algorithm." A default direction is provided for cases 121 * of a string containing no strong direction characters and the default 122 * cursor motion should be provided. 123 */ 124 LDAP_LUNICODE_F (ucstring_t *) 125 ucstring_create LDAP_P((unsigned long *source, 126 unsigned long start, 127 unsigned long end, 128 int default_direction, 129 int cursor_motion)); 130 /* 131 * This releases the string. 132 */ 133 LDAP_LUNICODE_F (void) ucstring_free LDAP_P((ucstring_t *string)); 134 135 /* 136 * This changes the cursor motion flag for the string. 137 */ 138 LDAP_LUNICODE_F (int) 139 ucstring_set_cursor_motion LDAP_P((ucstring_t *string, 140 int cursor_motion)); 141 142 /* 143 * This function will move the cursor to the right depending on the 144 * type of cursor motion that was specified for the string. 145 * 146 * A 0 is returned if no cursor motion is performed, otherwise a 147 * 1 is returned. 148 */ 149 LDAP_LUNICODE_F (int) 150 ucstring_cursor_right LDAP_P((ucstring_t *string, int count)); 151 152 /* 153 * This function will move the cursor to the left depending on the 154 * type of cursor motion that was specified for the string. 155 * 156 * A 0 is returned if no cursor motion is performed, otherwise a 157 * 1 is returned. 158 */ 159 LDAP_LUNICODE_F (int) 160 ucstring_cursor_left LDAP_P((ucstring_t *string, int count)); 161 162 /* 163 * This routine retrieves the direction of the run containing the cursor 164 * and the actual position in the original text string. 165 */ 166 LDAP_LUNICODE_F (void) 167 ucstring_cursor_info LDAP_P((ucstring_t *string, int *direction, 168 unsigned long *position)); 169 170 LDAP_END_DECL 171 172 #endif /* _h_ucpgba */ 173