17777dab0Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
27777dab0Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
37777dab0Sopenharmony_ci/*
47777dab0Sopenharmony_ci******************************************************************************
57777dab0Sopenharmony_ci*
67777dab0Sopenharmony_ci*   Copyright (C) 1999-2013, International Business Machines
77777dab0Sopenharmony_ci*   Corporation and others.  All Rights Reserved.
87777dab0Sopenharmony_ci*
97777dab0Sopenharmony_ci******************************************************************************
107777dab0Sopenharmony_ci*   file name:  ubidi.h
117777dab0Sopenharmony_ci*   encoding:   UTF-8
127777dab0Sopenharmony_ci*   tab size:   8 (not used)
137777dab0Sopenharmony_ci*   indentation:4
147777dab0Sopenharmony_ci*
157777dab0Sopenharmony_ci*   created on: 1999jul27
167777dab0Sopenharmony_ci*   created by: Markus W. Scherer, updated by Matitiahu Allouche
177777dab0Sopenharmony_ci*/
187777dab0Sopenharmony_ci
197777dab0Sopenharmony_ci#ifndef UBIDI_H
207777dab0Sopenharmony_ci#define UBIDI_H
217777dab0Sopenharmony_ci
227777dab0Sopenharmony_ci#include "unicode/utypes.h"
237777dab0Sopenharmony_ci#include "unicode/uchar.h"
247777dab0Sopenharmony_ci
257777dab0Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API
267777dab0Sopenharmony_ci#include "unicode/localpointer.h"
277777dab0Sopenharmony_ci#endif   // U_SHOW_CPLUSPLUS_API
287777dab0Sopenharmony_ci
297777dab0Sopenharmony_ci/**
307777dab0Sopenharmony_ci *\file
317777dab0Sopenharmony_ci * \brief C API: Bidi algorithm
327777dab0Sopenharmony_ci *
337777dab0Sopenharmony_ci * <h2>Bidi algorithm for ICU</h2>
347777dab0Sopenharmony_ci *
357777dab0Sopenharmony_ci * This is an implementation of the Unicode Bidirectional Algorithm.
367777dab0Sopenharmony_ci * The algorithm is defined in the
377777dab0Sopenharmony_ci * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.<p>
387777dab0Sopenharmony_ci *
397777dab0Sopenharmony_ci * Note: Libraries that perform a bidirectional algorithm and
407777dab0Sopenharmony_ci * reorder strings accordingly are sometimes called "Storage Layout Engines".
417777dab0Sopenharmony_ci * ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such
427777dab0Sopenharmony_ci * "Storage Layout Engines".
437777dab0Sopenharmony_ci *
447777dab0Sopenharmony_ci * <h3>General remarks about the API:</h3>
457777dab0Sopenharmony_ci *
467777dab0Sopenharmony_ci * In functions with an error code parameter,
477777dab0Sopenharmony_ci * the <code>pErrorCode</code> pointer must be valid
487777dab0Sopenharmony_ci * and the value that it points to must not indicate a failure before
497777dab0Sopenharmony_ci * the function call. Otherwise, the function returns immediately.
507777dab0Sopenharmony_ci * After the function call, the value indicates success or failure.<p>
517777dab0Sopenharmony_ci *
527777dab0Sopenharmony_ci * The &quot;limit&quot; of a sequence of characters is the position just after their
537777dab0Sopenharmony_ci * last character, i.e., one more than that position.<p>
547777dab0Sopenharmony_ci *
557777dab0Sopenharmony_ci * Some of the API functions provide access to &quot;runs&quot;.
567777dab0Sopenharmony_ci * Such a &quot;run&quot; is defined as a sequence of characters
577777dab0Sopenharmony_ci * that are at the same embedding level
587777dab0Sopenharmony_ci * after performing the Bidi algorithm.<p>
597777dab0Sopenharmony_ci *
607777dab0Sopenharmony_ci * @author Markus W. Scherer
617777dab0Sopenharmony_ci * @version 1.0
627777dab0Sopenharmony_ci *
637777dab0Sopenharmony_ci *
647777dab0Sopenharmony_ci * <h4> Sample code for the ICU Bidi API </h4>
657777dab0Sopenharmony_ci *
667777dab0Sopenharmony_ci * <h5>Rendering a paragraph with the ICU Bidi API</h5>
677777dab0Sopenharmony_ci *
687777dab0Sopenharmony_ci * This is (hypothetical) sample code that illustrates
697777dab0Sopenharmony_ci * how the ICU Bidi API could be used to render a paragraph of text.
707777dab0Sopenharmony_ci * Rendering code depends highly on the graphics system,
717777dab0Sopenharmony_ci * therefore this sample code must make a lot of assumptions,
727777dab0Sopenharmony_ci * which may or may not match any existing graphics system's properties.
737777dab0Sopenharmony_ci *
747777dab0Sopenharmony_ci * <p>The basic assumptions are:</p>
757777dab0Sopenharmony_ci * <ul>
767777dab0Sopenharmony_ci * <li>Rendering is done from left to right on a horizontal line.</li>
777777dab0Sopenharmony_ci * <li>A run of single-style, unidirectional text can be rendered at once.</li>
787777dab0Sopenharmony_ci * <li>Such a run of text is passed to the graphics system with
797777dab0Sopenharmony_ci *     characters (code units) in logical order.</li>
807777dab0Sopenharmony_ci * <li>The line-breaking algorithm is very complicated
817777dab0Sopenharmony_ci *     and Locale-dependent -
827777dab0Sopenharmony_ci *     and therefore its implementation omitted from this sample code.</li>
837777dab0Sopenharmony_ci * </ul>
847777dab0Sopenharmony_ci *
857777dab0Sopenharmony_ci * <pre>
867777dab0Sopenharmony_ci * \code
877777dab0Sopenharmony_ci *#include <unicode/ubidi.h>
887777dab0Sopenharmony_ci *
897777dab0Sopenharmony_ci *typedef enum {
907777dab0Sopenharmony_ci *     styleNormal=0, styleSelected=1,
917777dab0Sopenharmony_ci *     styleBold=2, styleItalics=4,
927777dab0Sopenharmony_ci *     styleSuper=8, styleSub=16
937777dab0Sopenharmony_ci *} Style;
947777dab0Sopenharmony_ci *
957777dab0Sopenharmony_ci *typedef struct { int32_t limit; Style style; } StyleRun;
967777dab0Sopenharmony_ci *
977777dab0Sopenharmony_ci *int getTextWidth(const UChar *text, int32_t start, int32_t limit,
987777dab0Sopenharmony_ci *                  const StyleRun *styleRuns, int styleRunCount);
997777dab0Sopenharmony_ci *
1007777dab0Sopenharmony_ci * // set *pLimit and *pStyleRunLimit for a line
1017777dab0Sopenharmony_ci * // from text[start] and from styleRuns[styleRunStart]
1027777dab0Sopenharmony_ci * // using ubidi_getLogicalRun(para, ...)
1037777dab0Sopenharmony_ci *void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,
1047777dab0Sopenharmony_ci *                  UBiDi *para,
1057777dab0Sopenharmony_ci *                  const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,
1067777dab0Sopenharmony_ci *                  int *pLineWidth);
1077777dab0Sopenharmony_ci *
1087777dab0Sopenharmony_ci * // render runs on a line sequentially, always from left to right
1097777dab0Sopenharmony_ci *
1107777dab0Sopenharmony_ci * // prepare rendering a new line
1117777dab0Sopenharmony_ci * void startLine(UBiDiDirection textDirection, int lineWidth);
1127777dab0Sopenharmony_ci *
1137777dab0Sopenharmony_ci * // render a run of text and advance to the right by the run width
1147777dab0Sopenharmony_ci * // the text[start..limit-1] is always in logical order
1157777dab0Sopenharmony_ci * void renderRun(const UChar *text, int32_t start, int32_t limit,
1167777dab0Sopenharmony_ci *               UBiDiDirection textDirection, Style style);
1177777dab0Sopenharmony_ci *
1187777dab0Sopenharmony_ci * // We could compute a cross-product
1197777dab0Sopenharmony_ci * // from the style runs with the directional runs
1207777dab0Sopenharmony_ci * // and then reorder it.
1217777dab0Sopenharmony_ci * // Instead, here we iterate over each run type
1227777dab0Sopenharmony_ci * // and render the intersections -
1237777dab0Sopenharmony_ci * // with shortcuts in simple (and common) cases.
1247777dab0Sopenharmony_ci * // renderParagraph() is the main function.
1257777dab0Sopenharmony_ci *
1267777dab0Sopenharmony_ci * // render a directional run with
1277777dab0Sopenharmony_ci * // (possibly) multiple style runs intersecting with it
1287777dab0Sopenharmony_ci * void renderDirectionalRun(const UChar *text,
1297777dab0Sopenharmony_ci *                           int32_t start, int32_t limit,
1307777dab0Sopenharmony_ci *                           UBiDiDirection direction,
1317777dab0Sopenharmony_ci *                           const StyleRun *styleRuns, int styleRunCount) {
1327777dab0Sopenharmony_ci *     int i;
1337777dab0Sopenharmony_ci *
1347777dab0Sopenharmony_ci *     // iterate over style runs
1357777dab0Sopenharmony_ci *     if(direction==UBIDI_LTR) {
1367777dab0Sopenharmony_ci *         int styleLimit;
1377777dab0Sopenharmony_ci *
1387777dab0Sopenharmony_ci *         for(i=0; i<styleRunCount; ++i) {
1397777dab0Sopenharmony_ci *             styleLimit=styleRuns[i].limit;
1407777dab0Sopenharmony_ci *             if(start<styleLimit) {
1417777dab0Sopenharmony_ci *                 if(styleLimit>limit) { styleLimit=limit; }
1427777dab0Sopenharmony_ci *                 renderRun(text, start, styleLimit,
1437777dab0Sopenharmony_ci *                           direction, styleRuns[i].style);
1447777dab0Sopenharmony_ci *                 if(styleLimit==limit) { break; }
1457777dab0Sopenharmony_ci *                 start=styleLimit;
1467777dab0Sopenharmony_ci *             }
1477777dab0Sopenharmony_ci *         }
1487777dab0Sopenharmony_ci *     } else {
1497777dab0Sopenharmony_ci *         int styleStart;
1507777dab0Sopenharmony_ci *
1517777dab0Sopenharmony_ci *         for(i=styleRunCount-1; i>=0; --i) {
1527777dab0Sopenharmony_ci *             if(i>0) {
1537777dab0Sopenharmony_ci *                 styleStart=styleRuns[i-1].limit;
1547777dab0Sopenharmony_ci *             } else {
1557777dab0Sopenharmony_ci *                 styleStart=0;
1567777dab0Sopenharmony_ci *             }
1577777dab0Sopenharmony_ci *             if(limit>=styleStart) {
1587777dab0Sopenharmony_ci *                 if(styleStart<start) { styleStart=start; }
1597777dab0Sopenharmony_ci *                 renderRun(text, styleStart, limit,
1607777dab0Sopenharmony_ci *                           direction, styleRuns[i].style);
1617777dab0Sopenharmony_ci *                 if(styleStart==start) { break; }
1627777dab0Sopenharmony_ci *                 limit=styleStart;
1637777dab0Sopenharmony_ci *             }
1647777dab0Sopenharmony_ci *         }
1657777dab0Sopenharmony_ci *     }
1667777dab0Sopenharmony_ci * }
1677777dab0Sopenharmony_ci *
1687777dab0Sopenharmony_ci * // the line object represents text[start..limit-1]
1697777dab0Sopenharmony_ci * void renderLine(UBiDi *line, const UChar *text,
1707777dab0Sopenharmony_ci *                 int32_t start, int32_t limit,
1717777dab0Sopenharmony_ci *                 const StyleRun *styleRuns, int styleRunCount,
1727777dab0Sopenharmony_ci *                 UErrorCode *pErrorCode) {
1737777dab0Sopenharmony_ci *     UBiDiDirection direction=ubidi_getDirection(line);
1747777dab0Sopenharmony_ci *     if(direction!=UBIDI_MIXED) {
1757777dab0Sopenharmony_ci *         // unidirectional
1767777dab0Sopenharmony_ci *         if(styleRunCount<=1) {
1777777dab0Sopenharmony_ci *             renderRun(text, start, limit, direction, styleRuns[0].style);
1787777dab0Sopenharmony_ci *         } else {
1797777dab0Sopenharmony_ci *             renderDirectionalRun(text, start, limit,
1807777dab0Sopenharmony_ci *                                  direction, styleRuns, styleRunCount);
1817777dab0Sopenharmony_ci *         }
1827777dab0Sopenharmony_ci *     } else {
1837777dab0Sopenharmony_ci *         // mixed-directional
1847777dab0Sopenharmony_ci *         int32_t count, i, length;
1857777dab0Sopenharmony_ci *         UBiDiLevel level;
1867777dab0Sopenharmony_ci *
1877777dab0Sopenharmony_ci *         count=ubidi_countRuns(line, pErrorCode);
1887777dab0Sopenharmony_ci *         if(U_SUCCESS(*pErrorCode)) {
1897777dab0Sopenharmony_ci *             if(styleRunCount<=1) {
1907777dab0Sopenharmony_ci *                 Style style=styleRuns[0].style;
1917777dab0Sopenharmony_ci *
1927777dab0Sopenharmony_ci *                 // iterate over directional runs
1937777dab0Sopenharmony_ci *                for(i=0; i<count; ++i) {
1947777dab0Sopenharmony_ci *                    direction=ubidi_getVisualRun(line, i, &start, &length);
1957777dab0Sopenharmony_ci *                     renderRun(text, start, start+length, direction, style);
1967777dab0Sopenharmony_ci *                }
1977777dab0Sopenharmony_ci *             } else {
1987777dab0Sopenharmony_ci *                 int32_t j;
1997777dab0Sopenharmony_ci *
2007777dab0Sopenharmony_ci *                 // iterate over both directional and style runs
2017777dab0Sopenharmony_ci *                 for(i=0; i<count; ++i) {
2027777dab0Sopenharmony_ci *                     direction=ubidi_getVisualRun(line, i, &start, &length);
2037777dab0Sopenharmony_ci *                     renderDirectionalRun(text, start, start+length,
2047777dab0Sopenharmony_ci *                                          direction, styleRuns, styleRunCount);
2057777dab0Sopenharmony_ci *                 }
2067777dab0Sopenharmony_ci *             }
2077777dab0Sopenharmony_ci *         }
2087777dab0Sopenharmony_ci *     }
2097777dab0Sopenharmony_ci * }
2107777dab0Sopenharmony_ci *
2117777dab0Sopenharmony_ci *void renderParagraph(const UChar *text, int32_t length,
2127777dab0Sopenharmony_ci *                     UBiDiDirection textDirection,
2137777dab0Sopenharmony_ci *                      const StyleRun *styleRuns, int styleRunCount,
2147777dab0Sopenharmony_ci *                      int lineWidth,
2157777dab0Sopenharmony_ci *                      UErrorCode *pErrorCode) {
2167777dab0Sopenharmony_ci *     UBiDi *para;
2177777dab0Sopenharmony_ci *
2187777dab0Sopenharmony_ci *     if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {
2197777dab0Sopenharmony_ci *         return;
2207777dab0Sopenharmony_ci *     }
2217777dab0Sopenharmony_ci *
2227777dab0Sopenharmony_ci *     para=ubidi_openSized(length, 0, pErrorCode);
2237777dab0Sopenharmony_ci *     if(para==NULL) { return; }
2247777dab0Sopenharmony_ci *
2257777dab0Sopenharmony_ci *     ubidi_setPara(para, text, length,
2267777dab0Sopenharmony_ci *                   textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
2277777dab0Sopenharmony_ci *                   NULL, pErrorCode);
2287777dab0Sopenharmony_ci *     if(U_SUCCESS(*pErrorCode)) {
2297777dab0Sopenharmony_ci *         UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);
2307777dab0Sopenharmony_ci *         StyleRun styleRun={ length, styleNormal };
2317777dab0Sopenharmony_ci *         int width;
2327777dab0Sopenharmony_ci *
2337777dab0Sopenharmony_ci *         if(styleRuns==NULL || styleRunCount<=0) {
2347777dab0Sopenharmony_ci *            styleRunCount=1;
2357777dab0Sopenharmony_ci *             styleRuns=&styleRun;
2367777dab0Sopenharmony_ci *         }
2377777dab0Sopenharmony_ci *
2387777dab0Sopenharmony_ci *        // assume styleRuns[styleRunCount-1].limit>=length
2397777dab0Sopenharmony_ci *
2407777dab0Sopenharmony_ci *         width=getTextWidth(text, 0, length, styleRuns, styleRunCount);
2417777dab0Sopenharmony_ci *         if(width<=lineWidth) {
2427777dab0Sopenharmony_ci *             // everything fits onto one line
2437777dab0Sopenharmony_ci *
2447777dab0Sopenharmony_ci *            // prepare rendering a new line from either left or right
2457777dab0Sopenharmony_ci *             startLine(paraLevel, width);
2467777dab0Sopenharmony_ci *
2477777dab0Sopenharmony_ci *             renderLine(para, text, 0, length,
2487777dab0Sopenharmony_ci *                        styleRuns, styleRunCount, pErrorCode);
2497777dab0Sopenharmony_ci *         } else {
2507777dab0Sopenharmony_ci *             UBiDi *line;
2517777dab0Sopenharmony_ci *
2527777dab0Sopenharmony_ci *             // we need to render several lines
2537777dab0Sopenharmony_ci *             line=ubidi_openSized(length, 0, pErrorCode);
2547777dab0Sopenharmony_ci *             if(line!=NULL) {
2557777dab0Sopenharmony_ci *                 int32_t start=0, limit;
2567777dab0Sopenharmony_ci *                 int styleRunStart=0, styleRunLimit;
2577777dab0Sopenharmony_ci *
2587777dab0Sopenharmony_ci *                 for(;;) {
2597777dab0Sopenharmony_ci *                     limit=length;
2607777dab0Sopenharmony_ci *                     styleRunLimit=styleRunCount;
2617777dab0Sopenharmony_ci *                     getLineBreak(text, start, &limit, para,
2627777dab0Sopenharmony_ci *                                  styleRuns, styleRunStart, &styleRunLimit,
2637777dab0Sopenharmony_ci *                                 &width);
2647777dab0Sopenharmony_ci *                     ubidi_setLine(para, start, limit, line, pErrorCode);
2657777dab0Sopenharmony_ci *                     if(U_SUCCESS(*pErrorCode)) {
2667777dab0Sopenharmony_ci *                         // prepare rendering a new line
2677777dab0Sopenharmony_ci *                         // from either left or right
2687777dab0Sopenharmony_ci *                         startLine(paraLevel, width);
2697777dab0Sopenharmony_ci *
2707777dab0Sopenharmony_ci *                         renderLine(line, text, start, limit,
2717777dab0Sopenharmony_ci *                                    styleRuns+styleRunStart,
2727777dab0Sopenharmony_ci *                                    styleRunLimit-styleRunStart, pErrorCode);
2737777dab0Sopenharmony_ci *                     }
2747777dab0Sopenharmony_ci *                     if(limit==length) { break; }
2757777dab0Sopenharmony_ci *                     start=limit;
2767777dab0Sopenharmony_ci *                     styleRunStart=styleRunLimit-1;
2777777dab0Sopenharmony_ci *                     if(start>=styleRuns[styleRunStart].limit) {
2787777dab0Sopenharmony_ci *                         ++styleRunStart;
2797777dab0Sopenharmony_ci *                     }
2807777dab0Sopenharmony_ci *                 }
2817777dab0Sopenharmony_ci *
2827777dab0Sopenharmony_ci *                 ubidi_close(line);
2837777dab0Sopenharmony_ci *             }
2847777dab0Sopenharmony_ci *        }
2857777dab0Sopenharmony_ci *    }
2867777dab0Sopenharmony_ci *
2877777dab0Sopenharmony_ci *     ubidi_close(para);
2887777dab0Sopenharmony_ci *}
2897777dab0Sopenharmony_ci *\endcode
2907777dab0Sopenharmony_ci * </pre>
2917777dab0Sopenharmony_ci */
2927777dab0Sopenharmony_ci
2937777dab0Sopenharmony_ci/*DOCXX_TAG*/
2947777dab0Sopenharmony_ci/*@{*/
2957777dab0Sopenharmony_ci
2967777dab0Sopenharmony_ci/**
2977777dab0Sopenharmony_ci * UBiDiLevel is the type of the level values in this
2987777dab0Sopenharmony_ci * Bidi implementation.
2997777dab0Sopenharmony_ci * It holds an embedding level and indicates the visual direction
3007777dab0Sopenharmony_ci * by its bit&nbsp;0 (even/odd value).<p>
3017777dab0Sopenharmony_ci *
3027777dab0Sopenharmony_ci * It can also hold non-level values for the
3037777dab0Sopenharmony_ci * <code>paraLevel</code> and <code>embeddingLevels</code>
3047777dab0Sopenharmony_ci * arguments of <code>ubidi_setPara()</code>; there:
3057777dab0Sopenharmony_ci * <ul>
3067777dab0Sopenharmony_ci * <li>bit&nbsp;7 of an <code>embeddingLevels[]</code>
3077777dab0Sopenharmony_ci * value indicates whether the using application is
3087777dab0Sopenharmony_ci * specifying the level of a character to <i>override</i> whatever the
3097777dab0Sopenharmony_ci * Bidi implementation would resolve it to.</li>
3107777dab0Sopenharmony_ci * <li><code>paraLevel</code> can be set to the
3117777dab0Sopenharmony_ci * pseudo-level values <code>UBIDI_DEFAULT_LTR</code>
3127777dab0Sopenharmony_ci * and <code>UBIDI_DEFAULT_RTL</code>.</li>
3137777dab0Sopenharmony_ci * </ul>
3147777dab0Sopenharmony_ci *
3157777dab0Sopenharmony_ci * @see ubidi_setPara
3167777dab0Sopenharmony_ci *
3177777dab0Sopenharmony_ci * <p>The related constants are not real, valid level values.
3187777dab0Sopenharmony_ci * <code>UBIDI_DEFAULT_XXX</code> can be used to specify
3197777dab0Sopenharmony_ci * a default for the paragraph level for
3207777dab0Sopenharmony_ci * when the <code>ubidi_setPara()</code> function
3217777dab0Sopenharmony_ci * shall determine it but there is no
3227777dab0Sopenharmony_ci * strongly typed character in the input.<p>
3237777dab0Sopenharmony_ci *
3247777dab0Sopenharmony_ci * Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even
3257777dab0Sopenharmony_ci * and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,
3267777dab0Sopenharmony_ci * just like with normal LTR and RTL level values -
3277777dab0Sopenharmony_ci * these special values are designed that way. Also, the implementation
3287777dab0Sopenharmony_ci * assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
3297777dab0Sopenharmony_ci *
3307777dab0Sopenharmony_ci * Note: The numeric values of the related constants will not change:
3317777dab0Sopenharmony_ci * They are tied to the use of 7-bit byte values (plus the override bit)
3327777dab0Sopenharmony_ci * and of the UBiDiLevel=uint8_t data type in this API.
3337777dab0Sopenharmony_ci *
3347777dab0Sopenharmony_ci * @see UBIDI_DEFAULT_LTR
3357777dab0Sopenharmony_ci * @see UBIDI_DEFAULT_RTL
3367777dab0Sopenharmony_ci * @see UBIDI_LEVEL_OVERRIDE
3377777dab0Sopenharmony_ci * @see UBIDI_MAX_EXPLICIT_LEVEL
3387777dab0Sopenharmony_ci * @stable ICU 2.0
3397777dab0Sopenharmony_ci */
3407777dab0Sopenharmony_citypedef uint8_t UBiDiLevel;
3417777dab0Sopenharmony_ci
3427777dab0Sopenharmony_ci/** Paragraph level setting.<p>
3437777dab0Sopenharmony_ci *
3447777dab0Sopenharmony_ci * Constant indicating that the base direction depends on the first strong
3457777dab0Sopenharmony_ci * directional character in the text according to the Unicode Bidirectional
3467777dab0Sopenharmony_ci * Algorithm. If no strong directional character is present,
3477777dab0Sopenharmony_ci * then set the paragraph level to 0 (left-to-right).<p>
3487777dab0Sopenharmony_ci *
3497777dab0Sopenharmony_ci * If this value is used in conjunction with reordering modes
3507777dab0Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
3517777dab0Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
3527777dab0Sopenharmony_ci * is assumed to be visual LTR, and the text after reordering is required
3537777dab0Sopenharmony_ci * to be the corresponding logical string with appropriate contextual
3547777dab0Sopenharmony_ci * direction. The direction of the result string will be RTL if either
3557777dab0Sopenharmony_ci * the righmost or leftmost strong character of the source text is RTL
3567777dab0Sopenharmony_ci * or Arabic Letter, the direction will be LTR otherwise.<p>
3577777dab0Sopenharmony_ci *
3587777dab0Sopenharmony_ci * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
3597777dab0Sopenharmony_ci * be added at the beginning of the result string to ensure round trip
3607777dab0Sopenharmony_ci * (that the result string, when reordered back to visual, will produce
3617777dab0Sopenharmony_ci * the original source text).
3627777dab0Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
3637777dab0Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
3647777dab0Sopenharmony_ci * @stable ICU 2.0
3657777dab0Sopenharmony_ci */
3667777dab0Sopenharmony_ci#define UBIDI_DEFAULT_LTR 0xfe
3677777dab0Sopenharmony_ci
3687777dab0Sopenharmony_ci/** Paragraph level setting.<p>
3697777dab0Sopenharmony_ci *
3707777dab0Sopenharmony_ci * Constant indicating that the base direction depends on the first strong
3717777dab0Sopenharmony_ci * directional character in the text according to the Unicode Bidirectional
3727777dab0Sopenharmony_ci * Algorithm. If no strong directional character is present,
3737777dab0Sopenharmony_ci * then set the paragraph level to 1 (right-to-left).<p>
3747777dab0Sopenharmony_ci *
3757777dab0Sopenharmony_ci * If this value is used in conjunction with reordering modes
3767777dab0Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
3777777dab0Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
3787777dab0Sopenharmony_ci * is assumed to be visual LTR, and the text after reordering is required
3797777dab0Sopenharmony_ci * to be the corresponding logical string with appropriate contextual
3807777dab0Sopenharmony_ci * direction. The direction of the result string will be RTL if either
3817777dab0Sopenharmony_ci * the righmost or leftmost strong character of the source text is RTL
3827777dab0Sopenharmony_ci * or Arabic Letter, or if the text contains no strong character;
3837777dab0Sopenharmony_ci * the direction will be LTR otherwise.<p>
3847777dab0Sopenharmony_ci *
3857777dab0Sopenharmony_ci * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
3867777dab0Sopenharmony_ci * be added at the beginning of the result string to ensure round trip
3877777dab0Sopenharmony_ci * (that the result string, when reordered back to visual, will produce
3887777dab0Sopenharmony_ci * the original source text).
3897777dab0Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
3907777dab0Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
3917777dab0Sopenharmony_ci * @stable ICU 2.0
3927777dab0Sopenharmony_ci */
3937777dab0Sopenharmony_ci#define UBIDI_DEFAULT_RTL 0xff
3947777dab0Sopenharmony_ci
3957777dab0Sopenharmony_ci/**
3967777dab0Sopenharmony_ci * Maximum explicit embedding level.
3977777dab0Sopenharmony_ci * Same as the max_depth value in the
3987777dab0Sopenharmony_ci * <a href="http://www.unicode.org/reports/tr9/#BD2">Unicode Bidirectional Algorithm</a>.
3997777dab0Sopenharmony_ci * (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).
4007777dab0Sopenharmony_ci * @stable ICU 2.0
4017777dab0Sopenharmony_ci */
4027777dab0Sopenharmony_ci#define UBIDI_MAX_EXPLICIT_LEVEL 125
4037777dab0Sopenharmony_ci
4047777dab0Sopenharmony_ci/** Bit flag for level input.
4057777dab0Sopenharmony_ci *  Overrides directional properties.
4067777dab0Sopenharmony_ci * @stable ICU 2.0
4077777dab0Sopenharmony_ci */
4087777dab0Sopenharmony_ci#define UBIDI_LEVEL_OVERRIDE 0x80
4097777dab0Sopenharmony_ci
4107777dab0Sopenharmony_ci/**
4117777dab0Sopenharmony_ci * Special value which can be returned by the mapping functions when a logical
4127777dab0Sopenharmony_ci * index has no corresponding visual index or vice-versa. This may happen
4137777dab0Sopenharmony_ci * for the logical-to-visual mapping of a Bidi control when option
4147777dab0Sopenharmony_ci * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is specified. This can also happen
4157777dab0Sopenharmony_ci * for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted
4167777dab0Sopenharmony_ci * by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
4177777dab0Sopenharmony_ci * @see ubidi_getVisualIndex
4187777dab0Sopenharmony_ci * @see ubidi_getVisualMap
4197777dab0Sopenharmony_ci * @see ubidi_getLogicalIndex
4207777dab0Sopenharmony_ci * @see ubidi_getLogicalMap
4217777dab0Sopenharmony_ci * @stable ICU 3.6
4227777dab0Sopenharmony_ci */
4237777dab0Sopenharmony_ci#define UBIDI_MAP_NOWHERE   (-1)
4247777dab0Sopenharmony_ci
4257777dab0Sopenharmony_ci/**
4267777dab0Sopenharmony_ci * <code>UBiDiDirection</code> values indicate the text direction.
4277777dab0Sopenharmony_ci * @stable ICU 2.0
4287777dab0Sopenharmony_ci */
4297777dab0Sopenharmony_cienum UBiDiDirection {
4307777dab0Sopenharmony_ci  /** Left-to-right text. This is a 0 value.
4317777dab0Sopenharmony_ci   * <ul>
4327777dab0Sopenharmony_ci   * <li>As return value for <code>ubidi_getDirection()</code>, it means
4337777dab0Sopenharmony_ci   *     that the source string contains no right-to-left characters, or
4347777dab0Sopenharmony_ci   *     that the source string is empty and the paragraph level is even.
4357777dab0Sopenharmony_ci   * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
4367777dab0Sopenharmony_ci   *      means that the first strong character of the source string has
4377777dab0Sopenharmony_ci   *      a left-to-right direction.
4387777dab0Sopenharmony_ci   * </ul>
4397777dab0Sopenharmony_ci   * @stable ICU 2.0
4407777dab0Sopenharmony_ci   */
4417777dab0Sopenharmony_ci  UBIDI_LTR,
4427777dab0Sopenharmony_ci  /** Right-to-left text. This is a 1 value.
4437777dab0Sopenharmony_ci   * <ul>
4447777dab0Sopenharmony_ci   * <li>As return value for <code>ubidi_getDirection()</code>, it means
4457777dab0Sopenharmony_ci   *     that the source string contains no left-to-right characters, or
4467777dab0Sopenharmony_ci   *     that the source string is empty and the paragraph level is odd.
4477777dab0Sopenharmony_ci   * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
4487777dab0Sopenharmony_ci   *      means that the first strong character of the source string has
4497777dab0Sopenharmony_ci   *      a right-to-left direction.
4507777dab0Sopenharmony_ci   * </ul>
4517777dab0Sopenharmony_ci   * @stable ICU 2.0
4527777dab0Sopenharmony_ci   */
4537777dab0Sopenharmony_ci  UBIDI_RTL,
4547777dab0Sopenharmony_ci  /** Mixed-directional text.
4557777dab0Sopenharmony_ci   * <p>As return value for <code>ubidi_getDirection()</code>, it means
4567777dab0Sopenharmony_ci   *    that the source string contains both left-to-right and
4577777dab0Sopenharmony_ci   *    right-to-left characters.
4587777dab0Sopenharmony_ci   * @stable ICU 2.0
4597777dab0Sopenharmony_ci   */
4607777dab0Sopenharmony_ci  UBIDI_MIXED,
4617777dab0Sopenharmony_ci  /** No strongly directional text.
4627777dab0Sopenharmony_ci   * <p>As return value for <code>ubidi_getBaseDirection()</code>, it means
4637777dab0Sopenharmony_ci   *    that the source string is missing or empty, or contains neither left-to-right
4647777dab0Sopenharmony_ci   *    nor right-to-left characters.
4657777dab0Sopenharmony_ci   * @stable ICU 4.6
4667777dab0Sopenharmony_ci   */
4677777dab0Sopenharmony_ci  UBIDI_NEUTRAL
4687777dab0Sopenharmony_ci};
4697777dab0Sopenharmony_ci
4707777dab0Sopenharmony_ci/** @stable ICU 2.0 */
4717777dab0Sopenharmony_citypedef enum UBiDiDirection UBiDiDirection;
4727777dab0Sopenharmony_ci
4737777dab0Sopenharmony_ci/**
4747777dab0Sopenharmony_ci * Forward declaration of the <code>UBiDi</code> structure for the declaration of
4757777dab0Sopenharmony_ci * the API functions. Its fields are implementation-specific.<p>
4767777dab0Sopenharmony_ci * This structure holds information about a paragraph (or multiple paragraphs)
4777777dab0Sopenharmony_ci * of text with Bidi-algorithm-related details, or about one line of
4787777dab0Sopenharmony_ci * such a paragraph.<p>
4797777dab0Sopenharmony_ci * Reordering can be done on a line, or on one or more paragraphs which are
4807777dab0Sopenharmony_ci * then interpreted each as one single line.
4817777dab0Sopenharmony_ci * @stable ICU 2.0
4827777dab0Sopenharmony_ci */
4837777dab0Sopenharmony_cistruct UBiDi;
4847777dab0Sopenharmony_ci
4857777dab0Sopenharmony_ci/** @stable ICU 2.0 */
4867777dab0Sopenharmony_citypedef struct UBiDi UBiDi;
4877777dab0Sopenharmony_ci
4887777dab0Sopenharmony_ci/**
4897777dab0Sopenharmony_ci * Allocate a <code>UBiDi</code> structure.
4907777dab0Sopenharmony_ci * Such an object is initially empty. It is assigned
4917777dab0Sopenharmony_ci * the Bidi properties of a piece of text containing one or more paragraphs
4927777dab0Sopenharmony_ci * by <code>ubidi_setPara()</code>
4937777dab0Sopenharmony_ci * or the Bidi properties of a line within a paragraph by
4947777dab0Sopenharmony_ci * <code>ubidi_setLine()</code>.<p>
4957777dab0Sopenharmony_ci * This object can be reused for as long as it is not deallocated
4967777dab0Sopenharmony_ci * by calling <code>ubidi_close()</code>.<p>
4977777dab0Sopenharmony_ci * <code>ubidi_setPara()</code> and <code>ubidi_setLine()</code> will allocate
4987777dab0Sopenharmony_ci * additional memory for internal structures as necessary.
4997777dab0Sopenharmony_ci *
5007777dab0Sopenharmony_ci * @return An empty <code>UBiDi</code> object.
5017777dab0Sopenharmony_ci * @stable ICU 2.0
5027777dab0Sopenharmony_ci */
5037777dab0Sopenharmony_ciU_CAPI UBiDi * U_EXPORT2
5047777dab0Sopenharmony_ciubidi_open(void);
5057777dab0Sopenharmony_ci
5067777dab0Sopenharmony_ci/**
5077777dab0Sopenharmony_ci * Allocate a <code>UBiDi</code> structure with preallocated memory
5087777dab0Sopenharmony_ci * for internal structures.
5097777dab0Sopenharmony_ci * This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>
5107777dab0Sopenharmony_ci * with no arguments, but it also preallocates memory for internal structures
5117777dab0Sopenharmony_ci * according to the sizings supplied by the caller.<p>
5127777dab0Sopenharmony_ci * Subsequent functions will not allocate any more memory, and are thus
5137777dab0Sopenharmony_ci * guaranteed not to fail because of lack of memory.<p>
5147777dab0Sopenharmony_ci * The preallocation can be limited to some of the internal memory
5157777dab0Sopenharmony_ci * by setting some values to 0 here. That means that if, e.g.,
5167777dab0Sopenharmony_ci * <code>maxRunCount</code> cannot be reasonably predetermined and should not
5177777dab0Sopenharmony_ci * be set to <code>maxLength</code> (the only failproof value) to avoid
5187777dab0Sopenharmony_ci * wasting memory, then <code>maxRunCount</code> could be set to 0 here
5197777dab0Sopenharmony_ci * and the internal structures that are associated with it will be allocated
5207777dab0Sopenharmony_ci * on demand, just like with <code>ubidi_open()</code>.
5217777dab0Sopenharmony_ci *
5227777dab0Sopenharmony_ci * @param maxLength is the maximum text or line length that internal memory
5237777dab0Sopenharmony_ci *        will be preallocated for. An attempt to associate this object with a
5247777dab0Sopenharmony_ci *        longer text will fail, unless this value is 0, which leaves the allocation
5257777dab0Sopenharmony_ci *        up to the implementation.
5267777dab0Sopenharmony_ci *
5277777dab0Sopenharmony_ci * @param maxRunCount is the maximum anticipated number of same-level runs
5287777dab0Sopenharmony_ci *        that internal memory will be preallocated for. An attempt to access
5297777dab0Sopenharmony_ci *        visual runs on an object that was not preallocated for as many runs
5307777dab0Sopenharmony_ci *        as the text was actually resolved to will fail,
5317777dab0Sopenharmony_ci *        unless this value is 0, which leaves the allocation up to the implementation.<br><br>
5327777dab0Sopenharmony_ci *        The number of runs depends on the actual text and maybe anywhere between
5337777dab0Sopenharmony_ci *        1 and <code>maxLength</code>. It is typically small.
5347777dab0Sopenharmony_ci *
5357777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
5367777dab0Sopenharmony_ci *
5377777dab0Sopenharmony_ci * @return An empty <code>UBiDi</code> object with preallocated memory.
5387777dab0Sopenharmony_ci * @stable ICU 2.0
5397777dab0Sopenharmony_ci */
5407777dab0Sopenharmony_ciU_CAPI UBiDi * U_EXPORT2
5417777dab0Sopenharmony_ciubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
5427777dab0Sopenharmony_ci
5437777dab0Sopenharmony_ci/**
5447777dab0Sopenharmony_ci * <code>ubidi_close()</code> must be called to free the memory
5457777dab0Sopenharmony_ci * associated with a UBiDi object.<p>
5467777dab0Sopenharmony_ci *
5477777dab0Sopenharmony_ci * <strong>Important: </strong>
5487777dab0Sopenharmony_ci * A parent <code>UBiDi</code> object must not be destroyed or reused if
5497777dab0Sopenharmony_ci * it still has children.
5507777dab0Sopenharmony_ci * If a <code>UBiDi</code> object has become the <i>child</i>
5517777dab0Sopenharmony_ci * of another one (its <i>parent</i>) by calling
5527777dab0Sopenharmony_ci * <code>ubidi_setLine()</code>, then the child object must
5537777dab0Sopenharmony_ci * be destroyed (closed) or reused (by calling
5547777dab0Sopenharmony_ci * <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)
5557777dab0Sopenharmony_ci * before the parent object.
5567777dab0Sopenharmony_ci *
5577777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
5587777dab0Sopenharmony_ci *
5597777dab0Sopenharmony_ci * @see ubidi_setPara
5607777dab0Sopenharmony_ci * @see ubidi_setLine
5617777dab0Sopenharmony_ci * @stable ICU 2.0
5627777dab0Sopenharmony_ci */
5637777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
5647777dab0Sopenharmony_ciubidi_close(UBiDi *pBiDi);
5657777dab0Sopenharmony_ci
5667777dab0Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API
5677777dab0Sopenharmony_ci
5687777dab0Sopenharmony_ciU_NAMESPACE_BEGIN
5697777dab0Sopenharmony_ci
5707777dab0Sopenharmony_ci/**
5717777dab0Sopenharmony_ci * \class LocalUBiDiPointer
5727777dab0Sopenharmony_ci * "Smart pointer" class, closes a UBiDi via ubidi_close().
5737777dab0Sopenharmony_ci * For most methods see the LocalPointerBase base class.
5747777dab0Sopenharmony_ci *
5757777dab0Sopenharmony_ci * @see LocalPointerBase
5767777dab0Sopenharmony_ci * @see LocalPointer
5777777dab0Sopenharmony_ci * @stable ICU 4.4
5787777dab0Sopenharmony_ci */
5797777dab0Sopenharmony_ciU_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);
5807777dab0Sopenharmony_ci
5817777dab0Sopenharmony_ciU_NAMESPACE_END
5827777dab0Sopenharmony_ci
5837777dab0Sopenharmony_ci#endif
5847777dab0Sopenharmony_ci
5857777dab0Sopenharmony_ci/**
5867777dab0Sopenharmony_ci * Modify the operation of the Bidi algorithm such that it
5877777dab0Sopenharmony_ci * approximates an "inverse Bidi" algorithm. This function
5887777dab0Sopenharmony_ci * must be called before <code>ubidi_setPara()</code>.
5897777dab0Sopenharmony_ci *
5907777dab0Sopenharmony_ci * <p>The normal operation of the Bidi algorithm as described
5917777dab0Sopenharmony_ci * in the Unicode Technical Report is to take text stored in logical
5927777dab0Sopenharmony_ci * (keyboard, typing) order and to determine the reordering of it for visual
5937777dab0Sopenharmony_ci * rendering.
5947777dab0Sopenharmony_ci * Some legacy systems store text in visual order, and for operations
5957777dab0Sopenharmony_ci * with standard, Unicode-based algorithms, the text needs to be transformed
5967777dab0Sopenharmony_ci * to logical order. This is effectively the inverse algorithm of the
5977777dab0Sopenharmony_ci * described Bidi algorithm. Note that there is no standard algorithm for
5987777dab0Sopenharmony_ci * this "inverse Bidi" and that the current implementation provides only an
5997777dab0Sopenharmony_ci * approximation of "inverse Bidi".</p>
6007777dab0Sopenharmony_ci *
6017777dab0Sopenharmony_ci * <p>With <code>isInverse</code> set to <code>true</code>,
6027777dab0Sopenharmony_ci * this function changes the behavior of some of the subsequent functions
6037777dab0Sopenharmony_ci * in a way that they can be used for the inverse Bidi algorithm.
6047777dab0Sopenharmony_ci * Specifically, runs of text with numeric characters will be treated in a
6057777dab0Sopenharmony_ci * special way and may need to be surrounded with LRM characters when they are
6067777dab0Sopenharmony_ci * written in reordered sequence.</p>
6077777dab0Sopenharmony_ci *
6087777dab0Sopenharmony_ci * <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.
6097777dab0Sopenharmony_ci * Since the actual input for "inverse Bidi" is visually ordered text and
6107777dab0Sopenharmony_ci * <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually
6117777dab0Sopenharmony_ci * the runs of the logically ordered output.</p>
6127777dab0Sopenharmony_ci *
6137777dab0Sopenharmony_ci * <p>Calling this function with argument <code>isInverse</code> set to
6147777dab0Sopenharmony_ci * <code>true</code> is equivalent to calling
6157777dab0Sopenharmony_ci * <code>ubidi_setReorderingMode</code> with argument
6167777dab0Sopenharmony_ci * <code>reorderingMode</code>
6177777dab0Sopenharmony_ci * set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
6187777dab0Sopenharmony_ci * Calling this function with argument <code>isInverse</code> set to
6197777dab0Sopenharmony_ci * <code>false</code> is equivalent to calling
6207777dab0Sopenharmony_ci * <code>ubidi_setReorderingMode</code> with argument
6217777dab0Sopenharmony_ci * <code>reorderingMode</code>
6227777dab0Sopenharmony_ci * set to <code>#UBIDI_REORDER_DEFAULT</code>.
6237777dab0Sopenharmony_ci *
6247777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6257777dab0Sopenharmony_ci *
6267777dab0Sopenharmony_ci * @param isInverse specifies "forward" or "inverse" Bidi operation.
6277777dab0Sopenharmony_ci *
6287777dab0Sopenharmony_ci * @see ubidi_setPara
6297777dab0Sopenharmony_ci * @see ubidi_writeReordered
6307777dab0Sopenharmony_ci * @see ubidi_setReorderingMode
6317777dab0Sopenharmony_ci * @stable ICU 2.0
6327777dab0Sopenharmony_ci */
6337777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
6347777dab0Sopenharmony_ciubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
6357777dab0Sopenharmony_ci
6367777dab0Sopenharmony_ci/**
6377777dab0Sopenharmony_ci * Is this Bidi object set to perform the inverse Bidi algorithm?
6387777dab0Sopenharmony_ci * <p>Note: calling this function after setting the reordering mode with
6397777dab0Sopenharmony_ci * <code>ubidi_setReorderingMode</code> will return <code>true</code> if the
6407777dab0Sopenharmony_ci * reordering mode was set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>,
6417777dab0Sopenharmony_ci * <code>false</code> for all other values.</p>
6427777dab0Sopenharmony_ci *
6437777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6447777dab0Sopenharmony_ci * @return true if the Bidi object is set to perform the inverse Bidi algorithm
6457777dab0Sopenharmony_ci * by handling numbers as L.
6467777dab0Sopenharmony_ci *
6477777dab0Sopenharmony_ci * @see ubidi_setInverse
6487777dab0Sopenharmony_ci * @see ubidi_setReorderingMode
6497777dab0Sopenharmony_ci * @stable ICU 2.0
6507777dab0Sopenharmony_ci */
6517777dab0Sopenharmony_ci
6527777dab0Sopenharmony_ciU_CAPI UBool U_EXPORT2
6537777dab0Sopenharmony_ciubidi_isInverse(UBiDi *pBiDi);
6547777dab0Sopenharmony_ci
6557777dab0Sopenharmony_ci/**
6567777dab0Sopenharmony_ci * Specify whether block separators must be allocated level zero,
6577777dab0Sopenharmony_ci * so that successive paragraphs will progress from left to right.
6587777dab0Sopenharmony_ci * This function must be called before <code>ubidi_setPara()</code>.
6597777dab0Sopenharmony_ci * Paragraph separators (B) may appear in the text.  Setting them to level zero
6607777dab0Sopenharmony_ci * means that all paragraph separators (including one possibly appearing
6617777dab0Sopenharmony_ci * in the last text position) are kept in the reordered text after the text
6627777dab0Sopenharmony_ci * that they follow in the source text.
6637777dab0Sopenharmony_ci * When this feature is not enabled, a paragraph separator at the last
6647777dab0Sopenharmony_ci * position of the text before reordering will go to the first position
6657777dab0Sopenharmony_ci * of the reordered text when the paragraph level is odd.
6667777dab0Sopenharmony_ci *
6677777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6687777dab0Sopenharmony_ci *
6697777dab0Sopenharmony_ci * @param orderParagraphsLTR specifies whether paragraph separators (B) must
6707777dab0Sopenharmony_ci * receive level 0, so that successive paragraphs progress from left to right.
6717777dab0Sopenharmony_ci *
6727777dab0Sopenharmony_ci * @see ubidi_setPara
6737777dab0Sopenharmony_ci * @stable ICU 3.4
6747777dab0Sopenharmony_ci */
6757777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
6767777dab0Sopenharmony_ciubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);
6777777dab0Sopenharmony_ci
6787777dab0Sopenharmony_ci/**
6797777dab0Sopenharmony_ci * Is this Bidi object set to allocate level 0 to block separators so that
6807777dab0Sopenharmony_ci * successive paragraphs progress from left to right?
6817777dab0Sopenharmony_ci *
6827777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6837777dab0Sopenharmony_ci * @return true if the Bidi object is set to allocate level 0 to block
6847777dab0Sopenharmony_ci *         separators.
6857777dab0Sopenharmony_ci *
6867777dab0Sopenharmony_ci * @see ubidi_orderParagraphsLTR
6877777dab0Sopenharmony_ci * @stable ICU 3.4
6887777dab0Sopenharmony_ci */
6897777dab0Sopenharmony_ciU_CAPI UBool U_EXPORT2
6907777dab0Sopenharmony_ciubidi_isOrderParagraphsLTR(UBiDi *pBiDi);
6917777dab0Sopenharmony_ci
6927777dab0Sopenharmony_ci/**
6937777dab0Sopenharmony_ci * <code>UBiDiReorderingMode</code> values indicate which variant of the Bidi
6947777dab0Sopenharmony_ci * algorithm to use.
6957777dab0Sopenharmony_ci *
6967777dab0Sopenharmony_ci * @see ubidi_setReorderingMode
6977777dab0Sopenharmony_ci * @stable ICU 3.6
6987777dab0Sopenharmony_ci */
6997777dab0Sopenharmony_citypedef enum UBiDiReorderingMode {
7007777dab0Sopenharmony_ci    /** Regular Logical to Visual Bidi algorithm according to Unicode.
7017777dab0Sopenharmony_ci      * This is a 0 value.
7027777dab0Sopenharmony_ci      * @stable ICU 3.6 */
7037777dab0Sopenharmony_ci    UBIDI_REORDER_DEFAULT = 0,
7047777dab0Sopenharmony_ci    /** Logical to Visual algorithm which handles numbers in a way which
7057777dab0Sopenharmony_ci      * mimics the behavior of Windows XP.
7067777dab0Sopenharmony_ci      * @stable ICU 3.6 */
7077777dab0Sopenharmony_ci    UBIDI_REORDER_NUMBERS_SPECIAL,
7087777dab0Sopenharmony_ci    /** Logical to Visual algorithm grouping numbers with adjacent R characters
7097777dab0Sopenharmony_ci      * (reversible algorithm).
7107777dab0Sopenharmony_ci      * @stable ICU 3.6 */
7117777dab0Sopenharmony_ci    UBIDI_REORDER_GROUP_NUMBERS_WITH_R,
7127777dab0Sopenharmony_ci    /** Reorder runs only to transform a Logical LTR string to the Logical RTL
7137777dab0Sopenharmony_ci      * string with the same display, or vice-versa.<br>
7147777dab0Sopenharmony_ci      * If this mode is set together with option
7157777dab0Sopenharmony_ci      * <code>#UBIDI_OPTION_INSERT_MARKS</code>, some Bidi controls in the source
7167777dab0Sopenharmony_ci      * text may be removed and other controls may be added to produce the
7177777dab0Sopenharmony_ci      * minimum combination which has the required display.
7187777dab0Sopenharmony_ci      * @stable ICU 3.6 */
7197777dab0Sopenharmony_ci    UBIDI_REORDER_RUNS_ONLY,
7207777dab0Sopenharmony_ci    /** Visual to Logical algorithm which handles numbers like L
7217777dab0Sopenharmony_ci      * (same algorithm as selected by <code>ubidi_setInverse(true)</code>.
7227777dab0Sopenharmony_ci      * @see ubidi_setInverse
7237777dab0Sopenharmony_ci      * @stable ICU 3.6 */
7247777dab0Sopenharmony_ci    UBIDI_REORDER_INVERSE_NUMBERS_AS_L,
7257777dab0Sopenharmony_ci    /** Visual to Logical algorithm equivalent to the regular Logical to Visual
7267777dab0Sopenharmony_ci      * algorithm.
7277777dab0Sopenharmony_ci      * @stable ICU 3.6 */
7287777dab0Sopenharmony_ci    UBIDI_REORDER_INVERSE_LIKE_DIRECT,
7297777dab0Sopenharmony_ci    /** Inverse Bidi (Visual to Logical) algorithm for the
7307777dab0Sopenharmony_ci      * <code>UBIDI_REORDER_NUMBERS_SPECIAL</code> Bidi algorithm.
7317777dab0Sopenharmony_ci      * @stable ICU 3.6 */
7327777dab0Sopenharmony_ci    UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,
7337777dab0Sopenharmony_ci} UBiDiReorderingMode;
7347777dab0Sopenharmony_ci
7357777dab0Sopenharmony_ci/**
7367777dab0Sopenharmony_ci * Modify the operation of the Bidi algorithm such that it implements some
7377777dab0Sopenharmony_ci * variant to the basic Bidi algorithm or approximates an "inverse Bidi"
7387777dab0Sopenharmony_ci * algorithm, depending on different values of the "reordering mode".
7397777dab0Sopenharmony_ci * This function must be called before <code>ubidi_setPara()</code>, and stays
7407777dab0Sopenharmony_ci * in effect until called again with a different argument.
7417777dab0Sopenharmony_ci *
7427777dab0Sopenharmony_ci * <p>The normal operation of the Bidi algorithm as described
7437777dab0Sopenharmony_ci * in the Unicode Standard Annex #9 is to take text stored in logical
7447777dab0Sopenharmony_ci * (keyboard, typing) order and to determine how to reorder it for visual
7457777dab0Sopenharmony_ci * rendering.</p>
7467777dab0Sopenharmony_ci *
7477777dab0Sopenharmony_ci * <p>With the reordering mode set to a value other than
7487777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_DEFAULT</code>, this function changes the behavior of
7497777dab0Sopenharmony_ci * some of the subsequent functions in a way such that they implement an
7507777dab0Sopenharmony_ci * inverse Bidi algorithm or some other algorithm variants.</p>
7517777dab0Sopenharmony_ci *
7527777dab0Sopenharmony_ci * <p>Some legacy systems store text in visual order, and for operations
7537777dab0Sopenharmony_ci * with standard, Unicode-based algorithms, the text needs to be transformed
7547777dab0Sopenharmony_ci * into logical order. This is effectively the inverse algorithm of the
7557777dab0Sopenharmony_ci * described Bidi algorithm. Note that there is no standard algorithm for
7567777dab0Sopenharmony_ci * this "inverse Bidi", so a number of variants are implemented here.</p>
7577777dab0Sopenharmony_ci *
7587777dab0Sopenharmony_ci * <p>In other cases, it may be desirable to emulate some variant of the
7597777dab0Sopenharmony_ci * Logical to Visual algorithm (e.g. one used in MS Windows), or perform a
7607777dab0Sopenharmony_ci * Logical to Logical transformation.</p>
7617777dab0Sopenharmony_ci *
7627777dab0Sopenharmony_ci * <ul>
7637777dab0Sopenharmony_ci * <li>When the reordering mode is set to <code>#UBIDI_REORDER_DEFAULT</code>,
7647777dab0Sopenharmony_ci * the standard Bidi Logical to Visual algorithm is applied.</li>
7657777dab0Sopenharmony_ci *
7667777dab0Sopenharmony_ci * <li>When the reordering mode is set to
7677777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_NUMBERS_SPECIAL</code>,
7687777dab0Sopenharmony_ci * the algorithm used to perform Bidi transformations when calling
7697777dab0Sopenharmony_ci * <code>ubidi_setPara</code> should approximate the algorithm used in
7707777dab0Sopenharmony_ci * Microsoft Windows XP rather than strictly conform to the Unicode Bidi
7717777dab0Sopenharmony_ci * algorithm.
7727777dab0Sopenharmony_ci * <br>
7737777dab0Sopenharmony_ci * The differences between the basic algorithm and the algorithm addressed
7747777dab0Sopenharmony_ci * by this option are as follows:
7757777dab0Sopenharmony_ci * <ul>
7767777dab0Sopenharmony_ci *   <li>Within text at an even embedding level, the sequence "123AB"
7777777dab0Sopenharmony_ci *   (where AB represent R or AL letters) is transformed to "123BA" by the
7787777dab0Sopenharmony_ci *   Unicode algorithm and to "BA123" by the Windows algorithm.</li>
7797777dab0Sopenharmony_ci *   <li>Arabic-Indic numbers (AN) are handled by the Windows algorithm just
7807777dab0Sopenharmony_ci *   like regular numbers (EN).</li>
7817777dab0Sopenharmony_ci * </ul></li>
7827777dab0Sopenharmony_ci *
7837777dab0Sopenharmony_ci * <li>When the reordering mode is set to
7847777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_GROUP_NUMBERS_WITH_R</code>,
7857777dab0Sopenharmony_ci * numbers located between LTR text and RTL text are associated with the RTL
7867777dab0Sopenharmony_ci * text. For instance, an LTR paragraph with content "abc 123 DEF" (where
7877777dab0Sopenharmony_ci * upper case letters represent RTL characters) will be transformed to
7887777dab0Sopenharmony_ci * "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed
7897777dab0Sopenharmony_ci * to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".
7907777dab0Sopenharmony_ci * This makes the algorithm reversible and makes it useful when round trip
7917777dab0Sopenharmony_ci * (from visual to logical and back to visual) must be achieved without
7927777dab0Sopenharmony_ci * adding LRM characters. However, this is a variation from the standard
7937777dab0Sopenharmony_ci * Unicode Bidi algorithm.<br>
7947777dab0Sopenharmony_ci * The source text should not contain Bidi control characters other than LRM
7957777dab0Sopenharmony_ci * or RLM.</li>
7967777dab0Sopenharmony_ci *
7977777dab0Sopenharmony_ci * <li>When the reordering mode is set to
7987777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_RUNS_ONLY</code>,
7997777dab0Sopenharmony_ci * a "Logical to Logical" transformation must be performed:
8007777dab0Sopenharmony_ci * <ul>
8017777dab0Sopenharmony_ci * <li>If the default text level of the source text (argument <code>paraLevel</code>
8027777dab0Sopenharmony_ci * in <code>ubidi_setPara</code>) is even, the source text will be handled as
8037777dab0Sopenharmony_ci * LTR logical text and will be transformed to the RTL logical text which has
8047777dab0Sopenharmony_ci * the same LTR visual display.</li>
8057777dab0Sopenharmony_ci * <li>If the default level of the source text is odd, the source text
8067777dab0Sopenharmony_ci * will be handled as RTL logical text and will be transformed to the
8077777dab0Sopenharmony_ci * LTR logical text which has the same LTR visual display.</li>
8087777dab0Sopenharmony_ci * </ul>
8097777dab0Sopenharmony_ci * This mode may be needed when logical text which is basically Arabic or
8107777dab0Sopenharmony_ci * Hebrew, with possible included numbers or phrases in English, has to be
8117777dab0Sopenharmony_ci * displayed as if it had an even embedding level (this can happen if the
8127777dab0Sopenharmony_ci * displaying application treats all text as if it was basically LTR).
8137777dab0Sopenharmony_ci * <br>
8147777dab0Sopenharmony_ci * This mode may also be needed in the reverse case, when logical text which is
8157777dab0Sopenharmony_ci * basically English, with possible included phrases in Arabic or Hebrew, has to
8167777dab0Sopenharmony_ci * be displayed as if it had an odd embedding level.
8177777dab0Sopenharmony_ci * <br>
8187777dab0Sopenharmony_ci * Both cases could be handled by adding LRE or RLE at the head of the text,
8197777dab0Sopenharmony_ci * if the display subsystem supports these formatting controls. If it does not,
8207777dab0Sopenharmony_ci * the problem may be handled by transforming the source text in this mode
8217777dab0Sopenharmony_ci * before displaying it, so that it will be displayed properly.<br>
8227777dab0Sopenharmony_ci * The source text should not contain Bidi control characters other than LRM
8237777dab0Sopenharmony_ci * or RLM.</li>
8247777dab0Sopenharmony_ci *
8257777dab0Sopenharmony_ci * <li>When the reordering mode is set to
8267777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>, an "inverse Bidi" algorithm
8277777dab0Sopenharmony_ci * is applied.
8287777dab0Sopenharmony_ci * Runs of text with numeric characters will be treated like LTR letters and
8297777dab0Sopenharmony_ci * may need to be surrounded with LRM characters when they are written in
8307777dab0Sopenharmony_ci * reordered sequence (the option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> can
8317777dab0Sopenharmony_ci * be used with function <code>ubidi_writeReordered</code> to this end. This
8327777dab0Sopenharmony_ci * mode is equivalent to calling <code>ubidi_setInverse()</code> with
8337777dab0Sopenharmony_ci * argument <code>isInverse</code> set to <code>true</code>.</li>
8347777dab0Sopenharmony_ci *
8357777dab0Sopenharmony_ci * <li>When the reordering mode is set to
8367777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code>, the "direct" Logical to Visual
8377777dab0Sopenharmony_ci * Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.
8387777dab0Sopenharmony_ci * This mode is similar to mode <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>
8397777dab0Sopenharmony_ci * but is closer to the regular Bidi algorithm.
8407777dab0Sopenharmony_ci * <br>
8417777dab0Sopenharmony_ci * For example, an LTR paragraph with the content "FED 123 456 CBA" (where
8427777dab0Sopenharmony_ci * upper case represents RTL characters) will be transformed to
8437777dab0Sopenharmony_ci * "ABC 456 123 DEF", as opposed to "DEF 123 456 ABC"
8447777dab0Sopenharmony_ci * with mode <code>UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
8457777dab0Sopenharmony_ci * When used in conjunction with option
8467777dab0Sopenharmony_ci * <code>#UBIDI_OPTION_INSERT_MARKS</code>, this mode generally
8477777dab0Sopenharmony_ci * adds Bidi marks to the output significantly more sparingly than mode
8487777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> with option
8497777dab0Sopenharmony_ci * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to
8507777dab0Sopenharmony_ci * <code>ubidi_writeReordered</code>.</li>
8517777dab0Sopenharmony_ci *
8527777dab0Sopenharmony_ci * <li>When the reordering mode is set to
8537777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the Logical to Visual
8547777dab0Sopenharmony_ci * Bidi algorithm used in Windows XP is used as an approximation of an "inverse Bidi" algorithm.
8557777dab0Sopenharmony_ci * <br>
8567777dab0Sopenharmony_ci * For example, an LTR paragraph with the content "abc FED123" (where
8577777dab0Sopenharmony_ci * upper case represents RTL characters) will be transformed to "abc 123DEF."</li>
8587777dab0Sopenharmony_ci * </ul>
8597777dab0Sopenharmony_ci *
8607777dab0Sopenharmony_ci * <p>In all the reordering modes specifying an "inverse Bidi" algorithm
8617777dab0Sopenharmony_ci * (i.e. those with a name starting with <code>UBIDI_REORDER_INVERSE</code>),
8627777dab0Sopenharmony_ci * output runs should be retrieved using
8637777dab0Sopenharmony_ci * <code>ubidi_getVisualRun()</code>, and the output text with
8647777dab0Sopenharmony_ci * <code>ubidi_writeReordered()</code>. The caller should keep in mind that in
8657777dab0Sopenharmony_ci * "inverse Bidi" modes the input is actually visually ordered text and
8667777dab0Sopenharmony_ci * reordered output returned by <code>ubidi_getVisualRun()</code> or
8677777dab0Sopenharmony_ci * <code>ubidi_writeReordered()</code> are actually runs or character string
8687777dab0Sopenharmony_ci * of logically ordered output.<br>
8697777dab0Sopenharmony_ci * For all the "inverse Bidi" modes, the source text should not contain
8707777dab0Sopenharmony_ci * Bidi control characters other than LRM or RLM.</p>
8717777dab0Sopenharmony_ci *
8727777dab0Sopenharmony_ci * <p>Note that option <code>#UBIDI_OUTPUT_REVERSE</code> of
8737777dab0Sopenharmony_ci * <code>ubidi_writeReordered</code> has no useful meaning and should not be
8747777dab0Sopenharmony_ci * used in conjunction with any value of the reordering mode specifying
8757777dab0Sopenharmony_ci * "inverse Bidi" or with value <code>UBIDI_REORDER_RUNS_ONLY</code>.
8767777dab0Sopenharmony_ci *
8777777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
8787777dab0Sopenharmony_ci * @param reorderingMode specifies the required variant of the Bidi algorithm.
8797777dab0Sopenharmony_ci *
8807777dab0Sopenharmony_ci * @see UBiDiReorderingMode
8817777dab0Sopenharmony_ci * @see ubidi_setInverse
8827777dab0Sopenharmony_ci * @see ubidi_setPara
8837777dab0Sopenharmony_ci * @see ubidi_writeReordered
8847777dab0Sopenharmony_ci * @stable ICU 3.6
8857777dab0Sopenharmony_ci */
8867777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
8877777dab0Sopenharmony_ciubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);
8887777dab0Sopenharmony_ci
8897777dab0Sopenharmony_ci/**
8907777dab0Sopenharmony_ci * What is the requested reordering mode for a given Bidi object?
8917777dab0Sopenharmony_ci *
8927777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
8937777dab0Sopenharmony_ci * @return the current reordering mode of the Bidi object
8947777dab0Sopenharmony_ci * @see ubidi_setReorderingMode
8957777dab0Sopenharmony_ci * @stable ICU 3.6
8967777dab0Sopenharmony_ci */
8977777dab0Sopenharmony_ciU_CAPI UBiDiReorderingMode U_EXPORT2
8987777dab0Sopenharmony_ciubidi_getReorderingMode(UBiDi *pBiDi);
8997777dab0Sopenharmony_ci
9007777dab0Sopenharmony_ci/**
9017777dab0Sopenharmony_ci * <code>UBiDiReorderingOption</code> values indicate which options are
9027777dab0Sopenharmony_ci * specified to affect the Bidi algorithm.
9037777dab0Sopenharmony_ci *
9047777dab0Sopenharmony_ci * @see ubidi_setReorderingOptions
9057777dab0Sopenharmony_ci * @stable ICU 3.6
9067777dab0Sopenharmony_ci */
9077777dab0Sopenharmony_citypedef enum UBiDiReorderingOption {
9087777dab0Sopenharmony_ci    /**
9097777dab0Sopenharmony_ci     * option value for <code>ubidi_setReorderingOptions</code>:
9107777dab0Sopenharmony_ci     * disable all the options which can be set with this function
9117777dab0Sopenharmony_ci     * @see ubidi_setReorderingOptions
9127777dab0Sopenharmony_ci     * @stable ICU 3.6
9137777dab0Sopenharmony_ci     */
9147777dab0Sopenharmony_ci    UBIDI_OPTION_DEFAULT = 0,
9157777dab0Sopenharmony_ci
9167777dab0Sopenharmony_ci    /**
9177777dab0Sopenharmony_ci     * option bit for <code>ubidi_setReorderingOptions</code>:
9187777dab0Sopenharmony_ci     * insert Bidi marks (LRM or RLM) when needed to ensure correct result of
9197777dab0Sopenharmony_ci     * a reordering to a Logical order
9207777dab0Sopenharmony_ci     *
9217777dab0Sopenharmony_ci     * <p>This option must be set or reset before calling
9227777dab0Sopenharmony_ci     * <code>ubidi_setPara</code>.</p>
9237777dab0Sopenharmony_ci     *
9247777dab0Sopenharmony_ci     * <p>This option is significant only with reordering modes which generate
9257777dab0Sopenharmony_ci     * a result with Logical order, specifically:</p>
9267777dab0Sopenharmony_ci     * <ul>
9277777dab0Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_RUNS_ONLY</code></li>
9287777dab0Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code></li>
9297777dab0Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code></li>
9307777dab0Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code></li>
9317777dab0Sopenharmony_ci     * </ul>
9327777dab0Sopenharmony_ci     *
9337777dab0Sopenharmony_ci     * <p>If this option is set in conjunction with reordering mode
9347777dab0Sopenharmony_ci     * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> or with calling
9357777dab0Sopenharmony_ci     * <code>ubidi_setInverse(true)</code>, it implies
9367777dab0Sopenharmony_ci     * option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>
9377777dab0Sopenharmony_ci     * in calls to function <code>ubidi_writeReordered()</code>.</p>
9387777dab0Sopenharmony_ci     *
9397777dab0Sopenharmony_ci     * <p>For other reordering modes, a minimum number of LRM or RLM characters
9407777dab0Sopenharmony_ci     * will be added to the source text after reordering it so as to ensure
9417777dab0Sopenharmony_ci     * round trip, i.e. when applying the inverse reordering mode on the
9427777dab0Sopenharmony_ci     * resulting logical text with removal of Bidi marks
9437777dab0Sopenharmony_ci     * (option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> set before calling
9447777dab0Sopenharmony_ci     * <code>ubidi_setPara()</code> or option <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
9457777dab0Sopenharmony_ci     * in <code>ubidi_writeReordered</code>), the result will be identical to the
9467777dab0Sopenharmony_ci     * source text in the first transformation.
9477777dab0Sopenharmony_ci     *
9487777dab0Sopenharmony_ci     * <p>This option will be ignored if specified together with option
9497777dab0Sopenharmony_ci     * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>. It inhibits option
9507777dab0Sopenharmony_ci     * <code>UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to function
9517777dab0Sopenharmony_ci     * <code>ubidi_writeReordered()</code> and it implies option
9527777dab0Sopenharmony_ci     * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to function
9537777dab0Sopenharmony_ci     * <code>ubidi_writeReordered()</code> if the reordering mode is
9547777dab0Sopenharmony_ci     * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.</p>
9557777dab0Sopenharmony_ci     *
9567777dab0Sopenharmony_ci     * @see ubidi_setReorderingMode
9577777dab0Sopenharmony_ci     * @see ubidi_setReorderingOptions
9587777dab0Sopenharmony_ci     * @stable ICU 3.6
9597777dab0Sopenharmony_ci     */
9607777dab0Sopenharmony_ci    UBIDI_OPTION_INSERT_MARKS = 1,
9617777dab0Sopenharmony_ci
9627777dab0Sopenharmony_ci    /**
9637777dab0Sopenharmony_ci     * option bit for <code>ubidi_setReorderingOptions</code>:
9647777dab0Sopenharmony_ci     * remove Bidi control characters
9657777dab0Sopenharmony_ci     *
9667777dab0Sopenharmony_ci     * <p>This option must be set or reset before calling
9677777dab0Sopenharmony_ci     * <code>ubidi_setPara</code>.</p>
9687777dab0Sopenharmony_ci     *
9697777dab0Sopenharmony_ci     * <p>This option nullifies option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
9707777dab0Sopenharmony_ci     * It inhibits option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls
9717777dab0Sopenharmony_ci     * to function <code>ubidi_writeReordered()</code> and it implies option
9727777dab0Sopenharmony_ci     * <code>#UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to that function.</p>
9737777dab0Sopenharmony_ci     *
9747777dab0Sopenharmony_ci     * @see ubidi_setReorderingMode
9757777dab0Sopenharmony_ci     * @see ubidi_setReorderingOptions
9767777dab0Sopenharmony_ci     * @stable ICU 3.6
9777777dab0Sopenharmony_ci     */
9787777dab0Sopenharmony_ci    UBIDI_OPTION_REMOVE_CONTROLS = 2,
9797777dab0Sopenharmony_ci
9807777dab0Sopenharmony_ci    /**
9817777dab0Sopenharmony_ci     * option bit for <code>ubidi_setReorderingOptions</code>:
9827777dab0Sopenharmony_ci     * process the output as part of a stream to be continued
9837777dab0Sopenharmony_ci     *
9847777dab0Sopenharmony_ci     * <p>This option must be set or reset before calling
9857777dab0Sopenharmony_ci     * <code>ubidi_setPara</code>.</p>
9867777dab0Sopenharmony_ci     *
9877777dab0Sopenharmony_ci     * <p>This option specifies that the caller is interested in processing large
9887777dab0Sopenharmony_ci     * text object in parts.
9897777dab0Sopenharmony_ci     * The results of the successive calls are expected to be concatenated by the
9907777dab0Sopenharmony_ci     * caller. Only the call for the last part will have this option bit off.</p>
9917777dab0Sopenharmony_ci     *
9927777dab0Sopenharmony_ci     * <p>When this option bit is on, <code>ubidi_setPara()</code> may process
9937777dab0Sopenharmony_ci     * less than the full source text in order to truncate the text at a meaningful
9947777dab0Sopenharmony_ci     * boundary. The caller should call <code>ubidi_getProcessedLength()</code>
9957777dab0Sopenharmony_ci     * immediately after calling <code>ubidi_setPara()</code> in order to
9967777dab0Sopenharmony_ci     * determine how much of the source text has been processed.
9977777dab0Sopenharmony_ci     * Source text beyond that length should be resubmitted in following calls to
9987777dab0Sopenharmony_ci     * <code>ubidi_setPara</code>. The processed length may be less than
9997777dab0Sopenharmony_ci     * the length of the source text if a character preceding the last character of
10007777dab0Sopenharmony_ci     * the source text constitutes a reasonable boundary (like a block separator)
10017777dab0Sopenharmony_ci     * for text to be continued.<br>
10027777dab0Sopenharmony_ci     * If the last character of the source text constitutes a reasonable
10037777dab0Sopenharmony_ci     * boundary, the whole text will be processed at once.<br>
10047777dab0Sopenharmony_ci     * If nowhere in the source text there exists
10057777dab0Sopenharmony_ci     * such a reasonable boundary, the processed length will be zero.<br>
10067777dab0Sopenharmony_ci     * The caller should check for such an occurrence and do one of the following:
10077777dab0Sopenharmony_ci     * <ul><li>submit a larger amount of text with a better chance to include
10087777dab0Sopenharmony_ci     *         a reasonable boundary.</li>
10097777dab0Sopenharmony_ci     *     <li>resubmit the same text after turning off option
10107777dab0Sopenharmony_ci     *         <code>UBIDI_OPTION_STREAMING</code>.</li></ul>
10117777dab0Sopenharmony_ci     * In all cases, this option should be turned off before processing the last
10127777dab0Sopenharmony_ci     * part of the text.</p>
10137777dab0Sopenharmony_ci     *
10147777dab0Sopenharmony_ci     * <p>When the <code>UBIDI_OPTION_STREAMING</code> option is used,
10157777dab0Sopenharmony_ci     * it is recommended to call <code>ubidi_orderParagraphsLTR()</code> with
10167777dab0Sopenharmony_ci     * argument <code>orderParagraphsLTR</code> set to <code>true</code> before
10177777dab0Sopenharmony_ci     * calling <code>ubidi_setPara</code> so that later paragraphs may be
10187777dab0Sopenharmony_ci     * concatenated to previous paragraphs on the right.</p>
10197777dab0Sopenharmony_ci     *
10207777dab0Sopenharmony_ci     * @see ubidi_setReorderingMode
10217777dab0Sopenharmony_ci     * @see ubidi_setReorderingOptions
10227777dab0Sopenharmony_ci     * @see ubidi_getProcessedLength
10237777dab0Sopenharmony_ci     * @see ubidi_orderParagraphsLTR
10247777dab0Sopenharmony_ci     * @stable ICU 3.6
10257777dab0Sopenharmony_ci     */
10267777dab0Sopenharmony_ci    UBIDI_OPTION_STREAMING = 4
10277777dab0Sopenharmony_ci} UBiDiReorderingOption;
10287777dab0Sopenharmony_ci
10297777dab0Sopenharmony_ci/**
10307777dab0Sopenharmony_ci * Specify which of the reordering options
10317777dab0Sopenharmony_ci * should be applied during Bidi transformations.
10327777dab0Sopenharmony_ci *
10337777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
10347777dab0Sopenharmony_ci * @param reorderingOptions is a combination of zero or more of the following
10357777dab0Sopenharmony_ci * options:
10367777dab0Sopenharmony_ci * <code>#UBIDI_OPTION_DEFAULT</code>, <code>#UBIDI_OPTION_INSERT_MARKS</code>,
10377777dab0Sopenharmony_ci * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>, <code>#UBIDI_OPTION_STREAMING</code>.
10387777dab0Sopenharmony_ci *
10397777dab0Sopenharmony_ci * @see ubidi_getReorderingOptions
10407777dab0Sopenharmony_ci * @stable ICU 3.6
10417777dab0Sopenharmony_ci */
10427777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
10437777dab0Sopenharmony_ciubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);
10447777dab0Sopenharmony_ci
10457777dab0Sopenharmony_ci/**
10467777dab0Sopenharmony_ci * What are the reordering options applied to a given Bidi object?
10477777dab0Sopenharmony_ci *
10487777dab0Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
10497777dab0Sopenharmony_ci * @return the current reordering options of the Bidi object
10507777dab0Sopenharmony_ci * @see ubidi_setReorderingOptions
10517777dab0Sopenharmony_ci * @stable ICU 3.6
10527777dab0Sopenharmony_ci */
10537777dab0Sopenharmony_ciU_CAPI uint32_t U_EXPORT2
10547777dab0Sopenharmony_ciubidi_getReorderingOptions(UBiDi *pBiDi);
10557777dab0Sopenharmony_ci
10567777dab0Sopenharmony_ci/**
10577777dab0Sopenharmony_ci * Set the context before a call to ubidi_setPara().<p>
10587777dab0Sopenharmony_ci *
10597777dab0Sopenharmony_ci * ubidi_setPara() computes the left-right directionality for a given piece
10607777dab0Sopenharmony_ci * of text which is supplied as one of its arguments. Sometimes this piece
10617777dab0Sopenharmony_ci * of text (the "main text") should be considered in context, because text
10627777dab0Sopenharmony_ci * appearing before ("prologue") and/or after ("epilogue") the main text
10637777dab0Sopenharmony_ci * may affect the result of this computation.<p>
10647777dab0Sopenharmony_ci *
10657777dab0Sopenharmony_ci * This function specifies the prologue and/or the epilogue for the next
10667777dab0Sopenharmony_ci * call to ubidi_setPara(). The characters specified as prologue and
10677777dab0Sopenharmony_ci * epilogue should not be modified by the calling program until the call
10687777dab0Sopenharmony_ci * to ubidi_setPara() has returned. If successive calls to ubidi_setPara()
10697777dab0Sopenharmony_ci * all need specification of a context, ubidi_setContext() must be called
10707777dab0Sopenharmony_ci * before each call to ubidi_setPara(). In other words, a context is not
10717777dab0Sopenharmony_ci * "remembered" after the following successful call to ubidi_setPara().<p>
10727777dab0Sopenharmony_ci *
10737777dab0Sopenharmony_ci * If a call to ubidi_setPara() specifies UBIDI_DEFAULT_LTR or
10747777dab0Sopenharmony_ci * UBIDI_DEFAULT_RTL as paraLevel and is preceded by a call to
10757777dab0Sopenharmony_ci * ubidi_setContext() which specifies a prologue, the paragraph level will
10767777dab0Sopenharmony_ci * be computed taking in consideration the text in the prologue.<p>
10777777dab0Sopenharmony_ci *
10787777dab0Sopenharmony_ci * When ubidi_setPara() is called without a previous call to
10797777dab0Sopenharmony_ci * ubidi_setContext, the main text is handled as if preceded and followed
10807777dab0Sopenharmony_ci * by strong directional characters at the current paragraph level.
10817777dab0Sopenharmony_ci * Calling ubidi_setContext() with specification of a prologue will change
10827777dab0Sopenharmony_ci * this behavior by handling the main text as if preceded by the last
10837777dab0Sopenharmony_ci * strong character appearing in the prologue, if any.
10847777dab0Sopenharmony_ci * Calling ubidi_setContext() with specification of an epilogue will change
10857777dab0Sopenharmony_ci * the behavior of ubidi_setPara() by handling the main text as if followed
10867777dab0Sopenharmony_ci * by the first strong character or digit appearing in the epilogue, if any.<p>
10877777dab0Sopenharmony_ci *
10887777dab0Sopenharmony_ci * Note 1: if <code>ubidi_setContext</code> is called repeatedly without
10897777dab0Sopenharmony_ci *         calling <code>ubidi_setPara</code>, the earlier calls have no effect,
10907777dab0Sopenharmony_ci *         only the last call will be remembered for the next call to
10917777dab0Sopenharmony_ci *         <code>ubidi_setPara</code>.<p>
10927777dab0Sopenharmony_ci *
10937777dab0Sopenharmony_ci * Note 2: calling <code>ubidi_setContext(pBiDi, NULL, 0, NULL, 0, &errorCode)</code>
10947777dab0Sopenharmony_ci *         cancels any previous setting of non-empty prologue or epilogue.
10957777dab0Sopenharmony_ci *         The next call to <code>ubidi_setPara()</code> will process no
10967777dab0Sopenharmony_ci *         prologue or epilogue.<p>
10977777dab0Sopenharmony_ci *
10987777dab0Sopenharmony_ci * Note 3: users must be aware that even after setting the context
10997777dab0Sopenharmony_ci *         before a call to ubidi_setPara() to perform e.g. a logical to visual
11007777dab0Sopenharmony_ci *         transformation, the resulting string may not be identical to what it
11017777dab0Sopenharmony_ci *         would have been if all the text, including prologue and epilogue, had
11027777dab0Sopenharmony_ci *         been processed together.<br>
11037777dab0Sopenharmony_ci * Example (upper case letters represent RTL characters):<br>
11047777dab0Sopenharmony_ci * &nbsp;&nbsp;prologue = "<code>abc DE</code>"<br>
11057777dab0Sopenharmony_ci * &nbsp;&nbsp;epilogue = none<br>
11067777dab0Sopenharmony_ci * &nbsp;&nbsp;main text = "<code>FGH xyz</code>"<br>
11077777dab0Sopenharmony_ci * &nbsp;&nbsp;paraLevel = UBIDI_LTR<br>
11087777dab0Sopenharmony_ci * &nbsp;&nbsp;display without prologue = "<code>HGF xyz</code>"
11097777dab0Sopenharmony_ci *             ("HGF" is adjacent to "xyz")<br>
11107777dab0Sopenharmony_ci * &nbsp;&nbsp;display with prologue = "<code>abc HGFED xyz</code>"
11117777dab0Sopenharmony_ci *             ("HGF" is not adjacent to "xyz")<br>
11127777dab0Sopenharmony_ci *
11137777dab0Sopenharmony_ci * @param pBiDi is a paragraph <code>UBiDi</code> object.
11147777dab0Sopenharmony_ci *
11157777dab0Sopenharmony_ci * @param prologue is a pointer to the text which precedes the text that
11167777dab0Sopenharmony_ci *        will be specified in a coming call to ubidi_setPara().
11177777dab0Sopenharmony_ci *        If there is no prologue to consider, then <code>proLength</code>
11187777dab0Sopenharmony_ci *        must be zero and this pointer can be NULL.
11197777dab0Sopenharmony_ci *
11207777dab0Sopenharmony_ci * @param proLength is the length of the prologue; if <code>proLength==-1</code>
11217777dab0Sopenharmony_ci *        then the prologue must be zero-terminated.
11227777dab0Sopenharmony_ci *        Otherwise proLength must be >= 0. If <code>proLength==0</code>, it means
11237777dab0Sopenharmony_ci *        that there is no prologue to consider.
11247777dab0Sopenharmony_ci *
11257777dab0Sopenharmony_ci * @param epilogue is a pointer to the text which follows the text that
11267777dab0Sopenharmony_ci *        will be specified in a coming call to ubidi_setPara().
11277777dab0Sopenharmony_ci *        If there is no epilogue to consider, then <code>epiLength</code>
11287777dab0Sopenharmony_ci *        must be zero and this pointer can be NULL.
11297777dab0Sopenharmony_ci *
11307777dab0Sopenharmony_ci * @param epiLength is the length of the epilogue; if <code>epiLength==-1</code>
11317777dab0Sopenharmony_ci *        then the epilogue must be zero-terminated.
11327777dab0Sopenharmony_ci *        Otherwise epiLength must be >= 0. If <code>epiLength==0</code>, it means
11337777dab0Sopenharmony_ci *        that there is no epilogue to consider.
11347777dab0Sopenharmony_ci *
11357777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
11367777dab0Sopenharmony_ci *
11377777dab0Sopenharmony_ci * @see ubidi_setPara
11387777dab0Sopenharmony_ci * @stable ICU 4.8
11397777dab0Sopenharmony_ci */
11407777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
11417777dab0Sopenharmony_ciubidi_setContext(UBiDi *pBiDi,
11427777dab0Sopenharmony_ci                 const UChar *prologue, int32_t proLength,
11437777dab0Sopenharmony_ci                 const UChar *epilogue, int32_t epiLength,
11447777dab0Sopenharmony_ci                 UErrorCode *pErrorCode);
11457777dab0Sopenharmony_ci
11467777dab0Sopenharmony_ci/**
11477777dab0Sopenharmony_ci * Perform the Unicode Bidi algorithm. It is defined in the
11487777dab0Sopenharmony_ci * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
11497777dab0Sopenharmony_ci * version 13,
11507777dab0Sopenharmony_ci * also described in The Unicode Standard, Version 4.0 .<p>
11517777dab0Sopenharmony_ci *
11527777dab0Sopenharmony_ci * This function takes a piece of plain text containing one or more paragraphs,
11537777dab0Sopenharmony_ci * with or without externally specified embedding levels from <i>styled</i>
11547777dab0Sopenharmony_ci * text and computes the left-right-directionality of each character.<p>
11557777dab0Sopenharmony_ci *
11567777dab0Sopenharmony_ci * If the entire text is all of the same directionality, then
11577777dab0Sopenharmony_ci * the function may not perform all the steps described by the algorithm,
11587777dab0Sopenharmony_ci * i.e., some levels may not be the same as if all steps were performed.
11597777dab0Sopenharmony_ci * This is not relevant for unidirectional text.<br>
11607777dab0Sopenharmony_ci * For example, in pure LTR text with numbers the numbers would get
11617777dab0Sopenharmony_ci * a resolved level of 2 higher than the surrounding text according to
11627777dab0Sopenharmony_ci * the algorithm. This implementation may set all resolved levels to
11637777dab0Sopenharmony_ci * the same value in such a case.<p>
11647777dab0Sopenharmony_ci *
11657777dab0Sopenharmony_ci * The text can be composed of multiple paragraphs. Occurrence of a block
11667777dab0Sopenharmony_ci * separator in the text terminates a paragraph, and whatever comes next starts
11677777dab0Sopenharmony_ci * a new paragraph. The exception to this rule is when a Carriage Return (CR)
11687777dab0Sopenharmony_ci * is followed by a Line Feed (LF). Both CR and LF are block separators, but
11697777dab0Sopenharmony_ci * in that case, the pair of characters is considered as terminating the
11707777dab0Sopenharmony_ci * preceding paragraph, and a new paragraph will be started by a character
11717777dab0Sopenharmony_ci * coming after the LF.
11727777dab0Sopenharmony_ci *
11737777dab0Sopenharmony_ci * @param pBiDi A <code>UBiDi</code> object allocated with <code>ubidi_open()</code>
11747777dab0Sopenharmony_ci *        which will be set to contain the reordering information,
11757777dab0Sopenharmony_ci *        especially the resolved levels for all the characters in <code>text</code>.
11767777dab0Sopenharmony_ci *
11777777dab0Sopenharmony_ci * @param text is a pointer to the text that the Bidi algorithm will be performed on.
11787777dab0Sopenharmony_ci *        This pointer is stored in the UBiDi object and can be retrieved
11797777dab0Sopenharmony_ci *        with <code>ubidi_getText()</code>.<br>
11807777dab0Sopenharmony_ci *        <strong>Note:</strong> the text must be (at least) <code>length</code> long.
11817777dab0Sopenharmony_ci *
11827777dab0Sopenharmony_ci * @param length is the length of the text; if <code>length==-1</code> then
11837777dab0Sopenharmony_ci *        the text must be zero-terminated.
11847777dab0Sopenharmony_ci *
11857777dab0Sopenharmony_ci * @param paraLevel specifies the default level for the text;
11867777dab0Sopenharmony_ci *        it is typically 0 (LTR) or 1 (RTL).
11877777dab0Sopenharmony_ci *        If the function shall determine the paragraph level from the text,
11887777dab0Sopenharmony_ci *        then <code>paraLevel</code> can be set to
11897777dab0Sopenharmony_ci *        either <code>#UBIDI_DEFAULT_LTR</code>
11907777dab0Sopenharmony_ci *        or <code>#UBIDI_DEFAULT_RTL</code>; if the text contains multiple
11917777dab0Sopenharmony_ci *        paragraphs, the paragraph level shall be determined separately for
11927777dab0Sopenharmony_ci *        each paragraph; if a paragraph does not include any strongly typed
11937777dab0Sopenharmony_ci *        character, then the desired default is used (0 for LTR or 1 for RTL).
11947777dab0Sopenharmony_ci *        Any other value between 0 and <code>#UBIDI_MAX_EXPLICIT_LEVEL</code>
11957777dab0Sopenharmony_ci *        is also valid, with odd levels indicating RTL.
11967777dab0Sopenharmony_ci *
11977777dab0Sopenharmony_ci * @param embeddingLevels (in) may be used to preset the embedding and override levels,
11987777dab0Sopenharmony_ci *        ignoring characters like LRE and PDF in the text.
11997777dab0Sopenharmony_ci *        A level overrides the directional property of its corresponding
12007777dab0Sopenharmony_ci *        (same index) character if the level has the
12017777dab0Sopenharmony_ci *        <code>#UBIDI_LEVEL_OVERRIDE</code> bit set.<br><br>
12027777dab0Sopenharmony_ci *        Aside from that bit, it must be
12037777dab0Sopenharmony_ci *        <code>paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL</code>,
12047777dab0Sopenharmony_ci *        except that level 0 is always allowed.
12057777dab0Sopenharmony_ci *        Level 0 for a paragraph separator prevents reordering of paragraphs;
12067777dab0Sopenharmony_ci *        this only works reliably if <code>#UBIDI_LEVEL_OVERRIDE</code>
12077777dab0Sopenharmony_ci *        is also set for paragraph separators.
12087777dab0Sopenharmony_ci *        Level 0 for other characters is treated as a wildcard
12097777dab0Sopenharmony_ci *        and is lifted up to the resolved level of the surrounding paragraph.<br><br>
12107777dab0Sopenharmony_ci *        <strong>Caution: </strong>A copy of this pointer, not of the levels,
12117777dab0Sopenharmony_ci *        will be stored in the <code>UBiDi</code> object;
12127777dab0Sopenharmony_ci *        the <code>embeddingLevels</code> array must not be
12137777dab0Sopenharmony_ci *        deallocated before the <code>UBiDi</code> structure is destroyed or reused,
12147777dab0Sopenharmony_ci *        and the <code>embeddingLevels</code>
12157777dab0Sopenharmony_ci *        should not be modified to avoid unexpected results on subsequent Bidi operations.
12167777dab0Sopenharmony_ci *        However, the <code>ubidi_setPara()</code> and
12177777dab0Sopenharmony_ci *        <code>ubidi_setLine()</code> functions may modify some or all of the levels.<br><br>
12187777dab0Sopenharmony_ci *        After the <code>UBiDi</code> object is reused or destroyed, the caller
12197777dab0Sopenharmony_ci *        must take care of the deallocation of the <code>embeddingLevels</code> array.<br><br>
12207777dab0Sopenharmony_ci *        <strong>Note:</strong> the <code>embeddingLevels</code> array must be
12217777dab0Sopenharmony_ci *        at least <code>length</code> long.
12227777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
12237777dab0Sopenharmony_ci *        value is not necessary.
12247777dab0Sopenharmony_ci *
12257777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
12267777dab0Sopenharmony_ci * @stable ICU 2.0
12277777dab0Sopenharmony_ci */
12287777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
12297777dab0Sopenharmony_ciubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
12307777dab0Sopenharmony_ci              UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
12317777dab0Sopenharmony_ci              UErrorCode *pErrorCode);
12327777dab0Sopenharmony_ci
12337777dab0Sopenharmony_ci/**
12347777dab0Sopenharmony_ci * <code>ubidi_setLine()</code> sets a <code>UBiDi</code> to
12357777dab0Sopenharmony_ci * contain the reordering information, especially the resolved levels,
12367777dab0Sopenharmony_ci * for all the characters in a line of text. This line of text is
12377777dab0Sopenharmony_ci * specified by referring to a <code>UBiDi</code> object representing
12387777dab0Sopenharmony_ci * this information for a piece of text containing one or more paragraphs,
12397777dab0Sopenharmony_ci * and by specifying a range of indexes in this text.<p>
12407777dab0Sopenharmony_ci * In the new line object, the indexes will range from 0 to <code>limit-start-1</code>.<p>
12417777dab0Sopenharmony_ci *
12427777dab0Sopenharmony_ci * This is used after calling <code>ubidi_setPara()</code>
12437777dab0Sopenharmony_ci * for a piece of text, and after line-breaking on that text.
12447777dab0Sopenharmony_ci * It is not necessary if each paragraph is treated as a single line.<p>
12457777dab0Sopenharmony_ci *
12467777dab0Sopenharmony_ci * After line-breaking, rules (L1) and (L2) for the treatment of
12477777dab0Sopenharmony_ci * trailing WS and for reordering are performed on
12487777dab0Sopenharmony_ci * a <code>UBiDi</code> object that represents a line.<p>
12497777dab0Sopenharmony_ci *
12507777dab0Sopenharmony_ci * <strong>Important: </strong><code>pLineBiDi</code> shares data with
12517777dab0Sopenharmony_ci * <code>pParaBiDi</code>.
12527777dab0Sopenharmony_ci * You must destroy or reuse <code>pLineBiDi</code> before <code>pParaBiDi</code>.
12537777dab0Sopenharmony_ci * In other words, you must destroy or reuse the <code>UBiDi</code> object for a line
12547777dab0Sopenharmony_ci * before the object for its parent paragraph.<p>
12557777dab0Sopenharmony_ci *
12567777dab0Sopenharmony_ci * The text pointer that was stored in <code>pParaBiDi</code> is also copied,
12577777dab0Sopenharmony_ci * and <code>start</code> is added to it so that it points to the beginning of the
12587777dab0Sopenharmony_ci * line for this object.
12597777dab0Sopenharmony_ci *
12607777dab0Sopenharmony_ci * @param pParaBiDi is the parent paragraph object. It must have been set
12617777dab0Sopenharmony_ci * by a successful call to ubidi_setPara.
12627777dab0Sopenharmony_ci *
12637777dab0Sopenharmony_ci * @param start is the line's first index into the text.
12647777dab0Sopenharmony_ci *
12657777dab0Sopenharmony_ci * @param limit is just behind the line's last index into the text
12667777dab0Sopenharmony_ci *        (its last index +1).<br>
12677777dab0Sopenharmony_ci *        It must be <code>0<=start<limit<=</code>containing paragraph limit.
12687777dab0Sopenharmony_ci *        If the specified line crosses a paragraph boundary, the function
12697777dab0Sopenharmony_ci *        will terminate with error code U_ILLEGAL_ARGUMENT_ERROR.
12707777dab0Sopenharmony_ci *
12717777dab0Sopenharmony_ci * @param pLineBiDi is the object that will now represent a line of the text.
12727777dab0Sopenharmony_ci *
12737777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
12747777dab0Sopenharmony_ci *
12757777dab0Sopenharmony_ci * @see ubidi_setPara
12767777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
12777777dab0Sopenharmony_ci * @stable ICU 2.0
12787777dab0Sopenharmony_ci */
12797777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
12807777dab0Sopenharmony_ciubidi_setLine(const UBiDi *pParaBiDi,
12817777dab0Sopenharmony_ci              int32_t start, int32_t limit,
12827777dab0Sopenharmony_ci              UBiDi *pLineBiDi,
12837777dab0Sopenharmony_ci              UErrorCode *pErrorCode);
12847777dab0Sopenharmony_ci
12857777dab0Sopenharmony_ci/**
12867777dab0Sopenharmony_ci * Get the directionality of the text.
12877777dab0Sopenharmony_ci *
12887777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
12897777dab0Sopenharmony_ci *
12907777dab0Sopenharmony_ci * @return a value of <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>
12917777dab0Sopenharmony_ci *         or <code>UBIDI_MIXED</code>
12927777dab0Sopenharmony_ci *         that indicates if the entire text
12937777dab0Sopenharmony_ci *         represented by this object is unidirectional,
12947777dab0Sopenharmony_ci *         and which direction, or if it is mixed-directional.
12957777dab0Sopenharmony_ci * Note -  The value <code>UBIDI_NEUTRAL</code> is never returned from this method.
12967777dab0Sopenharmony_ci *
12977777dab0Sopenharmony_ci * @see UBiDiDirection
12987777dab0Sopenharmony_ci * @stable ICU 2.0
12997777dab0Sopenharmony_ci */
13007777dab0Sopenharmony_ciU_CAPI UBiDiDirection U_EXPORT2
13017777dab0Sopenharmony_ciubidi_getDirection(const UBiDi *pBiDi);
13027777dab0Sopenharmony_ci
13037777dab0Sopenharmony_ci/**
13047777dab0Sopenharmony_ci * Gets the base direction of the text provided according
13057777dab0Sopenharmony_ci * to the Unicode Bidirectional Algorithm. The base direction
13067777dab0Sopenharmony_ci * is derived from the first character in the string with bidirectional
13077777dab0Sopenharmony_ci * character type L, R, or AL. If the first such character has type L,
13087777dab0Sopenharmony_ci * <code>UBIDI_LTR</code> is returned. If the first such character has
13097777dab0Sopenharmony_ci * type R or AL, <code>UBIDI_RTL</code> is returned. If the string does
13107777dab0Sopenharmony_ci * not contain any character of these types, then
13117777dab0Sopenharmony_ci * <code>UBIDI_NEUTRAL</code> is returned.
13127777dab0Sopenharmony_ci *
13137777dab0Sopenharmony_ci * This is a lightweight function for use when only the base direction
13147777dab0Sopenharmony_ci * is needed and no further bidi processing of the text is needed.
13157777dab0Sopenharmony_ci *
13167777dab0Sopenharmony_ci * @param text is a pointer to the text whose base
13177777dab0Sopenharmony_ci *             direction is needed.
13187777dab0Sopenharmony_ci * Note: the text must be (at least) @c length long.
13197777dab0Sopenharmony_ci *
13207777dab0Sopenharmony_ci * @param length is the length of the text;
13217777dab0Sopenharmony_ci *               if <code>length==-1</code> then the text
13227777dab0Sopenharmony_ci *               must be zero-terminated.
13237777dab0Sopenharmony_ci *
13247777dab0Sopenharmony_ci * @return  <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>,
13257777dab0Sopenharmony_ci *          <code>UBIDI_NEUTRAL</code>
13267777dab0Sopenharmony_ci *
13277777dab0Sopenharmony_ci * @see UBiDiDirection
13287777dab0Sopenharmony_ci * @stable ICU 4.6
13297777dab0Sopenharmony_ci */
13307777dab0Sopenharmony_ciU_CAPI UBiDiDirection U_EXPORT2
13317777dab0Sopenharmony_ciubidi_getBaseDirection(const UChar *text,  int32_t length );
13327777dab0Sopenharmony_ci
13337777dab0Sopenharmony_ci/**
13347777dab0Sopenharmony_ci * Get the pointer to the text.
13357777dab0Sopenharmony_ci *
13367777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13377777dab0Sopenharmony_ci *
13387777dab0Sopenharmony_ci * @return The pointer to the text that the UBiDi object was created for.
13397777dab0Sopenharmony_ci *
13407777dab0Sopenharmony_ci * @see ubidi_setPara
13417777dab0Sopenharmony_ci * @see ubidi_setLine
13427777dab0Sopenharmony_ci * @stable ICU 2.0
13437777dab0Sopenharmony_ci */
13447777dab0Sopenharmony_ciU_CAPI const UChar * U_EXPORT2
13457777dab0Sopenharmony_ciubidi_getText(const UBiDi *pBiDi);
13467777dab0Sopenharmony_ci
13477777dab0Sopenharmony_ci/**
13487777dab0Sopenharmony_ci * Get the length of the text.
13497777dab0Sopenharmony_ci *
13507777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13517777dab0Sopenharmony_ci *
13527777dab0Sopenharmony_ci * @return The length of the text that the UBiDi object was created for.
13537777dab0Sopenharmony_ci * @stable ICU 2.0
13547777dab0Sopenharmony_ci */
13557777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
13567777dab0Sopenharmony_ciubidi_getLength(const UBiDi *pBiDi);
13577777dab0Sopenharmony_ci
13587777dab0Sopenharmony_ci/**
13597777dab0Sopenharmony_ci * Get the paragraph level of the text.
13607777dab0Sopenharmony_ci *
13617777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13627777dab0Sopenharmony_ci *
13637777dab0Sopenharmony_ci * @return The paragraph level. If there are multiple paragraphs, their
13647777dab0Sopenharmony_ci *         level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or
13657777dab0Sopenharmony_ci *         UBIDI_DEFAULT_RTL.  In that case, the level of the first paragraph
13667777dab0Sopenharmony_ci *         is returned.
13677777dab0Sopenharmony_ci *
13687777dab0Sopenharmony_ci * @see UBiDiLevel
13697777dab0Sopenharmony_ci * @see ubidi_getParagraph
13707777dab0Sopenharmony_ci * @see ubidi_getParagraphByIndex
13717777dab0Sopenharmony_ci * @stable ICU 2.0
13727777dab0Sopenharmony_ci */
13737777dab0Sopenharmony_ciU_CAPI UBiDiLevel U_EXPORT2
13747777dab0Sopenharmony_ciubidi_getParaLevel(const UBiDi *pBiDi);
13757777dab0Sopenharmony_ci
13767777dab0Sopenharmony_ci/**
13777777dab0Sopenharmony_ci * Get the number of paragraphs.
13787777dab0Sopenharmony_ci *
13797777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13807777dab0Sopenharmony_ci *
13817777dab0Sopenharmony_ci * @return The number of paragraphs.
13827777dab0Sopenharmony_ci * @stable ICU 3.4
13837777dab0Sopenharmony_ci */
13847777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
13857777dab0Sopenharmony_ciubidi_countParagraphs(UBiDi *pBiDi);
13867777dab0Sopenharmony_ci
13877777dab0Sopenharmony_ci/**
13887777dab0Sopenharmony_ci * Get a paragraph, given a position within the text.
13897777dab0Sopenharmony_ci * This function returns information about a paragraph.<br>
13907777dab0Sopenharmony_ci * Note: if the paragraph index is known, it is more efficient to
13917777dab0Sopenharmony_ci * retrieve the paragraph information using ubidi_getParagraphByIndex().<p>
13927777dab0Sopenharmony_ci *
13937777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13947777dab0Sopenharmony_ci *
13957777dab0Sopenharmony_ci * @param charIndex is the index of a character within the text, in the
13967777dab0Sopenharmony_ci *        range <code>[0..ubidi_getProcessedLength(pBiDi)-1]</code>.
13977777dab0Sopenharmony_ci *
13987777dab0Sopenharmony_ci * @param pParaStart will receive the index of the first character of the
13997777dab0Sopenharmony_ci *        paragraph in the text.
14007777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14017777dab0Sopenharmony_ci *        value is not necessary.
14027777dab0Sopenharmony_ci *
14037777dab0Sopenharmony_ci * @param pParaLimit will receive the limit of the paragraph.
14047777dab0Sopenharmony_ci *        The l-value that you point to here may be the
14057777dab0Sopenharmony_ci *        same expression (variable) as the one for
14067777dab0Sopenharmony_ci *        <code>charIndex</code>.
14077777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14087777dab0Sopenharmony_ci *        value is not necessary.
14097777dab0Sopenharmony_ci *
14107777dab0Sopenharmony_ci * @param pParaLevel will receive the level of the paragraph.
14117777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14127777dab0Sopenharmony_ci *        value is not necessary.
14137777dab0Sopenharmony_ci *
14147777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
14157777dab0Sopenharmony_ci *
14167777dab0Sopenharmony_ci * @return The index of the paragraph containing the specified position.
14177777dab0Sopenharmony_ci *
14187777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
14197777dab0Sopenharmony_ci * @stable ICU 3.4
14207777dab0Sopenharmony_ci */
14217777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
14227777dab0Sopenharmony_ciubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,
14237777dab0Sopenharmony_ci                   int32_t *pParaLimit, UBiDiLevel *pParaLevel,
14247777dab0Sopenharmony_ci                   UErrorCode *pErrorCode);
14257777dab0Sopenharmony_ci
14267777dab0Sopenharmony_ci/**
14277777dab0Sopenharmony_ci * Get a paragraph, given the index of this paragraph.
14287777dab0Sopenharmony_ci *
14297777dab0Sopenharmony_ci * This function returns information about a paragraph.<p>
14307777dab0Sopenharmony_ci *
14317777dab0Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
14327777dab0Sopenharmony_ci *
14337777dab0Sopenharmony_ci * @param paraIndex is the number of the paragraph, in the
14347777dab0Sopenharmony_ci *        range <code>[0..ubidi_countParagraphs(pBiDi)-1]</code>.
14357777dab0Sopenharmony_ci *
14367777dab0Sopenharmony_ci * @param pParaStart will receive the index of the first character of the
14377777dab0Sopenharmony_ci *        paragraph in the text.
14387777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14397777dab0Sopenharmony_ci *        value is not necessary.
14407777dab0Sopenharmony_ci *
14417777dab0Sopenharmony_ci * @param pParaLimit will receive the limit of the paragraph.
14427777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14437777dab0Sopenharmony_ci *        value is not necessary.
14447777dab0Sopenharmony_ci *
14457777dab0Sopenharmony_ci * @param pParaLevel will receive the level of the paragraph.
14467777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14477777dab0Sopenharmony_ci *        value is not necessary.
14487777dab0Sopenharmony_ci *
14497777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
14507777dab0Sopenharmony_ci *
14517777dab0Sopenharmony_ci * @stable ICU 3.4
14527777dab0Sopenharmony_ci */
14537777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
14547777dab0Sopenharmony_ciubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,
14557777dab0Sopenharmony_ci                          int32_t *pParaStart, int32_t *pParaLimit,
14567777dab0Sopenharmony_ci                          UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);
14577777dab0Sopenharmony_ci
14587777dab0Sopenharmony_ci/**
14597777dab0Sopenharmony_ci * Get the level for one character.
14607777dab0Sopenharmony_ci *
14617777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
14627777dab0Sopenharmony_ci *
14637777dab0Sopenharmony_ci * @param charIndex the index of a character. It must be in the range
14647777dab0Sopenharmony_ci *         [0..ubidi_getProcessedLength(pBiDi)].
14657777dab0Sopenharmony_ci *
14667777dab0Sopenharmony_ci * @return The level for the character at charIndex (0 if charIndex is not
14677777dab0Sopenharmony_ci *         in the valid range).
14687777dab0Sopenharmony_ci *
14697777dab0Sopenharmony_ci * @see UBiDiLevel
14707777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
14717777dab0Sopenharmony_ci * @stable ICU 2.0
14727777dab0Sopenharmony_ci */
14737777dab0Sopenharmony_ciU_CAPI UBiDiLevel U_EXPORT2
14747777dab0Sopenharmony_ciubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);
14757777dab0Sopenharmony_ci
14767777dab0Sopenharmony_ci/**
14777777dab0Sopenharmony_ci * Get an array of levels for each character.<p>
14787777dab0Sopenharmony_ci *
14797777dab0Sopenharmony_ci * Note that this function may allocate memory under some
14807777dab0Sopenharmony_ci * circumstances, unlike <code>ubidi_getLevelAt()</code>.
14817777dab0Sopenharmony_ci *
14827777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object, whose
14837777dab0Sopenharmony_ci *        text length must be strictly positive.
14847777dab0Sopenharmony_ci *
14857777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
14867777dab0Sopenharmony_ci *
14877777dab0Sopenharmony_ci * @return The levels array for the text,
14887777dab0Sopenharmony_ci *         or <code>NULL</code> if an error occurs.
14897777dab0Sopenharmony_ci *
14907777dab0Sopenharmony_ci * @see UBiDiLevel
14917777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
14927777dab0Sopenharmony_ci * @stable ICU 2.0
14937777dab0Sopenharmony_ci */
14947777dab0Sopenharmony_ciU_CAPI const UBiDiLevel * U_EXPORT2
14957777dab0Sopenharmony_ciubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);
14967777dab0Sopenharmony_ci
14977777dab0Sopenharmony_ci/**
14987777dab0Sopenharmony_ci * Get a logical run.
14997777dab0Sopenharmony_ci * This function returns information about a run and is used
15007777dab0Sopenharmony_ci * to retrieve runs in logical order.<p>
15017777dab0Sopenharmony_ci * This is especially useful for line-breaking on a paragraph.
15027777dab0Sopenharmony_ci *
15037777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
15047777dab0Sopenharmony_ci *
15057777dab0Sopenharmony_ci * @param logicalPosition is a logical position within the source text.
15067777dab0Sopenharmony_ci *
15077777dab0Sopenharmony_ci * @param pLogicalLimit will receive the limit of the corresponding run.
15087777dab0Sopenharmony_ci *        The l-value that you point to here may be the
15097777dab0Sopenharmony_ci *        same expression (variable) as the one for
15107777dab0Sopenharmony_ci *        <code>logicalPosition</code>.
15117777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
15127777dab0Sopenharmony_ci *        value is not necessary.
15137777dab0Sopenharmony_ci *
15147777dab0Sopenharmony_ci * @param pLevel will receive the level of the corresponding run.
15157777dab0Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
15167777dab0Sopenharmony_ci *        value is not necessary.
15177777dab0Sopenharmony_ci *
15187777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
15197777dab0Sopenharmony_ci * @stable ICU 2.0
15207777dab0Sopenharmony_ci */
15217777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
15227777dab0Sopenharmony_ciubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,
15237777dab0Sopenharmony_ci                    int32_t *pLogicalLimit, UBiDiLevel *pLevel);
15247777dab0Sopenharmony_ci
15257777dab0Sopenharmony_ci/**
15267777dab0Sopenharmony_ci * Get the number of runs.
15277777dab0Sopenharmony_ci * This function may invoke the actual reordering on the
15287777dab0Sopenharmony_ci * <code>UBiDi</code> object, after <code>ubidi_setPara()</code>
15297777dab0Sopenharmony_ci * may have resolved only the levels of the text. Therefore,
15307777dab0Sopenharmony_ci * <code>ubidi_countRuns()</code> may have to allocate memory,
15317777dab0Sopenharmony_ci * and may fail doing so.
15327777dab0Sopenharmony_ci *
15337777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
15347777dab0Sopenharmony_ci *
15357777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
15367777dab0Sopenharmony_ci *
15377777dab0Sopenharmony_ci * @return The number of runs.
15387777dab0Sopenharmony_ci * @stable ICU 2.0
15397777dab0Sopenharmony_ci */
15407777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
15417777dab0Sopenharmony_ciubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
15427777dab0Sopenharmony_ci
15437777dab0Sopenharmony_ci/**
15447777dab0Sopenharmony_ci * Get one run's logical start, length, and directionality,
15457777dab0Sopenharmony_ci * which can be 0 for LTR or 1 for RTL.
15467777dab0Sopenharmony_ci * In an RTL run, the character at the logical start is
15477777dab0Sopenharmony_ci * visually on the right of the displayed run.
15487777dab0Sopenharmony_ci * The length is the number of characters in the run.<p>
15497777dab0Sopenharmony_ci * <code>ubidi_countRuns()</code> should be called
15507777dab0Sopenharmony_ci * before the runs are retrieved.
15517777dab0Sopenharmony_ci *
15527777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
15537777dab0Sopenharmony_ci *
15547777dab0Sopenharmony_ci * @param runIndex is the number of the run in visual order, in the
15557777dab0Sopenharmony_ci *        range <code>[0..ubidi_countRuns(pBiDi)-1]</code>.
15567777dab0Sopenharmony_ci *
15577777dab0Sopenharmony_ci * @param pLogicalStart is the first logical character index in the text.
15587777dab0Sopenharmony_ci *        The pointer may be <code>NULL</code> if this index is not needed.
15597777dab0Sopenharmony_ci *
15607777dab0Sopenharmony_ci * @param pLength is the number of characters (at least one) in the run.
15617777dab0Sopenharmony_ci *        The pointer may be <code>NULL</code> if this is not needed.
15627777dab0Sopenharmony_ci *
15637777dab0Sopenharmony_ci * @return the directionality of the run,
15647777dab0Sopenharmony_ci *         <code>UBIDI_LTR==0</code> or <code>UBIDI_RTL==1</code>,
15657777dab0Sopenharmony_ci *         never <code>UBIDI_MIXED</code>,
15667777dab0Sopenharmony_ci *         never <code>UBIDI_NEUTRAL</code>.
15677777dab0Sopenharmony_ci *
15687777dab0Sopenharmony_ci * @see ubidi_countRuns
15697777dab0Sopenharmony_ci *
15707777dab0Sopenharmony_ci * Example:
15717777dab0Sopenharmony_ci * <pre>
15727777dab0Sopenharmony_ci * \code
15737777dab0Sopenharmony_ci * int32_t i, count=ubidi_countRuns(pBiDi),
15747777dab0Sopenharmony_ci *         logicalStart, visualIndex=0, length;
15757777dab0Sopenharmony_ci * for(i=0; i<count; ++i) {
15767777dab0Sopenharmony_ci *    if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {
15777777dab0Sopenharmony_ci *         do { // LTR
15787777dab0Sopenharmony_ci *             show_char(text[logicalStart++], visualIndex++);
15797777dab0Sopenharmony_ci *         } while(--length>0);
15807777dab0Sopenharmony_ci *     } else {
15817777dab0Sopenharmony_ci *         logicalStart+=length;  // logicalLimit
15827777dab0Sopenharmony_ci *         do { // RTL
15837777dab0Sopenharmony_ci *             show_char(text[--logicalStart], visualIndex++);
15847777dab0Sopenharmony_ci *         } while(--length>0);
15857777dab0Sopenharmony_ci *     }
15867777dab0Sopenharmony_ci * }
15877777dab0Sopenharmony_ci *\endcode
15887777dab0Sopenharmony_ci * </pre>
15897777dab0Sopenharmony_ci *
15907777dab0Sopenharmony_ci * Note that in right-to-left runs, code like this places
15917777dab0Sopenharmony_ci * second surrogates before first ones (which is generally a bad idea)
15927777dab0Sopenharmony_ci * and combining characters before base characters.
15937777dab0Sopenharmony_ci * <p>
15947777dab0Sopenharmony_ci * Use of <code>ubidi_writeReordered()</code>, optionally with the
15957777dab0Sopenharmony_ci * <code>#UBIDI_KEEP_BASE_COMBINING</code> option, can be considered in order
15967777dab0Sopenharmony_ci * to avoid these issues.
15977777dab0Sopenharmony_ci * @stable ICU 2.0
15987777dab0Sopenharmony_ci */
15997777dab0Sopenharmony_ciU_CAPI UBiDiDirection U_EXPORT2
16007777dab0Sopenharmony_ciubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,
16017777dab0Sopenharmony_ci                   int32_t *pLogicalStart, int32_t *pLength);
16027777dab0Sopenharmony_ci
16037777dab0Sopenharmony_ci/**
16047777dab0Sopenharmony_ci * Get the visual position from a logical text position.
16057777dab0Sopenharmony_ci * If such a mapping is used many times on the same
16067777dab0Sopenharmony_ci * <code>UBiDi</code> object, then calling
16077777dab0Sopenharmony_ci * <code>ubidi_getLogicalMap()</code> is more efficient.<p>
16087777dab0Sopenharmony_ci *
16097777dab0Sopenharmony_ci * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
16107777dab0Sopenharmony_ci * visual position because the corresponding text character is a Bidi control
16117777dab0Sopenharmony_ci * removed from output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
16127777dab0Sopenharmony_ci * <p>
16137777dab0Sopenharmony_ci * When the visual output is altered by using options of
16147777dab0Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
16157777dab0Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
16167777dab0Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual position returned may not
16177777dab0Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
16187777dab0Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
16197777dab0Sopenharmony_ci * <p>
16207777dab0Sopenharmony_ci * Note that in right-to-left runs, this mapping places
16217777dab0Sopenharmony_ci * second surrogates before first ones (which is generally a bad idea)
16227777dab0Sopenharmony_ci * and combining characters before base characters.
16237777dab0Sopenharmony_ci * Use of <code>ubidi_writeReordered()</code>, optionally with the
16247777dab0Sopenharmony_ci * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
16257777dab0Sopenharmony_ci * of using the mapping, in order to avoid these issues.
16267777dab0Sopenharmony_ci *
16277777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
16287777dab0Sopenharmony_ci *
16297777dab0Sopenharmony_ci * @param logicalIndex is the index of a character in the text.
16307777dab0Sopenharmony_ci *
16317777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
16327777dab0Sopenharmony_ci *
16337777dab0Sopenharmony_ci * @return The visual position of this character.
16347777dab0Sopenharmony_ci *
16357777dab0Sopenharmony_ci * @see ubidi_getLogicalMap
16367777dab0Sopenharmony_ci * @see ubidi_getLogicalIndex
16377777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
16387777dab0Sopenharmony_ci * @stable ICU 2.0
16397777dab0Sopenharmony_ci */
16407777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
16417777dab0Sopenharmony_ciubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode);
16427777dab0Sopenharmony_ci
16437777dab0Sopenharmony_ci/**
16447777dab0Sopenharmony_ci * Get the logical text position from a visual position.
16457777dab0Sopenharmony_ci * If such a mapping is used many times on the same
16467777dab0Sopenharmony_ci * <code>UBiDi</code> object, then calling
16477777dab0Sopenharmony_ci * <code>ubidi_getVisualMap()</code> is more efficient.<p>
16487777dab0Sopenharmony_ci *
16497777dab0Sopenharmony_ci * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
16507777dab0Sopenharmony_ci * logical position because the corresponding text character is a Bidi mark
16517777dab0Sopenharmony_ci * inserted in the output by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
16527777dab0Sopenharmony_ci * <p>
16537777dab0Sopenharmony_ci * This is the inverse function to <code>ubidi_getVisualIndex()</code>.
16547777dab0Sopenharmony_ci * <p>
16557777dab0Sopenharmony_ci * When the visual output is altered by using options of
16567777dab0Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
16577777dab0Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
16587777dab0Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical position returned may not
16597777dab0Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
16607777dab0Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
16617777dab0Sopenharmony_ci *
16627777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
16637777dab0Sopenharmony_ci *
16647777dab0Sopenharmony_ci * @param visualIndex is the visual position of a character.
16657777dab0Sopenharmony_ci *
16667777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
16677777dab0Sopenharmony_ci *
16687777dab0Sopenharmony_ci * @return The index of this character in the text.
16697777dab0Sopenharmony_ci *
16707777dab0Sopenharmony_ci * @see ubidi_getVisualMap
16717777dab0Sopenharmony_ci * @see ubidi_getVisualIndex
16727777dab0Sopenharmony_ci * @see ubidi_getResultLength
16737777dab0Sopenharmony_ci * @stable ICU 2.0
16747777dab0Sopenharmony_ci */
16757777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
16767777dab0Sopenharmony_ciubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);
16777777dab0Sopenharmony_ci
16787777dab0Sopenharmony_ci/**
16797777dab0Sopenharmony_ci * Get a logical-to-visual index map (array) for the characters in the UBiDi
16807777dab0Sopenharmony_ci * (paragraph or line) object.
16817777dab0Sopenharmony_ci * <p>
16827777dab0Sopenharmony_ci * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
16837777dab0Sopenharmony_ci * corresponding text characters are Bidi controls removed from the visual
16847777dab0Sopenharmony_ci * output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
16857777dab0Sopenharmony_ci * <p>
16867777dab0Sopenharmony_ci * When the visual output is altered by using options of
16877777dab0Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
16887777dab0Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
16897777dab0Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual positions returned may not
16907777dab0Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
16917777dab0Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
16927777dab0Sopenharmony_ci * <p>
16937777dab0Sopenharmony_ci * Note that in right-to-left runs, this mapping places
16947777dab0Sopenharmony_ci * second surrogates before first ones (which is generally a bad idea)
16957777dab0Sopenharmony_ci * and combining characters before base characters.
16967777dab0Sopenharmony_ci * Use of <code>ubidi_writeReordered()</code>, optionally with the
16977777dab0Sopenharmony_ci * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
16987777dab0Sopenharmony_ci * of using the mapping, in order to avoid these issues.
16997777dab0Sopenharmony_ci *
17007777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
17017777dab0Sopenharmony_ci *
17027777dab0Sopenharmony_ci * @param indexMap is a pointer to an array of <code>ubidi_getProcessedLength()</code>
17037777dab0Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
17047777dab0Sopenharmony_ci *        If option <code>#UBIDI_OPTION_INSERT_MARKS</code> is set, the number
17057777dab0Sopenharmony_ci *        of elements allocated in <code>indexMap</code> must be no less than
17067777dab0Sopenharmony_ci *        <code>ubidi_getResultLength()</code>.
17077777dab0Sopenharmony_ci *        The array does not need to be initialized.<br><br>
17087777dab0Sopenharmony_ci *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
17097777dab0Sopenharmony_ci *
17107777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
17117777dab0Sopenharmony_ci *
17127777dab0Sopenharmony_ci * @see ubidi_getVisualMap
17137777dab0Sopenharmony_ci * @see ubidi_getVisualIndex
17147777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
17157777dab0Sopenharmony_ci * @see ubidi_getResultLength
17167777dab0Sopenharmony_ci * @stable ICU 2.0
17177777dab0Sopenharmony_ci */
17187777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
17197777dab0Sopenharmony_ciubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
17207777dab0Sopenharmony_ci
17217777dab0Sopenharmony_ci/**
17227777dab0Sopenharmony_ci * Get a visual-to-logical index map (array) for the characters in the UBiDi
17237777dab0Sopenharmony_ci * (paragraph or line) object.
17247777dab0Sopenharmony_ci * <p>
17257777dab0Sopenharmony_ci * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
17267777dab0Sopenharmony_ci * corresponding text characters are Bidi marks inserted in the visual output
17277777dab0Sopenharmony_ci * by the option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
17287777dab0Sopenharmony_ci * <p>
17297777dab0Sopenharmony_ci * When the visual output is altered by using options of
17307777dab0Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
17317777dab0Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
17327777dab0Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical positions returned may not
17337777dab0Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
17347777dab0Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
17357777dab0Sopenharmony_ci *
17367777dab0Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
17377777dab0Sopenharmony_ci *
17387777dab0Sopenharmony_ci * @param indexMap is a pointer to an array of <code>ubidi_getResultLength()</code>
17397777dab0Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
17407777dab0Sopenharmony_ci *        If option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is set, the number
17417777dab0Sopenharmony_ci *        of elements allocated in <code>indexMap</code> must be no less than
17427777dab0Sopenharmony_ci *        <code>ubidi_getProcessedLength()</code>.
17437777dab0Sopenharmony_ci *        The array does not need to be initialized.<br><br>
17447777dab0Sopenharmony_ci *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
17457777dab0Sopenharmony_ci *
17467777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
17477777dab0Sopenharmony_ci *
17487777dab0Sopenharmony_ci * @see ubidi_getLogicalMap
17497777dab0Sopenharmony_ci * @see ubidi_getLogicalIndex
17507777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
17517777dab0Sopenharmony_ci * @see ubidi_getResultLength
17527777dab0Sopenharmony_ci * @stable ICU 2.0
17537777dab0Sopenharmony_ci */
17547777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
17557777dab0Sopenharmony_ciubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
17567777dab0Sopenharmony_ci
17577777dab0Sopenharmony_ci/**
17587777dab0Sopenharmony_ci * This is a convenience function that does not use a UBiDi object.
17597777dab0Sopenharmony_ci * It is intended to be used for when an application has determined the levels
17607777dab0Sopenharmony_ci * of objects (character sequences) and just needs to have them reordered (L2).
17617777dab0Sopenharmony_ci * This is equivalent to using <code>ubidi_getLogicalMap()</code> on a
17627777dab0Sopenharmony_ci * <code>UBiDi</code> object.
17637777dab0Sopenharmony_ci *
17647777dab0Sopenharmony_ci * @param levels is an array with <code>length</code> levels that have been determined by
17657777dab0Sopenharmony_ci *        the application.
17667777dab0Sopenharmony_ci *
17677777dab0Sopenharmony_ci * @param length is the number of levels in the array, or, semantically,
17687777dab0Sopenharmony_ci *        the number of objects to be reordered.
17697777dab0Sopenharmony_ci *        It must be <code>length>0</code>.
17707777dab0Sopenharmony_ci *
17717777dab0Sopenharmony_ci * @param indexMap is a pointer to an array of <code>length</code>
17727777dab0Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
17737777dab0Sopenharmony_ci *        The array does not need to be initialized.<p>
17747777dab0Sopenharmony_ci *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
17757777dab0Sopenharmony_ci * @stable ICU 2.0
17767777dab0Sopenharmony_ci */
17777777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
17787777dab0Sopenharmony_ciubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
17797777dab0Sopenharmony_ci
17807777dab0Sopenharmony_ci/**
17817777dab0Sopenharmony_ci * This is a convenience function that does not use a UBiDi object.
17827777dab0Sopenharmony_ci * It is intended to be used for when an application has determined the levels
17837777dab0Sopenharmony_ci * of objects (character sequences) and just needs to have them reordered (L2).
17847777dab0Sopenharmony_ci * This is equivalent to using <code>ubidi_getVisualMap()</code> on a
17857777dab0Sopenharmony_ci * <code>UBiDi</code> object.
17867777dab0Sopenharmony_ci *
17877777dab0Sopenharmony_ci * @param levels is an array with <code>length</code> levels that have been determined by
17887777dab0Sopenharmony_ci *        the application.
17897777dab0Sopenharmony_ci *
17907777dab0Sopenharmony_ci * @param length is the number of levels in the array, or, semantically,
17917777dab0Sopenharmony_ci *        the number of objects to be reordered.
17927777dab0Sopenharmony_ci *        It must be <code>length>0</code>.
17937777dab0Sopenharmony_ci *
17947777dab0Sopenharmony_ci * @param indexMap is a pointer to an array of <code>length</code>
17957777dab0Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
17967777dab0Sopenharmony_ci *        The array does not need to be initialized.<p>
17977777dab0Sopenharmony_ci *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
17987777dab0Sopenharmony_ci * @stable ICU 2.0
17997777dab0Sopenharmony_ci */
18007777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
18017777dab0Sopenharmony_ciubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
18027777dab0Sopenharmony_ci
18037777dab0Sopenharmony_ci/**
18047777dab0Sopenharmony_ci * Invert an index map.
18057777dab0Sopenharmony_ci * The index mapping of the first map is inverted and written to
18067777dab0Sopenharmony_ci * the second one.
18077777dab0Sopenharmony_ci *
18087777dab0Sopenharmony_ci * @param srcMap is an array with <code>length</code> elements
18097777dab0Sopenharmony_ci *        which defines the original mapping from a source array containing
18107777dab0Sopenharmony_ci *        <code>length</code> elements to a destination array.
18117777dab0Sopenharmony_ci *        Some elements of the source array may have no mapping in the
18127777dab0Sopenharmony_ci *        destination array. In that case, their value will be
18137777dab0Sopenharmony_ci *        the special value <code>UBIDI_MAP_NOWHERE</code>.
18147777dab0Sopenharmony_ci *        All elements must be >=0 or equal to <code>UBIDI_MAP_NOWHERE</code>.
18157777dab0Sopenharmony_ci *        Some elements may have a value >= <code>length</code>, if the
18167777dab0Sopenharmony_ci *        destination array has more elements than the source array.
18177777dab0Sopenharmony_ci *        There must be no duplicate indexes (two or more elements with the
18187777dab0Sopenharmony_ci *        same value except <code>UBIDI_MAP_NOWHERE</code>).
18197777dab0Sopenharmony_ci *
18207777dab0Sopenharmony_ci * @param destMap is an array with a number of elements equal to 1 + the highest
18217777dab0Sopenharmony_ci *        value in <code>srcMap</code>.
18227777dab0Sopenharmony_ci *        <code>destMap</code> will be filled with the inverse mapping.
18237777dab0Sopenharmony_ci *        If element with index i in <code>srcMap</code> has a value k different
18247777dab0Sopenharmony_ci *        from <code>UBIDI_MAP_NOWHERE</code>, this means that element i of
18257777dab0Sopenharmony_ci *        the source array maps to element k in the destination array.
18267777dab0Sopenharmony_ci *        The inverse map will have value i in its k-th element.
18277777dab0Sopenharmony_ci *        For all elements of the destination array which do not map to
18287777dab0Sopenharmony_ci *        an element in the source array, the corresponding element in the
18297777dab0Sopenharmony_ci *        inverse map will have a value equal to <code>UBIDI_MAP_NOWHERE</code>.
18307777dab0Sopenharmony_ci *
18317777dab0Sopenharmony_ci * @param length is the length of each array.
18327777dab0Sopenharmony_ci * @see UBIDI_MAP_NOWHERE
18337777dab0Sopenharmony_ci * @stable ICU 2.0
18347777dab0Sopenharmony_ci */
18357777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
18367777dab0Sopenharmony_ciubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);
18377777dab0Sopenharmony_ci
18387777dab0Sopenharmony_ci/** option flags for ubidi_writeReordered() */
18397777dab0Sopenharmony_ci
18407777dab0Sopenharmony_ci/**
18417777dab0Sopenharmony_ci * option bit for ubidi_writeReordered():
18427777dab0Sopenharmony_ci * keep combining characters after their base characters in RTL runs
18437777dab0Sopenharmony_ci *
18447777dab0Sopenharmony_ci * @see ubidi_writeReordered
18457777dab0Sopenharmony_ci * @stable ICU 2.0
18467777dab0Sopenharmony_ci */
18477777dab0Sopenharmony_ci#define UBIDI_KEEP_BASE_COMBINING       1
18487777dab0Sopenharmony_ci
18497777dab0Sopenharmony_ci/**
18507777dab0Sopenharmony_ci * option bit for ubidi_writeReordered():
18517777dab0Sopenharmony_ci * replace characters with the "mirrored" property in RTL runs
18527777dab0Sopenharmony_ci * by their mirror-image mappings
18537777dab0Sopenharmony_ci *
18547777dab0Sopenharmony_ci * @see ubidi_writeReordered
18557777dab0Sopenharmony_ci * @stable ICU 2.0
18567777dab0Sopenharmony_ci */
18577777dab0Sopenharmony_ci#define UBIDI_DO_MIRRORING              2
18587777dab0Sopenharmony_ci
18597777dab0Sopenharmony_ci/**
18607777dab0Sopenharmony_ci * option bit for ubidi_writeReordered():
18617777dab0Sopenharmony_ci * surround the run with LRMs if necessary;
18627777dab0Sopenharmony_ci * this is part of the approximate "inverse Bidi" algorithm
18637777dab0Sopenharmony_ci *
18647777dab0Sopenharmony_ci * <p>This option does not imply corresponding adjustment of the index
18657777dab0Sopenharmony_ci * mappings.</p>
18667777dab0Sopenharmony_ci *
18677777dab0Sopenharmony_ci * @see ubidi_setInverse
18687777dab0Sopenharmony_ci * @see ubidi_writeReordered
18697777dab0Sopenharmony_ci * @stable ICU 2.0
18707777dab0Sopenharmony_ci */
18717777dab0Sopenharmony_ci#define UBIDI_INSERT_LRM_FOR_NUMERIC    4
18727777dab0Sopenharmony_ci
18737777dab0Sopenharmony_ci/**
18747777dab0Sopenharmony_ci * option bit for ubidi_writeReordered():
18757777dab0Sopenharmony_ci * remove Bidi control characters
18767777dab0Sopenharmony_ci * (this does not affect #UBIDI_INSERT_LRM_FOR_NUMERIC)
18777777dab0Sopenharmony_ci *
18787777dab0Sopenharmony_ci * <p>This option does not imply corresponding adjustment of the index
18797777dab0Sopenharmony_ci * mappings.</p>
18807777dab0Sopenharmony_ci *
18817777dab0Sopenharmony_ci * @see ubidi_writeReordered
18827777dab0Sopenharmony_ci * @stable ICU 2.0
18837777dab0Sopenharmony_ci */
18847777dab0Sopenharmony_ci#define UBIDI_REMOVE_BIDI_CONTROLS      8
18857777dab0Sopenharmony_ci
18867777dab0Sopenharmony_ci/**
18877777dab0Sopenharmony_ci * option bit for ubidi_writeReordered():
18887777dab0Sopenharmony_ci * write the output in reverse order
18897777dab0Sopenharmony_ci *
18907777dab0Sopenharmony_ci * <p>This has the same effect as calling <code>ubidi_writeReordered()</code>
18917777dab0Sopenharmony_ci * first without this option, and then calling
18927777dab0Sopenharmony_ci * <code>ubidi_writeReverse()</code> without mirroring.
18937777dab0Sopenharmony_ci * Doing this in the same step is faster and avoids a temporary buffer.
18947777dab0Sopenharmony_ci * An example for using this option is output to a character terminal that
18957777dab0Sopenharmony_ci * is designed for RTL scripts and stores text in reverse order.</p>
18967777dab0Sopenharmony_ci *
18977777dab0Sopenharmony_ci * @see ubidi_writeReordered
18987777dab0Sopenharmony_ci * @stable ICU 2.0
18997777dab0Sopenharmony_ci */
19007777dab0Sopenharmony_ci#define UBIDI_OUTPUT_REVERSE            16
19017777dab0Sopenharmony_ci
19027777dab0Sopenharmony_ci/**
19037777dab0Sopenharmony_ci * Get the length of the source text processed by the last call to
19047777dab0Sopenharmony_ci * <code>ubidi_setPara()</code>. This length may be different from the length
19057777dab0Sopenharmony_ci * of the source text if option <code>#UBIDI_OPTION_STREAMING</code>
19067777dab0Sopenharmony_ci * has been set.
19077777dab0Sopenharmony_ci * <br>
19087777dab0Sopenharmony_ci * Note that whenever the length of the text affects the execution or the
19097777dab0Sopenharmony_ci * result of a function, it is the processed length which must be considered,
19107777dab0Sopenharmony_ci * except for <code>ubidi_setPara</code> (which receives unprocessed source
19117777dab0Sopenharmony_ci * text) and <code>ubidi_getLength</code> (which returns the original length
19127777dab0Sopenharmony_ci * of the source text).<br>
19137777dab0Sopenharmony_ci * In particular, the processed length is the one to consider in the following
19147777dab0Sopenharmony_ci * cases:
19157777dab0Sopenharmony_ci * <ul>
19167777dab0Sopenharmony_ci * <li>maximum value of the <code>limit</code> argument of
19177777dab0Sopenharmony_ci * <code>ubidi_setLine</code></li>
19187777dab0Sopenharmony_ci * <li>maximum value of the <code>charIndex</code> argument of
19197777dab0Sopenharmony_ci * <code>ubidi_getParagraph</code></li>
19207777dab0Sopenharmony_ci * <li>maximum value of the <code>charIndex</code> argument of
19217777dab0Sopenharmony_ci * <code>ubidi_getLevelAt</code></li>
19227777dab0Sopenharmony_ci * <li>number of elements in the array returned by <code>ubidi_getLevels</code></li>
19237777dab0Sopenharmony_ci * <li>maximum value of the <code>logicalStart</code> argument of
19247777dab0Sopenharmony_ci * <code>ubidi_getLogicalRun</code></li>
19257777dab0Sopenharmony_ci * <li>maximum value of the <code>logicalIndex</code> argument of
19267777dab0Sopenharmony_ci * <code>ubidi_getVisualIndex</code></li>
19277777dab0Sopenharmony_ci * <li>number of elements filled in the <code>*indexMap</code> argument of
19287777dab0Sopenharmony_ci * <code>ubidi_getLogicalMap</code></li>
19297777dab0Sopenharmony_ci * <li>length of text processed by <code>ubidi_writeReordered</code></li>
19307777dab0Sopenharmony_ci * </ul>
19317777dab0Sopenharmony_ci *
19327777dab0Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
19337777dab0Sopenharmony_ci *
19347777dab0Sopenharmony_ci * @return The length of the part of the source text processed by
19357777dab0Sopenharmony_ci *         the last call to <code>ubidi_setPara</code>.
19367777dab0Sopenharmony_ci * @see ubidi_setPara
19377777dab0Sopenharmony_ci * @see UBIDI_OPTION_STREAMING
19387777dab0Sopenharmony_ci * @stable ICU 3.6
19397777dab0Sopenharmony_ci */
19407777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
19417777dab0Sopenharmony_ciubidi_getProcessedLength(const UBiDi *pBiDi);
19427777dab0Sopenharmony_ci
19437777dab0Sopenharmony_ci/**
19447777dab0Sopenharmony_ci * Get the length of the reordered text resulting from the last call to
19457777dab0Sopenharmony_ci * <code>ubidi_setPara()</code>. This length may be different from the length
19467777dab0Sopenharmony_ci * of the source text if option <code>#UBIDI_OPTION_INSERT_MARKS</code>
19477777dab0Sopenharmony_ci * or option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> has been set.
19487777dab0Sopenharmony_ci * <br>
19497777dab0Sopenharmony_ci * This resulting length is the one to consider in the following cases:
19507777dab0Sopenharmony_ci * <ul>
19517777dab0Sopenharmony_ci * <li>maximum value of the <code>visualIndex</code> argument of
19527777dab0Sopenharmony_ci * <code>ubidi_getLogicalIndex</code></li>
19537777dab0Sopenharmony_ci * <li>number of elements of the <code>*indexMap</code> argument of
19547777dab0Sopenharmony_ci * <code>ubidi_getVisualMap</code></li>
19557777dab0Sopenharmony_ci * </ul>
19567777dab0Sopenharmony_ci * Note that this length stays identical to the source text length if
19577777dab0Sopenharmony_ci * Bidi marks are inserted or removed using option bits of
19587777dab0Sopenharmony_ci * <code>ubidi_writeReordered</code>, or if option
19597777dab0Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> has been set.
19607777dab0Sopenharmony_ci *
19617777dab0Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
19627777dab0Sopenharmony_ci *
19637777dab0Sopenharmony_ci * @return The length of the reordered text resulting from
19647777dab0Sopenharmony_ci *         the last call to <code>ubidi_setPara</code>.
19657777dab0Sopenharmony_ci * @see ubidi_setPara
19667777dab0Sopenharmony_ci * @see UBIDI_OPTION_INSERT_MARKS
19677777dab0Sopenharmony_ci * @see UBIDI_OPTION_REMOVE_CONTROLS
19687777dab0Sopenharmony_ci * @stable ICU 3.6
19697777dab0Sopenharmony_ci */
19707777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
19717777dab0Sopenharmony_ciubidi_getResultLength(const UBiDi *pBiDi);
19727777dab0Sopenharmony_ci
19737777dab0Sopenharmony_ciU_CDECL_BEGIN
19747777dab0Sopenharmony_ci
19757777dab0Sopenharmony_ci/**
19767777dab0Sopenharmony_ci * Callback type declaration for overriding default Bidi class values with
19777777dab0Sopenharmony_ci * custom ones.
19787777dab0Sopenharmony_ci * <p>Usually, the function pointer will be propagated to a <code>UBiDi</code>
19797777dab0Sopenharmony_ci * object by calling the <code>ubidi_setClassCallback()</code> function;
19807777dab0Sopenharmony_ci * then the callback will be invoked by the UBA implementation any time the
19817777dab0Sopenharmony_ci * class of a character is to be determined.</p>
19827777dab0Sopenharmony_ci *
19837777dab0Sopenharmony_ci * @param context is a pointer to the callback private data.
19847777dab0Sopenharmony_ci *
19857777dab0Sopenharmony_ci * @param c       is the code point to get a Bidi class for.
19867777dab0Sopenharmony_ci *
19877777dab0Sopenharmony_ci * @return The directional property / Bidi class for the given code point
19887777dab0Sopenharmony_ci *         <code>c</code> if the default class has been overridden, or
19897777dab0Sopenharmony_ci *         <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>
19907777dab0Sopenharmony_ci *         if the standard Bidi class value for <code>c</code> is to be used.
19917777dab0Sopenharmony_ci * @see ubidi_setClassCallback
19927777dab0Sopenharmony_ci * @see ubidi_getClassCallback
19937777dab0Sopenharmony_ci * @stable ICU 3.6
19947777dab0Sopenharmony_ci */
19957777dab0Sopenharmony_citypedef UCharDirection U_CALLCONV
19967777dab0Sopenharmony_ciUBiDiClassCallback(const void *context, UChar32 c);
19977777dab0Sopenharmony_ci
19987777dab0Sopenharmony_ciU_CDECL_END
19997777dab0Sopenharmony_ci
20007777dab0Sopenharmony_ci/**
20017777dab0Sopenharmony_ci * Retrieve the Bidi class for a given code point.
20027777dab0Sopenharmony_ci * <p>If a <code>#UBiDiClassCallback</code> callback is defined and returns a
20037777dab0Sopenharmony_ci * value other than <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>,
20047777dab0Sopenharmony_ci * that value is used; otherwise the default class determination mechanism is invoked.</p>
20057777dab0Sopenharmony_ci *
20067777dab0Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
20077777dab0Sopenharmony_ci *
20087777dab0Sopenharmony_ci * @param c     is the code point whose Bidi class must be retrieved.
20097777dab0Sopenharmony_ci *
20107777dab0Sopenharmony_ci * @return The Bidi class for character <code>c</code> based
20117777dab0Sopenharmony_ci *         on the given <code>pBiDi</code> instance.
20127777dab0Sopenharmony_ci * @see UBiDiClassCallback
20137777dab0Sopenharmony_ci * @stable ICU 3.6
20147777dab0Sopenharmony_ci */
20157777dab0Sopenharmony_ciU_CAPI UCharDirection U_EXPORT2
20167777dab0Sopenharmony_ciubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c);
20177777dab0Sopenharmony_ci
20187777dab0Sopenharmony_ci/**
20197777dab0Sopenharmony_ci * Set the callback function and callback data used by the UBA
20207777dab0Sopenharmony_ci * implementation for Bidi class determination.
20217777dab0Sopenharmony_ci * <p>This may be useful for assigning Bidi classes to PUA characters, or
20227777dab0Sopenharmony_ci * for special application needs. For instance, an application may want to
20237777dab0Sopenharmony_ci * handle all spaces like L or R characters (according to the base direction)
20247777dab0Sopenharmony_ci * when creating the visual ordering of logical lines which are part of a report
20257777dab0Sopenharmony_ci * organized in columns: there should not be interaction between adjacent
20267777dab0Sopenharmony_ci * cells.<p>
20277777dab0Sopenharmony_ci *
20287777dab0Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
20297777dab0Sopenharmony_ci *
20307777dab0Sopenharmony_ci * @param newFn is the new callback function pointer.
20317777dab0Sopenharmony_ci *
20327777dab0Sopenharmony_ci * @param newContext is the new callback context pointer. This can be NULL.
20337777dab0Sopenharmony_ci *
20347777dab0Sopenharmony_ci * @param oldFn fillin: Returns the old callback function pointer. This can be
20357777dab0Sopenharmony_ci *                      NULL.
20367777dab0Sopenharmony_ci *
20377777dab0Sopenharmony_ci * @param oldContext fillin: Returns the old callback's context. This can be
20387777dab0Sopenharmony_ci *                           NULL.
20397777dab0Sopenharmony_ci *
20407777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
20417777dab0Sopenharmony_ci *
20427777dab0Sopenharmony_ci * @see ubidi_getClassCallback
20437777dab0Sopenharmony_ci * @stable ICU 3.6
20447777dab0Sopenharmony_ci */
20457777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
20467777dab0Sopenharmony_ciubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,
20477777dab0Sopenharmony_ci                       const void *newContext, UBiDiClassCallback **oldFn,
20487777dab0Sopenharmony_ci                       const void **oldContext, UErrorCode *pErrorCode);
20497777dab0Sopenharmony_ci
20507777dab0Sopenharmony_ci/**
20517777dab0Sopenharmony_ci * Get the current callback function used for Bidi class determination.
20527777dab0Sopenharmony_ci *
20537777dab0Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
20547777dab0Sopenharmony_ci *
20557777dab0Sopenharmony_ci * @param fn fillin: Returns the callback function pointer.
20567777dab0Sopenharmony_ci *
20577777dab0Sopenharmony_ci * @param context fillin: Returns the callback's private context.
20587777dab0Sopenharmony_ci *
20597777dab0Sopenharmony_ci * @see ubidi_setClassCallback
20607777dab0Sopenharmony_ci * @stable ICU 3.6
20617777dab0Sopenharmony_ci */
20627777dab0Sopenharmony_ciU_CAPI void U_EXPORT2
20637777dab0Sopenharmony_ciubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context);
20647777dab0Sopenharmony_ci
20657777dab0Sopenharmony_ci/**
20667777dab0Sopenharmony_ci * Take a <code>UBiDi</code> object containing the reordering
20677777dab0Sopenharmony_ci * information for a piece of text (one or more paragraphs) set by
20687777dab0Sopenharmony_ci * <code>ubidi_setPara()</code> or for a line of text set by
20697777dab0Sopenharmony_ci * <code>ubidi_setLine()</code> and write a reordered string to the
20707777dab0Sopenharmony_ci * destination buffer.
20717777dab0Sopenharmony_ci *
20727777dab0Sopenharmony_ci * This function preserves the integrity of characters with multiple
20737777dab0Sopenharmony_ci * code units and (optionally) combining characters.
20747777dab0Sopenharmony_ci * Characters in RTL runs can be replaced by mirror-image characters
20757777dab0Sopenharmony_ci * in the destination buffer. Note that "real" mirroring has
20767777dab0Sopenharmony_ci * to be done in a rendering engine by glyph selection
20777777dab0Sopenharmony_ci * and that for many "mirrored" characters there are no
20787777dab0Sopenharmony_ci * Unicode characters as mirror-image equivalents.
20797777dab0Sopenharmony_ci * There are also options to insert or remove Bidi control
20807777dab0Sopenharmony_ci * characters; see the description of the <code>destSize</code>
20817777dab0Sopenharmony_ci * and <code>options</code> parameters and of the option bit flags.
20827777dab0Sopenharmony_ci *
20837777dab0Sopenharmony_ci * @param pBiDi A pointer to a <code>UBiDi</code> object that
20847777dab0Sopenharmony_ci *              is set by <code>ubidi_setPara()</code> or
20857777dab0Sopenharmony_ci *              <code>ubidi_setLine()</code> and contains the reordering
20867777dab0Sopenharmony_ci *              information for the text that it was defined for,
20877777dab0Sopenharmony_ci *              as well as a pointer to that text.<br><br>
20887777dab0Sopenharmony_ci *              The text was aliased (only the pointer was stored
20897777dab0Sopenharmony_ci *              without copying the contents) and must not have been modified
20907777dab0Sopenharmony_ci *              since the <code>ubidi_setPara()</code> call.
20917777dab0Sopenharmony_ci *
20927777dab0Sopenharmony_ci * @param dest A pointer to where the reordered text is to be copied.
20937777dab0Sopenharmony_ci *             The source text and <code>dest[destSize]</code>
20947777dab0Sopenharmony_ci *             must not overlap.
20957777dab0Sopenharmony_ci *
20967777dab0Sopenharmony_ci * @param destSize The size of the <code>dest</code> buffer,
20977777dab0Sopenharmony_ci *                 in number of UChars.
20987777dab0Sopenharmony_ci *                 If the <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>
20997777dab0Sopenharmony_ci *                 option is set, then the destination length could be
21007777dab0Sopenharmony_ci *                 as large as
21017777dab0Sopenharmony_ci *                 <code>ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)</code>.
21027777dab0Sopenharmony_ci *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
21037777dab0Sopenharmony_ci *                 is set, then the destination length may be less than
21047777dab0Sopenharmony_ci *                 <code>ubidi_getLength(pBiDi)</code>.
21057777dab0Sopenharmony_ci *                 If none of these options is set, then the destination length
21067777dab0Sopenharmony_ci *                 will be exactly <code>ubidi_getProcessedLength(pBiDi)</code>.
21077777dab0Sopenharmony_ci *
21087777dab0Sopenharmony_ci * @param options A bit set of options for the reordering that control
21097777dab0Sopenharmony_ci *                how the reordered text is written.
21107777dab0Sopenharmony_ci *                The options include mirroring the characters on a code
21117777dab0Sopenharmony_ci *                point basis and inserting LRM characters, which is used
21127777dab0Sopenharmony_ci *                especially for transforming visually stored text
21137777dab0Sopenharmony_ci *                to logically stored text (although this is still an
21147777dab0Sopenharmony_ci *                imperfect implementation of an "inverse Bidi" algorithm
21157777dab0Sopenharmony_ci *                because it uses the "forward Bidi" algorithm at its core).
21167777dab0Sopenharmony_ci *                The available options are:
21177777dab0Sopenharmony_ci *                <code>#UBIDI_DO_MIRRORING</code>,
21187777dab0Sopenharmony_ci *                <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
21197777dab0Sopenharmony_ci *                <code>#UBIDI_KEEP_BASE_COMBINING</code>,
21207777dab0Sopenharmony_ci *                <code>#UBIDI_OUTPUT_REVERSE</code>,
21217777dab0Sopenharmony_ci *                <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
21227777dab0Sopenharmony_ci *
21237777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
21247777dab0Sopenharmony_ci *
21257777dab0Sopenharmony_ci * @return The length of the output string.
21267777dab0Sopenharmony_ci *
21277777dab0Sopenharmony_ci * @see ubidi_getProcessedLength
21287777dab0Sopenharmony_ci * @stable ICU 2.0
21297777dab0Sopenharmony_ci */
21307777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
21317777dab0Sopenharmony_ciubidi_writeReordered(UBiDi *pBiDi,
21327777dab0Sopenharmony_ci                     UChar *dest, int32_t destSize,
21337777dab0Sopenharmony_ci                     uint16_t options,
21347777dab0Sopenharmony_ci                     UErrorCode *pErrorCode);
21357777dab0Sopenharmony_ci
21367777dab0Sopenharmony_ci/**
21377777dab0Sopenharmony_ci * Reverse a Right-To-Left run of Unicode text.
21387777dab0Sopenharmony_ci *
21397777dab0Sopenharmony_ci * This function preserves the integrity of characters with multiple
21407777dab0Sopenharmony_ci * code units and (optionally) combining characters.
21417777dab0Sopenharmony_ci * Characters can be replaced by mirror-image characters
21427777dab0Sopenharmony_ci * in the destination buffer. Note that "real" mirroring has
21437777dab0Sopenharmony_ci * to be done in a rendering engine by glyph selection
21447777dab0Sopenharmony_ci * and that for many "mirrored" characters there are no
21457777dab0Sopenharmony_ci * Unicode characters as mirror-image equivalents.
21467777dab0Sopenharmony_ci * There are also options to insert or remove Bidi control
21477777dab0Sopenharmony_ci * characters.
21487777dab0Sopenharmony_ci *
21497777dab0Sopenharmony_ci * This function is the implementation for reversing RTL runs as part
21507777dab0Sopenharmony_ci * of <code>ubidi_writeReordered()</code>. For detailed descriptions
21517777dab0Sopenharmony_ci * of the parameters, see there.
21527777dab0Sopenharmony_ci * Since no Bidi controls are inserted here, the output string length
21537777dab0Sopenharmony_ci * will never exceed <code>srcLength</code>.
21547777dab0Sopenharmony_ci *
21557777dab0Sopenharmony_ci * @see ubidi_writeReordered
21567777dab0Sopenharmony_ci *
21577777dab0Sopenharmony_ci * @param src A pointer to the RTL run text.
21587777dab0Sopenharmony_ci *
21597777dab0Sopenharmony_ci * @param srcLength The length of the RTL run.
21607777dab0Sopenharmony_ci *
21617777dab0Sopenharmony_ci * @param dest A pointer to where the reordered text is to be copied.
21627777dab0Sopenharmony_ci *             <code>src[srcLength]</code> and <code>dest[destSize]</code>
21637777dab0Sopenharmony_ci *             must not overlap.
21647777dab0Sopenharmony_ci *
21657777dab0Sopenharmony_ci * @param destSize The size of the <code>dest</code> buffer,
21667777dab0Sopenharmony_ci *                 in number of UChars.
21677777dab0Sopenharmony_ci *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
21687777dab0Sopenharmony_ci *                 is set, then the destination length may be less than
21697777dab0Sopenharmony_ci *                 <code>srcLength</code>.
21707777dab0Sopenharmony_ci *                 If this option is not set, then the destination length
21717777dab0Sopenharmony_ci *                 will be exactly <code>srcLength</code>.
21727777dab0Sopenharmony_ci *
21737777dab0Sopenharmony_ci * @param options A bit set of options for the reordering that control
21747777dab0Sopenharmony_ci *                how the reordered text is written.
21757777dab0Sopenharmony_ci *                See the <code>options</code> parameter in <code>ubidi_writeReordered()</code>.
21767777dab0Sopenharmony_ci *
21777777dab0Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
21787777dab0Sopenharmony_ci *
21797777dab0Sopenharmony_ci * @return The length of the output string.
21807777dab0Sopenharmony_ci * @stable ICU 2.0
21817777dab0Sopenharmony_ci */
21827777dab0Sopenharmony_ciU_CAPI int32_t U_EXPORT2
21837777dab0Sopenharmony_ciubidi_writeReverse(const UChar *src, int32_t srcLength,
21847777dab0Sopenharmony_ci                   UChar *dest, int32_t destSize,
21857777dab0Sopenharmony_ci                   uint16_t options,
21867777dab0Sopenharmony_ci                   UErrorCode *pErrorCode);
21877777dab0Sopenharmony_ci
21887777dab0Sopenharmony_ci/*#define BIDI_SAMPLE_CODE*/
21897777dab0Sopenharmony_ci/*@}*/
21907777dab0Sopenharmony_ci
21917777dab0Sopenharmony_ci#endif
2192