xref: /aosp_15_r20/external/icu/libandroidicu/include/unicode/ubidi.h (revision 0e209d3975ff4a8c132096b14b0e9364a753506e)
1*0e209d39SAndroid Build Coastguard Worker // © 2016 and later: Unicode, Inc. and others.
2*0e209d39SAndroid Build Coastguard Worker // License & terms of use: http://www.unicode.org/copyright.html
3*0e209d39SAndroid Build Coastguard Worker /*
4*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
5*0e209d39SAndroid Build Coastguard Worker *
6*0e209d39SAndroid Build Coastguard Worker *   Copyright (C) 1999-2013, International Business Machines
7*0e209d39SAndroid Build Coastguard Worker *   Corporation and others.  All Rights Reserved.
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker ******************************************************************************
10*0e209d39SAndroid Build Coastguard Worker *   file name:  ubidi.h
11*0e209d39SAndroid Build Coastguard Worker *   encoding:   UTF-8
12*0e209d39SAndroid Build Coastguard Worker *   tab size:   8 (not used)
13*0e209d39SAndroid Build Coastguard Worker *   indentation:4
14*0e209d39SAndroid Build Coastguard Worker *
15*0e209d39SAndroid Build Coastguard Worker *   created on: 1999jul27
16*0e209d39SAndroid Build Coastguard Worker *   created by: Markus W. Scherer, updated by Matitiahu Allouche
17*0e209d39SAndroid Build Coastguard Worker */
18*0e209d39SAndroid Build Coastguard Worker 
19*0e209d39SAndroid Build Coastguard Worker #ifndef UBIDI_H
20*0e209d39SAndroid Build Coastguard Worker #define UBIDI_H
21*0e209d39SAndroid Build Coastguard Worker 
22*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
23*0e209d39SAndroid Build Coastguard Worker #include "unicode/uchar.h"
24*0e209d39SAndroid Build Coastguard Worker 
25*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
26*0e209d39SAndroid Build Coastguard Worker #include "unicode/localpointer.h"
27*0e209d39SAndroid Build Coastguard Worker #endif   // U_SHOW_CPLUSPLUS_API
28*0e209d39SAndroid Build Coastguard Worker 
29*0e209d39SAndroid Build Coastguard Worker /**
30*0e209d39SAndroid Build Coastguard Worker  *\file
31*0e209d39SAndroid Build Coastguard Worker  * \brief C API: Bidi algorithm
32*0e209d39SAndroid Build Coastguard Worker  *
33*0e209d39SAndroid Build Coastguard Worker  * <h2>Bidi algorithm for ICU</h2>
34*0e209d39SAndroid Build Coastguard Worker  *
35*0e209d39SAndroid Build Coastguard Worker  * This is an implementation of the Unicode Bidirectional Algorithm.
36*0e209d39SAndroid Build Coastguard Worker  * The algorithm is defined in the
37*0e209d39SAndroid Build Coastguard Worker  * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.<p>
38*0e209d39SAndroid Build Coastguard Worker  *
39*0e209d39SAndroid Build Coastguard Worker  * Note: Libraries that perform a bidirectional algorithm and
40*0e209d39SAndroid Build Coastguard Worker  * reorder strings accordingly are sometimes called "Storage Layout Engines".
41*0e209d39SAndroid Build Coastguard Worker  * ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such
42*0e209d39SAndroid Build Coastguard Worker  * "Storage Layout Engines".
43*0e209d39SAndroid Build Coastguard Worker  *
44*0e209d39SAndroid Build Coastguard Worker  * <h3>General remarks about the API:</h3>
45*0e209d39SAndroid Build Coastguard Worker  *
46*0e209d39SAndroid Build Coastguard Worker  * In functions with an error code parameter,
47*0e209d39SAndroid Build Coastguard Worker  * the <code>pErrorCode</code> pointer must be valid
48*0e209d39SAndroid Build Coastguard Worker  * and the value that it points to must not indicate a failure before
49*0e209d39SAndroid Build Coastguard Worker  * the function call. Otherwise, the function returns immediately.
50*0e209d39SAndroid Build Coastguard Worker  * After the function call, the value indicates success or failure.<p>
51*0e209d39SAndroid Build Coastguard Worker  *
52*0e209d39SAndroid Build Coastguard Worker  * The &quot;limit&quot; of a sequence of characters is the position just after their
53*0e209d39SAndroid Build Coastguard Worker  * last character, i.e., one more than that position.<p>
54*0e209d39SAndroid Build Coastguard Worker  *
55*0e209d39SAndroid Build Coastguard Worker  * Some of the API functions provide access to &quot;runs&quot;.
56*0e209d39SAndroid Build Coastguard Worker  * Such a &quot;run&quot; is defined as a sequence of characters
57*0e209d39SAndroid Build Coastguard Worker  * that are at the same embedding level
58*0e209d39SAndroid Build Coastguard Worker  * after performing the Bidi algorithm.<p>
59*0e209d39SAndroid Build Coastguard Worker  *
60*0e209d39SAndroid Build Coastguard Worker  * @author Markus W. Scherer
61*0e209d39SAndroid Build Coastguard Worker  * @version 1.0
62*0e209d39SAndroid Build Coastguard Worker  *
63*0e209d39SAndroid Build Coastguard Worker  *
64*0e209d39SAndroid Build Coastguard Worker  * <h4> Sample code for the ICU Bidi API </h4>
65*0e209d39SAndroid Build Coastguard Worker  *
66*0e209d39SAndroid Build Coastguard Worker  * <h5>Rendering a paragraph with the ICU Bidi API</h5>
67*0e209d39SAndroid Build Coastguard Worker  *
68*0e209d39SAndroid Build Coastguard Worker  * This is (hypothetical) sample code that illustrates
69*0e209d39SAndroid Build Coastguard Worker  * how the ICU Bidi API could be used to render a paragraph of text.
70*0e209d39SAndroid Build Coastguard Worker  * Rendering code depends highly on the graphics system,
71*0e209d39SAndroid Build Coastguard Worker  * therefore this sample code must make a lot of assumptions,
72*0e209d39SAndroid Build Coastguard Worker  * which may or may not match any existing graphics system's properties.
73*0e209d39SAndroid Build Coastguard Worker  *
74*0e209d39SAndroid Build Coastguard Worker  * <p>The basic assumptions are:</p>
75*0e209d39SAndroid Build Coastguard Worker  * <ul>
76*0e209d39SAndroid Build Coastguard Worker  * <li>Rendering is done from left to right on a horizontal line.</li>
77*0e209d39SAndroid Build Coastguard Worker  * <li>A run of single-style, unidirectional text can be rendered at once.</li>
78*0e209d39SAndroid Build Coastguard Worker  * <li>Such a run of text is passed to the graphics system with
79*0e209d39SAndroid Build Coastguard Worker  *     characters (code units) in logical order.</li>
80*0e209d39SAndroid Build Coastguard Worker  * <li>The line-breaking algorithm is very complicated
81*0e209d39SAndroid Build Coastguard Worker  *     and Locale-dependent -
82*0e209d39SAndroid Build Coastguard Worker  *     and therefore its implementation omitted from this sample code.</li>
83*0e209d39SAndroid Build Coastguard Worker  * </ul>
84*0e209d39SAndroid Build Coastguard Worker  *
85*0e209d39SAndroid Build Coastguard Worker  * <pre>
86*0e209d39SAndroid Build Coastguard Worker  * \code
87*0e209d39SAndroid Build Coastguard Worker  *#include <unicode/ubidi.h>
88*0e209d39SAndroid Build Coastguard Worker  *
89*0e209d39SAndroid Build Coastguard Worker  *typedef enum {
90*0e209d39SAndroid Build Coastguard Worker  *     styleNormal=0, styleSelected=1,
91*0e209d39SAndroid Build Coastguard Worker  *     styleBold=2, styleItalics=4,
92*0e209d39SAndroid Build Coastguard Worker  *     styleSuper=8, styleSub=16
93*0e209d39SAndroid Build Coastguard Worker  *} Style;
94*0e209d39SAndroid Build Coastguard Worker  *
95*0e209d39SAndroid Build Coastguard Worker  *typedef struct { int32_t limit; Style style; } StyleRun;
96*0e209d39SAndroid Build Coastguard Worker  *
97*0e209d39SAndroid Build Coastguard Worker  *int getTextWidth(const UChar *text, int32_t start, int32_t limit,
98*0e209d39SAndroid Build Coastguard Worker  *                  const StyleRun *styleRuns, int styleRunCount);
99*0e209d39SAndroid Build Coastguard Worker  *
100*0e209d39SAndroid Build Coastguard Worker  * // set *pLimit and *pStyleRunLimit for a line
101*0e209d39SAndroid Build Coastguard Worker  * // from text[start] and from styleRuns[styleRunStart]
102*0e209d39SAndroid Build Coastguard Worker  * // using ubidi_getLogicalRun(para, ...)
103*0e209d39SAndroid Build Coastguard Worker  *void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,
104*0e209d39SAndroid Build Coastguard Worker  *                  UBiDi *para,
105*0e209d39SAndroid Build Coastguard Worker  *                  const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,
106*0e209d39SAndroid Build Coastguard Worker  *                  int *pLineWidth);
107*0e209d39SAndroid Build Coastguard Worker  *
108*0e209d39SAndroid Build Coastguard Worker  * // render runs on a line sequentially, always from left to right
109*0e209d39SAndroid Build Coastguard Worker  *
110*0e209d39SAndroid Build Coastguard Worker  * // prepare rendering a new line
111*0e209d39SAndroid Build Coastguard Worker  * void startLine(UBiDiDirection textDirection, int lineWidth);
112*0e209d39SAndroid Build Coastguard Worker  *
113*0e209d39SAndroid Build Coastguard Worker  * // render a run of text and advance to the right by the run width
114*0e209d39SAndroid Build Coastguard Worker  * // the text[start..limit-1] is always in logical order
115*0e209d39SAndroid Build Coastguard Worker  * void renderRun(const UChar *text, int32_t start, int32_t limit,
116*0e209d39SAndroid Build Coastguard Worker  *               UBiDiDirection textDirection, Style style);
117*0e209d39SAndroid Build Coastguard Worker  *
118*0e209d39SAndroid Build Coastguard Worker  * // We could compute a cross-product
119*0e209d39SAndroid Build Coastguard Worker  * // from the style runs with the directional runs
120*0e209d39SAndroid Build Coastguard Worker  * // and then reorder it.
121*0e209d39SAndroid Build Coastguard Worker  * // Instead, here we iterate over each run type
122*0e209d39SAndroid Build Coastguard Worker  * // and render the intersections -
123*0e209d39SAndroid Build Coastguard Worker  * // with shortcuts in simple (and common) cases.
124*0e209d39SAndroid Build Coastguard Worker  * // renderParagraph() is the main function.
125*0e209d39SAndroid Build Coastguard Worker  *
126*0e209d39SAndroid Build Coastguard Worker  * // render a directional run with
127*0e209d39SAndroid Build Coastguard Worker  * // (possibly) multiple style runs intersecting with it
128*0e209d39SAndroid Build Coastguard Worker  * void renderDirectionalRun(const UChar *text,
129*0e209d39SAndroid Build Coastguard Worker  *                           int32_t start, int32_t limit,
130*0e209d39SAndroid Build Coastguard Worker  *                           UBiDiDirection direction,
131*0e209d39SAndroid Build Coastguard Worker  *                           const StyleRun *styleRuns, int styleRunCount) {
132*0e209d39SAndroid Build Coastguard Worker  *     int i;
133*0e209d39SAndroid Build Coastguard Worker  *
134*0e209d39SAndroid Build Coastguard Worker  *     // iterate over style runs
135*0e209d39SAndroid Build Coastguard Worker  *     if(direction==UBIDI_LTR) {
136*0e209d39SAndroid Build Coastguard Worker  *         int styleLimit;
137*0e209d39SAndroid Build Coastguard Worker  *
138*0e209d39SAndroid Build Coastguard Worker  *         for(i=0; i<styleRunCount; ++i) {
139*0e209d39SAndroid Build Coastguard Worker  *             styleLimit=styleRuns[i].limit;
140*0e209d39SAndroid Build Coastguard Worker  *             if(start<styleLimit) {
141*0e209d39SAndroid Build Coastguard Worker  *                 if(styleLimit>limit) { styleLimit=limit; }
142*0e209d39SAndroid Build Coastguard Worker  *                 renderRun(text, start, styleLimit,
143*0e209d39SAndroid Build Coastguard Worker  *                           direction, styleRuns[i].style);
144*0e209d39SAndroid Build Coastguard Worker  *                 if(styleLimit==limit) { break; }
145*0e209d39SAndroid Build Coastguard Worker  *                 start=styleLimit;
146*0e209d39SAndroid Build Coastguard Worker  *             }
147*0e209d39SAndroid Build Coastguard Worker  *         }
148*0e209d39SAndroid Build Coastguard Worker  *     } else {
149*0e209d39SAndroid Build Coastguard Worker  *         int styleStart;
150*0e209d39SAndroid Build Coastguard Worker  *
151*0e209d39SAndroid Build Coastguard Worker  *         for(i=styleRunCount-1; i>=0; --i) {
152*0e209d39SAndroid Build Coastguard Worker  *             if(i>0) {
153*0e209d39SAndroid Build Coastguard Worker  *                 styleStart=styleRuns[i-1].limit;
154*0e209d39SAndroid Build Coastguard Worker  *             } else {
155*0e209d39SAndroid Build Coastguard Worker  *                 styleStart=0;
156*0e209d39SAndroid Build Coastguard Worker  *             }
157*0e209d39SAndroid Build Coastguard Worker  *             if(limit>=styleStart) {
158*0e209d39SAndroid Build Coastguard Worker  *                 if(styleStart<start) { styleStart=start; }
159*0e209d39SAndroid Build Coastguard Worker  *                 renderRun(text, styleStart, limit,
160*0e209d39SAndroid Build Coastguard Worker  *                           direction, styleRuns[i].style);
161*0e209d39SAndroid Build Coastguard Worker  *                 if(styleStart==start) { break; }
162*0e209d39SAndroid Build Coastguard Worker  *                 limit=styleStart;
163*0e209d39SAndroid Build Coastguard Worker  *             }
164*0e209d39SAndroid Build Coastguard Worker  *         }
165*0e209d39SAndroid Build Coastguard Worker  *     }
166*0e209d39SAndroid Build Coastguard Worker  * }
167*0e209d39SAndroid Build Coastguard Worker  *
168*0e209d39SAndroid Build Coastguard Worker  * // the line object represents text[start..limit-1]
169*0e209d39SAndroid Build Coastguard Worker  * void renderLine(UBiDi *line, const UChar *text,
170*0e209d39SAndroid Build Coastguard Worker  *                 int32_t start, int32_t limit,
171*0e209d39SAndroid Build Coastguard Worker  *                 const StyleRun *styleRuns, int styleRunCount,
172*0e209d39SAndroid Build Coastguard Worker  *                 UErrorCode *pErrorCode) {
173*0e209d39SAndroid Build Coastguard Worker  *     UBiDiDirection direction=ubidi_getDirection(line);
174*0e209d39SAndroid Build Coastguard Worker  *     if(direction!=UBIDI_MIXED) {
175*0e209d39SAndroid Build Coastguard Worker  *         // unidirectional
176*0e209d39SAndroid Build Coastguard Worker  *         if(styleRunCount<=1) {
177*0e209d39SAndroid Build Coastguard Worker  *             renderRun(text, start, limit, direction, styleRuns[0].style);
178*0e209d39SAndroid Build Coastguard Worker  *         } else {
179*0e209d39SAndroid Build Coastguard Worker  *             renderDirectionalRun(text, start, limit,
180*0e209d39SAndroid Build Coastguard Worker  *                                  direction, styleRuns, styleRunCount);
181*0e209d39SAndroid Build Coastguard Worker  *         }
182*0e209d39SAndroid Build Coastguard Worker  *     } else {
183*0e209d39SAndroid Build Coastguard Worker  *         // mixed-directional
184*0e209d39SAndroid Build Coastguard Worker  *         int32_t count, i, length;
185*0e209d39SAndroid Build Coastguard Worker  *         UBiDiLevel level;
186*0e209d39SAndroid Build Coastguard Worker  *
187*0e209d39SAndroid Build Coastguard Worker  *         count=ubidi_countRuns(line, pErrorCode);
188*0e209d39SAndroid Build Coastguard Worker  *         if(U_SUCCESS(*pErrorCode)) {
189*0e209d39SAndroid Build Coastguard Worker  *             if(styleRunCount<=1) {
190*0e209d39SAndroid Build Coastguard Worker  *                 Style style=styleRuns[0].style;
191*0e209d39SAndroid Build Coastguard Worker  *
192*0e209d39SAndroid Build Coastguard Worker  *                 // iterate over directional runs
193*0e209d39SAndroid Build Coastguard Worker  *                for(i=0; i<count; ++i) {
194*0e209d39SAndroid Build Coastguard Worker  *                    direction=ubidi_getVisualRun(line, i, &start, &length);
195*0e209d39SAndroid Build Coastguard Worker  *                     renderRun(text, start, start+length, direction, style);
196*0e209d39SAndroid Build Coastguard Worker  *                }
197*0e209d39SAndroid Build Coastguard Worker  *             } else {
198*0e209d39SAndroid Build Coastguard Worker  *                 int32_t j;
199*0e209d39SAndroid Build Coastguard Worker  *
200*0e209d39SAndroid Build Coastguard Worker  *                 // iterate over both directional and style runs
201*0e209d39SAndroid Build Coastguard Worker  *                 for(i=0; i<count; ++i) {
202*0e209d39SAndroid Build Coastguard Worker  *                     direction=ubidi_getVisualRun(line, i, &start, &length);
203*0e209d39SAndroid Build Coastguard Worker  *                     renderDirectionalRun(text, start, start+length,
204*0e209d39SAndroid Build Coastguard Worker  *                                          direction, styleRuns, styleRunCount);
205*0e209d39SAndroid Build Coastguard Worker  *                 }
206*0e209d39SAndroid Build Coastguard Worker  *             }
207*0e209d39SAndroid Build Coastguard Worker  *         }
208*0e209d39SAndroid Build Coastguard Worker  *     }
209*0e209d39SAndroid Build Coastguard Worker  * }
210*0e209d39SAndroid Build Coastguard Worker  *
211*0e209d39SAndroid Build Coastguard Worker  *void renderParagraph(const UChar *text, int32_t length,
212*0e209d39SAndroid Build Coastguard Worker  *                     UBiDiDirection textDirection,
213*0e209d39SAndroid Build Coastguard Worker  *                      const StyleRun *styleRuns, int styleRunCount,
214*0e209d39SAndroid Build Coastguard Worker  *                      int lineWidth,
215*0e209d39SAndroid Build Coastguard Worker  *                      UErrorCode *pErrorCode) {
216*0e209d39SAndroid Build Coastguard Worker  *     UBiDi *para;
217*0e209d39SAndroid Build Coastguard Worker  *
218*0e209d39SAndroid Build Coastguard Worker  *     if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {
219*0e209d39SAndroid Build Coastguard Worker  *         return;
220*0e209d39SAndroid Build Coastguard Worker  *     }
221*0e209d39SAndroid Build Coastguard Worker  *
222*0e209d39SAndroid Build Coastguard Worker  *     para=ubidi_openSized(length, 0, pErrorCode);
223*0e209d39SAndroid Build Coastguard Worker  *     if(para==NULL) { return; }
224*0e209d39SAndroid Build Coastguard Worker  *
225*0e209d39SAndroid Build Coastguard Worker  *     ubidi_setPara(para, text, length,
226*0e209d39SAndroid Build Coastguard Worker  *                   textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
227*0e209d39SAndroid Build Coastguard Worker  *                   NULL, pErrorCode);
228*0e209d39SAndroid Build Coastguard Worker  *     if(U_SUCCESS(*pErrorCode)) {
229*0e209d39SAndroid Build Coastguard Worker  *         UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);
230*0e209d39SAndroid Build Coastguard Worker  *         StyleRun styleRun={ length, styleNormal };
231*0e209d39SAndroid Build Coastguard Worker  *         int width;
232*0e209d39SAndroid Build Coastguard Worker  *
233*0e209d39SAndroid Build Coastguard Worker  *         if(styleRuns==NULL || styleRunCount<=0) {
234*0e209d39SAndroid Build Coastguard Worker  *            styleRunCount=1;
235*0e209d39SAndroid Build Coastguard Worker  *             styleRuns=&styleRun;
236*0e209d39SAndroid Build Coastguard Worker  *         }
237*0e209d39SAndroid Build Coastguard Worker  *
238*0e209d39SAndroid Build Coastguard Worker  *        // assume styleRuns[styleRunCount-1].limit>=length
239*0e209d39SAndroid Build Coastguard Worker  *
240*0e209d39SAndroid Build Coastguard Worker  *         width=getTextWidth(text, 0, length, styleRuns, styleRunCount);
241*0e209d39SAndroid Build Coastguard Worker  *         if(width<=lineWidth) {
242*0e209d39SAndroid Build Coastguard Worker  *             // everything fits onto one line
243*0e209d39SAndroid Build Coastguard Worker  *
244*0e209d39SAndroid Build Coastguard Worker  *            // prepare rendering a new line from either left or right
245*0e209d39SAndroid Build Coastguard Worker  *             startLine(paraLevel, width);
246*0e209d39SAndroid Build Coastguard Worker  *
247*0e209d39SAndroid Build Coastguard Worker  *             renderLine(para, text, 0, length,
248*0e209d39SAndroid Build Coastguard Worker  *                        styleRuns, styleRunCount, pErrorCode);
249*0e209d39SAndroid Build Coastguard Worker  *         } else {
250*0e209d39SAndroid Build Coastguard Worker  *             UBiDi *line;
251*0e209d39SAndroid Build Coastguard Worker  *
252*0e209d39SAndroid Build Coastguard Worker  *             // we need to render several lines
253*0e209d39SAndroid Build Coastguard Worker  *             line=ubidi_openSized(length, 0, pErrorCode);
254*0e209d39SAndroid Build Coastguard Worker  *             if(line!=NULL) {
255*0e209d39SAndroid Build Coastguard Worker  *                 int32_t start=0, limit;
256*0e209d39SAndroid Build Coastguard Worker  *                 int styleRunStart=0, styleRunLimit;
257*0e209d39SAndroid Build Coastguard Worker  *
258*0e209d39SAndroid Build Coastguard Worker  *                 for(;;) {
259*0e209d39SAndroid Build Coastguard Worker  *                     limit=length;
260*0e209d39SAndroid Build Coastguard Worker  *                     styleRunLimit=styleRunCount;
261*0e209d39SAndroid Build Coastguard Worker  *                     getLineBreak(text, start, &limit, para,
262*0e209d39SAndroid Build Coastguard Worker  *                                  styleRuns, styleRunStart, &styleRunLimit,
263*0e209d39SAndroid Build Coastguard Worker  *                                 &width);
264*0e209d39SAndroid Build Coastguard Worker  *                     ubidi_setLine(para, start, limit, line, pErrorCode);
265*0e209d39SAndroid Build Coastguard Worker  *                     if(U_SUCCESS(*pErrorCode)) {
266*0e209d39SAndroid Build Coastguard Worker  *                         // prepare rendering a new line
267*0e209d39SAndroid Build Coastguard Worker  *                         // from either left or right
268*0e209d39SAndroid Build Coastguard Worker  *                         startLine(paraLevel, width);
269*0e209d39SAndroid Build Coastguard Worker  *
270*0e209d39SAndroid Build Coastguard Worker  *                         renderLine(line, text, start, limit,
271*0e209d39SAndroid Build Coastguard Worker  *                                    styleRuns+styleRunStart,
272*0e209d39SAndroid Build Coastguard Worker  *                                    styleRunLimit-styleRunStart, pErrorCode);
273*0e209d39SAndroid Build Coastguard Worker  *                     }
274*0e209d39SAndroid Build Coastguard Worker  *                     if(limit==length) { break; }
275*0e209d39SAndroid Build Coastguard Worker  *                     start=limit;
276*0e209d39SAndroid Build Coastguard Worker  *                     styleRunStart=styleRunLimit-1;
277*0e209d39SAndroid Build Coastguard Worker  *                     if(start>=styleRuns[styleRunStart].limit) {
278*0e209d39SAndroid Build Coastguard Worker  *                         ++styleRunStart;
279*0e209d39SAndroid Build Coastguard Worker  *                     }
280*0e209d39SAndroid Build Coastguard Worker  *                 }
281*0e209d39SAndroid Build Coastguard Worker  *
282*0e209d39SAndroid Build Coastguard Worker  *                 ubidi_close(line);
283*0e209d39SAndroid Build Coastguard Worker  *             }
284*0e209d39SAndroid Build Coastguard Worker  *        }
285*0e209d39SAndroid Build Coastguard Worker  *    }
286*0e209d39SAndroid Build Coastguard Worker  *
287*0e209d39SAndroid Build Coastguard Worker  *     ubidi_close(para);
288*0e209d39SAndroid Build Coastguard Worker  *}
289*0e209d39SAndroid Build Coastguard Worker  *\endcode
290*0e209d39SAndroid Build Coastguard Worker  * </pre>
291*0e209d39SAndroid Build Coastguard Worker  */
292*0e209d39SAndroid Build Coastguard Worker 
293*0e209d39SAndroid Build Coastguard Worker /*DOCXX_TAG*/
294*0e209d39SAndroid Build Coastguard Worker /*@{*/
295*0e209d39SAndroid Build Coastguard Worker 
296*0e209d39SAndroid Build Coastguard Worker /**
297*0e209d39SAndroid Build Coastguard Worker  * UBiDiLevel is the type of the level values in this
298*0e209d39SAndroid Build Coastguard Worker  * Bidi implementation.
299*0e209d39SAndroid Build Coastguard Worker  * It holds an embedding level and indicates the visual direction
300*0e209d39SAndroid Build Coastguard Worker  * by its bit&nbsp;0 (even/odd value).<p>
301*0e209d39SAndroid Build Coastguard Worker  *
302*0e209d39SAndroid Build Coastguard Worker  * It can also hold non-level values for the
303*0e209d39SAndroid Build Coastguard Worker  * <code>paraLevel</code> and <code>embeddingLevels</code>
304*0e209d39SAndroid Build Coastguard Worker  * arguments of <code>ubidi_setPara()</code>; there:
305*0e209d39SAndroid Build Coastguard Worker  * <ul>
306*0e209d39SAndroid Build Coastguard Worker  * <li>bit&nbsp;7 of an <code>embeddingLevels[]</code>
307*0e209d39SAndroid Build Coastguard Worker  * value indicates whether the using application is
308*0e209d39SAndroid Build Coastguard Worker  * specifying the level of a character to <i>override</i> whatever the
309*0e209d39SAndroid Build Coastguard Worker  * Bidi implementation would resolve it to.</li>
310*0e209d39SAndroid Build Coastguard Worker  * <li><code>paraLevel</code> can be set to the
311*0e209d39SAndroid Build Coastguard Worker  * pseudo-level values <code>UBIDI_DEFAULT_LTR</code>
312*0e209d39SAndroid Build Coastguard Worker  * and <code>UBIDI_DEFAULT_RTL</code>.</li>
313*0e209d39SAndroid Build Coastguard Worker  * </ul>
314*0e209d39SAndroid Build Coastguard Worker  *
315*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
316*0e209d39SAndroid Build Coastguard Worker  *
317*0e209d39SAndroid Build Coastguard Worker  * <p>The related constants are not real, valid level values.
318*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_DEFAULT_XXX</code> can be used to specify
319*0e209d39SAndroid Build Coastguard Worker  * a default for the paragraph level for
320*0e209d39SAndroid Build Coastguard Worker  * when the <code>ubidi_setPara()</code> function
321*0e209d39SAndroid Build Coastguard Worker  * shall determine it but there is no
322*0e209d39SAndroid Build Coastguard Worker  * strongly typed character in the input.<p>
323*0e209d39SAndroid Build Coastguard Worker  *
324*0e209d39SAndroid Build Coastguard Worker  * Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even
325*0e209d39SAndroid Build Coastguard Worker  * and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,
326*0e209d39SAndroid Build Coastguard Worker  * just like with normal LTR and RTL level values -
327*0e209d39SAndroid Build Coastguard Worker  * these special values are designed that way. Also, the implementation
328*0e209d39SAndroid Build Coastguard Worker  * assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
329*0e209d39SAndroid Build Coastguard Worker  *
330*0e209d39SAndroid Build Coastguard Worker  * Note: The numeric values of the related constants will not change:
331*0e209d39SAndroid Build Coastguard Worker  * They are tied to the use of 7-bit byte values (plus the override bit)
332*0e209d39SAndroid Build Coastguard Worker  * and of the UBiDiLevel=uint8_t data type in this API.
333*0e209d39SAndroid Build Coastguard Worker  *
334*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_DEFAULT_LTR
335*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_DEFAULT_RTL
336*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_LEVEL_OVERRIDE
337*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_MAX_EXPLICIT_LEVEL
338*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
339*0e209d39SAndroid Build Coastguard Worker  */
340*0e209d39SAndroid Build Coastguard Worker typedef uint8_t UBiDiLevel;
341*0e209d39SAndroid Build Coastguard Worker 
342*0e209d39SAndroid Build Coastguard Worker /** Paragraph level setting.<p>
343*0e209d39SAndroid Build Coastguard Worker  *
344*0e209d39SAndroid Build Coastguard Worker  * Constant indicating that the base direction depends on the first strong
345*0e209d39SAndroid Build Coastguard Worker  * directional character in the text according to the Unicode Bidirectional
346*0e209d39SAndroid Build Coastguard Worker  * Algorithm. If no strong directional character is present,
347*0e209d39SAndroid Build Coastguard Worker  * then set the paragraph level to 0 (left-to-right).<p>
348*0e209d39SAndroid Build Coastguard Worker  *
349*0e209d39SAndroid Build Coastguard Worker  * If this value is used in conjunction with reordering modes
350*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
351*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
352*0e209d39SAndroid Build Coastguard Worker  * is assumed to be visual LTR, and the text after reordering is required
353*0e209d39SAndroid Build Coastguard Worker  * to be the corresponding logical string with appropriate contextual
354*0e209d39SAndroid Build Coastguard Worker  * direction. The direction of the result string will be RTL if either
355*0e209d39SAndroid Build Coastguard Worker  * the righmost or leftmost strong character of the source text is RTL
356*0e209d39SAndroid Build Coastguard Worker  * or Arabic Letter, the direction will be LTR otherwise.<p>
357*0e209d39SAndroid Build Coastguard Worker  *
358*0e209d39SAndroid Build Coastguard Worker  * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
359*0e209d39SAndroid Build Coastguard Worker  * be added at the beginning of the result string to ensure round trip
360*0e209d39SAndroid Build Coastguard Worker  * (that the result string, when reordered back to visual, will produce
361*0e209d39SAndroid Build Coastguard Worker  * the original source text).
362*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
363*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
364*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
365*0e209d39SAndroid Build Coastguard Worker  */
366*0e209d39SAndroid Build Coastguard Worker #define UBIDI_DEFAULT_LTR 0xfe
367*0e209d39SAndroid Build Coastguard Worker 
368*0e209d39SAndroid Build Coastguard Worker /** Paragraph level setting.<p>
369*0e209d39SAndroid Build Coastguard Worker  *
370*0e209d39SAndroid Build Coastguard Worker  * Constant indicating that the base direction depends on the first strong
371*0e209d39SAndroid Build Coastguard Worker  * directional character in the text according to the Unicode Bidirectional
372*0e209d39SAndroid Build Coastguard Worker  * Algorithm. If no strong directional character is present,
373*0e209d39SAndroid Build Coastguard Worker  * then set the paragraph level to 1 (right-to-left).<p>
374*0e209d39SAndroid Build Coastguard Worker  *
375*0e209d39SAndroid Build Coastguard Worker  * If this value is used in conjunction with reordering modes
376*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
377*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
378*0e209d39SAndroid Build Coastguard Worker  * is assumed to be visual LTR, and the text after reordering is required
379*0e209d39SAndroid Build Coastguard Worker  * to be the corresponding logical string with appropriate contextual
380*0e209d39SAndroid Build Coastguard Worker  * direction. The direction of the result string will be RTL if either
381*0e209d39SAndroid Build Coastguard Worker  * the righmost or leftmost strong character of the source text is RTL
382*0e209d39SAndroid Build Coastguard Worker  * or Arabic Letter, or if the text contains no strong character;
383*0e209d39SAndroid Build Coastguard Worker  * the direction will be LTR otherwise.<p>
384*0e209d39SAndroid Build Coastguard Worker  *
385*0e209d39SAndroid Build Coastguard Worker  * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
386*0e209d39SAndroid Build Coastguard Worker  * be added at the beginning of the result string to ensure round trip
387*0e209d39SAndroid Build Coastguard Worker  * (that the result string, when reordered back to visual, will produce
388*0e209d39SAndroid Build Coastguard Worker  * the original source text).
389*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
390*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
391*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
392*0e209d39SAndroid Build Coastguard Worker  */
393*0e209d39SAndroid Build Coastguard Worker #define UBIDI_DEFAULT_RTL 0xff
394*0e209d39SAndroid Build Coastguard Worker 
395*0e209d39SAndroid Build Coastguard Worker /**
396*0e209d39SAndroid Build Coastguard Worker  * Maximum explicit embedding level.
397*0e209d39SAndroid Build Coastguard Worker  * Same as the max_depth value in the
398*0e209d39SAndroid Build Coastguard Worker  * <a href="http://www.unicode.org/reports/tr9/#BD2">Unicode Bidirectional Algorithm</a>.
399*0e209d39SAndroid Build Coastguard Worker  * (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).
400*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
401*0e209d39SAndroid Build Coastguard Worker  */
402*0e209d39SAndroid Build Coastguard Worker #define UBIDI_MAX_EXPLICIT_LEVEL 125
403*0e209d39SAndroid Build Coastguard Worker 
404*0e209d39SAndroid Build Coastguard Worker /** Bit flag for level input.
405*0e209d39SAndroid Build Coastguard Worker  *  Overrides directional properties.
406*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
407*0e209d39SAndroid Build Coastguard Worker  */
408*0e209d39SAndroid Build Coastguard Worker #define UBIDI_LEVEL_OVERRIDE 0x80
409*0e209d39SAndroid Build Coastguard Worker 
410*0e209d39SAndroid Build Coastguard Worker /**
411*0e209d39SAndroid Build Coastguard Worker  * Special value which can be returned by the mapping functions when a logical
412*0e209d39SAndroid Build Coastguard Worker  * index has no corresponding visual index or vice-versa. This may happen
413*0e209d39SAndroid Build Coastguard Worker  * for the logical-to-visual mapping of a Bidi control when option
414*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is specified. This can also happen
415*0e209d39SAndroid Build Coastguard Worker  * for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted
416*0e209d39SAndroid Build Coastguard Worker  * by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
417*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getVisualIndex
418*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getVisualMap
419*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getLogicalIndex
420*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getLogicalMap
421*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
422*0e209d39SAndroid Build Coastguard Worker  */
423*0e209d39SAndroid Build Coastguard Worker #define UBIDI_MAP_NOWHERE   (-1)
424*0e209d39SAndroid Build Coastguard Worker 
425*0e209d39SAndroid Build Coastguard Worker /**
426*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDiDirection</code> values indicate the text direction.
427*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
428*0e209d39SAndroid Build Coastguard Worker  */
429*0e209d39SAndroid Build Coastguard Worker enum UBiDiDirection {
430*0e209d39SAndroid Build Coastguard Worker   /** Left-to-right text. This is a 0 value.
431*0e209d39SAndroid Build Coastguard Worker    * <ul>
432*0e209d39SAndroid Build Coastguard Worker    * <li>As return value for <code>ubidi_getDirection()</code>, it means
433*0e209d39SAndroid Build Coastguard Worker    *     that the source string contains no right-to-left characters, or
434*0e209d39SAndroid Build Coastguard Worker    *     that the source string is empty and the paragraph level is even.
435*0e209d39SAndroid Build Coastguard Worker    * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
436*0e209d39SAndroid Build Coastguard Worker    *      means that the first strong character of the source string has
437*0e209d39SAndroid Build Coastguard Worker    *      a left-to-right direction.
438*0e209d39SAndroid Build Coastguard Worker    * </ul>
439*0e209d39SAndroid Build Coastguard Worker    * @stable ICU 2.0
440*0e209d39SAndroid Build Coastguard Worker    */
441*0e209d39SAndroid Build Coastguard Worker   UBIDI_LTR,
442*0e209d39SAndroid Build Coastguard Worker   /** Right-to-left text. This is a 1 value.
443*0e209d39SAndroid Build Coastguard Worker    * <ul>
444*0e209d39SAndroid Build Coastguard Worker    * <li>As return value for <code>ubidi_getDirection()</code>, it means
445*0e209d39SAndroid Build Coastguard Worker    *     that the source string contains no left-to-right characters, or
446*0e209d39SAndroid Build Coastguard Worker    *     that the source string is empty and the paragraph level is odd.
447*0e209d39SAndroid Build Coastguard Worker    * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
448*0e209d39SAndroid Build Coastguard Worker    *      means that the first strong character of the source string has
449*0e209d39SAndroid Build Coastguard Worker    *      a right-to-left direction.
450*0e209d39SAndroid Build Coastguard Worker    * </ul>
451*0e209d39SAndroid Build Coastguard Worker    * @stable ICU 2.0
452*0e209d39SAndroid Build Coastguard Worker    */
453*0e209d39SAndroid Build Coastguard Worker   UBIDI_RTL,
454*0e209d39SAndroid Build Coastguard Worker   /** Mixed-directional text.
455*0e209d39SAndroid Build Coastguard Worker    * <p>As return value for <code>ubidi_getDirection()</code>, it means
456*0e209d39SAndroid Build Coastguard Worker    *    that the source string contains both left-to-right and
457*0e209d39SAndroid Build Coastguard Worker    *    right-to-left characters.
458*0e209d39SAndroid Build Coastguard Worker    * @stable ICU 2.0
459*0e209d39SAndroid Build Coastguard Worker    */
460*0e209d39SAndroid Build Coastguard Worker   UBIDI_MIXED,
461*0e209d39SAndroid Build Coastguard Worker   /** No strongly directional text.
462*0e209d39SAndroid Build Coastguard Worker    * <p>As return value for <code>ubidi_getBaseDirection()</code>, it means
463*0e209d39SAndroid Build Coastguard Worker    *    that the source string is missing or empty, or contains neither left-to-right
464*0e209d39SAndroid Build Coastguard Worker    *    nor right-to-left characters.
465*0e209d39SAndroid Build Coastguard Worker    * @stable ICU 4.6
466*0e209d39SAndroid Build Coastguard Worker    */
467*0e209d39SAndroid Build Coastguard Worker   UBIDI_NEUTRAL
468*0e209d39SAndroid Build Coastguard Worker };
469*0e209d39SAndroid Build Coastguard Worker 
470*0e209d39SAndroid Build Coastguard Worker /** @stable ICU 2.0 */
471*0e209d39SAndroid Build Coastguard Worker typedef enum UBiDiDirection UBiDiDirection;
472*0e209d39SAndroid Build Coastguard Worker 
473*0e209d39SAndroid Build Coastguard Worker /**
474*0e209d39SAndroid Build Coastguard Worker  * Forward declaration of the <code>UBiDi</code> structure for the declaration of
475*0e209d39SAndroid Build Coastguard Worker  * the API functions. Its fields are implementation-specific.<p>
476*0e209d39SAndroid Build Coastguard Worker  * This structure holds information about a paragraph (or multiple paragraphs)
477*0e209d39SAndroid Build Coastguard Worker  * of text with Bidi-algorithm-related details, or about one line of
478*0e209d39SAndroid Build Coastguard Worker  * such a paragraph.<p>
479*0e209d39SAndroid Build Coastguard Worker  * Reordering can be done on a line, or on one or more paragraphs which are
480*0e209d39SAndroid Build Coastguard Worker  * then interpreted each as one single line.
481*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
482*0e209d39SAndroid Build Coastguard Worker  */
483*0e209d39SAndroid Build Coastguard Worker struct UBiDi;
484*0e209d39SAndroid Build Coastguard Worker 
485*0e209d39SAndroid Build Coastguard Worker /** @stable ICU 2.0 */
486*0e209d39SAndroid Build Coastguard Worker typedef struct UBiDi UBiDi;
487*0e209d39SAndroid Build Coastguard Worker 
488*0e209d39SAndroid Build Coastguard Worker /**
489*0e209d39SAndroid Build Coastguard Worker  * Allocate a <code>UBiDi</code> structure.
490*0e209d39SAndroid Build Coastguard Worker  * Such an object is initially empty. It is assigned
491*0e209d39SAndroid Build Coastguard Worker  * the Bidi properties of a piece of text containing one or more paragraphs
492*0e209d39SAndroid Build Coastguard Worker  * by <code>ubidi_setPara()</code>
493*0e209d39SAndroid Build Coastguard Worker  * or the Bidi properties of a line within a paragraph by
494*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setLine()</code>.<p>
495*0e209d39SAndroid Build Coastguard Worker  * This object can be reused for as long as it is not deallocated
496*0e209d39SAndroid Build Coastguard Worker  * by calling <code>ubidi_close()</code>.<p>
497*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setPara()</code> and <code>ubidi_setLine()</code> will allocate
498*0e209d39SAndroid Build Coastguard Worker  * additional memory for internal structures as necessary.
499*0e209d39SAndroid Build Coastguard Worker  *
500*0e209d39SAndroid Build Coastguard Worker  * @return An empty <code>UBiDi</code> object.
501*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
502*0e209d39SAndroid Build Coastguard Worker  */
503*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDi * U_EXPORT2
504*0e209d39SAndroid Build Coastguard Worker ubidi_open(void);
505*0e209d39SAndroid Build Coastguard Worker 
506*0e209d39SAndroid Build Coastguard Worker /**
507*0e209d39SAndroid Build Coastguard Worker  * Allocate a <code>UBiDi</code> structure with preallocated memory
508*0e209d39SAndroid Build Coastguard Worker  * for internal structures.
509*0e209d39SAndroid Build Coastguard Worker  * This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>
510*0e209d39SAndroid Build Coastguard Worker  * with no arguments, but it also preallocates memory for internal structures
511*0e209d39SAndroid Build Coastguard Worker  * according to the sizings supplied by the caller.<p>
512*0e209d39SAndroid Build Coastguard Worker  * Subsequent functions will not allocate any more memory, and are thus
513*0e209d39SAndroid Build Coastguard Worker  * guaranteed not to fail because of lack of memory.<p>
514*0e209d39SAndroid Build Coastguard Worker  * The preallocation can be limited to some of the internal memory
515*0e209d39SAndroid Build Coastguard Worker  * by setting some values to 0 here. That means that if, e.g.,
516*0e209d39SAndroid Build Coastguard Worker  * <code>maxRunCount</code> cannot be reasonably predetermined and should not
517*0e209d39SAndroid Build Coastguard Worker  * be set to <code>maxLength</code> (the only failproof value) to avoid
518*0e209d39SAndroid Build Coastguard Worker  * wasting memory, then <code>maxRunCount</code> could be set to 0 here
519*0e209d39SAndroid Build Coastguard Worker  * and the internal structures that are associated with it will be allocated
520*0e209d39SAndroid Build Coastguard Worker  * on demand, just like with <code>ubidi_open()</code>.
521*0e209d39SAndroid Build Coastguard Worker  *
522*0e209d39SAndroid Build Coastguard Worker  * @param maxLength is the maximum text or line length that internal memory
523*0e209d39SAndroid Build Coastguard Worker  *        will be preallocated for. An attempt to associate this object with a
524*0e209d39SAndroid Build Coastguard Worker  *        longer text will fail, unless this value is 0, which leaves the allocation
525*0e209d39SAndroid Build Coastguard Worker  *        up to the implementation.
526*0e209d39SAndroid Build Coastguard Worker  *
527*0e209d39SAndroid Build Coastguard Worker  * @param maxRunCount is the maximum anticipated number of same-level runs
528*0e209d39SAndroid Build Coastguard Worker  *        that internal memory will be preallocated for. An attempt to access
529*0e209d39SAndroid Build Coastguard Worker  *        visual runs on an object that was not preallocated for as many runs
530*0e209d39SAndroid Build Coastguard Worker  *        as the text was actually resolved to will fail,
531*0e209d39SAndroid Build Coastguard Worker  *        unless this value is 0, which leaves the allocation up to the implementation.<br><br>
532*0e209d39SAndroid Build Coastguard Worker  *        The number of runs depends on the actual text and maybe anywhere between
533*0e209d39SAndroid Build Coastguard Worker  *        1 and <code>maxLength</code>. It is typically small.
534*0e209d39SAndroid Build Coastguard Worker  *
535*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
536*0e209d39SAndroid Build Coastguard Worker  *
537*0e209d39SAndroid Build Coastguard Worker  * @return An empty <code>UBiDi</code> object with preallocated memory.
538*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
539*0e209d39SAndroid Build Coastguard Worker  */
540*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDi * U_EXPORT2
541*0e209d39SAndroid Build Coastguard Worker ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
542*0e209d39SAndroid Build Coastguard Worker 
543*0e209d39SAndroid Build Coastguard Worker /**
544*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_close()</code> must be called to free the memory
545*0e209d39SAndroid Build Coastguard Worker  * associated with a UBiDi object.<p>
546*0e209d39SAndroid Build Coastguard Worker  *
547*0e209d39SAndroid Build Coastguard Worker  * <strong>Important: </strong>
548*0e209d39SAndroid Build Coastguard Worker  * A parent <code>UBiDi</code> object must not be destroyed or reused if
549*0e209d39SAndroid Build Coastguard Worker  * it still has children.
550*0e209d39SAndroid Build Coastguard Worker  * If a <code>UBiDi</code> object has become the <i>child</i>
551*0e209d39SAndroid Build Coastguard Worker  * of another one (its <i>parent</i>) by calling
552*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setLine()</code>, then the child object must
553*0e209d39SAndroid Build Coastguard Worker  * be destroyed (closed) or reused (by calling
554*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)
555*0e209d39SAndroid Build Coastguard Worker  * before the parent object.
556*0e209d39SAndroid Build Coastguard Worker  *
557*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
558*0e209d39SAndroid Build Coastguard Worker  *
559*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
560*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setLine
561*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
562*0e209d39SAndroid Build Coastguard Worker  */
563*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
564*0e209d39SAndroid Build Coastguard Worker ubidi_close(UBiDi *pBiDi);
565*0e209d39SAndroid Build Coastguard Worker 
566*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
567*0e209d39SAndroid Build Coastguard Worker 
568*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
569*0e209d39SAndroid Build Coastguard Worker 
570*0e209d39SAndroid Build Coastguard Worker /**
571*0e209d39SAndroid Build Coastguard Worker  * \class LocalUBiDiPointer
572*0e209d39SAndroid Build Coastguard Worker  * "Smart pointer" class, closes a UBiDi via ubidi_close().
573*0e209d39SAndroid Build Coastguard Worker  * For most methods see the LocalPointerBase base class.
574*0e209d39SAndroid Build Coastguard Worker  *
575*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointerBase
576*0e209d39SAndroid Build Coastguard Worker  * @see LocalPointer
577*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 4.4
578*0e209d39SAndroid Build Coastguard Worker  */
579*0e209d39SAndroid Build Coastguard Worker U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);
580*0e209d39SAndroid Build Coastguard Worker 
581*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
582*0e209d39SAndroid Build Coastguard Worker 
583*0e209d39SAndroid Build Coastguard Worker #endif
584*0e209d39SAndroid Build Coastguard Worker 
585*0e209d39SAndroid Build Coastguard Worker /**
586*0e209d39SAndroid Build Coastguard Worker  * Modify the operation of the Bidi algorithm such that it
587*0e209d39SAndroid Build Coastguard Worker  * approximates an "inverse Bidi" algorithm. This function
588*0e209d39SAndroid Build Coastguard Worker  * must be called before <code>ubidi_setPara()</code>.
589*0e209d39SAndroid Build Coastguard Worker  *
590*0e209d39SAndroid Build Coastguard Worker  * <p>The normal operation of the Bidi algorithm as described
591*0e209d39SAndroid Build Coastguard Worker  * in the Unicode Technical Report is to take text stored in logical
592*0e209d39SAndroid Build Coastguard Worker  * (keyboard, typing) order and to determine the reordering of it for visual
593*0e209d39SAndroid Build Coastguard Worker  * rendering.
594*0e209d39SAndroid Build Coastguard Worker  * Some legacy systems store text in visual order, and for operations
595*0e209d39SAndroid Build Coastguard Worker  * with standard, Unicode-based algorithms, the text needs to be transformed
596*0e209d39SAndroid Build Coastguard Worker  * to logical order. This is effectively the inverse algorithm of the
597*0e209d39SAndroid Build Coastguard Worker  * described Bidi algorithm. Note that there is no standard algorithm for
598*0e209d39SAndroid Build Coastguard Worker  * this "inverse Bidi" and that the current implementation provides only an
599*0e209d39SAndroid Build Coastguard Worker  * approximation of "inverse Bidi".</p>
600*0e209d39SAndroid Build Coastguard Worker  *
601*0e209d39SAndroid Build Coastguard Worker  * <p>With <code>isInverse</code> set to <code>true</code>,
602*0e209d39SAndroid Build Coastguard Worker  * this function changes the behavior of some of the subsequent functions
603*0e209d39SAndroid Build Coastguard Worker  * in a way that they can be used for the inverse Bidi algorithm.
604*0e209d39SAndroid Build Coastguard Worker  * Specifically, runs of text with numeric characters will be treated in a
605*0e209d39SAndroid Build Coastguard Worker  * special way and may need to be surrounded with LRM characters when they are
606*0e209d39SAndroid Build Coastguard Worker  * written in reordered sequence.</p>
607*0e209d39SAndroid Build Coastguard Worker  *
608*0e209d39SAndroid Build Coastguard Worker  * <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.
609*0e209d39SAndroid Build Coastguard Worker  * Since the actual input for "inverse Bidi" is visually ordered text and
610*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually
611*0e209d39SAndroid Build Coastguard Worker  * the runs of the logically ordered output.</p>
612*0e209d39SAndroid Build Coastguard Worker  *
613*0e209d39SAndroid Build Coastguard Worker  * <p>Calling this function with argument <code>isInverse</code> set to
614*0e209d39SAndroid Build Coastguard Worker  * <code>true</code> is equivalent to calling
615*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setReorderingMode</code> with argument
616*0e209d39SAndroid Build Coastguard Worker  * <code>reorderingMode</code>
617*0e209d39SAndroid Build Coastguard Worker  * set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
618*0e209d39SAndroid Build Coastguard Worker  * Calling this function with argument <code>isInverse</code> set to
619*0e209d39SAndroid Build Coastguard Worker  * <code>false</code> is equivalent to calling
620*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setReorderingMode</code> with argument
621*0e209d39SAndroid Build Coastguard Worker  * <code>reorderingMode</code>
622*0e209d39SAndroid Build Coastguard Worker  * set to <code>#UBIDI_REORDER_DEFAULT</code>.
623*0e209d39SAndroid Build Coastguard Worker  *
624*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
625*0e209d39SAndroid Build Coastguard Worker  *
626*0e209d39SAndroid Build Coastguard Worker  * @param isInverse specifies "forward" or "inverse" Bidi operation.
627*0e209d39SAndroid Build Coastguard Worker  *
628*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
629*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
630*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setReorderingMode
631*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
632*0e209d39SAndroid Build Coastguard Worker  */
633*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
634*0e209d39SAndroid Build Coastguard Worker ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
635*0e209d39SAndroid Build Coastguard Worker 
636*0e209d39SAndroid Build Coastguard Worker /**
637*0e209d39SAndroid Build Coastguard Worker  * Is this Bidi object set to perform the inverse Bidi algorithm?
638*0e209d39SAndroid Build Coastguard Worker  * <p>Note: calling this function after setting the reordering mode with
639*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setReorderingMode</code> will return <code>true</code> if the
640*0e209d39SAndroid Build Coastguard Worker  * reordering mode was set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>,
641*0e209d39SAndroid Build Coastguard Worker  * <code>false</code> for all other values.</p>
642*0e209d39SAndroid Build Coastguard Worker  *
643*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
644*0e209d39SAndroid Build Coastguard Worker  * @return true if the Bidi object is set to perform the inverse Bidi algorithm
645*0e209d39SAndroid Build Coastguard Worker  * by handling numbers as L.
646*0e209d39SAndroid Build Coastguard Worker  *
647*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setInverse
648*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setReorderingMode
649*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
650*0e209d39SAndroid Build Coastguard Worker  */
651*0e209d39SAndroid Build Coastguard Worker 
652*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
653*0e209d39SAndroid Build Coastguard Worker ubidi_isInverse(UBiDi *pBiDi);
654*0e209d39SAndroid Build Coastguard Worker 
655*0e209d39SAndroid Build Coastguard Worker /**
656*0e209d39SAndroid Build Coastguard Worker  * Specify whether block separators must be allocated level zero,
657*0e209d39SAndroid Build Coastguard Worker  * so that successive paragraphs will progress from left to right.
658*0e209d39SAndroid Build Coastguard Worker  * This function must be called before <code>ubidi_setPara()</code>.
659*0e209d39SAndroid Build Coastguard Worker  * Paragraph separators (B) may appear in the text.  Setting them to level zero
660*0e209d39SAndroid Build Coastguard Worker  * means that all paragraph separators (including one possibly appearing
661*0e209d39SAndroid Build Coastguard Worker  * in the last text position) are kept in the reordered text after the text
662*0e209d39SAndroid Build Coastguard Worker  * that they follow in the source text.
663*0e209d39SAndroid Build Coastguard Worker  * When this feature is not enabled, a paragraph separator at the last
664*0e209d39SAndroid Build Coastguard Worker  * position of the text before reordering will go to the first position
665*0e209d39SAndroid Build Coastguard Worker  * of the reordered text when the paragraph level is odd.
666*0e209d39SAndroid Build Coastguard Worker  *
667*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
668*0e209d39SAndroid Build Coastguard Worker  *
669*0e209d39SAndroid Build Coastguard Worker  * @param orderParagraphsLTR specifies whether paragraph separators (B) must
670*0e209d39SAndroid Build Coastguard Worker  * receive level 0, so that successive paragraphs progress from left to right.
671*0e209d39SAndroid Build Coastguard Worker  *
672*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
673*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.4
674*0e209d39SAndroid Build Coastguard Worker  */
675*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
676*0e209d39SAndroid Build Coastguard Worker ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);
677*0e209d39SAndroid Build Coastguard Worker 
678*0e209d39SAndroid Build Coastguard Worker /**
679*0e209d39SAndroid Build Coastguard Worker  * Is this Bidi object set to allocate level 0 to block separators so that
680*0e209d39SAndroid Build Coastguard Worker  * successive paragraphs progress from left to right?
681*0e209d39SAndroid Build Coastguard Worker  *
682*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
683*0e209d39SAndroid Build Coastguard Worker  * @return true if the Bidi object is set to allocate level 0 to block
684*0e209d39SAndroid Build Coastguard Worker  *         separators.
685*0e209d39SAndroid Build Coastguard Worker  *
686*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_orderParagraphsLTR
687*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.4
688*0e209d39SAndroid Build Coastguard Worker  */
689*0e209d39SAndroid Build Coastguard Worker U_CAPI UBool U_EXPORT2
690*0e209d39SAndroid Build Coastguard Worker ubidi_isOrderParagraphsLTR(UBiDi *pBiDi);
691*0e209d39SAndroid Build Coastguard Worker 
692*0e209d39SAndroid Build Coastguard Worker /**
693*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDiReorderingMode</code> values indicate which variant of the Bidi
694*0e209d39SAndroid Build Coastguard Worker  * algorithm to use.
695*0e209d39SAndroid Build Coastguard Worker  *
696*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setReorderingMode
697*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
698*0e209d39SAndroid Build Coastguard Worker  */
699*0e209d39SAndroid Build Coastguard Worker typedef enum UBiDiReorderingMode {
700*0e209d39SAndroid Build Coastguard Worker     /** Regular Logical to Visual Bidi algorithm according to Unicode.
701*0e209d39SAndroid Build Coastguard Worker       * This is a 0 value.
702*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 3.6 */
703*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_DEFAULT = 0,
704*0e209d39SAndroid Build Coastguard Worker     /** Logical to Visual algorithm which handles numbers in a way which
705*0e209d39SAndroid Build Coastguard Worker       * mimics the behavior of Windows XP.
706*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 3.6 */
707*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_NUMBERS_SPECIAL,
708*0e209d39SAndroid Build Coastguard Worker     /** Logical to Visual algorithm grouping numbers with adjacent R characters
709*0e209d39SAndroid Build Coastguard Worker       * (reversible algorithm).
710*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 3.6 */
711*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_GROUP_NUMBERS_WITH_R,
712*0e209d39SAndroid Build Coastguard Worker     /** Reorder runs only to transform a Logical LTR string to the Logical RTL
713*0e209d39SAndroid Build Coastguard Worker       * string with the same display, or vice-versa.<br>
714*0e209d39SAndroid Build Coastguard Worker       * If this mode is set together with option
715*0e209d39SAndroid Build Coastguard Worker       * <code>#UBIDI_OPTION_INSERT_MARKS</code>, some Bidi controls in the source
716*0e209d39SAndroid Build Coastguard Worker       * text may be removed and other controls may be added to produce the
717*0e209d39SAndroid Build Coastguard Worker       * minimum combination which has the required display.
718*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 3.6 */
719*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_RUNS_ONLY,
720*0e209d39SAndroid Build Coastguard Worker     /** Visual to Logical algorithm which handles numbers like L
721*0e209d39SAndroid Build Coastguard Worker       * (same algorithm as selected by <code>ubidi_setInverse(true)</code>.
722*0e209d39SAndroid Build Coastguard Worker       * @see ubidi_setInverse
723*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 3.6 */
724*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_INVERSE_NUMBERS_AS_L,
725*0e209d39SAndroid Build Coastguard Worker     /** Visual to Logical algorithm equivalent to the regular Logical to Visual
726*0e209d39SAndroid Build Coastguard Worker       * algorithm.
727*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 3.6 */
728*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_INVERSE_LIKE_DIRECT,
729*0e209d39SAndroid Build Coastguard Worker     /** Inverse Bidi (Visual to Logical) algorithm for the
730*0e209d39SAndroid Build Coastguard Worker       * <code>UBIDI_REORDER_NUMBERS_SPECIAL</code> Bidi algorithm.
731*0e209d39SAndroid Build Coastguard Worker       * @stable ICU 3.6 */
732*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,
733*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
734*0e209d39SAndroid Build Coastguard Worker     /**
735*0e209d39SAndroid Build Coastguard Worker      * Number of values for reordering mode.
736*0e209d39SAndroid Build Coastguard Worker      * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
737*0e209d39SAndroid Build Coastguard Worker      */
738*0e209d39SAndroid Build Coastguard Worker     UBIDI_REORDER_COUNT
739*0e209d39SAndroid Build Coastguard Worker #endif  // U_HIDE_DEPRECATED_API
740*0e209d39SAndroid Build Coastguard Worker } UBiDiReorderingMode;
741*0e209d39SAndroid Build Coastguard Worker 
742*0e209d39SAndroid Build Coastguard Worker /**
743*0e209d39SAndroid Build Coastguard Worker  * Modify the operation of the Bidi algorithm such that it implements some
744*0e209d39SAndroid Build Coastguard Worker  * variant to the basic Bidi algorithm or approximates an "inverse Bidi"
745*0e209d39SAndroid Build Coastguard Worker  * algorithm, depending on different values of the "reordering mode".
746*0e209d39SAndroid Build Coastguard Worker  * This function must be called before <code>ubidi_setPara()</code>, and stays
747*0e209d39SAndroid Build Coastguard Worker  * in effect until called again with a different argument.
748*0e209d39SAndroid Build Coastguard Worker  *
749*0e209d39SAndroid Build Coastguard Worker  * <p>The normal operation of the Bidi algorithm as described
750*0e209d39SAndroid Build Coastguard Worker  * in the Unicode Standard Annex #9 is to take text stored in logical
751*0e209d39SAndroid Build Coastguard Worker  * (keyboard, typing) order and to determine how to reorder it for visual
752*0e209d39SAndroid Build Coastguard Worker  * rendering.</p>
753*0e209d39SAndroid Build Coastguard Worker  *
754*0e209d39SAndroid Build Coastguard Worker  * <p>With the reordering mode set to a value other than
755*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_DEFAULT</code>, this function changes the behavior of
756*0e209d39SAndroid Build Coastguard Worker  * some of the subsequent functions in a way such that they implement an
757*0e209d39SAndroid Build Coastguard Worker  * inverse Bidi algorithm or some other algorithm variants.</p>
758*0e209d39SAndroid Build Coastguard Worker  *
759*0e209d39SAndroid Build Coastguard Worker  * <p>Some legacy systems store text in visual order, and for operations
760*0e209d39SAndroid Build Coastguard Worker  * with standard, Unicode-based algorithms, the text needs to be transformed
761*0e209d39SAndroid Build Coastguard Worker  * into logical order. This is effectively the inverse algorithm of the
762*0e209d39SAndroid Build Coastguard Worker  * described Bidi algorithm. Note that there is no standard algorithm for
763*0e209d39SAndroid Build Coastguard Worker  * this "inverse Bidi", so a number of variants are implemented here.</p>
764*0e209d39SAndroid Build Coastguard Worker  *
765*0e209d39SAndroid Build Coastguard Worker  * <p>In other cases, it may be desirable to emulate some variant of the
766*0e209d39SAndroid Build Coastguard Worker  * Logical to Visual algorithm (e.g. one used in MS Windows), or perform a
767*0e209d39SAndroid Build Coastguard Worker  * Logical to Logical transformation.</p>
768*0e209d39SAndroid Build Coastguard Worker  *
769*0e209d39SAndroid Build Coastguard Worker  * <ul>
770*0e209d39SAndroid Build Coastguard Worker  * <li>When the reordering mode is set to <code>#UBIDI_REORDER_DEFAULT</code>,
771*0e209d39SAndroid Build Coastguard Worker  * the standard Bidi Logical to Visual algorithm is applied.</li>
772*0e209d39SAndroid Build Coastguard Worker  *
773*0e209d39SAndroid Build Coastguard Worker  * <li>When the reordering mode is set to
774*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_NUMBERS_SPECIAL</code>,
775*0e209d39SAndroid Build Coastguard Worker  * the algorithm used to perform Bidi transformations when calling
776*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setPara</code> should approximate the algorithm used in
777*0e209d39SAndroid Build Coastguard Worker  * Microsoft Windows XP rather than strictly conform to the Unicode Bidi
778*0e209d39SAndroid Build Coastguard Worker  * algorithm.
779*0e209d39SAndroid Build Coastguard Worker  * <br>
780*0e209d39SAndroid Build Coastguard Worker  * The differences between the basic algorithm and the algorithm addressed
781*0e209d39SAndroid Build Coastguard Worker  * by this option are as follows:
782*0e209d39SAndroid Build Coastguard Worker  * <ul>
783*0e209d39SAndroid Build Coastguard Worker  *   <li>Within text at an even embedding level, the sequence "123AB"
784*0e209d39SAndroid Build Coastguard Worker  *   (where AB represent R or AL letters) is transformed to "123BA" by the
785*0e209d39SAndroid Build Coastguard Worker  *   Unicode algorithm and to "BA123" by the Windows algorithm.</li>
786*0e209d39SAndroid Build Coastguard Worker  *   <li>Arabic-Indic numbers (AN) are handled by the Windows algorithm just
787*0e209d39SAndroid Build Coastguard Worker  *   like regular numbers (EN).</li>
788*0e209d39SAndroid Build Coastguard Worker  * </ul></li>
789*0e209d39SAndroid Build Coastguard Worker  *
790*0e209d39SAndroid Build Coastguard Worker  * <li>When the reordering mode is set to
791*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_GROUP_NUMBERS_WITH_R</code>,
792*0e209d39SAndroid Build Coastguard Worker  * numbers located between LTR text and RTL text are associated with the RTL
793*0e209d39SAndroid Build Coastguard Worker  * text. For instance, an LTR paragraph with content "abc 123 DEF" (where
794*0e209d39SAndroid Build Coastguard Worker  * upper case letters represent RTL characters) will be transformed to
795*0e209d39SAndroid Build Coastguard Worker  * "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed
796*0e209d39SAndroid Build Coastguard Worker  * to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".
797*0e209d39SAndroid Build Coastguard Worker  * This makes the algorithm reversible and makes it useful when round trip
798*0e209d39SAndroid Build Coastguard Worker  * (from visual to logical and back to visual) must be achieved without
799*0e209d39SAndroid Build Coastguard Worker  * adding LRM characters. However, this is a variation from the standard
800*0e209d39SAndroid Build Coastguard Worker  * Unicode Bidi algorithm.<br>
801*0e209d39SAndroid Build Coastguard Worker  * The source text should not contain Bidi control characters other than LRM
802*0e209d39SAndroid Build Coastguard Worker  * or RLM.</li>
803*0e209d39SAndroid Build Coastguard Worker  *
804*0e209d39SAndroid Build Coastguard Worker  * <li>When the reordering mode is set to
805*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_RUNS_ONLY</code>,
806*0e209d39SAndroid Build Coastguard Worker  * a "Logical to Logical" transformation must be performed:
807*0e209d39SAndroid Build Coastguard Worker  * <ul>
808*0e209d39SAndroid Build Coastguard Worker  * <li>If the default text level of the source text (argument <code>paraLevel</code>
809*0e209d39SAndroid Build Coastguard Worker  * in <code>ubidi_setPara</code>) is even, the source text will be handled as
810*0e209d39SAndroid Build Coastguard Worker  * LTR logical text and will be transformed to the RTL logical text which has
811*0e209d39SAndroid Build Coastguard Worker  * the same LTR visual display.</li>
812*0e209d39SAndroid Build Coastguard Worker  * <li>If the default level of the source text is odd, the source text
813*0e209d39SAndroid Build Coastguard Worker  * will be handled as RTL logical text and will be transformed to the
814*0e209d39SAndroid Build Coastguard Worker  * LTR logical text which has the same LTR visual display.</li>
815*0e209d39SAndroid Build Coastguard Worker  * </ul>
816*0e209d39SAndroid Build Coastguard Worker  * This mode may be needed when logical text which is basically Arabic or
817*0e209d39SAndroid Build Coastguard Worker  * Hebrew, with possible included numbers or phrases in English, has to be
818*0e209d39SAndroid Build Coastguard Worker  * displayed as if it had an even embedding level (this can happen if the
819*0e209d39SAndroid Build Coastguard Worker  * displaying application treats all text as if it was basically LTR).
820*0e209d39SAndroid Build Coastguard Worker  * <br>
821*0e209d39SAndroid Build Coastguard Worker  * This mode may also be needed in the reverse case, when logical text which is
822*0e209d39SAndroid Build Coastguard Worker  * basically English, with possible included phrases in Arabic or Hebrew, has to
823*0e209d39SAndroid Build Coastguard Worker  * be displayed as if it had an odd embedding level.
824*0e209d39SAndroid Build Coastguard Worker  * <br>
825*0e209d39SAndroid Build Coastguard Worker  * Both cases could be handled by adding LRE or RLE at the head of the text,
826*0e209d39SAndroid Build Coastguard Worker  * if the display subsystem supports these formatting controls. If it does not,
827*0e209d39SAndroid Build Coastguard Worker  * the problem may be handled by transforming the source text in this mode
828*0e209d39SAndroid Build Coastguard Worker  * before displaying it, so that it will be displayed properly.<br>
829*0e209d39SAndroid Build Coastguard Worker  * The source text should not contain Bidi control characters other than LRM
830*0e209d39SAndroid Build Coastguard Worker  * or RLM.</li>
831*0e209d39SAndroid Build Coastguard Worker  *
832*0e209d39SAndroid Build Coastguard Worker  * <li>When the reordering mode is set to
833*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>, an "inverse Bidi" algorithm
834*0e209d39SAndroid Build Coastguard Worker  * is applied.
835*0e209d39SAndroid Build Coastguard Worker  * Runs of text with numeric characters will be treated like LTR letters and
836*0e209d39SAndroid Build Coastguard Worker  * may need to be surrounded with LRM characters when they are written in
837*0e209d39SAndroid Build Coastguard Worker  * reordered sequence (the option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> can
838*0e209d39SAndroid Build Coastguard Worker  * be used with function <code>ubidi_writeReordered</code> to this end. This
839*0e209d39SAndroid Build Coastguard Worker  * mode is equivalent to calling <code>ubidi_setInverse()</code> with
840*0e209d39SAndroid Build Coastguard Worker  * argument <code>isInverse</code> set to <code>true</code>.</li>
841*0e209d39SAndroid Build Coastguard Worker  *
842*0e209d39SAndroid Build Coastguard Worker  * <li>When the reordering mode is set to
843*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code>, the "direct" Logical to Visual
844*0e209d39SAndroid Build Coastguard Worker  * Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.
845*0e209d39SAndroid Build Coastguard Worker  * This mode is similar to mode <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>
846*0e209d39SAndroid Build Coastguard Worker  * but is closer to the regular Bidi algorithm.
847*0e209d39SAndroid Build Coastguard Worker  * <br>
848*0e209d39SAndroid Build Coastguard Worker  * For example, an LTR paragraph with the content "FED 123 456 CBA" (where
849*0e209d39SAndroid Build Coastguard Worker  * upper case represents RTL characters) will be transformed to
850*0e209d39SAndroid Build Coastguard Worker  * "ABC 456 123 DEF", as opposed to "DEF 123 456 ABC"
851*0e209d39SAndroid Build Coastguard Worker  * with mode <code>UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
852*0e209d39SAndroid Build Coastguard Worker  * When used in conjunction with option
853*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_OPTION_INSERT_MARKS</code>, this mode generally
854*0e209d39SAndroid Build Coastguard Worker  * adds Bidi marks to the output significantly more sparingly than mode
855*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> with option
856*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to
857*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered</code>.</li>
858*0e209d39SAndroid Build Coastguard Worker  *
859*0e209d39SAndroid Build Coastguard Worker  * <li>When the reordering mode is set to
860*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the Logical to Visual
861*0e209d39SAndroid Build Coastguard Worker  * Bidi algorithm used in Windows XP is used as an approximation of an "inverse Bidi" algorithm.
862*0e209d39SAndroid Build Coastguard Worker  * <br>
863*0e209d39SAndroid Build Coastguard Worker  * For example, an LTR paragraph with the content "abc FED123" (where
864*0e209d39SAndroid Build Coastguard Worker  * upper case represents RTL characters) will be transformed to "abc 123DEF."</li>
865*0e209d39SAndroid Build Coastguard Worker  * </ul>
866*0e209d39SAndroid Build Coastguard Worker  *
867*0e209d39SAndroid Build Coastguard Worker  * <p>In all the reordering modes specifying an "inverse Bidi" algorithm
868*0e209d39SAndroid Build Coastguard Worker  * (i.e. those with a name starting with <code>UBIDI_REORDER_INVERSE</code>),
869*0e209d39SAndroid Build Coastguard Worker  * output runs should be retrieved using
870*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getVisualRun()</code>, and the output text with
871*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered()</code>. The caller should keep in mind that in
872*0e209d39SAndroid Build Coastguard Worker  * "inverse Bidi" modes the input is actually visually ordered text and
873*0e209d39SAndroid Build Coastguard Worker  * reordered output returned by <code>ubidi_getVisualRun()</code> or
874*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered()</code> are actually runs or character string
875*0e209d39SAndroid Build Coastguard Worker  * of logically ordered output.<br>
876*0e209d39SAndroid Build Coastguard Worker  * For all the "inverse Bidi" modes, the source text should not contain
877*0e209d39SAndroid Build Coastguard Worker  * Bidi control characters other than LRM or RLM.</p>
878*0e209d39SAndroid Build Coastguard Worker  *
879*0e209d39SAndroid Build Coastguard Worker  * <p>Note that option <code>#UBIDI_OUTPUT_REVERSE</code> of
880*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered</code> has no useful meaning and should not be
881*0e209d39SAndroid Build Coastguard Worker  * used in conjunction with any value of the reordering mode specifying
882*0e209d39SAndroid Build Coastguard Worker  * "inverse Bidi" or with value <code>UBIDI_REORDER_RUNS_ONLY</code>.
883*0e209d39SAndroid Build Coastguard Worker  *
884*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
885*0e209d39SAndroid Build Coastguard Worker  * @param reorderingMode specifies the required variant of the Bidi algorithm.
886*0e209d39SAndroid Build Coastguard Worker  *
887*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiReorderingMode
888*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setInverse
889*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
890*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
891*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
892*0e209d39SAndroid Build Coastguard Worker  */
893*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
894*0e209d39SAndroid Build Coastguard Worker ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);
895*0e209d39SAndroid Build Coastguard Worker 
896*0e209d39SAndroid Build Coastguard Worker /**
897*0e209d39SAndroid Build Coastguard Worker  * What is the requested reordering mode for a given Bidi object?
898*0e209d39SAndroid Build Coastguard Worker  *
899*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
900*0e209d39SAndroid Build Coastguard Worker  * @return the current reordering mode of the Bidi object
901*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setReorderingMode
902*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
903*0e209d39SAndroid Build Coastguard Worker  */
904*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDiReorderingMode U_EXPORT2
905*0e209d39SAndroid Build Coastguard Worker ubidi_getReorderingMode(UBiDi *pBiDi);
906*0e209d39SAndroid Build Coastguard Worker 
907*0e209d39SAndroid Build Coastguard Worker /**
908*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDiReorderingOption</code> values indicate which options are
909*0e209d39SAndroid Build Coastguard Worker  * specified to affect the Bidi algorithm.
910*0e209d39SAndroid Build Coastguard Worker  *
911*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setReorderingOptions
912*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
913*0e209d39SAndroid Build Coastguard Worker  */
914*0e209d39SAndroid Build Coastguard Worker typedef enum UBiDiReorderingOption {
915*0e209d39SAndroid Build Coastguard Worker     /**
916*0e209d39SAndroid Build Coastguard Worker      * option value for <code>ubidi_setReorderingOptions</code>:
917*0e209d39SAndroid Build Coastguard Worker      * disable all the options which can be set with this function
918*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_setReorderingOptions
919*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.6
920*0e209d39SAndroid Build Coastguard Worker      */
921*0e209d39SAndroid Build Coastguard Worker     UBIDI_OPTION_DEFAULT = 0,
922*0e209d39SAndroid Build Coastguard Worker 
923*0e209d39SAndroid Build Coastguard Worker     /**
924*0e209d39SAndroid Build Coastguard Worker      * option bit for <code>ubidi_setReorderingOptions</code>:
925*0e209d39SAndroid Build Coastguard Worker      * insert Bidi marks (LRM or RLM) when needed to ensure correct result of
926*0e209d39SAndroid Build Coastguard Worker      * a reordering to a Logical order
927*0e209d39SAndroid Build Coastguard Worker      *
928*0e209d39SAndroid Build Coastguard Worker      * <p>This option must be set or reset before calling
929*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_setPara</code>.</p>
930*0e209d39SAndroid Build Coastguard Worker      *
931*0e209d39SAndroid Build Coastguard Worker      * <p>This option is significant only with reordering modes which generate
932*0e209d39SAndroid Build Coastguard Worker      * a result with Logical order, specifically:</p>
933*0e209d39SAndroid Build Coastguard Worker      * <ul>
934*0e209d39SAndroid Build Coastguard Worker      *   <li><code>#UBIDI_REORDER_RUNS_ONLY</code></li>
935*0e209d39SAndroid Build Coastguard Worker      *   <li><code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code></li>
936*0e209d39SAndroid Build Coastguard Worker      *   <li><code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code></li>
937*0e209d39SAndroid Build Coastguard Worker      *   <li><code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code></li>
938*0e209d39SAndroid Build Coastguard Worker      * </ul>
939*0e209d39SAndroid Build Coastguard Worker      *
940*0e209d39SAndroid Build Coastguard Worker      * <p>If this option is set in conjunction with reordering mode
941*0e209d39SAndroid Build Coastguard Worker      * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> or with calling
942*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_setInverse(true)</code>, it implies
943*0e209d39SAndroid Build Coastguard Worker      * option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>
944*0e209d39SAndroid Build Coastguard Worker      * in calls to function <code>ubidi_writeReordered()</code>.</p>
945*0e209d39SAndroid Build Coastguard Worker      *
946*0e209d39SAndroid Build Coastguard Worker      * <p>For other reordering modes, a minimum number of LRM or RLM characters
947*0e209d39SAndroid Build Coastguard Worker      * will be added to the source text after reordering it so as to ensure
948*0e209d39SAndroid Build Coastguard Worker      * round trip, i.e. when applying the inverse reordering mode on the
949*0e209d39SAndroid Build Coastguard Worker      * resulting logical text with removal of Bidi marks
950*0e209d39SAndroid Build Coastguard Worker      * (option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> set before calling
951*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_setPara()</code> or option <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
952*0e209d39SAndroid Build Coastguard Worker      * in <code>ubidi_writeReordered</code>), the result will be identical to the
953*0e209d39SAndroid Build Coastguard Worker      * source text in the first transformation.
954*0e209d39SAndroid Build Coastguard Worker      *
955*0e209d39SAndroid Build Coastguard Worker      * <p>This option will be ignored if specified together with option
956*0e209d39SAndroid Build Coastguard Worker      * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>. It inhibits option
957*0e209d39SAndroid Build Coastguard Worker      * <code>UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to function
958*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_writeReordered()</code> and it implies option
959*0e209d39SAndroid Build Coastguard Worker      * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to function
960*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_writeReordered()</code> if the reordering mode is
961*0e209d39SAndroid Build Coastguard Worker      * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.</p>
962*0e209d39SAndroid Build Coastguard Worker      *
963*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_setReorderingMode
964*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_setReorderingOptions
965*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.6
966*0e209d39SAndroid Build Coastguard Worker      */
967*0e209d39SAndroid Build Coastguard Worker     UBIDI_OPTION_INSERT_MARKS = 1,
968*0e209d39SAndroid Build Coastguard Worker 
969*0e209d39SAndroid Build Coastguard Worker     /**
970*0e209d39SAndroid Build Coastguard Worker      * option bit for <code>ubidi_setReorderingOptions</code>:
971*0e209d39SAndroid Build Coastguard Worker      * remove Bidi control characters
972*0e209d39SAndroid Build Coastguard Worker      *
973*0e209d39SAndroid Build Coastguard Worker      * <p>This option must be set or reset before calling
974*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_setPara</code>.</p>
975*0e209d39SAndroid Build Coastguard Worker      *
976*0e209d39SAndroid Build Coastguard Worker      * <p>This option nullifies option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
977*0e209d39SAndroid Build Coastguard Worker      * It inhibits option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls
978*0e209d39SAndroid Build Coastguard Worker      * to function <code>ubidi_writeReordered()</code> and it implies option
979*0e209d39SAndroid Build Coastguard Worker      * <code>#UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to that function.</p>
980*0e209d39SAndroid Build Coastguard Worker      *
981*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_setReorderingMode
982*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_setReorderingOptions
983*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.6
984*0e209d39SAndroid Build Coastguard Worker      */
985*0e209d39SAndroid Build Coastguard Worker     UBIDI_OPTION_REMOVE_CONTROLS = 2,
986*0e209d39SAndroid Build Coastguard Worker 
987*0e209d39SAndroid Build Coastguard Worker     /**
988*0e209d39SAndroid Build Coastguard Worker      * option bit for <code>ubidi_setReorderingOptions</code>:
989*0e209d39SAndroid Build Coastguard Worker      * process the output as part of a stream to be continued
990*0e209d39SAndroid Build Coastguard Worker      *
991*0e209d39SAndroid Build Coastguard Worker      * <p>This option must be set or reset before calling
992*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_setPara</code>.</p>
993*0e209d39SAndroid Build Coastguard Worker      *
994*0e209d39SAndroid Build Coastguard Worker      * <p>This option specifies that the caller is interested in processing large
995*0e209d39SAndroid Build Coastguard Worker      * text object in parts.
996*0e209d39SAndroid Build Coastguard Worker      * The results of the successive calls are expected to be concatenated by the
997*0e209d39SAndroid Build Coastguard Worker      * caller. Only the call for the last part will have this option bit off.</p>
998*0e209d39SAndroid Build Coastguard Worker      *
999*0e209d39SAndroid Build Coastguard Worker      * <p>When this option bit is on, <code>ubidi_setPara()</code> may process
1000*0e209d39SAndroid Build Coastguard Worker      * less than the full source text in order to truncate the text at a meaningful
1001*0e209d39SAndroid Build Coastguard Worker      * boundary. The caller should call <code>ubidi_getProcessedLength()</code>
1002*0e209d39SAndroid Build Coastguard Worker      * immediately after calling <code>ubidi_setPara()</code> in order to
1003*0e209d39SAndroid Build Coastguard Worker      * determine how much of the source text has been processed.
1004*0e209d39SAndroid Build Coastguard Worker      * Source text beyond that length should be resubmitted in following calls to
1005*0e209d39SAndroid Build Coastguard Worker      * <code>ubidi_setPara</code>. The processed length may be less than
1006*0e209d39SAndroid Build Coastguard Worker      * the length of the source text if a character preceding the last character of
1007*0e209d39SAndroid Build Coastguard Worker      * the source text constitutes a reasonable boundary (like a block separator)
1008*0e209d39SAndroid Build Coastguard Worker      * for text to be continued.<br>
1009*0e209d39SAndroid Build Coastguard Worker      * If the last character of the source text constitutes a reasonable
1010*0e209d39SAndroid Build Coastguard Worker      * boundary, the whole text will be processed at once.<br>
1011*0e209d39SAndroid Build Coastguard Worker      * If nowhere in the source text there exists
1012*0e209d39SAndroid Build Coastguard Worker      * such a reasonable boundary, the processed length will be zero.<br>
1013*0e209d39SAndroid Build Coastguard Worker      * The caller should check for such an occurrence and do one of the following:
1014*0e209d39SAndroid Build Coastguard Worker      * <ul><li>submit a larger amount of text with a better chance to include
1015*0e209d39SAndroid Build Coastguard Worker      *         a reasonable boundary.</li>
1016*0e209d39SAndroid Build Coastguard Worker      *     <li>resubmit the same text after turning off option
1017*0e209d39SAndroid Build Coastguard Worker      *         <code>UBIDI_OPTION_STREAMING</code>.</li></ul>
1018*0e209d39SAndroid Build Coastguard Worker      * In all cases, this option should be turned off before processing the last
1019*0e209d39SAndroid Build Coastguard Worker      * part of the text.</p>
1020*0e209d39SAndroid Build Coastguard Worker      *
1021*0e209d39SAndroid Build Coastguard Worker      * <p>When the <code>UBIDI_OPTION_STREAMING</code> option is used,
1022*0e209d39SAndroid Build Coastguard Worker      * it is recommended to call <code>ubidi_orderParagraphsLTR()</code> with
1023*0e209d39SAndroid Build Coastguard Worker      * argument <code>orderParagraphsLTR</code> set to <code>true</code> before
1024*0e209d39SAndroid Build Coastguard Worker      * calling <code>ubidi_setPara</code> so that later paragraphs may be
1025*0e209d39SAndroid Build Coastguard Worker      * concatenated to previous paragraphs on the right.</p>
1026*0e209d39SAndroid Build Coastguard Worker      *
1027*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_setReorderingMode
1028*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_setReorderingOptions
1029*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_getProcessedLength
1030*0e209d39SAndroid Build Coastguard Worker      * @see ubidi_orderParagraphsLTR
1031*0e209d39SAndroid Build Coastguard Worker      * @stable ICU 3.6
1032*0e209d39SAndroid Build Coastguard Worker      */
1033*0e209d39SAndroid Build Coastguard Worker     UBIDI_OPTION_STREAMING = 4
1034*0e209d39SAndroid Build Coastguard Worker } UBiDiReorderingOption;
1035*0e209d39SAndroid Build Coastguard Worker 
1036*0e209d39SAndroid Build Coastguard Worker /**
1037*0e209d39SAndroid Build Coastguard Worker  * Specify which of the reordering options
1038*0e209d39SAndroid Build Coastguard Worker  * should be applied during Bidi transformations.
1039*0e209d39SAndroid Build Coastguard Worker  *
1040*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
1041*0e209d39SAndroid Build Coastguard Worker  * @param reorderingOptions is a combination of zero or more of the following
1042*0e209d39SAndroid Build Coastguard Worker  * options:
1043*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_OPTION_DEFAULT</code>, <code>#UBIDI_OPTION_INSERT_MARKS</code>,
1044*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>, <code>#UBIDI_OPTION_STREAMING</code>.
1045*0e209d39SAndroid Build Coastguard Worker  *
1046*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getReorderingOptions
1047*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
1048*0e209d39SAndroid Build Coastguard Worker  */
1049*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1050*0e209d39SAndroid Build Coastguard Worker ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);
1051*0e209d39SAndroid Build Coastguard Worker 
1052*0e209d39SAndroid Build Coastguard Worker /**
1053*0e209d39SAndroid Build Coastguard Worker  * What are the reordering options applied to a given Bidi object?
1054*0e209d39SAndroid Build Coastguard Worker  *
1055*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a <code>UBiDi</code> object.
1056*0e209d39SAndroid Build Coastguard Worker  * @return the current reordering options of the Bidi object
1057*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setReorderingOptions
1058*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
1059*0e209d39SAndroid Build Coastguard Worker  */
1060*0e209d39SAndroid Build Coastguard Worker U_CAPI uint32_t U_EXPORT2
1061*0e209d39SAndroid Build Coastguard Worker ubidi_getReorderingOptions(UBiDi *pBiDi);
1062*0e209d39SAndroid Build Coastguard Worker 
1063*0e209d39SAndroid Build Coastguard Worker /**
1064*0e209d39SAndroid Build Coastguard Worker  * Set the context before a call to ubidi_setPara().<p>
1065*0e209d39SAndroid Build Coastguard Worker  *
1066*0e209d39SAndroid Build Coastguard Worker  * ubidi_setPara() computes the left-right directionality for a given piece
1067*0e209d39SAndroid Build Coastguard Worker  * of text which is supplied as one of its arguments. Sometimes this piece
1068*0e209d39SAndroid Build Coastguard Worker  * of text (the "main text") should be considered in context, because text
1069*0e209d39SAndroid Build Coastguard Worker  * appearing before ("prologue") and/or after ("epilogue") the main text
1070*0e209d39SAndroid Build Coastguard Worker  * may affect the result of this computation.<p>
1071*0e209d39SAndroid Build Coastguard Worker  *
1072*0e209d39SAndroid Build Coastguard Worker  * This function specifies the prologue and/or the epilogue for the next
1073*0e209d39SAndroid Build Coastguard Worker  * call to ubidi_setPara(). The characters specified as prologue and
1074*0e209d39SAndroid Build Coastguard Worker  * epilogue should not be modified by the calling program until the call
1075*0e209d39SAndroid Build Coastguard Worker  * to ubidi_setPara() has returned. If successive calls to ubidi_setPara()
1076*0e209d39SAndroid Build Coastguard Worker  * all need specification of a context, ubidi_setContext() must be called
1077*0e209d39SAndroid Build Coastguard Worker  * before each call to ubidi_setPara(). In other words, a context is not
1078*0e209d39SAndroid Build Coastguard Worker  * "remembered" after the following successful call to ubidi_setPara().<p>
1079*0e209d39SAndroid Build Coastguard Worker  *
1080*0e209d39SAndroid Build Coastguard Worker  * If a call to ubidi_setPara() specifies UBIDI_DEFAULT_LTR or
1081*0e209d39SAndroid Build Coastguard Worker  * UBIDI_DEFAULT_RTL as paraLevel and is preceded by a call to
1082*0e209d39SAndroid Build Coastguard Worker  * ubidi_setContext() which specifies a prologue, the paragraph level will
1083*0e209d39SAndroid Build Coastguard Worker  * be computed taking in consideration the text in the prologue.<p>
1084*0e209d39SAndroid Build Coastguard Worker  *
1085*0e209d39SAndroid Build Coastguard Worker  * When ubidi_setPara() is called without a previous call to
1086*0e209d39SAndroid Build Coastguard Worker  * ubidi_setContext, the main text is handled as if preceded and followed
1087*0e209d39SAndroid Build Coastguard Worker  * by strong directional characters at the current paragraph level.
1088*0e209d39SAndroid Build Coastguard Worker  * Calling ubidi_setContext() with specification of a prologue will change
1089*0e209d39SAndroid Build Coastguard Worker  * this behavior by handling the main text as if preceded by the last
1090*0e209d39SAndroid Build Coastguard Worker  * strong character appearing in the prologue, if any.
1091*0e209d39SAndroid Build Coastguard Worker  * Calling ubidi_setContext() with specification of an epilogue will change
1092*0e209d39SAndroid Build Coastguard Worker  * the behavior of ubidi_setPara() by handling the main text as if followed
1093*0e209d39SAndroid Build Coastguard Worker  * by the first strong character or digit appearing in the epilogue, if any.<p>
1094*0e209d39SAndroid Build Coastguard Worker  *
1095*0e209d39SAndroid Build Coastguard Worker  * Note 1: if <code>ubidi_setContext</code> is called repeatedly without
1096*0e209d39SAndroid Build Coastguard Worker  *         calling <code>ubidi_setPara</code>, the earlier calls have no effect,
1097*0e209d39SAndroid Build Coastguard Worker  *         only the last call will be remembered for the next call to
1098*0e209d39SAndroid Build Coastguard Worker  *         <code>ubidi_setPara</code>.<p>
1099*0e209d39SAndroid Build Coastguard Worker  *
1100*0e209d39SAndroid Build Coastguard Worker  * Note 2: calling <code>ubidi_setContext(pBiDi, NULL, 0, NULL, 0, &errorCode)</code>
1101*0e209d39SAndroid Build Coastguard Worker  *         cancels any previous setting of non-empty prologue or epilogue.
1102*0e209d39SAndroid Build Coastguard Worker  *         The next call to <code>ubidi_setPara()</code> will process no
1103*0e209d39SAndroid Build Coastguard Worker  *         prologue or epilogue.<p>
1104*0e209d39SAndroid Build Coastguard Worker  *
1105*0e209d39SAndroid Build Coastguard Worker  * Note 3: users must be aware that even after setting the context
1106*0e209d39SAndroid Build Coastguard Worker  *         before a call to ubidi_setPara() to perform e.g. a logical to visual
1107*0e209d39SAndroid Build Coastguard Worker  *         transformation, the resulting string may not be identical to what it
1108*0e209d39SAndroid Build Coastguard Worker  *         would have been if all the text, including prologue and epilogue, had
1109*0e209d39SAndroid Build Coastguard Worker  *         been processed together.<br>
1110*0e209d39SAndroid Build Coastguard Worker  * Example (upper case letters represent RTL characters):<br>
1111*0e209d39SAndroid Build Coastguard Worker  * &nbsp;&nbsp;prologue = "<code>abc DE</code>"<br>
1112*0e209d39SAndroid Build Coastguard Worker  * &nbsp;&nbsp;epilogue = none<br>
1113*0e209d39SAndroid Build Coastguard Worker  * &nbsp;&nbsp;main text = "<code>FGH xyz</code>"<br>
1114*0e209d39SAndroid Build Coastguard Worker  * &nbsp;&nbsp;paraLevel = UBIDI_LTR<br>
1115*0e209d39SAndroid Build Coastguard Worker  * &nbsp;&nbsp;display without prologue = "<code>HGF xyz</code>"
1116*0e209d39SAndroid Build Coastguard Worker  *             ("HGF" is adjacent to "xyz")<br>
1117*0e209d39SAndroid Build Coastguard Worker  * &nbsp;&nbsp;display with prologue = "<code>abc HGFED xyz</code>"
1118*0e209d39SAndroid Build Coastguard Worker  *             ("HGF" is not adjacent to "xyz")<br>
1119*0e209d39SAndroid Build Coastguard Worker  *
1120*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is a paragraph <code>UBiDi</code> object.
1121*0e209d39SAndroid Build Coastguard Worker  *
1122*0e209d39SAndroid Build Coastguard Worker  * @param prologue is a pointer to the text which precedes the text that
1123*0e209d39SAndroid Build Coastguard Worker  *        will be specified in a coming call to ubidi_setPara().
1124*0e209d39SAndroid Build Coastguard Worker  *        If there is no prologue to consider, then <code>proLength</code>
1125*0e209d39SAndroid Build Coastguard Worker  *        must be zero and this pointer can be NULL.
1126*0e209d39SAndroid Build Coastguard Worker  *
1127*0e209d39SAndroid Build Coastguard Worker  * @param proLength is the length of the prologue; if <code>proLength==-1</code>
1128*0e209d39SAndroid Build Coastguard Worker  *        then the prologue must be zero-terminated.
1129*0e209d39SAndroid Build Coastguard Worker  *        Otherwise proLength must be >= 0. If <code>proLength==0</code>, it means
1130*0e209d39SAndroid Build Coastguard Worker  *        that there is no prologue to consider.
1131*0e209d39SAndroid Build Coastguard Worker  *
1132*0e209d39SAndroid Build Coastguard Worker  * @param epilogue is a pointer to the text which follows the text that
1133*0e209d39SAndroid Build Coastguard Worker  *        will be specified in a coming call to ubidi_setPara().
1134*0e209d39SAndroid Build Coastguard Worker  *        If there is no epilogue to consider, then <code>epiLength</code>
1135*0e209d39SAndroid Build Coastguard Worker  *        must be zero and this pointer can be NULL.
1136*0e209d39SAndroid Build Coastguard Worker  *
1137*0e209d39SAndroid Build Coastguard Worker  * @param epiLength is the length of the epilogue; if <code>epiLength==-1</code>
1138*0e209d39SAndroid Build Coastguard Worker  *        then the epilogue must be zero-terminated.
1139*0e209d39SAndroid Build Coastguard Worker  *        Otherwise epiLength must be >= 0. If <code>epiLength==0</code>, it means
1140*0e209d39SAndroid Build Coastguard Worker  *        that there is no epilogue to consider.
1141*0e209d39SAndroid Build Coastguard Worker  *
1142*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1143*0e209d39SAndroid Build Coastguard Worker  *
1144*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
1145*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 4.8
1146*0e209d39SAndroid Build Coastguard Worker  */
1147*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1148*0e209d39SAndroid Build Coastguard Worker ubidi_setContext(UBiDi *pBiDi,
1149*0e209d39SAndroid Build Coastguard Worker                  const UChar *prologue, int32_t proLength,
1150*0e209d39SAndroid Build Coastguard Worker                  const UChar *epilogue, int32_t epiLength,
1151*0e209d39SAndroid Build Coastguard Worker                  UErrorCode *pErrorCode);
1152*0e209d39SAndroid Build Coastguard Worker 
1153*0e209d39SAndroid Build Coastguard Worker /**
1154*0e209d39SAndroid Build Coastguard Worker  * Perform the Unicode Bidi algorithm. It is defined in the
1155*0e209d39SAndroid Build Coastguard Worker  * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
1156*0e209d39SAndroid Build Coastguard Worker  * version 13,
1157*0e209d39SAndroid Build Coastguard Worker  * also described in The Unicode Standard, Version 4.0 .<p>
1158*0e209d39SAndroid Build Coastguard Worker  *
1159*0e209d39SAndroid Build Coastguard Worker  * This function takes a piece of plain text containing one or more paragraphs,
1160*0e209d39SAndroid Build Coastguard Worker  * with or without externally specified embedding levels from <i>styled</i>
1161*0e209d39SAndroid Build Coastguard Worker  * text and computes the left-right-directionality of each character.<p>
1162*0e209d39SAndroid Build Coastguard Worker  *
1163*0e209d39SAndroid Build Coastguard Worker  * If the entire text is all of the same directionality, then
1164*0e209d39SAndroid Build Coastguard Worker  * the function may not perform all the steps described by the algorithm,
1165*0e209d39SAndroid Build Coastguard Worker  * i.e., some levels may not be the same as if all steps were performed.
1166*0e209d39SAndroid Build Coastguard Worker  * This is not relevant for unidirectional text.<br>
1167*0e209d39SAndroid Build Coastguard Worker  * For example, in pure LTR text with numbers the numbers would get
1168*0e209d39SAndroid Build Coastguard Worker  * a resolved level of 2 higher than the surrounding text according to
1169*0e209d39SAndroid Build Coastguard Worker  * the algorithm. This implementation may set all resolved levels to
1170*0e209d39SAndroid Build Coastguard Worker  * the same value in such a case.<p>
1171*0e209d39SAndroid Build Coastguard Worker  *
1172*0e209d39SAndroid Build Coastguard Worker  * The text can be composed of multiple paragraphs. Occurrence of a block
1173*0e209d39SAndroid Build Coastguard Worker  * separator in the text terminates a paragraph, and whatever comes next starts
1174*0e209d39SAndroid Build Coastguard Worker  * a new paragraph. The exception to this rule is when a Carriage Return (CR)
1175*0e209d39SAndroid Build Coastguard Worker  * is followed by a Line Feed (LF). Both CR and LF are block separators, but
1176*0e209d39SAndroid Build Coastguard Worker  * in that case, the pair of characters is considered as terminating the
1177*0e209d39SAndroid Build Coastguard Worker  * preceding paragraph, and a new paragraph will be started by a character
1178*0e209d39SAndroid Build Coastguard Worker  * coming after the LF.
1179*0e209d39SAndroid Build Coastguard Worker  *
1180*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi A <code>UBiDi</code> object allocated with <code>ubidi_open()</code>
1181*0e209d39SAndroid Build Coastguard Worker  *        which will be set to contain the reordering information,
1182*0e209d39SAndroid Build Coastguard Worker  *        especially the resolved levels for all the characters in <code>text</code>.
1183*0e209d39SAndroid Build Coastguard Worker  *
1184*0e209d39SAndroid Build Coastguard Worker  * @param text is a pointer to the text that the Bidi algorithm will be performed on.
1185*0e209d39SAndroid Build Coastguard Worker  *        This pointer is stored in the UBiDi object and can be retrieved
1186*0e209d39SAndroid Build Coastguard Worker  *        with <code>ubidi_getText()</code>.<br>
1187*0e209d39SAndroid Build Coastguard Worker  *        <strong>Note:</strong> the text must be (at least) <code>length</code> long.
1188*0e209d39SAndroid Build Coastguard Worker  *
1189*0e209d39SAndroid Build Coastguard Worker  * @param length is the length of the text; if <code>length==-1</code> then
1190*0e209d39SAndroid Build Coastguard Worker  *        the text must be zero-terminated.
1191*0e209d39SAndroid Build Coastguard Worker  *
1192*0e209d39SAndroid Build Coastguard Worker  * @param paraLevel specifies the default level for the text;
1193*0e209d39SAndroid Build Coastguard Worker  *        it is typically 0 (LTR) or 1 (RTL).
1194*0e209d39SAndroid Build Coastguard Worker  *        If the function shall determine the paragraph level from the text,
1195*0e209d39SAndroid Build Coastguard Worker  *        then <code>paraLevel</code> can be set to
1196*0e209d39SAndroid Build Coastguard Worker  *        either <code>#UBIDI_DEFAULT_LTR</code>
1197*0e209d39SAndroid Build Coastguard Worker  *        or <code>#UBIDI_DEFAULT_RTL</code>; if the text contains multiple
1198*0e209d39SAndroid Build Coastguard Worker  *        paragraphs, the paragraph level shall be determined separately for
1199*0e209d39SAndroid Build Coastguard Worker  *        each paragraph; if a paragraph does not include any strongly typed
1200*0e209d39SAndroid Build Coastguard Worker  *        character, then the desired default is used (0 for LTR or 1 for RTL).
1201*0e209d39SAndroid Build Coastguard Worker  *        Any other value between 0 and <code>#UBIDI_MAX_EXPLICIT_LEVEL</code>
1202*0e209d39SAndroid Build Coastguard Worker  *        is also valid, with odd levels indicating RTL.
1203*0e209d39SAndroid Build Coastguard Worker  *
1204*0e209d39SAndroid Build Coastguard Worker  * @param embeddingLevels (in) may be used to preset the embedding and override levels,
1205*0e209d39SAndroid Build Coastguard Worker  *        ignoring characters like LRE and PDF in the text.
1206*0e209d39SAndroid Build Coastguard Worker  *        A level overrides the directional property of its corresponding
1207*0e209d39SAndroid Build Coastguard Worker  *        (same index) character if the level has the
1208*0e209d39SAndroid Build Coastguard Worker  *        <code>#UBIDI_LEVEL_OVERRIDE</code> bit set.<br><br>
1209*0e209d39SAndroid Build Coastguard Worker  *        Aside from that bit, it must be
1210*0e209d39SAndroid Build Coastguard Worker  *        <code>paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL</code>,
1211*0e209d39SAndroid Build Coastguard Worker  *        except that level 0 is always allowed.
1212*0e209d39SAndroid Build Coastguard Worker  *        Level 0 for a paragraph separator prevents reordering of paragraphs;
1213*0e209d39SAndroid Build Coastguard Worker  *        this only works reliably if <code>#UBIDI_LEVEL_OVERRIDE</code>
1214*0e209d39SAndroid Build Coastguard Worker  *        is also set for paragraph separators.
1215*0e209d39SAndroid Build Coastguard Worker  *        Level 0 for other characters is treated as a wildcard
1216*0e209d39SAndroid Build Coastguard Worker  *        and is lifted up to the resolved level of the surrounding paragraph.<br><br>
1217*0e209d39SAndroid Build Coastguard Worker  *        <strong>Caution: </strong>A copy of this pointer, not of the levels,
1218*0e209d39SAndroid Build Coastguard Worker  *        will be stored in the <code>UBiDi</code> object;
1219*0e209d39SAndroid Build Coastguard Worker  *        the <code>embeddingLevels</code> array must not be
1220*0e209d39SAndroid Build Coastguard Worker  *        deallocated before the <code>UBiDi</code> structure is destroyed or reused,
1221*0e209d39SAndroid Build Coastguard Worker  *        and the <code>embeddingLevels</code>
1222*0e209d39SAndroid Build Coastguard Worker  *        should not be modified to avoid unexpected results on subsequent Bidi operations.
1223*0e209d39SAndroid Build Coastguard Worker  *        However, the <code>ubidi_setPara()</code> and
1224*0e209d39SAndroid Build Coastguard Worker  *        <code>ubidi_setLine()</code> functions may modify some or all of the levels.<br><br>
1225*0e209d39SAndroid Build Coastguard Worker  *        After the <code>UBiDi</code> object is reused or destroyed, the caller
1226*0e209d39SAndroid Build Coastguard Worker  *        must take care of the deallocation of the <code>embeddingLevels</code> array.<br><br>
1227*0e209d39SAndroid Build Coastguard Worker  *        <strong>Note:</strong> the <code>embeddingLevels</code> array must be
1228*0e209d39SAndroid Build Coastguard Worker  *        at least <code>length</code> long.
1229*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1230*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1231*0e209d39SAndroid Build Coastguard Worker  *
1232*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1233*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1234*0e209d39SAndroid Build Coastguard Worker  */
1235*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1236*0e209d39SAndroid Build Coastguard Worker ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
1237*0e209d39SAndroid Build Coastguard Worker               UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
1238*0e209d39SAndroid Build Coastguard Worker               UErrorCode *pErrorCode);
1239*0e209d39SAndroid Build Coastguard Worker 
1240*0e209d39SAndroid Build Coastguard Worker /**
1241*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setLine()</code> sets a <code>UBiDi</code> to
1242*0e209d39SAndroid Build Coastguard Worker  * contain the reordering information, especially the resolved levels,
1243*0e209d39SAndroid Build Coastguard Worker  * for all the characters in a line of text. This line of text is
1244*0e209d39SAndroid Build Coastguard Worker  * specified by referring to a <code>UBiDi</code> object representing
1245*0e209d39SAndroid Build Coastguard Worker  * this information for a piece of text containing one or more paragraphs,
1246*0e209d39SAndroid Build Coastguard Worker  * and by specifying a range of indexes in this text.<p>
1247*0e209d39SAndroid Build Coastguard Worker  * In the new line object, the indexes will range from 0 to <code>limit-start-1</code>.<p>
1248*0e209d39SAndroid Build Coastguard Worker  *
1249*0e209d39SAndroid Build Coastguard Worker  * This is used after calling <code>ubidi_setPara()</code>
1250*0e209d39SAndroid Build Coastguard Worker  * for a piece of text, and after line-breaking on that text.
1251*0e209d39SAndroid Build Coastguard Worker  * It is not necessary if each paragraph is treated as a single line.<p>
1252*0e209d39SAndroid Build Coastguard Worker  *
1253*0e209d39SAndroid Build Coastguard Worker  * After line-breaking, rules (L1) and (L2) for the treatment of
1254*0e209d39SAndroid Build Coastguard Worker  * trailing WS and for reordering are performed on
1255*0e209d39SAndroid Build Coastguard Worker  * a <code>UBiDi</code> object that represents a line.<p>
1256*0e209d39SAndroid Build Coastguard Worker  *
1257*0e209d39SAndroid Build Coastguard Worker  * <strong>Important: </strong><code>pLineBiDi</code> shares data with
1258*0e209d39SAndroid Build Coastguard Worker  * <code>pParaBiDi</code>.
1259*0e209d39SAndroid Build Coastguard Worker  * You must destroy or reuse <code>pLineBiDi</code> before <code>pParaBiDi</code>.
1260*0e209d39SAndroid Build Coastguard Worker  * In other words, you must destroy or reuse the <code>UBiDi</code> object for a line
1261*0e209d39SAndroid Build Coastguard Worker  * before the object for its parent paragraph.<p>
1262*0e209d39SAndroid Build Coastguard Worker  *
1263*0e209d39SAndroid Build Coastguard Worker  * The text pointer that was stored in <code>pParaBiDi</code> is also copied,
1264*0e209d39SAndroid Build Coastguard Worker  * and <code>start</code> is added to it so that it points to the beginning of the
1265*0e209d39SAndroid Build Coastguard Worker  * line for this object.
1266*0e209d39SAndroid Build Coastguard Worker  *
1267*0e209d39SAndroid Build Coastguard Worker  * @param pParaBiDi is the parent paragraph object. It must have been set
1268*0e209d39SAndroid Build Coastguard Worker  * by a successful call to ubidi_setPara.
1269*0e209d39SAndroid Build Coastguard Worker  *
1270*0e209d39SAndroid Build Coastguard Worker  * @param start is the line's first index into the text.
1271*0e209d39SAndroid Build Coastguard Worker  *
1272*0e209d39SAndroid Build Coastguard Worker  * @param limit is just behind the line's last index into the text
1273*0e209d39SAndroid Build Coastguard Worker  *        (its last index +1).<br>
1274*0e209d39SAndroid Build Coastguard Worker  *        It must be <code>0<=start<limit<=</code>containing paragraph limit.
1275*0e209d39SAndroid Build Coastguard Worker  *        If the specified line crosses a paragraph boundary, the function
1276*0e209d39SAndroid Build Coastguard Worker  *        will terminate with error code U_ILLEGAL_ARGUMENT_ERROR.
1277*0e209d39SAndroid Build Coastguard Worker  *
1278*0e209d39SAndroid Build Coastguard Worker  * @param pLineBiDi is the object that will now represent a line of the text.
1279*0e209d39SAndroid Build Coastguard Worker  *
1280*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1281*0e209d39SAndroid Build Coastguard Worker  *
1282*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
1283*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1284*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1285*0e209d39SAndroid Build Coastguard Worker  */
1286*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1287*0e209d39SAndroid Build Coastguard Worker ubidi_setLine(const UBiDi *pParaBiDi,
1288*0e209d39SAndroid Build Coastguard Worker               int32_t start, int32_t limit,
1289*0e209d39SAndroid Build Coastguard Worker               UBiDi *pLineBiDi,
1290*0e209d39SAndroid Build Coastguard Worker               UErrorCode *pErrorCode);
1291*0e209d39SAndroid Build Coastguard Worker 
1292*0e209d39SAndroid Build Coastguard Worker /**
1293*0e209d39SAndroid Build Coastguard Worker  * Get the directionality of the text.
1294*0e209d39SAndroid Build Coastguard Worker  *
1295*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1296*0e209d39SAndroid Build Coastguard Worker  *
1297*0e209d39SAndroid Build Coastguard Worker  * @return a value of <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>
1298*0e209d39SAndroid Build Coastguard Worker  *         or <code>UBIDI_MIXED</code>
1299*0e209d39SAndroid Build Coastguard Worker  *         that indicates if the entire text
1300*0e209d39SAndroid Build Coastguard Worker  *         represented by this object is unidirectional,
1301*0e209d39SAndroid Build Coastguard Worker  *         and which direction, or if it is mixed-directional.
1302*0e209d39SAndroid Build Coastguard Worker  * Note -  The value <code>UBIDI_NEUTRAL</code> is never returned from this method.
1303*0e209d39SAndroid Build Coastguard Worker  *
1304*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiDirection
1305*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1306*0e209d39SAndroid Build Coastguard Worker  */
1307*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDiDirection U_EXPORT2
1308*0e209d39SAndroid Build Coastguard Worker ubidi_getDirection(const UBiDi *pBiDi);
1309*0e209d39SAndroid Build Coastguard Worker 
1310*0e209d39SAndroid Build Coastguard Worker /**
1311*0e209d39SAndroid Build Coastguard Worker  * Gets the base direction of the text provided according
1312*0e209d39SAndroid Build Coastguard Worker  * to the Unicode Bidirectional Algorithm. The base direction
1313*0e209d39SAndroid Build Coastguard Worker  * is derived from the first character in the string with bidirectional
1314*0e209d39SAndroid Build Coastguard Worker  * character type L, R, or AL. If the first such character has type L,
1315*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_LTR</code> is returned. If the first such character has
1316*0e209d39SAndroid Build Coastguard Worker  * type R or AL, <code>UBIDI_RTL</code> is returned. If the string does
1317*0e209d39SAndroid Build Coastguard Worker  * not contain any character of these types, then
1318*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_NEUTRAL</code> is returned.
1319*0e209d39SAndroid Build Coastguard Worker  *
1320*0e209d39SAndroid Build Coastguard Worker  * This is a lightweight function for use when only the base direction
1321*0e209d39SAndroid Build Coastguard Worker  * is needed and no further bidi processing of the text is needed.
1322*0e209d39SAndroid Build Coastguard Worker  *
1323*0e209d39SAndroid Build Coastguard Worker  * @param text is a pointer to the text whose base
1324*0e209d39SAndroid Build Coastguard Worker  *             direction is needed.
1325*0e209d39SAndroid Build Coastguard Worker  * Note: the text must be (at least) @c length long.
1326*0e209d39SAndroid Build Coastguard Worker  *
1327*0e209d39SAndroid Build Coastguard Worker  * @param length is the length of the text;
1328*0e209d39SAndroid Build Coastguard Worker  *               if <code>length==-1</code> then the text
1329*0e209d39SAndroid Build Coastguard Worker  *               must be zero-terminated.
1330*0e209d39SAndroid Build Coastguard Worker  *
1331*0e209d39SAndroid Build Coastguard Worker  * @return  <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>,
1332*0e209d39SAndroid Build Coastguard Worker  *          <code>UBIDI_NEUTRAL</code>
1333*0e209d39SAndroid Build Coastguard Worker  *
1334*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiDirection
1335*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 4.6
1336*0e209d39SAndroid Build Coastguard Worker  */
1337*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDiDirection U_EXPORT2
1338*0e209d39SAndroid Build Coastguard Worker ubidi_getBaseDirection(const UChar *text,  int32_t length );
1339*0e209d39SAndroid Build Coastguard Worker 
1340*0e209d39SAndroid Build Coastguard Worker /**
1341*0e209d39SAndroid Build Coastguard Worker  * Get the pointer to the text.
1342*0e209d39SAndroid Build Coastguard Worker  *
1343*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1344*0e209d39SAndroid Build Coastguard Worker  *
1345*0e209d39SAndroid Build Coastguard Worker  * @return The pointer to the text that the UBiDi object was created for.
1346*0e209d39SAndroid Build Coastguard Worker  *
1347*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
1348*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setLine
1349*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1350*0e209d39SAndroid Build Coastguard Worker  */
1351*0e209d39SAndroid Build Coastguard Worker U_CAPI const UChar * U_EXPORT2
1352*0e209d39SAndroid Build Coastguard Worker ubidi_getText(const UBiDi *pBiDi);
1353*0e209d39SAndroid Build Coastguard Worker 
1354*0e209d39SAndroid Build Coastguard Worker /**
1355*0e209d39SAndroid Build Coastguard Worker  * Get the length of the text.
1356*0e209d39SAndroid Build Coastguard Worker  *
1357*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1358*0e209d39SAndroid Build Coastguard Worker  *
1359*0e209d39SAndroid Build Coastguard Worker  * @return The length of the text that the UBiDi object was created for.
1360*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1361*0e209d39SAndroid Build Coastguard Worker  */
1362*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1363*0e209d39SAndroid Build Coastguard Worker ubidi_getLength(const UBiDi *pBiDi);
1364*0e209d39SAndroid Build Coastguard Worker 
1365*0e209d39SAndroid Build Coastguard Worker /**
1366*0e209d39SAndroid Build Coastguard Worker  * Get the paragraph level of the text.
1367*0e209d39SAndroid Build Coastguard Worker  *
1368*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1369*0e209d39SAndroid Build Coastguard Worker  *
1370*0e209d39SAndroid Build Coastguard Worker  * @return The paragraph level. If there are multiple paragraphs, their
1371*0e209d39SAndroid Build Coastguard Worker  *         level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or
1372*0e209d39SAndroid Build Coastguard Worker  *         UBIDI_DEFAULT_RTL.  In that case, the level of the first paragraph
1373*0e209d39SAndroid Build Coastguard Worker  *         is returned.
1374*0e209d39SAndroid Build Coastguard Worker  *
1375*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiLevel
1376*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getParagraph
1377*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getParagraphByIndex
1378*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1379*0e209d39SAndroid Build Coastguard Worker  */
1380*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDiLevel U_EXPORT2
1381*0e209d39SAndroid Build Coastguard Worker ubidi_getParaLevel(const UBiDi *pBiDi);
1382*0e209d39SAndroid Build Coastguard Worker 
1383*0e209d39SAndroid Build Coastguard Worker /**
1384*0e209d39SAndroid Build Coastguard Worker  * Get the number of paragraphs.
1385*0e209d39SAndroid Build Coastguard Worker  *
1386*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1387*0e209d39SAndroid Build Coastguard Worker  *
1388*0e209d39SAndroid Build Coastguard Worker  * @return The number of paragraphs.
1389*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.4
1390*0e209d39SAndroid Build Coastguard Worker  */
1391*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1392*0e209d39SAndroid Build Coastguard Worker ubidi_countParagraphs(UBiDi *pBiDi);
1393*0e209d39SAndroid Build Coastguard Worker 
1394*0e209d39SAndroid Build Coastguard Worker /**
1395*0e209d39SAndroid Build Coastguard Worker  * Get a paragraph, given a position within the text.
1396*0e209d39SAndroid Build Coastguard Worker  * This function returns information about a paragraph.<br>
1397*0e209d39SAndroid Build Coastguard Worker  * Note: if the paragraph index is known, it is more efficient to
1398*0e209d39SAndroid Build Coastguard Worker  * retrieve the paragraph information using ubidi_getParagraphByIndex().<p>
1399*0e209d39SAndroid Build Coastguard Worker  *
1400*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1401*0e209d39SAndroid Build Coastguard Worker  *
1402*0e209d39SAndroid Build Coastguard Worker  * @param charIndex is the index of a character within the text, in the
1403*0e209d39SAndroid Build Coastguard Worker  *        range <code>[0..ubidi_getProcessedLength(pBiDi)-1]</code>.
1404*0e209d39SAndroid Build Coastguard Worker  *
1405*0e209d39SAndroid Build Coastguard Worker  * @param pParaStart will receive the index of the first character of the
1406*0e209d39SAndroid Build Coastguard Worker  *        paragraph in the text.
1407*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1408*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1409*0e209d39SAndroid Build Coastguard Worker  *
1410*0e209d39SAndroid Build Coastguard Worker  * @param pParaLimit will receive the limit of the paragraph.
1411*0e209d39SAndroid Build Coastguard Worker  *        The l-value that you point to here may be the
1412*0e209d39SAndroid Build Coastguard Worker  *        same expression (variable) as the one for
1413*0e209d39SAndroid Build Coastguard Worker  *        <code>charIndex</code>.
1414*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1415*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1416*0e209d39SAndroid Build Coastguard Worker  *
1417*0e209d39SAndroid Build Coastguard Worker  * @param pParaLevel will receive the level of the paragraph.
1418*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1419*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1420*0e209d39SAndroid Build Coastguard Worker  *
1421*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1422*0e209d39SAndroid Build Coastguard Worker  *
1423*0e209d39SAndroid Build Coastguard Worker  * @return The index of the paragraph containing the specified position.
1424*0e209d39SAndroid Build Coastguard Worker  *
1425*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1426*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.4
1427*0e209d39SAndroid Build Coastguard Worker  */
1428*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1429*0e209d39SAndroid Build Coastguard Worker ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,
1430*0e209d39SAndroid Build Coastguard Worker                    int32_t *pParaLimit, UBiDiLevel *pParaLevel,
1431*0e209d39SAndroid Build Coastguard Worker                    UErrorCode *pErrorCode);
1432*0e209d39SAndroid Build Coastguard Worker 
1433*0e209d39SAndroid Build Coastguard Worker /**
1434*0e209d39SAndroid Build Coastguard Worker  * Get a paragraph, given the index of this paragraph.
1435*0e209d39SAndroid Build Coastguard Worker  *
1436*0e209d39SAndroid Build Coastguard Worker  * This function returns information about a paragraph.<p>
1437*0e209d39SAndroid Build Coastguard Worker  *
1438*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph <code>UBiDi</code> object.
1439*0e209d39SAndroid Build Coastguard Worker  *
1440*0e209d39SAndroid Build Coastguard Worker  * @param paraIndex is the number of the paragraph, in the
1441*0e209d39SAndroid Build Coastguard Worker  *        range <code>[0..ubidi_countParagraphs(pBiDi)-1]</code>.
1442*0e209d39SAndroid Build Coastguard Worker  *
1443*0e209d39SAndroid Build Coastguard Worker  * @param pParaStart will receive the index of the first character of the
1444*0e209d39SAndroid Build Coastguard Worker  *        paragraph in the text.
1445*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1446*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1447*0e209d39SAndroid Build Coastguard Worker  *
1448*0e209d39SAndroid Build Coastguard Worker  * @param pParaLimit will receive the limit of the paragraph.
1449*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1450*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1451*0e209d39SAndroid Build Coastguard Worker  *
1452*0e209d39SAndroid Build Coastguard Worker  * @param pParaLevel will receive the level of the paragraph.
1453*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1454*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1455*0e209d39SAndroid Build Coastguard Worker  *
1456*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1457*0e209d39SAndroid Build Coastguard Worker  *
1458*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.4
1459*0e209d39SAndroid Build Coastguard Worker  */
1460*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1461*0e209d39SAndroid Build Coastguard Worker ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,
1462*0e209d39SAndroid Build Coastguard Worker                           int32_t *pParaStart, int32_t *pParaLimit,
1463*0e209d39SAndroid Build Coastguard Worker                           UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);
1464*0e209d39SAndroid Build Coastguard Worker 
1465*0e209d39SAndroid Build Coastguard Worker /**
1466*0e209d39SAndroid Build Coastguard Worker  * Get the level for one character.
1467*0e209d39SAndroid Build Coastguard Worker  *
1468*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1469*0e209d39SAndroid Build Coastguard Worker  *
1470*0e209d39SAndroid Build Coastguard Worker  * @param charIndex the index of a character. It must be in the range
1471*0e209d39SAndroid Build Coastguard Worker  *         [0..ubidi_getProcessedLength(pBiDi)].
1472*0e209d39SAndroid Build Coastguard Worker  *
1473*0e209d39SAndroid Build Coastguard Worker  * @return The level for the character at charIndex (0 if charIndex is not
1474*0e209d39SAndroid Build Coastguard Worker  *         in the valid range).
1475*0e209d39SAndroid Build Coastguard Worker  *
1476*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiLevel
1477*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1478*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1479*0e209d39SAndroid Build Coastguard Worker  */
1480*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDiLevel U_EXPORT2
1481*0e209d39SAndroid Build Coastguard Worker ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);
1482*0e209d39SAndroid Build Coastguard Worker 
1483*0e209d39SAndroid Build Coastguard Worker /**
1484*0e209d39SAndroid Build Coastguard Worker  * Get an array of levels for each character.<p>
1485*0e209d39SAndroid Build Coastguard Worker  *
1486*0e209d39SAndroid Build Coastguard Worker  * Note that this function may allocate memory under some
1487*0e209d39SAndroid Build Coastguard Worker  * circumstances, unlike <code>ubidi_getLevelAt()</code>.
1488*0e209d39SAndroid Build Coastguard Worker  *
1489*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object, whose
1490*0e209d39SAndroid Build Coastguard Worker  *        text length must be strictly positive.
1491*0e209d39SAndroid Build Coastguard Worker  *
1492*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1493*0e209d39SAndroid Build Coastguard Worker  *
1494*0e209d39SAndroid Build Coastguard Worker  * @return The levels array for the text,
1495*0e209d39SAndroid Build Coastguard Worker  *         or <code>NULL</code> if an error occurs.
1496*0e209d39SAndroid Build Coastguard Worker  *
1497*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiLevel
1498*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1499*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1500*0e209d39SAndroid Build Coastguard Worker  */
1501*0e209d39SAndroid Build Coastguard Worker U_CAPI const UBiDiLevel * U_EXPORT2
1502*0e209d39SAndroid Build Coastguard Worker ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);
1503*0e209d39SAndroid Build Coastguard Worker 
1504*0e209d39SAndroid Build Coastguard Worker /**
1505*0e209d39SAndroid Build Coastguard Worker  * Get a logical run.
1506*0e209d39SAndroid Build Coastguard Worker  * This function returns information about a run and is used
1507*0e209d39SAndroid Build Coastguard Worker  * to retrieve runs in logical order.<p>
1508*0e209d39SAndroid Build Coastguard Worker  * This is especially useful for line-breaking on a paragraph.
1509*0e209d39SAndroid Build Coastguard Worker  *
1510*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1511*0e209d39SAndroid Build Coastguard Worker  *
1512*0e209d39SAndroid Build Coastguard Worker  * @param logicalPosition is a logical position within the source text.
1513*0e209d39SAndroid Build Coastguard Worker  *
1514*0e209d39SAndroid Build Coastguard Worker  * @param pLogicalLimit will receive the limit of the corresponding run.
1515*0e209d39SAndroid Build Coastguard Worker  *        The l-value that you point to here may be the
1516*0e209d39SAndroid Build Coastguard Worker  *        same expression (variable) as the one for
1517*0e209d39SAndroid Build Coastguard Worker  *        <code>logicalPosition</code>.
1518*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1519*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1520*0e209d39SAndroid Build Coastguard Worker  *
1521*0e209d39SAndroid Build Coastguard Worker  * @param pLevel will receive the level of the corresponding run.
1522*0e209d39SAndroid Build Coastguard Worker  *        This pointer can be <code>NULL</code> if this
1523*0e209d39SAndroid Build Coastguard Worker  *        value is not necessary.
1524*0e209d39SAndroid Build Coastguard Worker  *
1525*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1526*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1527*0e209d39SAndroid Build Coastguard Worker  */
1528*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1529*0e209d39SAndroid Build Coastguard Worker ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,
1530*0e209d39SAndroid Build Coastguard Worker                     int32_t *pLogicalLimit, UBiDiLevel *pLevel);
1531*0e209d39SAndroid Build Coastguard Worker 
1532*0e209d39SAndroid Build Coastguard Worker /**
1533*0e209d39SAndroid Build Coastguard Worker  * Get the number of runs.
1534*0e209d39SAndroid Build Coastguard Worker  * This function may invoke the actual reordering on the
1535*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDi</code> object, after <code>ubidi_setPara()</code>
1536*0e209d39SAndroid Build Coastguard Worker  * may have resolved only the levels of the text. Therefore,
1537*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_countRuns()</code> may have to allocate memory,
1538*0e209d39SAndroid Build Coastguard Worker  * and may fail doing so.
1539*0e209d39SAndroid Build Coastguard Worker  *
1540*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1541*0e209d39SAndroid Build Coastguard Worker  *
1542*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1543*0e209d39SAndroid Build Coastguard Worker  *
1544*0e209d39SAndroid Build Coastguard Worker  * @return The number of runs.
1545*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1546*0e209d39SAndroid Build Coastguard Worker  */
1547*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1548*0e209d39SAndroid Build Coastguard Worker ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
1549*0e209d39SAndroid Build Coastguard Worker 
1550*0e209d39SAndroid Build Coastguard Worker /**
1551*0e209d39SAndroid Build Coastguard Worker  * Get one run's logical start, length, and directionality,
1552*0e209d39SAndroid Build Coastguard Worker  * which can be 0 for LTR or 1 for RTL.
1553*0e209d39SAndroid Build Coastguard Worker  * In an RTL run, the character at the logical start is
1554*0e209d39SAndroid Build Coastguard Worker  * visually on the right of the displayed run.
1555*0e209d39SAndroid Build Coastguard Worker  * The length is the number of characters in the run.<p>
1556*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_countRuns()</code> should be called
1557*0e209d39SAndroid Build Coastguard Worker  * before the runs are retrieved.
1558*0e209d39SAndroid Build Coastguard Worker  *
1559*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1560*0e209d39SAndroid Build Coastguard Worker  *
1561*0e209d39SAndroid Build Coastguard Worker  * @param runIndex is the number of the run in visual order, in the
1562*0e209d39SAndroid Build Coastguard Worker  *        range <code>[0..ubidi_countRuns(pBiDi)-1]</code>.
1563*0e209d39SAndroid Build Coastguard Worker  *
1564*0e209d39SAndroid Build Coastguard Worker  * @param pLogicalStart is the first logical character index in the text.
1565*0e209d39SAndroid Build Coastguard Worker  *        The pointer may be <code>NULL</code> if this index is not needed.
1566*0e209d39SAndroid Build Coastguard Worker  *
1567*0e209d39SAndroid Build Coastguard Worker  * @param pLength is the number of characters (at least one) in the run.
1568*0e209d39SAndroid Build Coastguard Worker  *        The pointer may be <code>NULL</code> if this is not needed.
1569*0e209d39SAndroid Build Coastguard Worker  *
1570*0e209d39SAndroid Build Coastguard Worker  * @return the directionality of the run,
1571*0e209d39SAndroid Build Coastguard Worker  *         <code>UBIDI_LTR==0</code> or <code>UBIDI_RTL==1</code>,
1572*0e209d39SAndroid Build Coastguard Worker  *         never <code>UBIDI_MIXED</code>,
1573*0e209d39SAndroid Build Coastguard Worker  *         never <code>UBIDI_NEUTRAL</code>.
1574*0e209d39SAndroid Build Coastguard Worker  *
1575*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_countRuns
1576*0e209d39SAndroid Build Coastguard Worker  *
1577*0e209d39SAndroid Build Coastguard Worker  * Example:
1578*0e209d39SAndroid Build Coastguard Worker  * <pre>
1579*0e209d39SAndroid Build Coastguard Worker  * \code
1580*0e209d39SAndroid Build Coastguard Worker  * int32_t i, count=ubidi_countRuns(pBiDi),
1581*0e209d39SAndroid Build Coastguard Worker  *         logicalStart, visualIndex=0, length;
1582*0e209d39SAndroid Build Coastguard Worker  * for(i=0; i<count; ++i) {
1583*0e209d39SAndroid Build Coastguard Worker  *    if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {
1584*0e209d39SAndroid Build Coastguard Worker  *         do { // LTR
1585*0e209d39SAndroid Build Coastguard Worker  *             show_char(text[logicalStart++], visualIndex++);
1586*0e209d39SAndroid Build Coastguard Worker  *         } while(--length>0);
1587*0e209d39SAndroid Build Coastguard Worker  *     } else {
1588*0e209d39SAndroid Build Coastguard Worker  *         logicalStart+=length;  // logicalLimit
1589*0e209d39SAndroid Build Coastguard Worker  *         do { // RTL
1590*0e209d39SAndroid Build Coastguard Worker  *             show_char(text[--logicalStart], visualIndex++);
1591*0e209d39SAndroid Build Coastguard Worker  *         } while(--length>0);
1592*0e209d39SAndroid Build Coastguard Worker  *     }
1593*0e209d39SAndroid Build Coastguard Worker  * }
1594*0e209d39SAndroid Build Coastguard Worker  *\endcode
1595*0e209d39SAndroid Build Coastguard Worker  * </pre>
1596*0e209d39SAndroid Build Coastguard Worker  *
1597*0e209d39SAndroid Build Coastguard Worker  * Note that in right-to-left runs, code like this places
1598*0e209d39SAndroid Build Coastguard Worker  * second surrogates before first ones (which is generally a bad idea)
1599*0e209d39SAndroid Build Coastguard Worker  * and combining characters before base characters.
1600*0e209d39SAndroid Build Coastguard Worker  * <p>
1601*0e209d39SAndroid Build Coastguard Worker  * Use of <code>ubidi_writeReordered()</code>, optionally with the
1602*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_KEEP_BASE_COMBINING</code> option, can be considered in order
1603*0e209d39SAndroid Build Coastguard Worker  * to avoid these issues.
1604*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1605*0e209d39SAndroid Build Coastguard Worker  */
1606*0e209d39SAndroid Build Coastguard Worker U_CAPI UBiDiDirection U_EXPORT2
1607*0e209d39SAndroid Build Coastguard Worker ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,
1608*0e209d39SAndroid Build Coastguard Worker                    int32_t *pLogicalStart, int32_t *pLength);
1609*0e209d39SAndroid Build Coastguard Worker 
1610*0e209d39SAndroid Build Coastguard Worker /**
1611*0e209d39SAndroid Build Coastguard Worker  * Get the visual position from a logical text position.
1612*0e209d39SAndroid Build Coastguard Worker  * If such a mapping is used many times on the same
1613*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDi</code> object, then calling
1614*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getLogicalMap()</code> is more efficient.<p>
1615*0e209d39SAndroid Build Coastguard Worker  *
1616*0e209d39SAndroid Build Coastguard Worker  * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
1617*0e209d39SAndroid Build Coastguard Worker  * visual position because the corresponding text character is a Bidi control
1618*0e209d39SAndroid Build Coastguard Worker  * removed from output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
1619*0e209d39SAndroid Build Coastguard Worker  * <p>
1620*0e209d39SAndroid Build Coastguard Worker  * When the visual output is altered by using options of
1621*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
1622*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
1623*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual position returned may not
1624*0e209d39SAndroid Build Coastguard Worker  * be correct. It is advised to use, when possible, reordering options
1625*0e209d39SAndroid Build Coastguard Worker  * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
1626*0e209d39SAndroid Build Coastguard Worker  * <p>
1627*0e209d39SAndroid Build Coastguard Worker  * Note that in right-to-left runs, this mapping places
1628*0e209d39SAndroid Build Coastguard Worker  * second surrogates before first ones (which is generally a bad idea)
1629*0e209d39SAndroid Build Coastguard Worker  * and combining characters before base characters.
1630*0e209d39SAndroid Build Coastguard Worker  * Use of <code>ubidi_writeReordered()</code>, optionally with the
1631*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
1632*0e209d39SAndroid Build Coastguard Worker  * of using the mapping, in order to avoid these issues.
1633*0e209d39SAndroid Build Coastguard Worker  *
1634*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1635*0e209d39SAndroid Build Coastguard Worker  *
1636*0e209d39SAndroid Build Coastguard Worker  * @param logicalIndex is the index of a character in the text.
1637*0e209d39SAndroid Build Coastguard Worker  *
1638*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1639*0e209d39SAndroid Build Coastguard Worker  *
1640*0e209d39SAndroid Build Coastguard Worker  * @return The visual position of this character.
1641*0e209d39SAndroid Build Coastguard Worker  *
1642*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getLogicalMap
1643*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getLogicalIndex
1644*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1645*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1646*0e209d39SAndroid Build Coastguard Worker  */
1647*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1648*0e209d39SAndroid Build Coastguard Worker ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode);
1649*0e209d39SAndroid Build Coastguard Worker 
1650*0e209d39SAndroid Build Coastguard Worker /**
1651*0e209d39SAndroid Build Coastguard Worker  * Get the logical text position from a visual position.
1652*0e209d39SAndroid Build Coastguard Worker  * If such a mapping is used many times on the same
1653*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDi</code> object, then calling
1654*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getVisualMap()</code> is more efficient.<p>
1655*0e209d39SAndroid Build Coastguard Worker  *
1656*0e209d39SAndroid Build Coastguard Worker  * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
1657*0e209d39SAndroid Build Coastguard Worker  * logical position because the corresponding text character is a Bidi mark
1658*0e209d39SAndroid Build Coastguard Worker  * inserted in the output by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
1659*0e209d39SAndroid Build Coastguard Worker  * <p>
1660*0e209d39SAndroid Build Coastguard Worker  * This is the inverse function to <code>ubidi_getVisualIndex()</code>.
1661*0e209d39SAndroid Build Coastguard Worker  * <p>
1662*0e209d39SAndroid Build Coastguard Worker  * When the visual output is altered by using options of
1663*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
1664*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
1665*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical position returned may not
1666*0e209d39SAndroid Build Coastguard Worker  * be correct. It is advised to use, when possible, reordering options
1667*0e209d39SAndroid Build Coastguard Worker  * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
1668*0e209d39SAndroid Build Coastguard Worker  *
1669*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1670*0e209d39SAndroid Build Coastguard Worker  *
1671*0e209d39SAndroid Build Coastguard Worker  * @param visualIndex is the visual position of a character.
1672*0e209d39SAndroid Build Coastguard Worker  *
1673*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1674*0e209d39SAndroid Build Coastguard Worker  *
1675*0e209d39SAndroid Build Coastguard Worker  * @return The index of this character in the text.
1676*0e209d39SAndroid Build Coastguard Worker  *
1677*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getVisualMap
1678*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getVisualIndex
1679*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getResultLength
1680*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1681*0e209d39SAndroid Build Coastguard Worker  */
1682*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1683*0e209d39SAndroid Build Coastguard Worker ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);
1684*0e209d39SAndroid Build Coastguard Worker 
1685*0e209d39SAndroid Build Coastguard Worker /**
1686*0e209d39SAndroid Build Coastguard Worker  * Get a logical-to-visual index map (array) for the characters in the UBiDi
1687*0e209d39SAndroid Build Coastguard Worker  * (paragraph or line) object.
1688*0e209d39SAndroid Build Coastguard Worker  * <p>
1689*0e209d39SAndroid Build Coastguard Worker  * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
1690*0e209d39SAndroid Build Coastguard Worker  * corresponding text characters are Bidi controls removed from the visual
1691*0e209d39SAndroid Build Coastguard Worker  * output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
1692*0e209d39SAndroid Build Coastguard Worker  * <p>
1693*0e209d39SAndroid Build Coastguard Worker  * When the visual output is altered by using options of
1694*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
1695*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
1696*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual positions returned may not
1697*0e209d39SAndroid Build Coastguard Worker  * be correct. It is advised to use, when possible, reordering options
1698*0e209d39SAndroid Build Coastguard Worker  * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
1699*0e209d39SAndroid Build Coastguard Worker  * <p>
1700*0e209d39SAndroid Build Coastguard Worker  * Note that in right-to-left runs, this mapping places
1701*0e209d39SAndroid Build Coastguard Worker  * second surrogates before first ones (which is generally a bad idea)
1702*0e209d39SAndroid Build Coastguard Worker  * and combining characters before base characters.
1703*0e209d39SAndroid Build Coastguard Worker  * Use of <code>ubidi_writeReordered()</code>, optionally with the
1704*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
1705*0e209d39SAndroid Build Coastguard Worker  * of using the mapping, in order to avoid these issues.
1706*0e209d39SAndroid Build Coastguard Worker  *
1707*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1708*0e209d39SAndroid Build Coastguard Worker  *
1709*0e209d39SAndroid Build Coastguard Worker  * @param indexMap is a pointer to an array of <code>ubidi_getProcessedLength()</code>
1710*0e209d39SAndroid Build Coastguard Worker  *        indexes which will reflect the reordering of the characters.
1711*0e209d39SAndroid Build Coastguard Worker  *        If option <code>#UBIDI_OPTION_INSERT_MARKS</code> is set, the number
1712*0e209d39SAndroid Build Coastguard Worker  *        of elements allocated in <code>indexMap</code> must be no less than
1713*0e209d39SAndroid Build Coastguard Worker  *        <code>ubidi_getResultLength()</code>.
1714*0e209d39SAndroid Build Coastguard Worker  *        The array does not need to be initialized.<br><br>
1715*0e209d39SAndroid Build Coastguard Worker  *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
1716*0e209d39SAndroid Build Coastguard Worker  *
1717*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1718*0e209d39SAndroid Build Coastguard Worker  *
1719*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getVisualMap
1720*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getVisualIndex
1721*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1722*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getResultLength
1723*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1724*0e209d39SAndroid Build Coastguard Worker  */
1725*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1726*0e209d39SAndroid Build Coastguard Worker ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
1727*0e209d39SAndroid Build Coastguard Worker 
1728*0e209d39SAndroid Build Coastguard Worker /**
1729*0e209d39SAndroid Build Coastguard Worker  * Get a visual-to-logical index map (array) for the characters in the UBiDi
1730*0e209d39SAndroid Build Coastguard Worker  * (paragraph or line) object.
1731*0e209d39SAndroid Build Coastguard Worker  * <p>
1732*0e209d39SAndroid Build Coastguard Worker  * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
1733*0e209d39SAndroid Build Coastguard Worker  * corresponding text characters are Bidi marks inserted in the visual output
1734*0e209d39SAndroid Build Coastguard Worker  * by the option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
1735*0e209d39SAndroid Build Coastguard Worker  * <p>
1736*0e209d39SAndroid Build Coastguard Worker  * When the visual output is altered by using options of
1737*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
1738*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
1739*0e209d39SAndroid Build Coastguard Worker  * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical positions returned may not
1740*0e209d39SAndroid Build Coastguard Worker  * be correct. It is advised to use, when possible, reordering options
1741*0e209d39SAndroid Build Coastguard Worker  * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
1742*0e209d39SAndroid Build Coastguard Worker  *
1743*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
1744*0e209d39SAndroid Build Coastguard Worker  *
1745*0e209d39SAndroid Build Coastguard Worker  * @param indexMap is a pointer to an array of <code>ubidi_getResultLength()</code>
1746*0e209d39SAndroid Build Coastguard Worker  *        indexes which will reflect the reordering of the characters.
1747*0e209d39SAndroid Build Coastguard Worker  *        If option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is set, the number
1748*0e209d39SAndroid Build Coastguard Worker  *        of elements allocated in <code>indexMap</code> must be no less than
1749*0e209d39SAndroid Build Coastguard Worker  *        <code>ubidi_getProcessedLength()</code>.
1750*0e209d39SAndroid Build Coastguard Worker  *        The array does not need to be initialized.<br><br>
1751*0e209d39SAndroid Build Coastguard Worker  *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
1752*0e209d39SAndroid Build Coastguard Worker  *
1753*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
1754*0e209d39SAndroid Build Coastguard Worker  *
1755*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getLogicalMap
1756*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getLogicalIndex
1757*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
1758*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getResultLength
1759*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1760*0e209d39SAndroid Build Coastguard Worker  */
1761*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1762*0e209d39SAndroid Build Coastguard Worker ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
1763*0e209d39SAndroid Build Coastguard Worker 
1764*0e209d39SAndroid Build Coastguard Worker /**
1765*0e209d39SAndroid Build Coastguard Worker  * This is a convenience function that does not use a UBiDi object.
1766*0e209d39SAndroid Build Coastguard Worker  * It is intended to be used for when an application has determined the levels
1767*0e209d39SAndroid Build Coastguard Worker  * of objects (character sequences) and just needs to have them reordered (L2).
1768*0e209d39SAndroid Build Coastguard Worker  * This is equivalent to using <code>ubidi_getLogicalMap()</code> on a
1769*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDi</code> object.
1770*0e209d39SAndroid Build Coastguard Worker  *
1771*0e209d39SAndroid Build Coastguard Worker  * @param levels is an array with <code>length</code> levels that have been determined by
1772*0e209d39SAndroid Build Coastguard Worker  *        the application.
1773*0e209d39SAndroid Build Coastguard Worker  *
1774*0e209d39SAndroid Build Coastguard Worker  * @param length is the number of levels in the array, or, semantically,
1775*0e209d39SAndroid Build Coastguard Worker  *        the number of objects to be reordered.
1776*0e209d39SAndroid Build Coastguard Worker  *        It must be <code>length>0</code>.
1777*0e209d39SAndroid Build Coastguard Worker  *
1778*0e209d39SAndroid Build Coastguard Worker  * @param indexMap is a pointer to an array of <code>length</code>
1779*0e209d39SAndroid Build Coastguard Worker  *        indexes which will reflect the reordering of the characters.
1780*0e209d39SAndroid Build Coastguard Worker  *        The array does not need to be initialized.<p>
1781*0e209d39SAndroid Build Coastguard Worker  *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
1782*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1783*0e209d39SAndroid Build Coastguard Worker  */
1784*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1785*0e209d39SAndroid Build Coastguard Worker ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
1786*0e209d39SAndroid Build Coastguard Worker 
1787*0e209d39SAndroid Build Coastguard Worker /**
1788*0e209d39SAndroid Build Coastguard Worker  * This is a convenience function that does not use a UBiDi object.
1789*0e209d39SAndroid Build Coastguard Worker  * It is intended to be used for when an application has determined the levels
1790*0e209d39SAndroid Build Coastguard Worker  * of objects (character sequences) and just needs to have them reordered (L2).
1791*0e209d39SAndroid Build Coastguard Worker  * This is equivalent to using <code>ubidi_getVisualMap()</code> on a
1792*0e209d39SAndroid Build Coastguard Worker  * <code>UBiDi</code> object.
1793*0e209d39SAndroid Build Coastguard Worker  *
1794*0e209d39SAndroid Build Coastguard Worker  * @param levels is an array with <code>length</code> levels that have been determined by
1795*0e209d39SAndroid Build Coastguard Worker  *        the application.
1796*0e209d39SAndroid Build Coastguard Worker  *
1797*0e209d39SAndroid Build Coastguard Worker  * @param length is the number of levels in the array, or, semantically,
1798*0e209d39SAndroid Build Coastguard Worker  *        the number of objects to be reordered.
1799*0e209d39SAndroid Build Coastguard Worker  *        It must be <code>length>0</code>.
1800*0e209d39SAndroid Build Coastguard Worker  *
1801*0e209d39SAndroid Build Coastguard Worker  * @param indexMap is a pointer to an array of <code>length</code>
1802*0e209d39SAndroid Build Coastguard Worker  *        indexes which will reflect the reordering of the characters.
1803*0e209d39SAndroid Build Coastguard Worker  *        The array does not need to be initialized.<p>
1804*0e209d39SAndroid Build Coastguard Worker  *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
1805*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1806*0e209d39SAndroid Build Coastguard Worker  */
1807*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1808*0e209d39SAndroid Build Coastguard Worker ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
1809*0e209d39SAndroid Build Coastguard Worker 
1810*0e209d39SAndroid Build Coastguard Worker /**
1811*0e209d39SAndroid Build Coastguard Worker  * Invert an index map.
1812*0e209d39SAndroid Build Coastguard Worker  * The index mapping of the first map is inverted and written to
1813*0e209d39SAndroid Build Coastguard Worker  * the second one.
1814*0e209d39SAndroid Build Coastguard Worker  *
1815*0e209d39SAndroid Build Coastguard Worker  * @param srcMap is an array with <code>length</code> elements
1816*0e209d39SAndroid Build Coastguard Worker  *        which defines the original mapping from a source array containing
1817*0e209d39SAndroid Build Coastguard Worker  *        <code>length</code> elements to a destination array.
1818*0e209d39SAndroid Build Coastguard Worker  *        Some elements of the source array may have no mapping in the
1819*0e209d39SAndroid Build Coastguard Worker  *        destination array. In that case, their value will be
1820*0e209d39SAndroid Build Coastguard Worker  *        the special value <code>UBIDI_MAP_NOWHERE</code>.
1821*0e209d39SAndroid Build Coastguard Worker  *        All elements must be >=0 or equal to <code>UBIDI_MAP_NOWHERE</code>.
1822*0e209d39SAndroid Build Coastguard Worker  *        Some elements may have a value >= <code>length</code>, if the
1823*0e209d39SAndroid Build Coastguard Worker  *        destination array has more elements than the source array.
1824*0e209d39SAndroid Build Coastguard Worker  *        There must be no duplicate indexes (two or more elements with the
1825*0e209d39SAndroid Build Coastguard Worker  *        same value except <code>UBIDI_MAP_NOWHERE</code>).
1826*0e209d39SAndroid Build Coastguard Worker  *
1827*0e209d39SAndroid Build Coastguard Worker  * @param destMap is an array with a number of elements equal to 1 + the highest
1828*0e209d39SAndroid Build Coastguard Worker  *        value in <code>srcMap</code>.
1829*0e209d39SAndroid Build Coastguard Worker  *        <code>destMap</code> will be filled with the inverse mapping.
1830*0e209d39SAndroid Build Coastguard Worker  *        If element with index i in <code>srcMap</code> has a value k different
1831*0e209d39SAndroid Build Coastguard Worker  *        from <code>UBIDI_MAP_NOWHERE</code>, this means that element i of
1832*0e209d39SAndroid Build Coastguard Worker  *        the source array maps to element k in the destination array.
1833*0e209d39SAndroid Build Coastguard Worker  *        The inverse map will have value i in its k-th element.
1834*0e209d39SAndroid Build Coastguard Worker  *        For all elements of the destination array which do not map to
1835*0e209d39SAndroid Build Coastguard Worker  *        an element in the source array, the corresponding element in the
1836*0e209d39SAndroid Build Coastguard Worker  *        inverse map will have a value equal to <code>UBIDI_MAP_NOWHERE</code>.
1837*0e209d39SAndroid Build Coastguard Worker  *
1838*0e209d39SAndroid Build Coastguard Worker  * @param length is the length of each array.
1839*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_MAP_NOWHERE
1840*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1841*0e209d39SAndroid Build Coastguard Worker  */
1842*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
1843*0e209d39SAndroid Build Coastguard Worker ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);
1844*0e209d39SAndroid Build Coastguard Worker 
1845*0e209d39SAndroid Build Coastguard Worker /** option flags for ubidi_writeReordered() */
1846*0e209d39SAndroid Build Coastguard Worker 
1847*0e209d39SAndroid Build Coastguard Worker /**
1848*0e209d39SAndroid Build Coastguard Worker  * option bit for ubidi_writeReordered():
1849*0e209d39SAndroid Build Coastguard Worker  * keep combining characters after their base characters in RTL runs
1850*0e209d39SAndroid Build Coastguard Worker  *
1851*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
1852*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1853*0e209d39SAndroid Build Coastguard Worker  */
1854*0e209d39SAndroid Build Coastguard Worker #define UBIDI_KEEP_BASE_COMBINING       1
1855*0e209d39SAndroid Build Coastguard Worker 
1856*0e209d39SAndroid Build Coastguard Worker /**
1857*0e209d39SAndroid Build Coastguard Worker  * option bit for ubidi_writeReordered():
1858*0e209d39SAndroid Build Coastguard Worker  * replace characters with the "mirrored" property in RTL runs
1859*0e209d39SAndroid Build Coastguard Worker  * by their mirror-image mappings
1860*0e209d39SAndroid Build Coastguard Worker  *
1861*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
1862*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1863*0e209d39SAndroid Build Coastguard Worker  */
1864*0e209d39SAndroid Build Coastguard Worker #define UBIDI_DO_MIRRORING              2
1865*0e209d39SAndroid Build Coastguard Worker 
1866*0e209d39SAndroid Build Coastguard Worker /**
1867*0e209d39SAndroid Build Coastguard Worker  * option bit for ubidi_writeReordered():
1868*0e209d39SAndroid Build Coastguard Worker  * surround the run with LRMs if necessary;
1869*0e209d39SAndroid Build Coastguard Worker  * this is part of the approximate "inverse Bidi" algorithm
1870*0e209d39SAndroid Build Coastguard Worker  *
1871*0e209d39SAndroid Build Coastguard Worker  * <p>This option does not imply corresponding adjustment of the index
1872*0e209d39SAndroid Build Coastguard Worker  * mappings.</p>
1873*0e209d39SAndroid Build Coastguard Worker  *
1874*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setInverse
1875*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
1876*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1877*0e209d39SAndroid Build Coastguard Worker  */
1878*0e209d39SAndroid Build Coastguard Worker #define UBIDI_INSERT_LRM_FOR_NUMERIC    4
1879*0e209d39SAndroid Build Coastguard Worker 
1880*0e209d39SAndroid Build Coastguard Worker /**
1881*0e209d39SAndroid Build Coastguard Worker  * option bit for ubidi_writeReordered():
1882*0e209d39SAndroid Build Coastguard Worker  * remove Bidi control characters
1883*0e209d39SAndroid Build Coastguard Worker  * (this does not affect #UBIDI_INSERT_LRM_FOR_NUMERIC)
1884*0e209d39SAndroid Build Coastguard Worker  *
1885*0e209d39SAndroid Build Coastguard Worker  * <p>This option does not imply corresponding adjustment of the index
1886*0e209d39SAndroid Build Coastguard Worker  * mappings.</p>
1887*0e209d39SAndroid Build Coastguard Worker  *
1888*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
1889*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1890*0e209d39SAndroid Build Coastguard Worker  */
1891*0e209d39SAndroid Build Coastguard Worker #define UBIDI_REMOVE_BIDI_CONTROLS      8
1892*0e209d39SAndroid Build Coastguard Worker 
1893*0e209d39SAndroid Build Coastguard Worker /**
1894*0e209d39SAndroid Build Coastguard Worker  * option bit for ubidi_writeReordered():
1895*0e209d39SAndroid Build Coastguard Worker  * write the output in reverse order
1896*0e209d39SAndroid Build Coastguard Worker  *
1897*0e209d39SAndroid Build Coastguard Worker  * <p>This has the same effect as calling <code>ubidi_writeReordered()</code>
1898*0e209d39SAndroid Build Coastguard Worker  * first without this option, and then calling
1899*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReverse()</code> without mirroring.
1900*0e209d39SAndroid Build Coastguard Worker  * Doing this in the same step is faster and avoids a temporary buffer.
1901*0e209d39SAndroid Build Coastguard Worker  * An example for using this option is output to a character terminal that
1902*0e209d39SAndroid Build Coastguard Worker  * is designed for RTL scripts and stores text in reverse order.</p>
1903*0e209d39SAndroid Build Coastguard Worker  *
1904*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
1905*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
1906*0e209d39SAndroid Build Coastguard Worker  */
1907*0e209d39SAndroid Build Coastguard Worker #define UBIDI_OUTPUT_REVERSE            16
1908*0e209d39SAndroid Build Coastguard Worker 
1909*0e209d39SAndroid Build Coastguard Worker /**
1910*0e209d39SAndroid Build Coastguard Worker  * Get the length of the source text processed by the last call to
1911*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setPara()</code>. This length may be different from the length
1912*0e209d39SAndroid Build Coastguard Worker  * of the source text if option <code>#UBIDI_OPTION_STREAMING</code>
1913*0e209d39SAndroid Build Coastguard Worker  * has been set.
1914*0e209d39SAndroid Build Coastguard Worker  * <br>
1915*0e209d39SAndroid Build Coastguard Worker  * Note that whenever the length of the text affects the execution or the
1916*0e209d39SAndroid Build Coastguard Worker  * result of a function, it is the processed length which must be considered,
1917*0e209d39SAndroid Build Coastguard Worker  * except for <code>ubidi_setPara</code> (which receives unprocessed source
1918*0e209d39SAndroid Build Coastguard Worker  * text) and <code>ubidi_getLength</code> (which returns the original length
1919*0e209d39SAndroid Build Coastguard Worker  * of the source text).<br>
1920*0e209d39SAndroid Build Coastguard Worker  * In particular, the processed length is the one to consider in the following
1921*0e209d39SAndroid Build Coastguard Worker  * cases:
1922*0e209d39SAndroid Build Coastguard Worker  * <ul>
1923*0e209d39SAndroid Build Coastguard Worker  * <li>maximum value of the <code>limit</code> argument of
1924*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setLine</code></li>
1925*0e209d39SAndroid Build Coastguard Worker  * <li>maximum value of the <code>charIndex</code> argument of
1926*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getParagraph</code></li>
1927*0e209d39SAndroid Build Coastguard Worker  * <li>maximum value of the <code>charIndex</code> argument of
1928*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getLevelAt</code></li>
1929*0e209d39SAndroid Build Coastguard Worker  * <li>number of elements in the array returned by <code>ubidi_getLevels</code></li>
1930*0e209d39SAndroid Build Coastguard Worker  * <li>maximum value of the <code>logicalStart</code> argument of
1931*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getLogicalRun</code></li>
1932*0e209d39SAndroid Build Coastguard Worker  * <li>maximum value of the <code>logicalIndex</code> argument of
1933*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getVisualIndex</code></li>
1934*0e209d39SAndroid Build Coastguard Worker  * <li>number of elements filled in the <code>*indexMap</code> argument of
1935*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getLogicalMap</code></li>
1936*0e209d39SAndroid Build Coastguard Worker  * <li>length of text processed by <code>ubidi_writeReordered</code></li>
1937*0e209d39SAndroid Build Coastguard Worker  * </ul>
1938*0e209d39SAndroid Build Coastguard Worker  *
1939*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph <code>UBiDi</code> object.
1940*0e209d39SAndroid Build Coastguard Worker  *
1941*0e209d39SAndroid Build Coastguard Worker  * @return The length of the part of the source text processed by
1942*0e209d39SAndroid Build Coastguard Worker  *         the last call to <code>ubidi_setPara</code>.
1943*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
1944*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_OPTION_STREAMING
1945*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
1946*0e209d39SAndroid Build Coastguard Worker  */
1947*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1948*0e209d39SAndroid Build Coastguard Worker ubidi_getProcessedLength(const UBiDi *pBiDi);
1949*0e209d39SAndroid Build Coastguard Worker 
1950*0e209d39SAndroid Build Coastguard Worker /**
1951*0e209d39SAndroid Build Coastguard Worker  * Get the length of the reordered text resulting from the last call to
1952*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setPara()</code>. This length may be different from the length
1953*0e209d39SAndroid Build Coastguard Worker  * of the source text if option <code>#UBIDI_OPTION_INSERT_MARKS</code>
1954*0e209d39SAndroid Build Coastguard Worker  * or option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> has been set.
1955*0e209d39SAndroid Build Coastguard Worker  * <br>
1956*0e209d39SAndroid Build Coastguard Worker  * This resulting length is the one to consider in the following cases:
1957*0e209d39SAndroid Build Coastguard Worker  * <ul>
1958*0e209d39SAndroid Build Coastguard Worker  * <li>maximum value of the <code>visualIndex</code> argument of
1959*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getLogicalIndex</code></li>
1960*0e209d39SAndroid Build Coastguard Worker  * <li>number of elements of the <code>*indexMap</code> argument of
1961*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_getVisualMap</code></li>
1962*0e209d39SAndroid Build Coastguard Worker  * </ul>
1963*0e209d39SAndroid Build Coastguard Worker  * Note that this length stays identical to the source text length if
1964*0e209d39SAndroid Build Coastguard Worker  * Bidi marks are inserted or removed using option bits of
1965*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_writeReordered</code>, or if option
1966*0e209d39SAndroid Build Coastguard Worker  * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> has been set.
1967*0e209d39SAndroid Build Coastguard Worker  *
1968*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph <code>UBiDi</code> object.
1969*0e209d39SAndroid Build Coastguard Worker  *
1970*0e209d39SAndroid Build Coastguard Worker  * @return The length of the reordered text resulting from
1971*0e209d39SAndroid Build Coastguard Worker  *         the last call to <code>ubidi_setPara</code>.
1972*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setPara
1973*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_OPTION_INSERT_MARKS
1974*0e209d39SAndroid Build Coastguard Worker  * @see UBIDI_OPTION_REMOVE_CONTROLS
1975*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
1976*0e209d39SAndroid Build Coastguard Worker  */
1977*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
1978*0e209d39SAndroid Build Coastguard Worker ubidi_getResultLength(const UBiDi *pBiDi);
1979*0e209d39SAndroid Build Coastguard Worker 
1980*0e209d39SAndroid Build Coastguard Worker U_CDECL_BEGIN
1981*0e209d39SAndroid Build Coastguard Worker 
1982*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
1983*0e209d39SAndroid Build Coastguard Worker /**
1984*0e209d39SAndroid Build Coastguard Worker  * Value returned by <code>UBiDiClassCallback</code> callbacks when
1985*0e209d39SAndroid Build Coastguard Worker  * there is no need to override the standard Bidi class for a given code point.
1986*0e209d39SAndroid Build Coastguard Worker  *
1987*0e209d39SAndroid Build Coastguard Worker  * This constant is deprecated; use u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1 instead.
1988*0e209d39SAndroid Build Coastguard Worker  *
1989*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiClassCallback
1990*0e209d39SAndroid Build Coastguard Worker  * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
1991*0e209d39SAndroid Build Coastguard Worker  */
1992*0e209d39SAndroid Build Coastguard Worker #define U_BIDI_CLASS_DEFAULT  U_CHAR_DIRECTION_COUNT
1993*0e209d39SAndroid Build Coastguard Worker #endif  // U_HIDE_DEPRECATED_API
1994*0e209d39SAndroid Build Coastguard Worker 
1995*0e209d39SAndroid Build Coastguard Worker /**
1996*0e209d39SAndroid Build Coastguard Worker  * Callback type declaration for overriding default Bidi class values with
1997*0e209d39SAndroid Build Coastguard Worker  * custom ones.
1998*0e209d39SAndroid Build Coastguard Worker  * <p>Usually, the function pointer will be propagated to a <code>UBiDi</code>
1999*0e209d39SAndroid Build Coastguard Worker  * object by calling the <code>ubidi_setClassCallback()</code> function;
2000*0e209d39SAndroid Build Coastguard Worker  * then the callback will be invoked by the UBA implementation any time the
2001*0e209d39SAndroid Build Coastguard Worker  * class of a character is to be determined.</p>
2002*0e209d39SAndroid Build Coastguard Worker  *
2003*0e209d39SAndroid Build Coastguard Worker  * @param context is a pointer to the callback private data.
2004*0e209d39SAndroid Build Coastguard Worker  *
2005*0e209d39SAndroid Build Coastguard Worker  * @param c       is the code point to get a Bidi class for.
2006*0e209d39SAndroid Build Coastguard Worker  *
2007*0e209d39SAndroid Build Coastguard Worker  * @return The directional property / Bidi class for the given code point
2008*0e209d39SAndroid Build Coastguard Worker  *         <code>c</code> if the default class has been overridden, or
2009*0e209d39SAndroid Build Coastguard Worker  *         <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>
2010*0e209d39SAndroid Build Coastguard Worker  *         if the standard Bidi class value for <code>c</code> is to be used.
2011*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setClassCallback
2012*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getClassCallback
2013*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
2014*0e209d39SAndroid Build Coastguard Worker  */
2015*0e209d39SAndroid Build Coastguard Worker typedef UCharDirection U_CALLCONV
2016*0e209d39SAndroid Build Coastguard Worker UBiDiClassCallback(const void *context, UChar32 c);
2017*0e209d39SAndroid Build Coastguard Worker 
2018*0e209d39SAndroid Build Coastguard Worker U_CDECL_END
2019*0e209d39SAndroid Build Coastguard Worker 
2020*0e209d39SAndroid Build Coastguard Worker /**
2021*0e209d39SAndroid Build Coastguard Worker  * Retrieve the Bidi class for a given code point.
2022*0e209d39SAndroid Build Coastguard Worker  * <p>If a <code>#UBiDiClassCallback</code> callback is defined and returns a
2023*0e209d39SAndroid Build Coastguard Worker  * value other than <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>,
2024*0e209d39SAndroid Build Coastguard Worker  * that value is used; otherwise the default class determination mechanism is invoked.</p>
2025*0e209d39SAndroid Build Coastguard Worker  *
2026*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph <code>UBiDi</code> object.
2027*0e209d39SAndroid Build Coastguard Worker  *
2028*0e209d39SAndroid Build Coastguard Worker  * @param c     is the code point whose Bidi class must be retrieved.
2029*0e209d39SAndroid Build Coastguard Worker  *
2030*0e209d39SAndroid Build Coastguard Worker  * @return The Bidi class for character <code>c</code> based
2031*0e209d39SAndroid Build Coastguard Worker  *         on the given <code>pBiDi</code> instance.
2032*0e209d39SAndroid Build Coastguard Worker  * @see UBiDiClassCallback
2033*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
2034*0e209d39SAndroid Build Coastguard Worker  */
2035*0e209d39SAndroid Build Coastguard Worker U_CAPI UCharDirection U_EXPORT2
2036*0e209d39SAndroid Build Coastguard Worker ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c);
2037*0e209d39SAndroid Build Coastguard Worker 
2038*0e209d39SAndroid Build Coastguard Worker /**
2039*0e209d39SAndroid Build Coastguard Worker  * Set the callback function and callback data used by the UBA
2040*0e209d39SAndroid Build Coastguard Worker  * implementation for Bidi class determination.
2041*0e209d39SAndroid Build Coastguard Worker  * <p>This may be useful for assigning Bidi classes to PUA characters, or
2042*0e209d39SAndroid Build Coastguard Worker  * for special application needs. For instance, an application may want to
2043*0e209d39SAndroid Build Coastguard Worker  * handle all spaces like L or R characters (according to the base direction)
2044*0e209d39SAndroid Build Coastguard Worker  * when creating the visual ordering of logical lines which are part of a report
2045*0e209d39SAndroid Build Coastguard Worker  * organized in columns: there should not be interaction between adjacent
2046*0e209d39SAndroid Build Coastguard Worker  * cells.<p>
2047*0e209d39SAndroid Build Coastguard Worker  *
2048*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph <code>UBiDi</code> object.
2049*0e209d39SAndroid Build Coastguard Worker  *
2050*0e209d39SAndroid Build Coastguard Worker  * @param newFn is the new callback function pointer.
2051*0e209d39SAndroid Build Coastguard Worker  *
2052*0e209d39SAndroid Build Coastguard Worker  * @param newContext is the new callback context pointer. This can be NULL.
2053*0e209d39SAndroid Build Coastguard Worker  *
2054*0e209d39SAndroid Build Coastguard Worker  * @param oldFn fillin: Returns the old callback function pointer. This can be
2055*0e209d39SAndroid Build Coastguard Worker  *                      NULL.
2056*0e209d39SAndroid Build Coastguard Worker  *
2057*0e209d39SAndroid Build Coastguard Worker  * @param oldContext fillin: Returns the old callback's context. This can be
2058*0e209d39SAndroid Build Coastguard Worker  *                           NULL.
2059*0e209d39SAndroid Build Coastguard Worker  *
2060*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
2061*0e209d39SAndroid Build Coastguard Worker  *
2062*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getClassCallback
2063*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
2064*0e209d39SAndroid Build Coastguard Worker  */
2065*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
2066*0e209d39SAndroid Build Coastguard Worker ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,
2067*0e209d39SAndroid Build Coastguard Worker                        const void *newContext, UBiDiClassCallback **oldFn,
2068*0e209d39SAndroid Build Coastguard Worker                        const void **oldContext, UErrorCode *pErrorCode);
2069*0e209d39SAndroid Build Coastguard Worker 
2070*0e209d39SAndroid Build Coastguard Worker /**
2071*0e209d39SAndroid Build Coastguard Worker  * Get the current callback function used for Bidi class determination.
2072*0e209d39SAndroid Build Coastguard Worker  *
2073*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi is the paragraph <code>UBiDi</code> object.
2074*0e209d39SAndroid Build Coastguard Worker  *
2075*0e209d39SAndroid Build Coastguard Worker  * @param fn fillin: Returns the callback function pointer.
2076*0e209d39SAndroid Build Coastguard Worker  *
2077*0e209d39SAndroid Build Coastguard Worker  * @param context fillin: Returns the callback's private context.
2078*0e209d39SAndroid Build Coastguard Worker  *
2079*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_setClassCallback
2080*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 3.6
2081*0e209d39SAndroid Build Coastguard Worker  */
2082*0e209d39SAndroid Build Coastguard Worker U_CAPI void U_EXPORT2
2083*0e209d39SAndroid Build Coastguard Worker ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context);
2084*0e209d39SAndroid Build Coastguard Worker 
2085*0e209d39SAndroid Build Coastguard Worker /**
2086*0e209d39SAndroid Build Coastguard Worker  * Take a <code>UBiDi</code> object containing the reordering
2087*0e209d39SAndroid Build Coastguard Worker  * information for a piece of text (one or more paragraphs) set by
2088*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setPara()</code> or for a line of text set by
2089*0e209d39SAndroid Build Coastguard Worker  * <code>ubidi_setLine()</code> and write a reordered string to the
2090*0e209d39SAndroid Build Coastguard Worker  * destination buffer.
2091*0e209d39SAndroid Build Coastguard Worker  *
2092*0e209d39SAndroid Build Coastguard Worker  * This function preserves the integrity of characters with multiple
2093*0e209d39SAndroid Build Coastguard Worker  * code units and (optionally) combining characters.
2094*0e209d39SAndroid Build Coastguard Worker  * Characters in RTL runs can be replaced by mirror-image characters
2095*0e209d39SAndroid Build Coastguard Worker  * in the destination buffer. Note that "real" mirroring has
2096*0e209d39SAndroid Build Coastguard Worker  * to be done in a rendering engine by glyph selection
2097*0e209d39SAndroid Build Coastguard Worker  * and that for many "mirrored" characters there are no
2098*0e209d39SAndroid Build Coastguard Worker  * Unicode characters as mirror-image equivalents.
2099*0e209d39SAndroid Build Coastguard Worker  * There are also options to insert or remove Bidi control
2100*0e209d39SAndroid Build Coastguard Worker  * characters; see the description of the <code>destSize</code>
2101*0e209d39SAndroid Build Coastguard Worker  * and <code>options</code> parameters and of the option bit flags.
2102*0e209d39SAndroid Build Coastguard Worker  *
2103*0e209d39SAndroid Build Coastguard Worker  * @param pBiDi A pointer to a <code>UBiDi</code> object that
2104*0e209d39SAndroid Build Coastguard Worker  *              is set by <code>ubidi_setPara()</code> or
2105*0e209d39SAndroid Build Coastguard Worker  *              <code>ubidi_setLine()</code> and contains the reordering
2106*0e209d39SAndroid Build Coastguard Worker  *              information for the text that it was defined for,
2107*0e209d39SAndroid Build Coastguard Worker  *              as well as a pointer to that text.<br><br>
2108*0e209d39SAndroid Build Coastguard Worker  *              The text was aliased (only the pointer was stored
2109*0e209d39SAndroid Build Coastguard Worker  *              without copying the contents) and must not have been modified
2110*0e209d39SAndroid Build Coastguard Worker  *              since the <code>ubidi_setPara()</code> call.
2111*0e209d39SAndroid Build Coastguard Worker  *
2112*0e209d39SAndroid Build Coastguard Worker  * @param dest A pointer to where the reordered text is to be copied.
2113*0e209d39SAndroid Build Coastguard Worker  *             The source text and <code>dest[destSize]</code>
2114*0e209d39SAndroid Build Coastguard Worker  *             must not overlap.
2115*0e209d39SAndroid Build Coastguard Worker  *
2116*0e209d39SAndroid Build Coastguard Worker  * @param destSize The size of the <code>dest</code> buffer,
2117*0e209d39SAndroid Build Coastguard Worker  *                 in number of UChars.
2118*0e209d39SAndroid Build Coastguard Worker  *                 If the <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>
2119*0e209d39SAndroid Build Coastguard Worker  *                 option is set, then the destination length could be
2120*0e209d39SAndroid Build Coastguard Worker  *                 as large as
2121*0e209d39SAndroid Build Coastguard Worker  *                 <code>ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)</code>.
2122*0e209d39SAndroid Build Coastguard Worker  *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
2123*0e209d39SAndroid Build Coastguard Worker  *                 is set, then the destination length may be less than
2124*0e209d39SAndroid Build Coastguard Worker  *                 <code>ubidi_getLength(pBiDi)</code>.
2125*0e209d39SAndroid Build Coastguard Worker  *                 If none of these options is set, then the destination length
2126*0e209d39SAndroid Build Coastguard Worker  *                 will be exactly <code>ubidi_getProcessedLength(pBiDi)</code>.
2127*0e209d39SAndroid Build Coastguard Worker  *
2128*0e209d39SAndroid Build Coastguard Worker  * @param options A bit set of options for the reordering that control
2129*0e209d39SAndroid Build Coastguard Worker  *                how the reordered text is written.
2130*0e209d39SAndroid Build Coastguard Worker  *                The options include mirroring the characters on a code
2131*0e209d39SAndroid Build Coastguard Worker  *                point basis and inserting LRM characters, which is used
2132*0e209d39SAndroid Build Coastguard Worker  *                especially for transforming visually stored text
2133*0e209d39SAndroid Build Coastguard Worker  *                to logically stored text (although this is still an
2134*0e209d39SAndroid Build Coastguard Worker  *                imperfect implementation of an "inverse Bidi" algorithm
2135*0e209d39SAndroid Build Coastguard Worker  *                because it uses the "forward Bidi" algorithm at its core).
2136*0e209d39SAndroid Build Coastguard Worker  *                The available options are:
2137*0e209d39SAndroid Build Coastguard Worker  *                <code>#UBIDI_DO_MIRRORING</code>,
2138*0e209d39SAndroid Build Coastguard Worker  *                <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
2139*0e209d39SAndroid Build Coastguard Worker  *                <code>#UBIDI_KEEP_BASE_COMBINING</code>,
2140*0e209d39SAndroid Build Coastguard Worker  *                <code>#UBIDI_OUTPUT_REVERSE</code>,
2141*0e209d39SAndroid Build Coastguard Worker  *                <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
2142*0e209d39SAndroid Build Coastguard Worker  *
2143*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
2144*0e209d39SAndroid Build Coastguard Worker  *
2145*0e209d39SAndroid Build Coastguard Worker  * @return The length of the output string.
2146*0e209d39SAndroid Build Coastguard Worker  *
2147*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_getProcessedLength
2148*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
2149*0e209d39SAndroid Build Coastguard Worker  */
2150*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
2151*0e209d39SAndroid Build Coastguard Worker ubidi_writeReordered(UBiDi *pBiDi,
2152*0e209d39SAndroid Build Coastguard Worker                      UChar *dest, int32_t destSize,
2153*0e209d39SAndroid Build Coastguard Worker                      uint16_t options,
2154*0e209d39SAndroid Build Coastguard Worker                      UErrorCode *pErrorCode);
2155*0e209d39SAndroid Build Coastguard Worker 
2156*0e209d39SAndroid Build Coastguard Worker /**
2157*0e209d39SAndroid Build Coastguard Worker  * Reverse a Right-To-Left run of Unicode text.
2158*0e209d39SAndroid Build Coastguard Worker  *
2159*0e209d39SAndroid Build Coastguard Worker  * This function preserves the integrity of characters with multiple
2160*0e209d39SAndroid Build Coastguard Worker  * code units and (optionally) combining characters.
2161*0e209d39SAndroid Build Coastguard Worker  * Characters can be replaced by mirror-image characters
2162*0e209d39SAndroid Build Coastguard Worker  * in the destination buffer. Note that "real" mirroring has
2163*0e209d39SAndroid Build Coastguard Worker  * to be done in a rendering engine by glyph selection
2164*0e209d39SAndroid Build Coastguard Worker  * and that for many "mirrored" characters there are no
2165*0e209d39SAndroid Build Coastguard Worker  * Unicode characters as mirror-image equivalents.
2166*0e209d39SAndroid Build Coastguard Worker  * There are also options to insert or remove Bidi control
2167*0e209d39SAndroid Build Coastguard Worker  * characters.
2168*0e209d39SAndroid Build Coastguard Worker  *
2169*0e209d39SAndroid Build Coastguard Worker  * This function is the implementation for reversing RTL runs as part
2170*0e209d39SAndroid Build Coastguard Worker  * of <code>ubidi_writeReordered()</code>. For detailed descriptions
2171*0e209d39SAndroid Build Coastguard Worker  * of the parameters, see there.
2172*0e209d39SAndroid Build Coastguard Worker  * Since no Bidi controls are inserted here, the output string length
2173*0e209d39SAndroid Build Coastguard Worker  * will never exceed <code>srcLength</code>.
2174*0e209d39SAndroid Build Coastguard Worker  *
2175*0e209d39SAndroid Build Coastguard Worker  * @see ubidi_writeReordered
2176*0e209d39SAndroid Build Coastguard Worker  *
2177*0e209d39SAndroid Build Coastguard Worker  * @param src A pointer to the RTL run text.
2178*0e209d39SAndroid Build Coastguard Worker  *
2179*0e209d39SAndroid Build Coastguard Worker  * @param srcLength The length of the RTL run.
2180*0e209d39SAndroid Build Coastguard Worker  *
2181*0e209d39SAndroid Build Coastguard Worker  * @param dest A pointer to where the reordered text is to be copied.
2182*0e209d39SAndroid Build Coastguard Worker  *             <code>src[srcLength]</code> and <code>dest[destSize]</code>
2183*0e209d39SAndroid Build Coastguard Worker  *             must not overlap.
2184*0e209d39SAndroid Build Coastguard Worker  *
2185*0e209d39SAndroid Build Coastguard Worker  * @param destSize The size of the <code>dest</code> buffer,
2186*0e209d39SAndroid Build Coastguard Worker  *                 in number of UChars.
2187*0e209d39SAndroid Build Coastguard Worker  *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
2188*0e209d39SAndroid Build Coastguard Worker  *                 is set, then the destination length may be less than
2189*0e209d39SAndroid Build Coastguard Worker  *                 <code>srcLength</code>.
2190*0e209d39SAndroid Build Coastguard Worker  *                 If this option is not set, then the destination length
2191*0e209d39SAndroid Build Coastguard Worker  *                 will be exactly <code>srcLength</code>.
2192*0e209d39SAndroid Build Coastguard Worker  *
2193*0e209d39SAndroid Build Coastguard Worker  * @param options A bit set of options for the reordering that control
2194*0e209d39SAndroid Build Coastguard Worker  *                how the reordered text is written.
2195*0e209d39SAndroid Build Coastguard Worker  *                See the <code>options</code> parameter in <code>ubidi_writeReordered()</code>.
2196*0e209d39SAndroid Build Coastguard Worker  *
2197*0e209d39SAndroid Build Coastguard Worker  * @param pErrorCode must be a valid pointer to an error code value.
2198*0e209d39SAndroid Build Coastguard Worker  *
2199*0e209d39SAndroid Build Coastguard Worker  * @return The length of the output string.
2200*0e209d39SAndroid Build Coastguard Worker  * @stable ICU 2.0
2201*0e209d39SAndroid Build Coastguard Worker  */
2202*0e209d39SAndroid Build Coastguard Worker U_CAPI int32_t U_EXPORT2
2203*0e209d39SAndroid Build Coastguard Worker ubidi_writeReverse(const UChar *src, int32_t srcLength,
2204*0e209d39SAndroid Build Coastguard Worker                    UChar *dest, int32_t destSize,
2205*0e209d39SAndroid Build Coastguard Worker                    uint16_t options,
2206*0e209d39SAndroid Build Coastguard Worker                    UErrorCode *pErrorCode);
2207*0e209d39SAndroid Build Coastguard Worker 
2208*0e209d39SAndroid Build Coastguard Worker /*#define BIDI_SAMPLE_CODE*/
2209*0e209d39SAndroid Build Coastguard Worker /*@}*/
2210*0e209d39SAndroid Build Coastguard Worker 
2211*0e209d39SAndroid Build Coastguard Worker #endif
2212