11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others.
21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html
31cb0ef41Sopenharmony_ci/*
41cb0ef41Sopenharmony_ci******************************************************************************
51cb0ef41Sopenharmony_ci*
61cb0ef41Sopenharmony_ci*   Copyright (C) 1999-2013, International Business Machines
71cb0ef41Sopenharmony_ci*   Corporation and others.  All Rights Reserved.
81cb0ef41Sopenharmony_ci*
91cb0ef41Sopenharmony_ci******************************************************************************
101cb0ef41Sopenharmony_ci*   file name:  ubidi.h
111cb0ef41Sopenharmony_ci*   encoding:   UTF-8
121cb0ef41Sopenharmony_ci*   tab size:   8 (not used)
131cb0ef41Sopenharmony_ci*   indentation:4
141cb0ef41Sopenharmony_ci*
151cb0ef41Sopenharmony_ci*   created on: 1999jul27
161cb0ef41Sopenharmony_ci*   created by: Markus W. Scherer, updated by Matitiahu Allouche
171cb0ef41Sopenharmony_ci*/
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci#ifndef UBIDI_H
201cb0ef41Sopenharmony_ci#define UBIDI_H
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci#include "unicode/utypes.h"
231cb0ef41Sopenharmony_ci#include "unicode/uchar.h"
241cb0ef41Sopenharmony_ci
251cb0ef41Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API
261cb0ef41Sopenharmony_ci#include "unicode/localpointer.h"
271cb0ef41Sopenharmony_ci#endif   // U_SHOW_CPLUSPLUS_API
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci/**
301cb0ef41Sopenharmony_ci *\file
311cb0ef41Sopenharmony_ci * \brief C API: Bidi algorithm
321cb0ef41Sopenharmony_ci *
331cb0ef41Sopenharmony_ci * <h2>Bidi algorithm for ICU</h2>
341cb0ef41Sopenharmony_ci *
351cb0ef41Sopenharmony_ci * This is an implementation of the Unicode Bidirectional Algorithm.
361cb0ef41Sopenharmony_ci * The algorithm is defined in the
371cb0ef41Sopenharmony_ci * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.<p>
381cb0ef41Sopenharmony_ci *
391cb0ef41Sopenharmony_ci * Note: Libraries that perform a bidirectional algorithm and
401cb0ef41Sopenharmony_ci * reorder strings accordingly are sometimes called "Storage Layout Engines".
411cb0ef41Sopenharmony_ci * ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such
421cb0ef41Sopenharmony_ci * "Storage Layout Engines".
431cb0ef41Sopenharmony_ci *
441cb0ef41Sopenharmony_ci * <h3>General remarks about the API:</h3>
451cb0ef41Sopenharmony_ci *
461cb0ef41Sopenharmony_ci * In functions with an error code parameter,
471cb0ef41Sopenharmony_ci * the <code>pErrorCode</code> pointer must be valid
481cb0ef41Sopenharmony_ci * and the value that it points to must not indicate a failure before
491cb0ef41Sopenharmony_ci * the function call. Otherwise, the function returns immediately.
501cb0ef41Sopenharmony_ci * After the function call, the value indicates success or failure.<p>
511cb0ef41Sopenharmony_ci *
521cb0ef41Sopenharmony_ci * The &quot;limit&quot; of a sequence of characters is the position just after their
531cb0ef41Sopenharmony_ci * last character, i.e., one more than that position.<p>
541cb0ef41Sopenharmony_ci *
551cb0ef41Sopenharmony_ci * Some of the API functions provide access to &quot;runs&quot;.
561cb0ef41Sopenharmony_ci * Such a &quot;run&quot; is defined as a sequence of characters
571cb0ef41Sopenharmony_ci * that are at the same embedding level
581cb0ef41Sopenharmony_ci * after performing the Bidi algorithm.<p>
591cb0ef41Sopenharmony_ci *
601cb0ef41Sopenharmony_ci * @author Markus W. Scherer
611cb0ef41Sopenharmony_ci * @version 1.0
621cb0ef41Sopenharmony_ci *
631cb0ef41Sopenharmony_ci *
641cb0ef41Sopenharmony_ci * <h4> Sample code for the ICU Bidi API </h4>
651cb0ef41Sopenharmony_ci *
661cb0ef41Sopenharmony_ci * <h5>Rendering a paragraph with the ICU Bidi API</h5>
671cb0ef41Sopenharmony_ci *
681cb0ef41Sopenharmony_ci * This is (hypothetical) sample code that illustrates
691cb0ef41Sopenharmony_ci * how the ICU Bidi API could be used to render a paragraph of text.
701cb0ef41Sopenharmony_ci * Rendering code depends highly on the graphics system,
711cb0ef41Sopenharmony_ci * therefore this sample code must make a lot of assumptions,
721cb0ef41Sopenharmony_ci * which may or may not match any existing graphics system's properties.
731cb0ef41Sopenharmony_ci *
741cb0ef41Sopenharmony_ci * <p>The basic assumptions are:</p>
751cb0ef41Sopenharmony_ci * <ul>
761cb0ef41Sopenharmony_ci * <li>Rendering is done from left to right on a horizontal line.</li>
771cb0ef41Sopenharmony_ci * <li>A run of single-style, unidirectional text can be rendered at once.</li>
781cb0ef41Sopenharmony_ci * <li>Such a run of text is passed to the graphics system with
791cb0ef41Sopenharmony_ci *     characters (code units) in logical order.</li>
801cb0ef41Sopenharmony_ci * <li>The line-breaking algorithm is very complicated
811cb0ef41Sopenharmony_ci *     and Locale-dependent -
821cb0ef41Sopenharmony_ci *     and therefore its implementation omitted from this sample code.</li>
831cb0ef41Sopenharmony_ci * </ul>
841cb0ef41Sopenharmony_ci *
851cb0ef41Sopenharmony_ci * <pre>
861cb0ef41Sopenharmony_ci * \code
871cb0ef41Sopenharmony_ci *#include <unicode/ubidi.h>
881cb0ef41Sopenharmony_ci *
891cb0ef41Sopenharmony_ci *typedef enum {
901cb0ef41Sopenharmony_ci *     styleNormal=0, styleSelected=1,
911cb0ef41Sopenharmony_ci *     styleBold=2, styleItalics=4,
921cb0ef41Sopenharmony_ci *     styleSuper=8, styleSub=16
931cb0ef41Sopenharmony_ci *} Style;
941cb0ef41Sopenharmony_ci *
951cb0ef41Sopenharmony_ci *typedef struct { int32_t limit; Style style; } StyleRun;
961cb0ef41Sopenharmony_ci *
971cb0ef41Sopenharmony_ci *int getTextWidth(const UChar *text, int32_t start, int32_t limit,
981cb0ef41Sopenharmony_ci *                  const StyleRun *styleRuns, int styleRunCount);
991cb0ef41Sopenharmony_ci *
1001cb0ef41Sopenharmony_ci * // set *pLimit and *pStyleRunLimit for a line
1011cb0ef41Sopenharmony_ci * // from text[start] and from styleRuns[styleRunStart]
1021cb0ef41Sopenharmony_ci * // using ubidi_getLogicalRun(para, ...)
1031cb0ef41Sopenharmony_ci *void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,
1041cb0ef41Sopenharmony_ci *                  UBiDi *para,
1051cb0ef41Sopenharmony_ci *                  const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,
1061cb0ef41Sopenharmony_ci *                  int *pLineWidth);
1071cb0ef41Sopenharmony_ci *
1081cb0ef41Sopenharmony_ci * // render runs on a line sequentially, always from left to right
1091cb0ef41Sopenharmony_ci *
1101cb0ef41Sopenharmony_ci * // prepare rendering a new line
1111cb0ef41Sopenharmony_ci * void startLine(UBiDiDirection textDirection, int lineWidth);
1121cb0ef41Sopenharmony_ci *
1131cb0ef41Sopenharmony_ci * // render a run of text and advance to the right by the run width
1141cb0ef41Sopenharmony_ci * // the text[start..limit-1] is always in logical order
1151cb0ef41Sopenharmony_ci * void renderRun(const UChar *text, int32_t start, int32_t limit,
1161cb0ef41Sopenharmony_ci *               UBiDiDirection textDirection, Style style);
1171cb0ef41Sopenharmony_ci *
1181cb0ef41Sopenharmony_ci * // We could compute a cross-product
1191cb0ef41Sopenharmony_ci * // from the style runs with the directional runs
1201cb0ef41Sopenharmony_ci * // and then reorder it.
1211cb0ef41Sopenharmony_ci * // Instead, here we iterate over each run type
1221cb0ef41Sopenharmony_ci * // and render the intersections -
1231cb0ef41Sopenharmony_ci * // with shortcuts in simple (and common) cases.
1241cb0ef41Sopenharmony_ci * // renderParagraph() is the main function.
1251cb0ef41Sopenharmony_ci *
1261cb0ef41Sopenharmony_ci * // render a directional run with
1271cb0ef41Sopenharmony_ci * // (possibly) multiple style runs intersecting with it
1281cb0ef41Sopenharmony_ci * void renderDirectionalRun(const UChar *text,
1291cb0ef41Sopenharmony_ci *                           int32_t start, int32_t limit,
1301cb0ef41Sopenharmony_ci *                           UBiDiDirection direction,
1311cb0ef41Sopenharmony_ci *                           const StyleRun *styleRuns, int styleRunCount) {
1321cb0ef41Sopenharmony_ci *     int i;
1331cb0ef41Sopenharmony_ci *
1341cb0ef41Sopenharmony_ci *     // iterate over style runs
1351cb0ef41Sopenharmony_ci *     if(direction==UBIDI_LTR) {
1361cb0ef41Sopenharmony_ci *         int styleLimit;
1371cb0ef41Sopenharmony_ci *
1381cb0ef41Sopenharmony_ci *         for(i=0; i<styleRunCount; ++i) {
1391cb0ef41Sopenharmony_ci *             styleLimit=styleRuns[i].limit;
1401cb0ef41Sopenharmony_ci *             if(start<styleLimit) {
1411cb0ef41Sopenharmony_ci *                 if(styleLimit>limit) { styleLimit=limit; }
1421cb0ef41Sopenharmony_ci *                 renderRun(text, start, styleLimit,
1431cb0ef41Sopenharmony_ci *                           direction, styleRuns[i].style);
1441cb0ef41Sopenharmony_ci *                 if(styleLimit==limit) { break; }
1451cb0ef41Sopenharmony_ci *                 start=styleLimit;
1461cb0ef41Sopenharmony_ci *             }
1471cb0ef41Sopenharmony_ci *         }
1481cb0ef41Sopenharmony_ci *     } else {
1491cb0ef41Sopenharmony_ci *         int styleStart;
1501cb0ef41Sopenharmony_ci *
1511cb0ef41Sopenharmony_ci *         for(i=styleRunCount-1; i>=0; --i) {
1521cb0ef41Sopenharmony_ci *             if(i>0) {
1531cb0ef41Sopenharmony_ci *                 styleStart=styleRuns[i-1].limit;
1541cb0ef41Sopenharmony_ci *             } else {
1551cb0ef41Sopenharmony_ci *                 styleStart=0;
1561cb0ef41Sopenharmony_ci *             }
1571cb0ef41Sopenharmony_ci *             if(limit>=styleStart) {
1581cb0ef41Sopenharmony_ci *                 if(styleStart<start) { styleStart=start; }
1591cb0ef41Sopenharmony_ci *                 renderRun(text, styleStart, limit,
1601cb0ef41Sopenharmony_ci *                           direction, styleRuns[i].style);
1611cb0ef41Sopenharmony_ci *                 if(styleStart==start) { break; }
1621cb0ef41Sopenharmony_ci *                 limit=styleStart;
1631cb0ef41Sopenharmony_ci *             }
1641cb0ef41Sopenharmony_ci *         }
1651cb0ef41Sopenharmony_ci *     }
1661cb0ef41Sopenharmony_ci * }
1671cb0ef41Sopenharmony_ci *
1681cb0ef41Sopenharmony_ci * // the line object represents text[start..limit-1]
1691cb0ef41Sopenharmony_ci * void renderLine(UBiDi *line, const UChar *text,
1701cb0ef41Sopenharmony_ci *                 int32_t start, int32_t limit,
1711cb0ef41Sopenharmony_ci *                 const StyleRun *styleRuns, int styleRunCount,
1721cb0ef41Sopenharmony_ci *                 UErrorCode *pErrorCode) {
1731cb0ef41Sopenharmony_ci *     UBiDiDirection direction=ubidi_getDirection(line);
1741cb0ef41Sopenharmony_ci *     if(direction!=UBIDI_MIXED) {
1751cb0ef41Sopenharmony_ci *         // unidirectional
1761cb0ef41Sopenharmony_ci *         if(styleRunCount<=1) {
1771cb0ef41Sopenharmony_ci *             renderRun(text, start, limit, direction, styleRuns[0].style);
1781cb0ef41Sopenharmony_ci *         } else {
1791cb0ef41Sopenharmony_ci *             renderDirectionalRun(text, start, limit,
1801cb0ef41Sopenharmony_ci *                                  direction, styleRuns, styleRunCount);
1811cb0ef41Sopenharmony_ci *         }
1821cb0ef41Sopenharmony_ci *     } else {
1831cb0ef41Sopenharmony_ci *         // mixed-directional
1841cb0ef41Sopenharmony_ci *         int32_t count, i, length;
1851cb0ef41Sopenharmony_ci *         UBiDiLevel level;
1861cb0ef41Sopenharmony_ci *
1871cb0ef41Sopenharmony_ci *         count=ubidi_countRuns(line, pErrorCode);
1881cb0ef41Sopenharmony_ci *         if(U_SUCCESS(*pErrorCode)) {
1891cb0ef41Sopenharmony_ci *             if(styleRunCount<=1) {
1901cb0ef41Sopenharmony_ci *                 Style style=styleRuns[0].style;
1911cb0ef41Sopenharmony_ci *
1921cb0ef41Sopenharmony_ci *                 // iterate over directional runs
1931cb0ef41Sopenharmony_ci *                for(i=0; i<count; ++i) {
1941cb0ef41Sopenharmony_ci *                    direction=ubidi_getVisualRun(line, i, &start, &length);
1951cb0ef41Sopenharmony_ci *                     renderRun(text, start, start+length, direction, style);
1961cb0ef41Sopenharmony_ci *                }
1971cb0ef41Sopenharmony_ci *             } else {
1981cb0ef41Sopenharmony_ci *                 int32_t j;
1991cb0ef41Sopenharmony_ci *
2001cb0ef41Sopenharmony_ci *                 // iterate over both directional and style runs
2011cb0ef41Sopenharmony_ci *                 for(i=0; i<count; ++i) {
2021cb0ef41Sopenharmony_ci *                     direction=ubidi_getVisualRun(line, i, &start, &length);
2031cb0ef41Sopenharmony_ci *                     renderDirectionalRun(text, start, start+length,
2041cb0ef41Sopenharmony_ci *                                          direction, styleRuns, styleRunCount);
2051cb0ef41Sopenharmony_ci *                 }
2061cb0ef41Sopenharmony_ci *             }
2071cb0ef41Sopenharmony_ci *         }
2081cb0ef41Sopenharmony_ci *     }
2091cb0ef41Sopenharmony_ci * }
2101cb0ef41Sopenharmony_ci *
2111cb0ef41Sopenharmony_ci *void renderParagraph(const UChar *text, int32_t length,
2121cb0ef41Sopenharmony_ci *                     UBiDiDirection textDirection,
2131cb0ef41Sopenharmony_ci *                      const StyleRun *styleRuns, int styleRunCount,
2141cb0ef41Sopenharmony_ci *                      int lineWidth,
2151cb0ef41Sopenharmony_ci *                      UErrorCode *pErrorCode) {
2161cb0ef41Sopenharmony_ci *     UBiDi *para;
2171cb0ef41Sopenharmony_ci *
2181cb0ef41Sopenharmony_ci *     if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {
2191cb0ef41Sopenharmony_ci *         return;
2201cb0ef41Sopenharmony_ci *     }
2211cb0ef41Sopenharmony_ci *
2221cb0ef41Sopenharmony_ci *     para=ubidi_openSized(length, 0, pErrorCode);
2231cb0ef41Sopenharmony_ci *     if(para==NULL) { return; }
2241cb0ef41Sopenharmony_ci *
2251cb0ef41Sopenharmony_ci *     ubidi_setPara(para, text, length,
2261cb0ef41Sopenharmony_ci *                   textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
2271cb0ef41Sopenharmony_ci *                   NULL, pErrorCode);
2281cb0ef41Sopenharmony_ci *     if(U_SUCCESS(*pErrorCode)) {
2291cb0ef41Sopenharmony_ci *         UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);
2301cb0ef41Sopenharmony_ci *         StyleRun styleRun={ length, styleNormal };
2311cb0ef41Sopenharmony_ci *         int width;
2321cb0ef41Sopenharmony_ci *
2331cb0ef41Sopenharmony_ci *         if(styleRuns==NULL || styleRunCount<=0) {
2341cb0ef41Sopenharmony_ci *            styleRunCount=1;
2351cb0ef41Sopenharmony_ci *             styleRuns=&styleRun;
2361cb0ef41Sopenharmony_ci *         }
2371cb0ef41Sopenharmony_ci *
2381cb0ef41Sopenharmony_ci *        // assume styleRuns[styleRunCount-1].limit>=length
2391cb0ef41Sopenharmony_ci *
2401cb0ef41Sopenharmony_ci *         width=getTextWidth(text, 0, length, styleRuns, styleRunCount);
2411cb0ef41Sopenharmony_ci *         if(width<=lineWidth) {
2421cb0ef41Sopenharmony_ci *             // everything fits onto one line
2431cb0ef41Sopenharmony_ci *
2441cb0ef41Sopenharmony_ci *            // prepare rendering a new line from either left or right
2451cb0ef41Sopenharmony_ci *             startLine(paraLevel, width);
2461cb0ef41Sopenharmony_ci *
2471cb0ef41Sopenharmony_ci *             renderLine(para, text, 0, length,
2481cb0ef41Sopenharmony_ci *                        styleRuns, styleRunCount, pErrorCode);
2491cb0ef41Sopenharmony_ci *         } else {
2501cb0ef41Sopenharmony_ci *             UBiDi *line;
2511cb0ef41Sopenharmony_ci *
2521cb0ef41Sopenharmony_ci *             // we need to render several lines
2531cb0ef41Sopenharmony_ci *             line=ubidi_openSized(length, 0, pErrorCode);
2541cb0ef41Sopenharmony_ci *             if(line!=NULL) {
2551cb0ef41Sopenharmony_ci *                 int32_t start=0, limit;
2561cb0ef41Sopenharmony_ci *                 int styleRunStart=0, styleRunLimit;
2571cb0ef41Sopenharmony_ci *
2581cb0ef41Sopenharmony_ci *                 for(;;) {
2591cb0ef41Sopenharmony_ci *                     limit=length;
2601cb0ef41Sopenharmony_ci *                     styleRunLimit=styleRunCount;
2611cb0ef41Sopenharmony_ci *                     getLineBreak(text, start, &limit, para,
2621cb0ef41Sopenharmony_ci *                                  styleRuns, styleRunStart, &styleRunLimit,
2631cb0ef41Sopenharmony_ci *                                 &width);
2641cb0ef41Sopenharmony_ci *                     ubidi_setLine(para, start, limit, line, pErrorCode);
2651cb0ef41Sopenharmony_ci *                     if(U_SUCCESS(*pErrorCode)) {
2661cb0ef41Sopenharmony_ci *                         // prepare rendering a new line
2671cb0ef41Sopenharmony_ci *                         // from either left or right
2681cb0ef41Sopenharmony_ci *                         startLine(paraLevel, width);
2691cb0ef41Sopenharmony_ci *
2701cb0ef41Sopenharmony_ci *                         renderLine(line, text, start, limit,
2711cb0ef41Sopenharmony_ci *                                    styleRuns+styleRunStart,
2721cb0ef41Sopenharmony_ci *                                    styleRunLimit-styleRunStart, pErrorCode);
2731cb0ef41Sopenharmony_ci *                     }
2741cb0ef41Sopenharmony_ci *                     if(limit==length) { break; }
2751cb0ef41Sopenharmony_ci *                     start=limit;
2761cb0ef41Sopenharmony_ci *                     styleRunStart=styleRunLimit-1;
2771cb0ef41Sopenharmony_ci *                     if(start>=styleRuns[styleRunStart].limit) {
2781cb0ef41Sopenharmony_ci *                         ++styleRunStart;
2791cb0ef41Sopenharmony_ci *                     }
2801cb0ef41Sopenharmony_ci *                 }
2811cb0ef41Sopenharmony_ci *
2821cb0ef41Sopenharmony_ci *                 ubidi_close(line);
2831cb0ef41Sopenharmony_ci *             }
2841cb0ef41Sopenharmony_ci *        }
2851cb0ef41Sopenharmony_ci *    }
2861cb0ef41Sopenharmony_ci *
2871cb0ef41Sopenharmony_ci *     ubidi_close(para);
2881cb0ef41Sopenharmony_ci *}
2891cb0ef41Sopenharmony_ci *\endcode
2901cb0ef41Sopenharmony_ci * </pre>
2911cb0ef41Sopenharmony_ci */
2921cb0ef41Sopenharmony_ci
2931cb0ef41Sopenharmony_ci/*DOCXX_TAG*/
2941cb0ef41Sopenharmony_ci/*@{*/
2951cb0ef41Sopenharmony_ci
2961cb0ef41Sopenharmony_ci/**
2971cb0ef41Sopenharmony_ci * UBiDiLevel is the type of the level values in this
2981cb0ef41Sopenharmony_ci * Bidi implementation.
2991cb0ef41Sopenharmony_ci * It holds an embedding level and indicates the visual direction
3001cb0ef41Sopenharmony_ci * by its bit&nbsp;0 (even/odd value).<p>
3011cb0ef41Sopenharmony_ci *
3021cb0ef41Sopenharmony_ci * It can also hold non-level values for the
3031cb0ef41Sopenharmony_ci * <code>paraLevel</code> and <code>embeddingLevels</code>
3041cb0ef41Sopenharmony_ci * arguments of <code>ubidi_setPara()</code>; there:
3051cb0ef41Sopenharmony_ci * <ul>
3061cb0ef41Sopenharmony_ci * <li>bit&nbsp;7 of an <code>embeddingLevels[]</code>
3071cb0ef41Sopenharmony_ci * value indicates whether the using application is
3081cb0ef41Sopenharmony_ci * specifying the level of a character to <i>override</i> whatever the
3091cb0ef41Sopenharmony_ci * Bidi implementation would resolve it to.</li>
3101cb0ef41Sopenharmony_ci * <li><code>paraLevel</code> can be set to the
3111cb0ef41Sopenharmony_ci * pseudo-level values <code>UBIDI_DEFAULT_LTR</code>
3121cb0ef41Sopenharmony_ci * and <code>UBIDI_DEFAULT_RTL</code>.</li>
3131cb0ef41Sopenharmony_ci * </ul>
3141cb0ef41Sopenharmony_ci *
3151cb0ef41Sopenharmony_ci * @see ubidi_setPara
3161cb0ef41Sopenharmony_ci *
3171cb0ef41Sopenharmony_ci * <p>The related constants are not real, valid level values.
3181cb0ef41Sopenharmony_ci * <code>UBIDI_DEFAULT_XXX</code> can be used to specify
3191cb0ef41Sopenharmony_ci * a default for the paragraph level for
3201cb0ef41Sopenharmony_ci * when the <code>ubidi_setPara()</code> function
3211cb0ef41Sopenharmony_ci * shall determine it but there is no
3221cb0ef41Sopenharmony_ci * strongly typed character in the input.<p>
3231cb0ef41Sopenharmony_ci *
3241cb0ef41Sopenharmony_ci * Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even
3251cb0ef41Sopenharmony_ci * and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,
3261cb0ef41Sopenharmony_ci * just like with normal LTR and RTL level values -
3271cb0ef41Sopenharmony_ci * these special values are designed that way. Also, the implementation
3281cb0ef41Sopenharmony_ci * assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
3291cb0ef41Sopenharmony_ci *
3301cb0ef41Sopenharmony_ci * Note: The numeric values of the related constants will not change:
3311cb0ef41Sopenharmony_ci * They are tied to the use of 7-bit byte values (plus the override bit)
3321cb0ef41Sopenharmony_ci * and of the UBiDiLevel=uint8_t data type in this API.
3331cb0ef41Sopenharmony_ci *
3341cb0ef41Sopenharmony_ci * @see UBIDI_DEFAULT_LTR
3351cb0ef41Sopenharmony_ci * @see UBIDI_DEFAULT_RTL
3361cb0ef41Sopenharmony_ci * @see UBIDI_LEVEL_OVERRIDE
3371cb0ef41Sopenharmony_ci * @see UBIDI_MAX_EXPLICIT_LEVEL
3381cb0ef41Sopenharmony_ci * @stable ICU 2.0
3391cb0ef41Sopenharmony_ci */
3401cb0ef41Sopenharmony_citypedef uint8_t UBiDiLevel;
3411cb0ef41Sopenharmony_ci
3421cb0ef41Sopenharmony_ci/** Paragraph level setting.<p>
3431cb0ef41Sopenharmony_ci *
3441cb0ef41Sopenharmony_ci * Constant indicating that the base direction depends on the first strong
3451cb0ef41Sopenharmony_ci * directional character in the text according to the Unicode Bidirectional
3461cb0ef41Sopenharmony_ci * Algorithm. If no strong directional character is present,
3471cb0ef41Sopenharmony_ci * then set the paragraph level to 0 (left-to-right).<p>
3481cb0ef41Sopenharmony_ci *
3491cb0ef41Sopenharmony_ci * If this value is used in conjunction with reordering modes
3501cb0ef41Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
3511cb0ef41Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
3521cb0ef41Sopenharmony_ci * is assumed to be visual LTR, and the text after reordering is required
3531cb0ef41Sopenharmony_ci * to be the corresponding logical string with appropriate contextual
3541cb0ef41Sopenharmony_ci * direction. The direction of the result string will be RTL if either
3551cb0ef41Sopenharmony_ci * the righmost or leftmost strong character of the source text is RTL
3561cb0ef41Sopenharmony_ci * or Arabic Letter, the direction will be LTR otherwise.<p>
3571cb0ef41Sopenharmony_ci *
3581cb0ef41Sopenharmony_ci * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
3591cb0ef41Sopenharmony_ci * be added at the beginning of the result string to ensure round trip
3601cb0ef41Sopenharmony_ci * (that the result string, when reordered back to visual, will produce
3611cb0ef41Sopenharmony_ci * the original source text).
3621cb0ef41Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
3631cb0ef41Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
3641cb0ef41Sopenharmony_ci * @stable ICU 2.0
3651cb0ef41Sopenharmony_ci */
3661cb0ef41Sopenharmony_ci#define UBIDI_DEFAULT_LTR 0xfe
3671cb0ef41Sopenharmony_ci
3681cb0ef41Sopenharmony_ci/** Paragraph level setting.<p>
3691cb0ef41Sopenharmony_ci *
3701cb0ef41Sopenharmony_ci * Constant indicating that the base direction depends on the first strong
3711cb0ef41Sopenharmony_ci * directional character in the text according to the Unicode Bidirectional
3721cb0ef41Sopenharmony_ci * Algorithm. If no strong directional character is present,
3731cb0ef41Sopenharmony_ci * then set the paragraph level to 1 (right-to-left).<p>
3741cb0ef41Sopenharmony_ci *
3751cb0ef41Sopenharmony_ci * If this value is used in conjunction with reordering modes
3761cb0ef41Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
3771cb0ef41Sopenharmony_ci * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
3781cb0ef41Sopenharmony_ci * is assumed to be visual LTR, and the text after reordering is required
3791cb0ef41Sopenharmony_ci * to be the corresponding logical string with appropriate contextual
3801cb0ef41Sopenharmony_ci * direction. The direction of the result string will be RTL if either
3811cb0ef41Sopenharmony_ci * the righmost or leftmost strong character of the source text is RTL
3821cb0ef41Sopenharmony_ci * or Arabic Letter, or if the text contains no strong character;
3831cb0ef41Sopenharmony_ci * the direction will be LTR otherwise.<p>
3841cb0ef41Sopenharmony_ci *
3851cb0ef41Sopenharmony_ci * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
3861cb0ef41Sopenharmony_ci * be added at the beginning of the result string to ensure round trip
3871cb0ef41Sopenharmony_ci * (that the result string, when reordered back to visual, will produce
3881cb0ef41Sopenharmony_ci * the original source text).
3891cb0ef41Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
3901cb0ef41Sopenharmony_ci * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
3911cb0ef41Sopenharmony_ci * @stable ICU 2.0
3921cb0ef41Sopenharmony_ci */
3931cb0ef41Sopenharmony_ci#define UBIDI_DEFAULT_RTL 0xff
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_ci/**
3961cb0ef41Sopenharmony_ci * Maximum explicit embedding level.
3971cb0ef41Sopenharmony_ci * Same as the max_depth value in the
3981cb0ef41Sopenharmony_ci * <a href="http://www.unicode.org/reports/tr9/#BD2">Unicode Bidirectional Algorithm</a>.
3991cb0ef41Sopenharmony_ci * (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).
4001cb0ef41Sopenharmony_ci * @stable ICU 2.0
4011cb0ef41Sopenharmony_ci */
4021cb0ef41Sopenharmony_ci#define UBIDI_MAX_EXPLICIT_LEVEL 125
4031cb0ef41Sopenharmony_ci
4041cb0ef41Sopenharmony_ci/** Bit flag for level input.
4051cb0ef41Sopenharmony_ci *  Overrides directional properties.
4061cb0ef41Sopenharmony_ci * @stable ICU 2.0
4071cb0ef41Sopenharmony_ci */
4081cb0ef41Sopenharmony_ci#define UBIDI_LEVEL_OVERRIDE 0x80
4091cb0ef41Sopenharmony_ci
4101cb0ef41Sopenharmony_ci/**
4111cb0ef41Sopenharmony_ci * Special value which can be returned by the mapping functions when a logical
4121cb0ef41Sopenharmony_ci * index has no corresponding visual index or vice-versa. This may happen
4131cb0ef41Sopenharmony_ci * for the logical-to-visual mapping of a Bidi control when option
4141cb0ef41Sopenharmony_ci * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is specified. This can also happen
4151cb0ef41Sopenharmony_ci * for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted
4161cb0ef41Sopenharmony_ci * by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
4171cb0ef41Sopenharmony_ci * @see ubidi_getVisualIndex
4181cb0ef41Sopenharmony_ci * @see ubidi_getVisualMap
4191cb0ef41Sopenharmony_ci * @see ubidi_getLogicalIndex
4201cb0ef41Sopenharmony_ci * @see ubidi_getLogicalMap
4211cb0ef41Sopenharmony_ci * @stable ICU 3.6
4221cb0ef41Sopenharmony_ci */
4231cb0ef41Sopenharmony_ci#define UBIDI_MAP_NOWHERE   (-1)
4241cb0ef41Sopenharmony_ci
4251cb0ef41Sopenharmony_ci/**
4261cb0ef41Sopenharmony_ci * <code>UBiDiDirection</code> values indicate the text direction.
4271cb0ef41Sopenharmony_ci * @stable ICU 2.0
4281cb0ef41Sopenharmony_ci */
4291cb0ef41Sopenharmony_cienum UBiDiDirection {
4301cb0ef41Sopenharmony_ci  /** Left-to-right text. This is a 0 value.
4311cb0ef41Sopenharmony_ci   * <ul>
4321cb0ef41Sopenharmony_ci   * <li>As return value for <code>ubidi_getDirection()</code>, it means
4331cb0ef41Sopenharmony_ci   *     that the source string contains no right-to-left characters, or
4341cb0ef41Sopenharmony_ci   *     that the source string is empty and the paragraph level is even.
4351cb0ef41Sopenharmony_ci   * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
4361cb0ef41Sopenharmony_ci   *      means that the first strong character of the source string has
4371cb0ef41Sopenharmony_ci   *      a left-to-right direction.
4381cb0ef41Sopenharmony_ci   * </ul>
4391cb0ef41Sopenharmony_ci   * @stable ICU 2.0
4401cb0ef41Sopenharmony_ci   */
4411cb0ef41Sopenharmony_ci  UBIDI_LTR,
4421cb0ef41Sopenharmony_ci  /** Right-to-left text. This is a 1 value.
4431cb0ef41Sopenharmony_ci   * <ul>
4441cb0ef41Sopenharmony_ci   * <li>As return value for <code>ubidi_getDirection()</code>, it means
4451cb0ef41Sopenharmony_ci   *     that the source string contains no left-to-right characters, or
4461cb0ef41Sopenharmony_ci   *     that the source string is empty and the paragraph level is odd.
4471cb0ef41Sopenharmony_ci   * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
4481cb0ef41Sopenharmony_ci   *      means that the first strong character of the source string has
4491cb0ef41Sopenharmony_ci   *      a right-to-left direction.
4501cb0ef41Sopenharmony_ci   * </ul>
4511cb0ef41Sopenharmony_ci   * @stable ICU 2.0
4521cb0ef41Sopenharmony_ci   */
4531cb0ef41Sopenharmony_ci  UBIDI_RTL,
4541cb0ef41Sopenharmony_ci  /** Mixed-directional text.
4551cb0ef41Sopenharmony_ci   * <p>As return value for <code>ubidi_getDirection()</code>, it means
4561cb0ef41Sopenharmony_ci   *    that the source string contains both left-to-right and
4571cb0ef41Sopenharmony_ci   *    right-to-left characters.
4581cb0ef41Sopenharmony_ci   * @stable ICU 2.0
4591cb0ef41Sopenharmony_ci   */
4601cb0ef41Sopenharmony_ci  UBIDI_MIXED,
4611cb0ef41Sopenharmony_ci  /** No strongly directional text.
4621cb0ef41Sopenharmony_ci   * <p>As return value for <code>ubidi_getBaseDirection()</code>, it means
4631cb0ef41Sopenharmony_ci   *    that the source string is missing or empty, or contains neither left-to-right
4641cb0ef41Sopenharmony_ci   *    nor right-to-left characters.
4651cb0ef41Sopenharmony_ci   * @stable ICU 4.6
4661cb0ef41Sopenharmony_ci   */
4671cb0ef41Sopenharmony_ci  UBIDI_NEUTRAL
4681cb0ef41Sopenharmony_ci};
4691cb0ef41Sopenharmony_ci
4701cb0ef41Sopenharmony_ci/** @stable ICU 2.0 */
4711cb0ef41Sopenharmony_citypedef enum UBiDiDirection UBiDiDirection;
4721cb0ef41Sopenharmony_ci
4731cb0ef41Sopenharmony_ci/**
4741cb0ef41Sopenharmony_ci * Forward declaration of the <code>UBiDi</code> structure for the declaration of
4751cb0ef41Sopenharmony_ci * the API functions. Its fields are implementation-specific.<p>
4761cb0ef41Sopenharmony_ci * This structure holds information about a paragraph (or multiple paragraphs)
4771cb0ef41Sopenharmony_ci * of text with Bidi-algorithm-related details, or about one line of
4781cb0ef41Sopenharmony_ci * such a paragraph.<p>
4791cb0ef41Sopenharmony_ci * Reordering can be done on a line, or on one or more paragraphs which are
4801cb0ef41Sopenharmony_ci * then interpreted each as one single line.
4811cb0ef41Sopenharmony_ci * @stable ICU 2.0
4821cb0ef41Sopenharmony_ci */
4831cb0ef41Sopenharmony_cistruct UBiDi;
4841cb0ef41Sopenharmony_ci
4851cb0ef41Sopenharmony_ci/** @stable ICU 2.0 */
4861cb0ef41Sopenharmony_citypedef struct UBiDi UBiDi;
4871cb0ef41Sopenharmony_ci
4881cb0ef41Sopenharmony_ci/**
4891cb0ef41Sopenharmony_ci * Allocate a <code>UBiDi</code> structure.
4901cb0ef41Sopenharmony_ci * Such an object is initially empty. It is assigned
4911cb0ef41Sopenharmony_ci * the Bidi properties of a piece of text containing one or more paragraphs
4921cb0ef41Sopenharmony_ci * by <code>ubidi_setPara()</code>
4931cb0ef41Sopenharmony_ci * or the Bidi properties of a line within a paragraph by
4941cb0ef41Sopenharmony_ci * <code>ubidi_setLine()</code>.<p>
4951cb0ef41Sopenharmony_ci * This object can be reused for as long as it is not deallocated
4961cb0ef41Sopenharmony_ci * by calling <code>ubidi_close()</code>.<p>
4971cb0ef41Sopenharmony_ci * <code>ubidi_setPara()</code> and <code>ubidi_setLine()</code> will allocate
4981cb0ef41Sopenharmony_ci * additional memory for internal structures as necessary.
4991cb0ef41Sopenharmony_ci *
5001cb0ef41Sopenharmony_ci * @return An empty <code>UBiDi</code> object.
5011cb0ef41Sopenharmony_ci * @stable ICU 2.0
5021cb0ef41Sopenharmony_ci */
5031cb0ef41Sopenharmony_ciU_CAPI UBiDi * U_EXPORT2
5041cb0ef41Sopenharmony_ciubidi_open(void);
5051cb0ef41Sopenharmony_ci
5061cb0ef41Sopenharmony_ci/**
5071cb0ef41Sopenharmony_ci * Allocate a <code>UBiDi</code> structure with preallocated memory
5081cb0ef41Sopenharmony_ci * for internal structures.
5091cb0ef41Sopenharmony_ci * This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>
5101cb0ef41Sopenharmony_ci * with no arguments, but it also preallocates memory for internal structures
5111cb0ef41Sopenharmony_ci * according to the sizings supplied by the caller.<p>
5121cb0ef41Sopenharmony_ci * Subsequent functions will not allocate any more memory, and are thus
5131cb0ef41Sopenharmony_ci * guaranteed not to fail because of lack of memory.<p>
5141cb0ef41Sopenharmony_ci * The preallocation can be limited to some of the internal memory
5151cb0ef41Sopenharmony_ci * by setting some values to 0 here. That means that if, e.g.,
5161cb0ef41Sopenharmony_ci * <code>maxRunCount</code> cannot be reasonably predetermined and should not
5171cb0ef41Sopenharmony_ci * be set to <code>maxLength</code> (the only failproof value) to avoid
5181cb0ef41Sopenharmony_ci * wasting memory, then <code>maxRunCount</code> could be set to 0 here
5191cb0ef41Sopenharmony_ci * and the internal structures that are associated with it will be allocated
5201cb0ef41Sopenharmony_ci * on demand, just like with <code>ubidi_open()</code>.
5211cb0ef41Sopenharmony_ci *
5221cb0ef41Sopenharmony_ci * @param maxLength is the maximum text or line length that internal memory
5231cb0ef41Sopenharmony_ci *        will be preallocated for. An attempt to associate this object with a
5241cb0ef41Sopenharmony_ci *        longer text will fail, unless this value is 0, which leaves the allocation
5251cb0ef41Sopenharmony_ci *        up to the implementation.
5261cb0ef41Sopenharmony_ci *
5271cb0ef41Sopenharmony_ci * @param maxRunCount is the maximum anticipated number of same-level runs
5281cb0ef41Sopenharmony_ci *        that internal memory will be preallocated for. An attempt to access
5291cb0ef41Sopenharmony_ci *        visual runs on an object that was not preallocated for as many runs
5301cb0ef41Sopenharmony_ci *        as the text was actually resolved to will fail,
5311cb0ef41Sopenharmony_ci *        unless this value is 0, which leaves the allocation up to the implementation.<br><br>
5321cb0ef41Sopenharmony_ci *        The number of runs depends on the actual text and maybe anywhere between
5331cb0ef41Sopenharmony_ci *        1 and <code>maxLength</code>. It is typically small.
5341cb0ef41Sopenharmony_ci *
5351cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
5361cb0ef41Sopenharmony_ci *
5371cb0ef41Sopenharmony_ci * @return An empty <code>UBiDi</code> object with preallocated memory.
5381cb0ef41Sopenharmony_ci * @stable ICU 2.0
5391cb0ef41Sopenharmony_ci */
5401cb0ef41Sopenharmony_ciU_CAPI UBiDi * U_EXPORT2
5411cb0ef41Sopenharmony_ciubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
5421cb0ef41Sopenharmony_ci
5431cb0ef41Sopenharmony_ci/**
5441cb0ef41Sopenharmony_ci * <code>ubidi_close()</code> must be called to free the memory
5451cb0ef41Sopenharmony_ci * associated with a UBiDi object.<p>
5461cb0ef41Sopenharmony_ci *
5471cb0ef41Sopenharmony_ci * <strong>Important: </strong>
5481cb0ef41Sopenharmony_ci * A parent <code>UBiDi</code> object must not be destroyed or reused if
5491cb0ef41Sopenharmony_ci * it still has children.
5501cb0ef41Sopenharmony_ci * If a <code>UBiDi</code> object has become the <i>child</i>
5511cb0ef41Sopenharmony_ci * of another one (its <i>parent</i>) by calling
5521cb0ef41Sopenharmony_ci * <code>ubidi_setLine()</code>, then the child object must
5531cb0ef41Sopenharmony_ci * be destroyed (closed) or reused (by calling
5541cb0ef41Sopenharmony_ci * <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)
5551cb0ef41Sopenharmony_ci * before the parent object.
5561cb0ef41Sopenharmony_ci *
5571cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
5581cb0ef41Sopenharmony_ci *
5591cb0ef41Sopenharmony_ci * @see ubidi_setPara
5601cb0ef41Sopenharmony_ci * @see ubidi_setLine
5611cb0ef41Sopenharmony_ci * @stable ICU 2.0
5621cb0ef41Sopenharmony_ci */
5631cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
5641cb0ef41Sopenharmony_ciubidi_close(UBiDi *pBiDi);
5651cb0ef41Sopenharmony_ci
5661cb0ef41Sopenharmony_ci#if U_SHOW_CPLUSPLUS_API
5671cb0ef41Sopenharmony_ci
5681cb0ef41Sopenharmony_ciU_NAMESPACE_BEGIN
5691cb0ef41Sopenharmony_ci
5701cb0ef41Sopenharmony_ci/**
5711cb0ef41Sopenharmony_ci * \class LocalUBiDiPointer
5721cb0ef41Sopenharmony_ci * "Smart pointer" class, closes a UBiDi via ubidi_close().
5731cb0ef41Sopenharmony_ci * For most methods see the LocalPointerBase base class.
5741cb0ef41Sopenharmony_ci *
5751cb0ef41Sopenharmony_ci * @see LocalPointerBase
5761cb0ef41Sopenharmony_ci * @see LocalPointer
5771cb0ef41Sopenharmony_ci * @stable ICU 4.4
5781cb0ef41Sopenharmony_ci */
5791cb0ef41Sopenharmony_ciU_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);
5801cb0ef41Sopenharmony_ci
5811cb0ef41Sopenharmony_ciU_NAMESPACE_END
5821cb0ef41Sopenharmony_ci
5831cb0ef41Sopenharmony_ci#endif
5841cb0ef41Sopenharmony_ci
5851cb0ef41Sopenharmony_ci/**
5861cb0ef41Sopenharmony_ci * Modify the operation of the Bidi algorithm such that it
5871cb0ef41Sopenharmony_ci * approximates an "inverse Bidi" algorithm. This function
5881cb0ef41Sopenharmony_ci * must be called before <code>ubidi_setPara()</code>.
5891cb0ef41Sopenharmony_ci *
5901cb0ef41Sopenharmony_ci * <p>The normal operation of the Bidi algorithm as described
5911cb0ef41Sopenharmony_ci * in the Unicode Technical Report is to take text stored in logical
5921cb0ef41Sopenharmony_ci * (keyboard, typing) order and to determine the reordering of it for visual
5931cb0ef41Sopenharmony_ci * rendering.
5941cb0ef41Sopenharmony_ci * Some legacy systems store text in visual order, and for operations
5951cb0ef41Sopenharmony_ci * with standard, Unicode-based algorithms, the text needs to be transformed
5961cb0ef41Sopenharmony_ci * to logical order. This is effectively the inverse algorithm of the
5971cb0ef41Sopenharmony_ci * described Bidi algorithm. Note that there is no standard algorithm for
5981cb0ef41Sopenharmony_ci * this "inverse Bidi" and that the current implementation provides only an
5991cb0ef41Sopenharmony_ci * approximation of "inverse Bidi".</p>
6001cb0ef41Sopenharmony_ci *
6011cb0ef41Sopenharmony_ci * <p>With <code>isInverse</code> set to <code>true</code>,
6021cb0ef41Sopenharmony_ci * this function changes the behavior of some of the subsequent functions
6031cb0ef41Sopenharmony_ci * in a way that they can be used for the inverse Bidi algorithm.
6041cb0ef41Sopenharmony_ci * Specifically, runs of text with numeric characters will be treated in a
6051cb0ef41Sopenharmony_ci * special way and may need to be surrounded with LRM characters when they are
6061cb0ef41Sopenharmony_ci * written in reordered sequence.</p>
6071cb0ef41Sopenharmony_ci *
6081cb0ef41Sopenharmony_ci * <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.
6091cb0ef41Sopenharmony_ci * Since the actual input for "inverse Bidi" is visually ordered text and
6101cb0ef41Sopenharmony_ci * <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually
6111cb0ef41Sopenharmony_ci * the runs of the logically ordered output.</p>
6121cb0ef41Sopenharmony_ci *
6131cb0ef41Sopenharmony_ci * <p>Calling this function with argument <code>isInverse</code> set to
6141cb0ef41Sopenharmony_ci * <code>true</code> is equivalent to calling
6151cb0ef41Sopenharmony_ci * <code>ubidi_setReorderingMode</code> with argument
6161cb0ef41Sopenharmony_ci * <code>reorderingMode</code>
6171cb0ef41Sopenharmony_ci * set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
6181cb0ef41Sopenharmony_ci * Calling this function with argument <code>isInverse</code> set to
6191cb0ef41Sopenharmony_ci * <code>false</code> is equivalent to calling
6201cb0ef41Sopenharmony_ci * <code>ubidi_setReorderingMode</code> with argument
6211cb0ef41Sopenharmony_ci * <code>reorderingMode</code>
6221cb0ef41Sopenharmony_ci * set to <code>#UBIDI_REORDER_DEFAULT</code>.
6231cb0ef41Sopenharmony_ci *
6241cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6251cb0ef41Sopenharmony_ci *
6261cb0ef41Sopenharmony_ci * @param isInverse specifies "forward" or "inverse" Bidi operation.
6271cb0ef41Sopenharmony_ci *
6281cb0ef41Sopenharmony_ci * @see ubidi_setPara
6291cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
6301cb0ef41Sopenharmony_ci * @see ubidi_setReorderingMode
6311cb0ef41Sopenharmony_ci * @stable ICU 2.0
6321cb0ef41Sopenharmony_ci */
6331cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
6341cb0ef41Sopenharmony_ciubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
6351cb0ef41Sopenharmony_ci
6361cb0ef41Sopenharmony_ci/**
6371cb0ef41Sopenharmony_ci * Is this Bidi object set to perform the inverse Bidi algorithm?
6381cb0ef41Sopenharmony_ci * <p>Note: calling this function after setting the reordering mode with
6391cb0ef41Sopenharmony_ci * <code>ubidi_setReorderingMode</code> will return <code>true</code> if the
6401cb0ef41Sopenharmony_ci * reordering mode was set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>,
6411cb0ef41Sopenharmony_ci * <code>false</code> for all other values.</p>
6421cb0ef41Sopenharmony_ci *
6431cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6441cb0ef41Sopenharmony_ci * @return true if the Bidi object is set to perform the inverse Bidi algorithm
6451cb0ef41Sopenharmony_ci * by handling numbers as L.
6461cb0ef41Sopenharmony_ci *
6471cb0ef41Sopenharmony_ci * @see ubidi_setInverse
6481cb0ef41Sopenharmony_ci * @see ubidi_setReorderingMode
6491cb0ef41Sopenharmony_ci * @stable ICU 2.0
6501cb0ef41Sopenharmony_ci */
6511cb0ef41Sopenharmony_ci
6521cb0ef41Sopenharmony_ciU_CAPI UBool U_EXPORT2
6531cb0ef41Sopenharmony_ciubidi_isInverse(UBiDi *pBiDi);
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_ci/**
6561cb0ef41Sopenharmony_ci * Specify whether block separators must be allocated level zero,
6571cb0ef41Sopenharmony_ci * so that successive paragraphs will progress from left to right.
6581cb0ef41Sopenharmony_ci * This function must be called before <code>ubidi_setPara()</code>.
6591cb0ef41Sopenharmony_ci * Paragraph separators (B) may appear in the text.  Setting them to level zero
6601cb0ef41Sopenharmony_ci * means that all paragraph separators (including one possibly appearing
6611cb0ef41Sopenharmony_ci * in the last text position) are kept in the reordered text after the text
6621cb0ef41Sopenharmony_ci * that they follow in the source text.
6631cb0ef41Sopenharmony_ci * When this feature is not enabled, a paragraph separator at the last
6641cb0ef41Sopenharmony_ci * position of the text before reordering will go to the first position
6651cb0ef41Sopenharmony_ci * of the reordered text when the paragraph level is odd.
6661cb0ef41Sopenharmony_ci *
6671cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6681cb0ef41Sopenharmony_ci *
6691cb0ef41Sopenharmony_ci * @param orderParagraphsLTR specifies whether paragraph separators (B) must
6701cb0ef41Sopenharmony_ci * receive level 0, so that successive paragraphs progress from left to right.
6711cb0ef41Sopenharmony_ci *
6721cb0ef41Sopenharmony_ci * @see ubidi_setPara
6731cb0ef41Sopenharmony_ci * @stable ICU 3.4
6741cb0ef41Sopenharmony_ci */
6751cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
6761cb0ef41Sopenharmony_ciubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);
6771cb0ef41Sopenharmony_ci
6781cb0ef41Sopenharmony_ci/**
6791cb0ef41Sopenharmony_ci * Is this Bidi object set to allocate level 0 to block separators so that
6801cb0ef41Sopenharmony_ci * successive paragraphs progress from left to right?
6811cb0ef41Sopenharmony_ci *
6821cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
6831cb0ef41Sopenharmony_ci * @return true if the Bidi object is set to allocate level 0 to block
6841cb0ef41Sopenharmony_ci *         separators.
6851cb0ef41Sopenharmony_ci *
6861cb0ef41Sopenharmony_ci * @see ubidi_orderParagraphsLTR
6871cb0ef41Sopenharmony_ci * @stable ICU 3.4
6881cb0ef41Sopenharmony_ci */
6891cb0ef41Sopenharmony_ciU_CAPI UBool U_EXPORT2
6901cb0ef41Sopenharmony_ciubidi_isOrderParagraphsLTR(UBiDi *pBiDi);
6911cb0ef41Sopenharmony_ci
6921cb0ef41Sopenharmony_ci/**
6931cb0ef41Sopenharmony_ci * <code>UBiDiReorderingMode</code> values indicate which variant of the Bidi
6941cb0ef41Sopenharmony_ci * algorithm to use.
6951cb0ef41Sopenharmony_ci *
6961cb0ef41Sopenharmony_ci * @see ubidi_setReorderingMode
6971cb0ef41Sopenharmony_ci * @stable ICU 3.6
6981cb0ef41Sopenharmony_ci */
6991cb0ef41Sopenharmony_citypedef enum UBiDiReorderingMode {
7001cb0ef41Sopenharmony_ci    /** Regular Logical to Visual Bidi algorithm according to Unicode.
7011cb0ef41Sopenharmony_ci      * This is a 0 value.
7021cb0ef41Sopenharmony_ci      * @stable ICU 3.6 */
7031cb0ef41Sopenharmony_ci    UBIDI_REORDER_DEFAULT = 0,
7041cb0ef41Sopenharmony_ci    /** Logical to Visual algorithm which handles numbers in a way which
7051cb0ef41Sopenharmony_ci      * mimics the behavior of Windows XP.
7061cb0ef41Sopenharmony_ci      * @stable ICU 3.6 */
7071cb0ef41Sopenharmony_ci    UBIDI_REORDER_NUMBERS_SPECIAL,
7081cb0ef41Sopenharmony_ci    /** Logical to Visual algorithm grouping numbers with adjacent R characters
7091cb0ef41Sopenharmony_ci      * (reversible algorithm).
7101cb0ef41Sopenharmony_ci      * @stable ICU 3.6 */
7111cb0ef41Sopenharmony_ci    UBIDI_REORDER_GROUP_NUMBERS_WITH_R,
7121cb0ef41Sopenharmony_ci    /** Reorder runs only to transform a Logical LTR string to the Logical RTL
7131cb0ef41Sopenharmony_ci      * string with the same display, or vice-versa.<br>
7141cb0ef41Sopenharmony_ci      * If this mode is set together with option
7151cb0ef41Sopenharmony_ci      * <code>#UBIDI_OPTION_INSERT_MARKS</code>, some Bidi controls in the source
7161cb0ef41Sopenharmony_ci      * text may be removed and other controls may be added to produce the
7171cb0ef41Sopenharmony_ci      * minimum combination which has the required display.
7181cb0ef41Sopenharmony_ci      * @stable ICU 3.6 */
7191cb0ef41Sopenharmony_ci    UBIDI_REORDER_RUNS_ONLY,
7201cb0ef41Sopenharmony_ci    /** Visual to Logical algorithm which handles numbers like L
7211cb0ef41Sopenharmony_ci      * (same algorithm as selected by <code>ubidi_setInverse(true)</code>.
7221cb0ef41Sopenharmony_ci      * @see ubidi_setInverse
7231cb0ef41Sopenharmony_ci      * @stable ICU 3.6 */
7241cb0ef41Sopenharmony_ci    UBIDI_REORDER_INVERSE_NUMBERS_AS_L,
7251cb0ef41Sopenharmony_ci    /** Visual to Logical algorithm equivalent to the regular Logical to Visual
7261cb0ef41Sopenharmony_ci      * algorithm.
7271cb0ef41Sopenharmony_ci      * @stable ICU 3.6 */
7281cb0ef41Sopenharmony_ci    UBIDI_REORDER_INVERSE_LIKE_DIRECT,
7291cb0ef41Sopenharmony_ci    /** Inverse Bidi (Visual to Logical) algorithm for the
7301cb0ef41Sopenharmony_ci      * <code>UBIDI_REORDER_NUMBERS_SPECIAL</code> Bidi algorithm.
7311cb0ef41Sopenharmony_ci      * @stable ICU 3.6 */
7321cb0ef41Sopenharmony_ci    UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,
7331cb0ef41Sopenharmony_ci#ifndef U_HIDE_DEPRECATED_API
7341cb0ef41Sopenharmony_ci    /**
7351cb0ef41Sopenharmony_ci     * Number of values for reordering mode.
7361cb0ef41Sopenharmony_ci     * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
7371cb0ef41Sopenharmony_ci     */
7381cb0ef41Sopenharmony_ci    UBIDI_REORDER_COUNT
7391cb0ef41Sopenharmony_ci#endif  // U_HIDE_DEPRECATED_API
7401cb0ef41Sopenharmony_ci} UBiDiReorderingMode;
7411cb0ef41Sopenharmony_ci
7421cb0ef41Sopenharmony_ci/**
7431cb0ef41Sopenharmony_ci * Modify the operation of the Bidi algorithm such that it implements some
7441cb0ef41Sopenharmony_ci * variant to the basic Bidi algorithm or approximates an "inverse Bidi"
7451cb0ef41Sopenharmony_ci * algorithm, depending on different values of the "reordering mode".
7461cb0ef41Sopenharmony_ci * This function must be called before <code>ubidi_setPara()</code>, and stays
7471cb0ef41Sopenharmony_ci * in effect until called again with a different argument.
7481cb0ef41Sopenharmony_ci *
7491cb0ef41Sopenharmony_ci * <p>The normal operation of the Bidi algorithm as described
7501cb0ef41Sopenharmony_ci * in the Unicode Standard Annex #9 is to take text stored in logical
7511cb0ef41Sopenharmony_ci * (keyboard, typing) order and to determine how to reorder it for visual
7521cb0ef41Sopenharmony_ci * rendering.</p>
7531cb0ef41Sopenharmony_ci *
7541cb0ef41Sopenharmony_ci * <p>With the reordering mode set to a value other than
7551cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_DEFAULT</code>, this function changes the behavior of
7561cb0ef41Sopenharmony_ci * some of the subsequent functions in a way such that they implement an
7571cb0ef41Sopenharmony_ci * inverse Bidi algorithm or some other algorithm variants.</p>
7581cb0ef41Sopenharmony_ci *
7591cb0ef41Sopenharmony_ci * <p>Some legacy systems store text in visual order, and for operations
7601cb0ef41Sopenharmony_ci * with standard, Unicode-based algorithms, the text needs to be transformed
7611cb0ef41Sopenharmony_ci * into logical order. This is effectively the inverse algorithm of the
7621cb0ef41Sopenharmony_ci * described Bidi algorithm. Note that there is no standard algorithm for
7631cb0ef41Sopenharmony_ci * this "inverse Bidi", so a number of variants are implemented here.</p>
7641cb0ef41Sopenharmony_ci *
7651cb0ef41Sopenharmony_ci * <p>In other cases, it may be desirable to emulate some variant of the
7661cb0ef41Sopenharmony_ci * Logical to Visual algorithm (e.g. one used in MS Windows), or perform a
7671cb0ef41Sopenharmony_ci * Logical to Logical transformation.</p>
7681cb0ef41Sopenharmony_ci *
7691cb0ef41Sopenharmony_ci * <ul>
7701cb0ef41Sopenharmony_ci * <li>When the reordering mode is set to <code>#UBIDI_REORDER_DEFAULT</code>,
7711cb0ef41Sopenharmony_ci * the standard Bidi Logical to Visual algorithm is applied.</li>
7721cb0ef41Sopenharmony_ci *
7731cb0ef41Sopenharmony_ci * <li>When the reordering mode is set to
7741cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_NUMBERS_SPECIAL</code>,
7751cb0ef41Sopenharmony_ci * the algorithm used to perform Bidi transformations when calling
7761cb0ef41Sopenharmony_ci * <code>ubidi_setPara</code> should approximate the algorithm used in
7771cb0ef41Sopenharmony_ci * Microsoft Windows XP rather than strictly conform to the Unicode Bidi
7781cb0ef41Sopenharmony_ci * algorithm.
7791cb0ef41Sopenharmony_ci * <br>
7801cb0ef41Sopenharmony_ci * The differences between the basic algorithm and the algorithm addressed
7811cb0ef41Sopenharmony_ci * by this option are as follows:
7821cb0ef41Sopenharmony_ci * <ul>
7831cb0ef41Sopenharmony_ci *   <li>Within text at an even embedding level, the sequence "123AB"
7841cb0ef41Sopenharmony_ci *   (where AB represent R or AL letters) is transformed to "123BA" by the
7851cb0ef41Sopenharmony_ci *   Unicode algorithm and to "BA123" by the Windows algorithm.</li>
7861cb0ef41Sopenharmony_ci *   <li>Arabic-Indic numbers (AN) are handled by the Windows algorithm just
7871cb0ef41Sopenharmony_ci *   like regular numbers (EN).</li>
7881cb0ef41Sopenharmony_ci * </ul></li>
7891cb0ef41Sopenharmony_ci *
7901cb0ef41Sopenharmony_ci * <li>When the reordering mode is set to
7911cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_GROUP_NUMBERS_WITH_R</code>,
7921cb0ef41Sopenharmony_ci * numbers located between LTR text and RTL text are associated with the RTL
7931cb0ef41Sopenharmony_ci * text. For instance, an LTR paragraph with content "abc 123 DEF" (where
7941cb0ef41Sopenharmony_ci * upper case letters represent RTL characters) will be transformed to
7951cb0ef41Sopenharmony_ci * "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed
7961cb0ef41Sopenharmony_ci * to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".
7971cb0ef41Sopenharmony_ci * This makes the algorithm reversible and makes it useful when round trip
7981cb0ef41Sopenharmony_ci * (from visual to logical and back to visual) must be achieved without
7991cb0ef41Sopenharmony_ci * adding LRM characters. However, this is a variation from the standard
8001cb0ef41Sopenharmony_ci * Unicode Bidi algorithm.<br>
8011cb0ef41Sopenharmony_ci * The source text should not contain Bidi control characters other than LRM
8021cb0ef41Sopenharmony_ci * or RLM.</li>
8031cb0ef41Sopenharmony_ci *
8041cb0ef41Sopenharmony_ci * <li>When the reordering mode is set to
8051cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_RUNS_ONLY</code>,
8061cb0ef41Sopenharmony_ci * a "Logical to Logical" transformation must be performed:
8071cb0ef41Sopenharmony_ci * <ul>
8081cb0ef41Sopenharmony_ci * <li>If the default text level of the source text (argument <code>paraLevel</code>
8091cb0ef41Sopenharmony_ci * in <code>ubidi_setPara</code>) is even, the source text will be handled as
8101cb0ef41Sopenharmony_ci * LTR logical text and will be transformed to the RTL logical text which has
8111cb0ef41Sopenharmony_ci * the same LTR visual display.</li>
8121cb0ef41Sopenharmony_ci * <li>If the default level of the source text is odd, the source text
8131cb0ef41Sopenharmony_ci * will be handled as RTL logical text and will be transformed to the
8141cb0ef41Sopenharmony_ci * LTR logical text which has the same LTR visual display.</li>
8151cb0ef41Sopenharmony_ci * </ul>
8161cb0ef41Sopenharmony_ci * This mode may be needed when logical text which is basically Arabic or
8171cb0ef41Sopenharmony_ci * Hebrew, with possible included numbers or phrases in English, has to be
8181cb0ef41Sopenharmony_ci * displayed as if it had an even embedding level (this can happen if the
8191cb0ef41Sopenharmony_ci * displaying application treats all text as if it was basically LTR).
8201cb0ef41Sopenharmony_ci * <br>
8211cb0ef41Sopenharmony_ci * This mode may also be needed in the reverse case, when logical text which is
8221cb0ef41Sopenharmony_ci * basically English, with possible included phrases in Arabic or Hebrew, has to
8231cb0ef41Sopenharmony_ci * be displayed as if it had an odd embedding level.
8241cb0ef41Sopenharmony_ci * <br>
8251cb0ef41Sopenharmony_ci * Both cases could be handled by adding LRE or RLE at the head of the text,
8261cb0ef41Sopenharmony_ci * if the display subsystem supports these formatting controls. If it does not,
8271cb0ef41Sopenharmony_ci * the problem may be handled by transforming the source text in this mode
8281cb0ef41Sopenharmony_ci * before displaying it, so that it will be displayed properly.<br>
8291cb0ef41Sopenharmony_ci * The source text should not contain Bidi control characters other than LRM
8301cb0ef41Sopenharmony_ci * or RLM.</li>
8311cb0ef41Sopenharmony_ci *
8321cb0ef41Sopenharmony_ci * <li>When the reordering mode is set to
8331cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>, an "inverse Bidi" algorithm
8341cb0ef41Sopenharmony_ci * is applied.
8351cb0ef41Sopenharmony_ci * Runs of text with numeric characters will be treated like LTR letters and
8361cb0ef41Sopenharmony_ci * may need to be surrounded with LRM characters when they are written in
8371cb0ef41Sopenharmony_ci * reordered sequence (the option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> can
8381cb0ef41Sopenharmony_ci * be used with function <code>ubidi_writeReordered</code> to this end. This
8391cb0ef41Sopenharmony_ci * mode is equivalent to calling <code>ubidi_setInverse()</code> with
8401cb0ef41Sopenharmony_ci * argument <code>isInverse</code> set to <code>true</code>.</li>
8411cb0ef41Sopenharmony_ci *
8421cb0ef41Sopenharmony_ci * <li>When the reordering mode is set to
8431cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code>, the "direct" Logical to Visual
8441cb0ef41Sopenharmony_ci * Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.
8451cb0ef41Sopenharmony_ci * This mode is similar to mode <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>
8461cb0ef41Sopenharmony_ci * but is closer to the regular Bidi algorithm.
8471cb0ef41Sopenharmony_ci * <br>
8481cb0ef41Sopenharmony_ci * For example, an LTR paragraph with the content "FED 123 456 CBA" (where
8491cb0ef41Sopenharmony_ci * upper case represents RTL characters) will be transformed to
8501cb0ef41Sopenharmony_ci * "ABC 456 123 DEF", as opposed to "DEF 123 456 ABC"
8511cb0ef41Sopenharmony_ci * with mode <code>UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
8521cb0ef41Sopenharmony_ci * When used in conjunction with option
8531cb0ef41Sopenharmony_ci * <code>#UBIDI_OPTION_INSERT_MARKS</code>, this mode generally
8541cb0ef41Sopenharmony_ci * adds Bidi marks to the output significantly more sparingly than mode
8551cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> with option
8561cb0ef41Sopenharmony_ci * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to
8571cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered</code>.</li>
8581cb0ef41Sopenharmony_ci *
8591cb0ef41Sopenharmony_ci * <li>When the reordering mode is set to
8601cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the Logical to Visual
8611cb0ef41Sopenharmony_ci * Bidi algorithm used in Windows XP is used as an approximation of an "inverse Bidi" algorithm.
8621cb0ef41Sopenharmony_ci * <br>
8631cb0ef41Sopenharmony_ci * For example, an LTR paragraph with the content "abc FED123" (where
8641cb0ef41Sopenharmony_ci * upper case represents RTL characters) will be transformed to "abc 123DEF."</li>
8651cb0ef41Sopenharmony_ci * </ul>
8661cb0ef41Sopenharmony_ci *
8671cb0ef41Sopenharmony_ci * <p>In all the reordering modes specifying an "inverse Bidi" algorithm
8681cb0ef41Sopenharmony_ci * (i.e. those with a name starting with <code>UBIDI_REORDER_INVERSE</code>),
8691cb0ef41Sopenharmony_ci * output runs should be retrieved using
8701cb0ef41Sopenharmony_ci * <code>ubidi_getVisualRun()</code>, and the output text with
8711cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered()</code>. The caller should keep in mind that in
8721cb0ef41Sopenharmony_ci * "inverse Bidi" modes the input is actually visually ordered text and
8731cb0ef41Sopenharmony_ci * reordered output returned by <code>ubidi_getVisualRun()</code> or
8741cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered()</code> are actually runs or character string
8751cb0ef41Sopenharmony_ci * of logically ordered output.<br>
8761cb0ef41Sopenharmony_ci * For all the "inverse Bidi" modes, the source text should not contain
8771cb0ef41Sopenharmony_ci * Bidi control characters other than LRM or RLM.</p>
8781cb0ef41Sopenharmony_ci *
8791cb0ef41Sopenharmony_ci * <p>Note that option <code>#UBIDI_OUTPUT_REVERSE</code> of
8801cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered</code> has no useful meaning and should not be
8811cb0ef41Sopenharmony_ci * used in conjunction with any value of the reordering mode specifying
8821cb0ef41Sopenharmony_ci * "inverse Bidi" or with value <code>UBIDI_REORDER_RUNS_ONLY</code>.
8831cb0ef41Sopenharmony_ci *
8841cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
8851cb0ef41Sopenharmony_ci * @param reorderingMode specifies the required variant of the Bidi algorithm.
8861cb0ef41Sopenharmony_ci *
8871cb0ef41Sopenharmony_ci * @see UBiDiReorderingMode
8881cb0ef41Sopenharmony_ci * @see ubidi_setInverse
8891cb0ef41Sopenharmony_ci * @see ubidi_setPara
8901cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
8911cb0ef41Sopenharmony_ci * @stable ICU 3.6
8921cb0ef41Sopenharmony_ci */
8931cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
8941cb0ef41Sopenharmony_ciubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);
8951cb0ef41Sopenharmony_ci
8961cb0ef41Sopenharmony_ci/**
8971cb0ef41Sopenharmony_ci * What is the requested reordering mode for a given Bidi object?
8981cb0ef41Sopenharmony_ci *
8991cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
9001cb0ef41Sopenharmony_ci * @return the current reordering mode of the Bidi object
9011cb0ef41Sopenharmony_ci * @see ubidi_setReorderingMode
9021cb0ef41Sopenharmony_ci * @stable ICU 3.6
9031cb0ef41Sopenharmony_ci */
9041cb0ef41Sopenharmony_ciU_CAPI UBiDiReorderingMode U_EXPORT2
9051cb0ef41Sopenharmony_ciubidi_getReorderingMode(UBiDi *pBiDi);
9061cb0ef41Sopenharmony_ci
9071cb0ef41Sopenharmony_ci/**
9081cb0ef41Sopenharmony_ci * <code>UBiDiReorderingOption</code> values indicate which options are
9091cb0ef41Sopenharmony_ci * specified to affect the Bidi algorithm.
9101cb0ef41Sopenharmony_ci *
9111cb0ef41Sopenharmony_ci * @see ubidi_setReorderingOptions
9121cb0ef41Sopenharmony_ci * @stable ICU 3.6
9131cb0ef41Sopenharmony_ci */
9141cb0ef41Sopenharmony_citypedef enum UBiDiReorderingOption {
9151cb0ef41Sopenharmony_ci    /**
9161cb0ef41Sopenharmony_ci     * option value for <code>ubidi_setReorderingOptions</code>:
9171cb0ef41Sopenharmony_ci     * disable all the options which can be set with this function
9181cb0ef41Sopenharmony_ci     * @see ubidi_setReorderingOptions
9191cb0ef41Sopenharmony_ci     * @stable ICU 3.6
9201cb0ef41Sopenharmony_ci     */
9211cb0ef41Sopenharmony_ci    UBIDI_OPTION_DEFAULT = 0,
9221cb0ef41Sopenharmony_ci
9231cb0ef41Sopenharmony_ci    /**
9241cb0ef41Sopenharmony_ci     * option bit for <code>ubidi_setReorderingOptions</code>:
9251cb0ef41Sopenharmony_ci     * insert Bidi marks (LRM or RLM) when needed to ensure correct result of
9261cb0ef41Sopenharmony_ci     * a reordering to a Logical order
9271cb0ef41Sopenharmony_ci     *
9281cb0ef41Sopenharmony_ci     * <p>This option must be set or reset before calling
9291cb0ef41Sopenharmony_ci     * <code>ubidi_setPara</code>.</p>
9301cb0ef41Sopenharmony_ci     *
9311cb0ef41Sopenharmony_ci     * <p>This option is significant only with reordering modes which generate
9321cb0ef41Sopenharmony_ci     * a result with Logical order, specifically:</p>
9331cb0ef41Sopenharmony_ci     * <ul>
9341cb0ef41Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_RUNS_ONLY</code></li>
9351cb0ef41Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code></li>
9361cb0ef41Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code></li>
9371cb0ef41Sopenharmony_ci     *   <li><code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code></li>
9381cb0ef41Sopenharmony_ci     * </ul>
9391cb0ef41Sopenharmony_ci     *
9401cb0ef41Sopenharmony_ci     * <p>If this option is set in conjunction with reordering mode
9411cb0ef41Sopenharmony_ci     * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> or with calling
9421cb0ef41Sopenharmony_ci     * <code>ubidi_setInverse(true)</code>, it implies
9431cb0ef41Sopenharmony_ci     * option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>
9441cb0ef41Sopenharmony_ci     * in calls to function <code>ubidi_writeReordered()</code>.</p>
9451cb0ef41Sopenharmony_ci     *
9461cb0ef41Sopenharmony_ci     * <p>For other reordering modes, a minimum number of LRM or RLM characters
9471cb0ef41Sopenharmony_ci     * will be added to the source text after reordering it so as to ensure
9481cb0ef41Sopenharmony_ci     * round trip, i.e. when applying the inverse reordering mode on the
9491cb0ef41Sopenharmony_ci     * resulting logical text with removal of Bidi marks
9501cb0ef41Sopenharmony_ci     * (option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> set before calling
9511cb0ef41Sopenharmony_ci     * <code>ubidi_setPara()</code> or option <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
9521cb0ef41Sopenharmony_ci     * in <code>ubidi_writeReordered</code>), the result will be identical to the
9531cb0ef41Sopenharmony_ci     * source text in the first transformation.
9541cb0ef41Sopenharmony_ci     *
9551cb0ef41Sopenharmony_ci     * <p>This option will be ignored if specified together with option
9561cb0ef41Sopenharmony_ci     * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>. It inhibits option
9571cb0ef41Sopenharmony_ci     * <code>UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to function
9581cb0ef41Sopenharmony_ci     * <code>ubidi_writeReordered()</code> and it implies option
9591cb0ef41Sopenharmony_ci     * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to function
9601cb0ef41Sopenharmony_ci     * <code>ubidi_writeReordered()</code> if the reordering mode is
9611cb0ef41Sopenharmony_ci     * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.</p>
9621cb0ef41Sopenharmony_ci     *
9631cb0ef41Sopenharmony_ci     * @see ubidi_setReorderingMode
9641cb0ef41Sopenharmony_ci     * @see ubidi_setReorderingOptions
9651cb0ef41Sopenharmony_ci     * @stable ICU 3.6
9661cb0ef41Sopenharmony_ci     */
9671cb0ef41Sopenharmony_ci    UBIDI_OPTION_INSERT_MARKS = 1,
9681cb0ef41Sopenharmony_ci
9691cb0ef41Sopenharmony_ci    /**
9701cb0ef41Sopenharmony_ci     * option bit for <code>ubidi_setReorderingOptions</code>:
9711cb0ef41Sopenharmony_ci     * remove Bidi control characters
9721cb0ef41Sopenharmony_ci     *
9731cb0ef41Sopenharmony_ci     * <p>This option must be set or reset before calling
9741cb0ef41Sopenharmony_ci     * <code>ubidi_setPara</code>.</p>
9751cb0ef41Sopenharmony_ci     *
9761cb0ef41Sopenharmony_ci     * <p>This option nullifies option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
9771cb0ef41Sopenharmony_ci     * It inhibits option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls
9781cb0ef41Sopenharmony_ci     * to function <code>ubidi_writeReordered()</code> and it implies option
9791cb0ef41Sopenharmony_ci     * <code>#UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to that function.</p>
9801cb0ef41Sopenharmony_ci     *
9811cb0ef41Sopenharmony_ci     * @see ubidi_setReorderingMode
9821cb0ef41Sopenharmony_ci     * @see ubidi_setReorderingOptions
9831cb0ef41Sopenharmony_ci     * @stable ICU 3.6
9841cb0ef41Sopenharmony_ci     */
9851cb0ef41Sopenharmony_ci    UBIDI_OPTION_REMOVE_CONTROLS = 2,
9861cb0ef41Sopenharmony_ci
9871cb0ef41Sopenharmony_ci    /**
9881cb0ef41Sopenharmony_ci     * option bit for <code>ubidi_setReorderingOptions</code>:
9891cb0ef41Sopenharmony_ci     * process the output as part of a stream to be continued
9901cb0ef41Sopenharmony_ci     *
9911cb0ef41Sopenharmony_ci     * <p>This option must be set or reset before calling
9921cb0ef41Sopenharmony_ci     * <code>ubidi_setPara</code>.</p>
9931cb0ef41Sopenharmony_ci     *
9941cb0ef41Sopenharmony_ci     * <p>This option specifies that the caller is interested in processing large
9951cb0ef41Sopenharmony_ci     * text object in parts.
9961cb0ef41Sopenharmony_ci     * The results of the successive calls are expected to be concatenated by the
9971cb0ef41Sopenharmony_ci     * caller. Only the call for the last part will have this option bit off.</p>
9981cb0ef41Sopenharmony_ci     *
9991cb0ef41Sopenharmony_ci     * <p>When this option bit is on, <code>ubidi_setPara()</code> may process
10001cb0ef41Sopenharmony_ci     * less than the full source text in order to truncate the text at a meaningful
10011cb0ef41Sopenharmony_ci     * boundary. The caller should call <code>ubidi_getProcessedLength()</code>
10021cb0ef41Sopenharmony_ci     * immediately after calling <code>ubidi_setPara()</code> in order to
10031cb0ef41Sopenharmony_ci     * determine how much of the source text has been processed.
10041cb0ef41Sopenharmony_ci     * Source text beyond that length should be resubmitted in following calls to
10051cb0ef41Sopenharmony_ci     * <code>ubidi_setPara</code>. The processed length may be less than
10061cb0ef41Sopenharmony_ci     * the length of the source text if a character preceding the last character of
10071cb0ef41Sopenharmony_ci     * the source text constitutes a reasonable boundary (like a block separator)
10081cb0ef41Sopenharmony_ci     * for text to be continued.<br>
10091cb0ef41Sopenharmony_ci     * If the last character of the source text constitutes a reasonable
10101cb0ef41Sopenharmony_ci     * boundary, the whole text will be processed at once.<br>
10111cb0ef41Sopenharmony_ci     * If nowhere in the source text there exists
10121cb0ef41Sopenharmony_ci     * such a reasonable boundary, the processed length will be zero.<br>
10131cb0ef41Sopenharmony_ci     * The caller should check for such an occurrence and do one of the following:
10141cb0ef41Sopenharmony_ci     * <ul><li>submit a larger amount of text with a better chance to include
10151cb0ef41Sopenharmony_ci     *         a reasonable boundary.</li>
10161cb0ef41Sopenharmony_ci     *     <li>resubmit the same text after turning off option
10171cb0ef41Sopenharmony_ci     *         <code>UBIDI_OPTION_STREAMING</code>.</li></ul>
10181cb0ef41Sopenharmony_ci     * In all cases, this option should be turned off before processing the last
10191cb0ef41Sopenharmony_ci     * part of the text.</p>
10201cb0ef41Sopenharmony_ci     *
10211cb0ef41Sopenharmony_ci     * <p>When the <code>UBIDI_OPTION_STREAMING</code> option is used,
10221cb0ef41Sopenharmony_ci     * it is recommended to call <code>ubidi_orderParagraphsLTR()</code> with
10231cb0ef41Sopenharmony_ci     * argument <code>orderParagraphsLTR</code> set to <code>true</code> before
10241cb0ef41Sopenharmony_ci     * calling <code>ubidi_setPara</code> so that later paragraphs may be
10251cb0ef41Sopenharmony_ci     * concatenated to previous paragraphs on the right.</p>
10261cb0ef41Sopenharmony_ci     *
10271cb0ef41Sopenharmony_ci     * @see ubidi_setReorderingMode
10281cb0ef41Sopenharmony_ci     * @see ubidi_setReorderingOptions
10291cb0ef41Sopenharmony_ci     * @see ubidi_getProcessedLength
10301cb0ef41Sopenharmony_ci     * @see ubidi_orderParagraphsLTR
10311cb0ef41Sopenharmony_ci     * @stable ICU 3.6
10321cb0ef41Sopenharmony_ci     */
10331cb0ef41Sopenharmony_ci    UBIDI_OPTION_STREAMING = 4
10341cb0ef41Sopenharmony_ci} UBiDiReorderingOption;
10351cb0ef41Sopenharmony_ci
10361cb0ef41Sopenharmony_ci/**
10371cb0ef41Sopenharmony_ci * Specify which of the reordering options
10381cb0ef41Sopenharmony_ci * should be applied during Bidi transformations.
10391cb0ef41Sopenharmony_ci *
10401cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
10411cb0ef41Sopenharmony_ci * @param reorderingOptions is a combination of zero or more of the following
10421cb0ef41Sopenharmony_ci * options:
10431cb0ef41Sopenharmony_ci * <code>#UBIDI_OPTION_DEFAULT</code>, <code>#UBIDI_OPTION_INSERT_MARKS</code>,
10441cb0ef41Sopenharmony_ci * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>, <code>#UBIDI_OPTION_STREAMING</code>.
10451cb0ef41Sopenharmony_ci *
10461cb0ef41Sopenharmony_ci * @see ubidi_getReorderingOptions
10471cb0ef41Sopenharmony_ci * @stable ICU 3.6
10481cb0ef41Sopenharmony_ci */
10491cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
10501cb0ef41Sopenharmony_ciubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);
10511cb0ef41Sopenharmony_ci
10521cb0ef41Sopenharmony_ci/**
10531cb0ef41Sopenharmony_ci * What are the reordering options applied to a given Bidi object?
10541cb0ef41Sopenharmony_ci *
10551cb0ef41Sopenharmony_ci * @param pBiDi is a <code>UBiDi</code> object.
10561cb0ef41Sopenharmony_ci * @return the current reordering options of the Bidi object
10571cb0ef41Sopenharmony_ci * @see ubidi_setReorderingOptions
10581cb0ef41Sopenharmony_ci * @stable ICU 3.6
10591cb0ef41Sopenharmony_ci */
10601cb0ef41Sopenharmony_ciU_CAPI uint32_t U_EXPORT2
10611cb0ef41Sopenharmony_ciubidi_getReorderingOptions(UBiDi *pBiDi);
10621cb0ef41Sopenharmony_ci
10631cb0ef41Sopenharmony_ci/**
10641cb0ef41Sopenharmony_ci * Set the context before a call to ubidi_setPara().<p>
10651cb0ef41Sopenharmony_ci *
10661cb0ef41Sopenharmony_ci * ubidi_setPara() computes the left-right directionality for a given piece
10671cb0ef41Sopenharmony_ci * of text which is supplied as one of its arguments. Sometimes this piece
10681cb0ef41Sopenharmony_ci * of text (the "main text") should be considered in context, because text
10691cb0ef41Sopenharmony_ci * appearing before ("prologue") and/or after ("epilogue") the main text
10701cb0ef41Sopenharmony_ci * may affect the result of this computation.<p>
10711cb0ef41Sopenharmony_ci *
10721cb0ef41Sopenharmony_ci * This function specifies the prologue and/or the epilogue for the next
10731cb0ef41Sopenharmony_ci * call to ubidi_setPara(). The characters specified as prologue and
10741cb0ef41Sopenharmony_ci * epilogue should not be modified by the calling program until the call
10751cb0ef41Sopenharmony_ci * to ubidi_setPara() has returned. If successive calls to ubidi_setPara()
10761cb0ef41Sopenharmony_ci * all need specification of a context, ubidi_setContext() must be called
10771cb0ef41Sopenharmony_ci * before each call to ubidi_setPara(). In other words, a context is not
10781cb0ef41Sopenharmony_ci * "remembered" after the following successful call to ubidi_setPara().<p>
10791cb0ef41Sopenharmony_ci *
10801cb0ef41Sopenharmony_ci * If a call to ubidi_setPara() specifies UBIDI_DEFAULT_LTR or
10811cb0ef41Sopenharmony_ci * UBIDI_DEFAULT_RTL as paraLevel and is preceded by a call to
10821cb0ef41Sopenharmony_ci * ubidi_setContext() which specifies a prologue, the paragraph level will
10831cb0ef41Sopenharmony_ci * be computed taking in consideration the text in the prologue.<p>
10841cb0ef41Sopenharmony_ci *
10851cb0ef41Sopenharmony_ci * When ubidi_setPara() is called without a previous call to
10861cb0ef41Sopenharmony_ci * ubidi_setContext, the main text is handled as if preceded and followed
10871cb0ef41Sopenharmony_ci * by strong directional characters at the current paragraph level.
10881cb0ef41Sopenharmony_ci * Calling ubidi_setContext() with specification of a prologue will change
10891cb0ef41Sopenharmony_ci * this behavior by handling the main text as if preceded by the last
10901cb0ef41Sopenharmony_ci * strong character appearing in the prologue, if any.
10911cb0ef41Sopenharmony_ci * Calling ubidi_setContext() with specification of an epilogue will change
10921cb0ef41Sopenharmony_ci * the behavior of ubidi_setPara() by handling the main text as if followed
10931cb0ef41Sopenharmony_ci * by the first strong character or digit appearing in the epilogue, if any.<p>
10941cb0ef41Sopenharmony_ci *
10951cb0ef41Sopenharmony_ci * Note 1: if <code>ubidi_setContext</code> is called repeatedly without
10961cb0ef41Sopenharmony_ci *         calling <code>ubidi_setPara</code>, the earlier calls have no effect,
10971cb0ef41Sopenharmony_ci *         only the last call will be remembered for the next call to
10981cb0ef41Sopenharmony_ci *         <code>ubidi_setPara</code>.<p>
10991cb0ef41Sopenharmony_ci *
11001cb0ef41Sopenharmony_ci * Note 2: calling <code>ubidi_setContext(pBiDi, NULL, 0, NULL, 0, &errorCode)</code>
11011cb0ef41Sopenharmony_ci *         cancels any previous setting of non-empty prologue or epilogue.
11021cb0ef41Sopenharmony_ci *         The next call to <code>ubidi_setPara()</code> will process no
11031cb0ef41Sopenharmony_ci *         prologue or epilogue.<p>
11041cb0ef41Sopenharmony_ci *
11051cb0ef41Sopenharmony_ci * Note 3: users must be aware that even after setting the context
11061cb0ef41Sopenharmony_ci *         before a call to ubidi_setPara() to perform e.g. a logical to visual
11071cb0ef41Sopenharmony_ci *         transformation, the resulting string may not be identical to what it
11081cb0ef41Sopenharmony_ci *         would have been if all the text, including prologue and epilogue, had
11091cb0ef41Sopenharmony_ci *         been processed together.<br>
11101cb0ef41Sopenharmony_ci * Example (upper case letters represent RTL characters):<br>
11111cb0ef41Sopenharmony_ci * &nbsp;&nbsp;prologue = "<code>abc DE</code>"<br>
11121cb0ef41Sopenharmony_ci * &nbsp;&nbsp;epilogue = none<br>
11131cb0ef41Sopenharmony_ci * &nbsp;&nbsp;main text = "<code>FGH xyz</code>"<br>
11141cb0ef41Sopenharmony_ci * &nbsp;&nbsp;paraLevel = UBIDI_LTR<br>
11151cb0ef41Sopenharmony_ci * &nbsp;&nbsp;display without prologue = "<code>HGF xyz</code>"
11161cb0ef41Sopenharmony_ci *             ("HGF" is adjacent to "xyz")<br>
11171cb0ef41Sopenharmony_ci * &nbsp;&nbsp;display with prologue = "<code>abc HGFED xyz</code>"
11181cb0ef41Sopenharmony_ci *             ("HGF" is not adjacent to "xyz")<br>
11191cb0ef41Sopenharmony_ci *
11201cb0ef41Sopenharmony_ci * @param pBiDi is a paragraph <code>UBiDi</code> object.
11211cb0ef41Sopenharmony_ci *
11221cb0ef41Sopenharmony_ci * @param prologue is a pointer to the text which precedes the text that
11231cb0ef41Sopenharmony_ci *        will be specified in a coming call to ubidi_setPara().
11241cb0ef41Sopenharmony_ci *        If there is no prologue to consider, then <code>proLength</code>
11251cb0ef41Sopenharmony_ci *        must be zero and this pointer can be NULL.
11261cb0ef41Sopenharmony_ci *
11271cb0ef41Sopenharmony_ci * @param proLength is the length of the prologue; if <code>proLength==-1</code>
11281cb0ef41Sopenharmony_ci *        then the prologue must be zero-terminated.
11291cb0ef41Sopenharmony_ci *        Otherwise proLength must be >= 0. If <code>proLength==0</code>, it means
11301cb0ef41Sopenharmony_ci *        that there is no prologue to consider.
11311cb0ef41Sopenharmony_ci *
11321cb0ef41Sopenharmony_ci * @param epilogue is a pointer to the text which follows the text that
11331cb0ef41Sopenharmony_ci *        will be specified in a coming call to ubidi_setPara().
11341cb0ef41Sopenharmony_ci *        If there is no epilogue to consider, then <code>epiLength</code>
11351cb0ef41Sopenharmony_ci *        must be zero and this pointer can be NULL.
11361cb0ef41Sopenharmony_ci *
11371cb0ef41Sopenharmony_ci * @param epiLength is the length of the epilogue; if <code>epiLength==-1</code>
11381cb0ef41Sopenharmony_ci *        then the epilogue must be zero-terminated.
11391cb0ef41Sopenharmony_ci *        Otherwise epiLength must be >= 0. If <code>epiLength==0</code>, it means
11401cb0ef41Sopenharmony_ci *        that there is no epilogue to consider.
11411cb0ef41Sopenharmony_ci *
11421cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
11431cb0ef41Sopenharmony_ci *
11441cb0ef41Sopenharmony_ci * @see ubidi_setPara
11451cb0ef41Sopenharmony_ci * @stable ICU 4.8
11461cb0ef41Sopenharmony_ci */
11471cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
11481cb0ef41Sopenharmony_ciubidi_setContext(UBiDi *pBiDi,
11491cb0ef41Sopenharmony_ci                 const UChar *prologue, int32_t proLength,
11501cb0ef41Sopenharmony_ci                 const UChar *epilogue, int32_t epiLength,
11511cb0ef41Sopenharmony_ci                 UErrorCode *pErrorCode);
11521cb0ef41Sopenharmony_ci
11531cb0ef41Sopenharmony_ci/**
11541cb0ef41Sopenharmony_ci * Perform the Unicode Bidi algorithm. It is defined in the
11551cb0ef41Sopenharmony_ci * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
11561cb0ef41Sopenharmony_ci * version 13,
11571cb0ef41Sopenharmony_ci * also described in The Unicode Standard, Version 4.0 .<p>
11581cb0ef41Sopenharmony_ci *
11591cb0ef41Sopenharmony_ci * This function takes a piece of plain text containing one or more paragraphs,
11601cb0ef41Sopenharmony_ci * with or without externally specified embedding levels from <i>styled</i>
11611cb0ef41Sopenharmony_ci * text and computes the left-right-directionality of each character.<p>
11621cb0ef41Sopenharmony_ci *
11631cb0ef41Sopenharmony_ci * If the entire text is all of the same directionality, then
11641cb0ef41Sopenharmony_ci * the function may not perform all the steps described by the algorithm,
11651cb0ef41Sopenharmony_ci * i.e., some levels may not be the same as if all steps were performed.
11661cb0ef41Sopenharmony_ci * This is not relevant for unidirectional text.<br>
11671cb0ef41Sopenharmony_ci * For example, in pure LTR text with numbers the numbers would get
11681cb0ef41Sopenharmony_ci * a resolved level of 2 higher than the surrounding text according to
11691cb0ef41Sopenharmony_ci * the algorithm. This implementation may set all resolved levels to
11701cb0ef41Sopenharmony_ci * the same value in such a case.<p>
11711cb0ef41Sopenharmony_ci *
11721cb0ef41Sopenharmony_ci * The text can be composed of multiple paragraphs. Occurrence of a block
11731cb0ef41Sopenharmony_ci * separator in the text terminates a paragraph, and whatever comes next starts
11741cb0ef41Sopenharmony_ci * a new paragraph. The exception to this rule is when a Carriage Return (CR)
11751cb0ef41Sopenharmony_ci * is followed by a Line Feed (LF). Both CR and LF are block separators, but
11761cb0ef41Sopenharmony_ci * in that case, the pair of characters is considered as terminating the
11771cb0ef41Sopenharmony_ci * preceding paragraph, and a new paragraph will be started by a character
11781cb0ef41Sopenharmony_ci * coming after the LF.
11791cb0ef41Sopenharmony_ci *
11801cb0ef41Sopenharmony_ci * @param pBiDi A <code>UBiDi</code> object allocated with <code>ubidi_open()</code>
11811cb0ef41Sopenharmony_ci *        which will be set to contain the reordering information,
11821cb0ef41Sopenharmony_ci *        especially the resolved levels for all the characters in <code>text</code>.
11831cb0ef41Sopenharmony_ci *
11841cb0ef41Sopenharmony_ci * @param text is a pointer to the text that the Bidi algorithm will be performed on.
11851cb0ef41Sopenharmony_ci *        This pointer is stored in the UBiDi object and can be retrieved
11861cb0ef41Sopenharmony_ci *        with <code>ubidi_getText()</code>.<br>
11871cb0ef41Sopenharmony_ci *        <strong>Note:</strong> the text must be (at least) <code>length</code> long.
11881cb0ef41Sopenharmony_ci *
11891cb0ef41Sopenharmony_ci * @param length is the length of the text; if <code>length==-1</code> then
11901cb0ef41Sopenharmony_ci *        the text must be zero-terminated.
11911cb0ef41Sopenharmony_ci *
11921cb0ef41Sopenharmony_ci * @param paraLevel specifies the default level for the text;
11931cb0ef41Sopenharmony_ci *        it is typically 0 (LTR) or 1 (RTL).
11941cb0ef41Sopenharmony_ci *        If the function shall determine the paragraph level from the text,
11951cb0ef41Sopenharmony_ci *        then <code>paraLevel</code> can be set to
11961cb0ef41Sopenharmony_ci *        either <code>#UBIDI_DEFAULT_LTR</code>
11971cb0ef41Sopenharmony_ci *        or <code>#UBIDI_DEFAULT_RTL</code>; if the text contains multiple
11981cb0ef41Sopenharmony_ci *        paragraphs, the paragraph level shall be determined separately for
11991cb0ef41Sopenharmony_ci *        each paragraph; if a paragraph does not include any strongly typed
12001cb0ef41Sopenharmony_ci *        character, then the desired default is used (0 for LTR or 1 for RTL).
12011cb0ef41Sopenharmony_ci *        Any other value between 0 and <code>#UBIDI_MAX_EXPLICIT_LEVEL</code>
12021cb0ef41Sopenharmony_ci *        is also valid, with odd levels indicating RTL.
12031cb0ef41Sopenharmony_ci *
12041cb0ef41Sopenharmony_ci * @param embeddingLevels (in) may be used to preset the embedding and override levels,
12051cb0ef41Sopenharmony_ci *        ignoring characters like LRE and PDF in the text.
12061cb0ef41Sopenharmony_ci *        A level overrides the directional property of its corresponding
12071cb0ef41Sopenharmony_ci *        (same index) character if the level has the
12081cb0ef41Sopenharmony_ci *        <code>#UBIDI_LEVEL_OVERRIDE</code> bit set.<br><br>
12091cb0ef41Sopenharmony_ci *        Aside from that bit, it must be
12101cb0ef41Sopenharmony_ci *        <code>paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL</code>,
12111cb0ef41Sopenharmony_ci *        except that level 0 is always allowed.
12121cb0ef41Sopenharmony_ci *        Level 0 for a paragraph separator prevents reordering of paragraphs;
12131cb0ef41Sopenharmony_ci *        this only works reliably if <code>#UBIDI_LEVEL_OVERRIDE</code>
12141cb0ef41Sopenharmony_ci *        is also set for paragraph separators.
12151cb0ef41Sopenharmony_ci *        Level 0 for other characters is treated as a wildcard
12161cb0ef41Sopenharmony_ci *        and is lifted up to the resolved level of the surrounding paragraph.<br><br>
12171cb0ef41Sopenharmony_ci *        <strong>Caution: </strong>A copy of this pointer, not of the levels,
12181cb0ef41Sopenharmony_ci *        will be stored in the <code>UBiDi</code> object;
12191cb0ef41Sopenharmony_ci *        the <code>embeddingLevels</code> array must not be
12201cb0ef41Sopenharmony_ci *        deallocated before the <code>UBiDi</code> structure is destroyed or reused,
12211cb0ef41Sopenharmony_ci *        and the <code>embeddingLevels</code>
12221cb0ef41Sopenharmony_ci *        should not be modified to avoid unexpected results on subsequent Bidi operations.
12231cb0ef41Sopenharmony_ci *        However, the <code>ubidi_setPara()</code> and
12241cb0ef41Sopenharmony_ci *        <code>ubidi_setLine()</code> functions may modify some or all of the levels.<br><br>
12251cb0ef41Sopenharmony_ci *        After the <code>UBiDi</code> object is reused or destroyed, the caller
12261cb0ef41Sopenharmony_ci *        must take care of the deallocation of the <code>embeddingLevels</code> array.<br><br>
12271cb0ef41Sopenharmony_ci *        <strong>Note:</strong> the <code>embeddingLevels</code> array must be
12281cb0ef41Sopenharmony_ci *        at least <code>length</code> long.
12291cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
12301cb0ef41Sopenharmony_ci *        value is not necessary.
12311cb0ef41Sopenharmony_ci *
12321cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
12331cb0ef41Sopenharmony_ci * @stable ICU 2.0
12341cb0ef41Sopenharmony_ci */
12351cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
12361cb0ef41Sopenharmony_ciubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
12371cb0ef41Sopenharmony_ci              UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
12381cb0ef41Sopenharmony_ci              UErrorCode *pErrorCode);
12391cb0ef41Sopenharmony_ci
12401cb0ef41Sopenharmony_ci/**
12411cb0ef41Sopenharmony_ci * <code>ubidi_setLine()</code> sets a <code>UBiDi</code> to
12421cb0ef41Sopenharmony_ci * contain the reordering information, especially the resolved levels,
12431cb0ef41Sopenharmony_ci * for all the characters in a line of text. This line of text is
12441cb0ef41Sopenharmony_ci * specified by referring to a <code>UBiDi</code> object representing
12451cb0ef41Sopenharmony_ci * this information for a piece of text containing one or more paragraphs,
12461cb0ef41Sopenharmony_ci * and by specifying a range of indexes in this text.<p>
12471cb0ef41Sopenharmony_ci * In the new line object, the indexes will range from 0 to <code>limit-start-1</code>.<p>
12481cb0ef41Sopenharmony_ci *
12491cb0ef41Sopenharmony_ci * This is used after calling <code>ubidi_setPara()</code>
12501cb0ef41Sopenharmony_ci * for a piece of text, and after line-breaking on that text.
12511cb0ef41Sopenharmony_ci * It is not necessary if each paragraph is treated as a single line.<p>
12521cb0ef41Sopenharmony_ci *
12531cb0ef41Sopenharmony_ci * After line-breaking, rules (L1) and (L2) for the treatment of
12541cb0ef41Sopenharmony_ci * trailing WS and for reordering are performed on
12551cb0ef41Sopenharmony_ci * a <code>UBiDi</code> object that represents a line.<p>
12561cb0ef41Sopenharmony_ci *
12571cb0ef41Sopenharmony_ci * <strong>Important: </strong><code>pLineBiDi</code> shares data with
12581cb0ef41Sopenharmony_ci * <code>pParaBiDi</code>.
12591cb0ef41Sopenharmony_ci * You must destroy or reuse <code>pLineBiDi</code> before <code>pParaBiDi</code>.
12601cb0ef41Sopenharmony_ci * In other words, you must destroy or reuse the <code>UBiDi</code> object for a line
12611cb0ef41Sopenharmony_ci * before the object for its parent paragraph.<p>
12621cb0ef41Sopenharmony_ci *
12631cb0ef41Sopenharmony_ci * The text pointer that was stored in <code>pParaBiDi</code> is also copied,
12641cb0ef41Sopenharmony_ci * and <code>start</code> is added to it so that it points to the beginning of the
12651cb0ef41Sopenharmony_ci * line for this object.
12661cb0ef41Sopenharmony_ci *
12671cb0ef41Sopenharmony_ci * @param pParaBiDi is the parent paragraph object. It must have been set
12681cb0ef41Sopenharmony_ci * by a successful call to ubidi_setPara.
12691cb0ef41Sopenharmony_ci *
12701cb0ef41Sopenharmony_ci * @param start is the line's first index into the text.
12711cb0ef41Sopenharmony_ci *
12721cb0ef41Sopenharmony_ci * @param limit is just behind the line's last index into the text
12731cb0ef41Sopenharmony_ci *        (its last index +1).<br>
12741cb0ef41Sopenharmony_ci *        It must be <code>0<=start<limit<=</code>containing paragraph limit.
12751cb0ef41Sopenharmony_ci *        If the specified line crosses a paragraph boundary, the function
12761cb0ef41Sopenharmony_ci *        will terminate with error code U_ILLEGAL_ARGUMENT_ERROR.
12771cb0ef41Sopenharmony_ci *
12781cb0ef41Sopenharmony_ci * @param pLineBiDi is the object that will now represent a line of the text.
12791cb0ef41Sopenharmony_ci *
12801cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
12811cb0ef41Sopenharmony_ci *
12821cb0ef41Sopenharmony_ci * @see ubidi_setPara
12831cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
12841cb0ef41Sopenharmony_ci * @stable ICU 2.0
12851cb0ef41Sopenharmony_ci */
12861cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
12871cb0ef41Sopenharmony_ciubidi_setLine(const UBiDi *pParaBiDi,
12881cb0ef41Sopenharmony_ci              int32_t start, int32_t limit,
12891cb0ef41Sopenharmony_ci              UBiDi *pLineBiDi,
12901cb0ef41Sopenharmony_ci              UErrorCode *pErrorCode);
12911cb0ef41Sopenharmony_ci
12921cb0ef41Sopenharmony_ci/**
12931cb0ef41Sopenharmony_ci * Get the directionality of the text.
12941cb0ef41Sopenharmony_ci *
12951cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
12961cb0ef41Sopenharmony_ci *
12971cb0ef41Sopenharmony_ci * @return a value of <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>
12981cb0ef41Sopenharmony_ci *         or <code>UBIDI_MIXED</code>
12991cb0ef41Sopenharmony_ci *         that indicates if the entire text
13001cb0ef41Sopenharmony_ci *         represented by this object is unidirectional,
13011cb0ef41Sopenharmony_ci *         and which direction, or if it is mixed-directional.
13021cb0ef41Sopenharmony_ci * Note -  The value <code>UBIDI_NEUTRAL</code> is never returned from this method.
13031cb0ef41Sopenharmony_ci *
13041cb0ef41Sopenharmony_ci * @see UBiDiDirection
13051cb0ef41Sopenharmony_ci * @stable ICU 2.0
13061cb0ef41Sopenharmony_ci */
13071cb0ef41Sopenharmony_ciU_CAPI UBiDiDirection U_EXPORT2
13081cb0ef41Sopenharmony_ciubidi_getDirection(const UBiDi *pBiDi);
13091cb0ef41Sopenharmony_ci
13101cb0ef41Sopenharmony_ci/**
13111cb0ef41Sopenharmony_ci * Gets the base direction of the text provided according
13121cb0ef41Sopenharmony_ci * to the Unicode Bidirectional Algorithm. The base direction
13131cb0ef41Sopenharmony_ci * is derived from the first character in the string with bidirectional
13141cb0ef41Sopenharmony_ci * character type L, R, or AL. If the first such character has type L,
13151cb0ef41Sopenharmony_ci * <code>UBIDI_LTR</code> is returned. If the first such character has
13161cb0ef41Sopenharmony_ci * type R or AL, <code>UBIDI_RTL</code> is returned. If the string does
13171cb0ef41Sopenharmony_ci * not contain any character of these types, then
13181cb0ef41Sopenharmony_ci * <code>UBIDI_NEUTRAL</code> is returned.
13191cb0ef41Sopenharmony_ci *
13201cb0ef41Sopenharmony_ci * This is a lightweight function for use when only the base direction
13211cb0ef41Sopenharmony_ci * is needed and no further bidi processing of the text is needed.
13221cb0ef41Sopenharmony_ci *
13231cb0ef41Sopenharmony_ci * @param text is a pointer to the text whose base
13241cb0ef41Sopenharmony_ci *             direction is needed.
13251cb0ef41Sopenharmony_ci * Note: the text must be (at least) @c length long.
13261cb0ef41Sopenharmony_ci *
13271cb0ef41Sopenharmony_ci * @param length is the length of the text;
13281cb0ef41Sopenharmony_ci *               if <code>length==-1</code> then the text
13291cb0ef41Sopenharmony_ci *               must be zero-terminated.
13301cb0ef41Sopenharmony_ci *
13311cb0ef41Sopenharmony_ci * @return  <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>,
13321cb0ef41Sopenharmony_ci *          <code>UBIDI_NEUTRAL</code>
13331cb0ef41Sopenharmony_ci *
13341cb0ef41Sopenharmony_ci * @see UBiDiDirection
13351cb0ef41Sopenharmony_ci * @stable ICU 4.6
13361cb0ef41Sopenharmony_ci */
13371cb0ef41Sopenharmony_ciU_CAPI UBiDiDirection U_EXPORT2
13381cb0ef41Sopenharmony_ciubidi_getBaseDirection(const UChar *text,  int32_t length );
13391cb0ef41Sopenharmony_ci
13401cb0ef41Sopenharmony_ci/**
13411cb0ef41Sopenharmony_ci * Get the pointer to the text.
13421cb0ef41Sopenharmony_ci *
13431cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13441cb0ef41Sopenharmony_ci *
13451cb0ef41Sopenharmony_ci * @return The pointer to the text that the UBiDi object was created for.
13461cb0ef41Sopenharmony_ci *
13471cb0ef41Sopenharmony_ci * @see ubidi_setPara
13481cb0ef41Sopenharmony_ci * @see ubidi_setLine
13491cb0ef41Sopenharmony_ci * @stable ICU 2.0
13501cb0ef41Sopenharmony_ci */
13511cb0ef41Sopenharmony_ciU_CAPI const UChar * U_EXPORT2
13521cb0ef41Sopenharmony_ciubidi_getText(const UBiDi *pBiDi);
13531cb0ef41Sopenharmony_ci
13541cb0ef41Sopenharmony_ci/**
13551cb0ef41Sopenharmony_ci * Get the length of the text.
13561cb0ef41Sopenharmony_ci *
13571cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13581cb0ef41Sopenharmony_ci *
13591cb0ef41Sopenharmony_ci * @return The length of the text that the UBiDi object was created for.
13601cb0ef41Sopenharmony_ci * @stable ICU 2.0
13611cb0ef41Sopenharmony_ci */
13621cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
13631cb0ef41Sopenharmony_ciubidi_getLength(const UBiDi *pBiDi);
13641cb0ef41Sopenharmony_ci
13651cb0ef41Sopenharmony_ci/**
13661cb0ef41Sopenharmony_ci * Get the paragraph level of the text.
13671cb0ef41Sopenharmony_ci *
13681cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13691cb0ef41Sopenharmony_ci *
13701cb0ef41Sopenharmony_ci * @return The paragraph level. If there are multiple paragraphs, their
13711cb0ef41Sopenharmony_ci *         level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or
13721cb0ef41Sopenharmony_ci *         UBIDI_DEFAULT_RTL.  In that case, the level of the first paragraph
13731cb0ef41Sopenharmony_ci *         is returned.
13741cb0ef41Sopenharmony_ci *
13751cb0ef41Sopenharmony_ci * @see UBiDiLevel
13761cb0ef41Sopenharmony_ci * @see ubidi_getParagraph
13771cb0ef41Sopenharmony_ci * @see ubidi_getParagraphByIndex
13781cb0ef41Sopenharmony_ci * @stable ICU 2.0
13791cb0ef41Sopenharmony_ci */
13801cb0ef41Sopenharmony_ciU_CAPI UBiDiLevel U_EXPORT2
13811cb0ef41Sopenharmony_ciubidi_getParaLevel(const UBiDi *pBiDi);
13821cb0ef41Sopenharmony_ci
13831cb0ef41Sopenharmony_ci/**
13841cb0ef41Sopenharmony_ci * Get the number of paragraphs.
13851cb0ef41Sopenharmony_ci *
13861cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
13871cb0ef41Sopenharmony_ci *
13881cb0ef41Sopenharmony_ci * @return The number of paragraphs.
13891cb0ef41Sopenharmony_ci * @stable ICU 3.4
13901cb0ef41Sopenharmony_ci */
13911cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
13921cb0ef41Sopenharmony_ciubidi_countParagraphs(UBiDi *pBiDi);
13931cb0ef41Sopenharmony_ci
13941cb0ef41Sopenharmony_ci/**
13951cb0ef41Sopenharmony_ci * Get a paragraph, given a position within the text.
13961cb0ef41Sopenharmony_ci * This function returns information about a paragraph.<br>
13971cb0ef41Sopenharmony_ci * Note: if the paragraph index is known, it is more efficient to
13981cb0ef41Sopenharmony_ci * retrieve the paragraph information using ubidi_getParagraphByIndex().<p>
13991cb0ef41Sopenharmony_ci *
14001cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
14011cb0ef41Sopenharmony_ci *
14021cb0ef41Sopenharmony_ci * @param charIndex is the index of a character within the text, in the
14031cb0ef41Sopenharmony_ci *        range <code>[0..ubidi_getProcessedLength(pBiDi)-1]</code>.
14041cb0ef41Sopenharmony_ci *
14051cb0ef41Sopenharmony_ci * @param pParaStart will receive the index of the first character of the
14061cb0ef41Sopenharmony_ci *        paragraph in the text.
14071cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14081cb0ef41Sopenharmony_ci *        value is not necessary.
14091cb0ef41Sopenharmony_ci *
14101cb0ef41Sopenharmony_ci * @param pParaLimit will receive the limit of the paragraph.
14111cb0ef41Sopenharmony_ci *        The l-value that you point to here may be the
14121cb0ef41Sopenharmony_ci *        same expression (variable) as the one for
14131cb0ef41Sopenharmony_ci *        <code>charIndex</code>.
14141cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14151cb0ef41Sopenharmony_ci *        value is not necessary.
14161cb0ef41Sopenharmony_ci *
14171cb0ef41Sopenharmony_ci * @param pParaLevel will receive the level of the paragraph.
14181cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14191cb0ef41Sopenharmony_ci *        value is not necessary.
14201cb0ef41Sopenharmony_ci *
14211cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
14221cb0ef41Sopenharmony_ci *
14231cb0ef41Sopenharmony_ci * @return The index of the paragraph containing the specified position.
14241cb0ef41Sopenharmony_ci *
14251cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
14261cb0ef41Sopenharmony_ci * @stable ICU 3.4
14271cb0ef41Sopenharmony_ci */
14281cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
14291cb0ef41Sopenharmony_ciubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,
14301cb0ef41Sopenharmony_ci                   int32_t *pParaLimit, UBiDiLevel *pParaLevel,
14311cb0ef41Sopenharmony_ci                   UErrorCode *pErrorCode);
14321cb0ef41Sopenharmony_ci
14331cb0ef41Sopenharmony_ci/**
14341cb0ef41Sopenharmony_ci * Get a paragraph, given the index of this paragraph.
14351cb0ef41Sopenharmony_ci *
14361cb0ef41Sopenharmony_ci * This function returns information about a paragraph.<p>
14371cb0ef41Sopenharmony_ci *
14381cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
14391cb0ef41Sopenharmony_ci *
14401cb0ef41Sopenharmony_ci * @param paraIndex is the number of the paragraph, in the
14411cb0ef41Sopenharmony_ci *        range <code>[0..ubidi_countParagraphs(pBiDi)-1]</code>.
14421cb0ef41Sopenharmony_ci *
14431cb0ef41Sopenharmony_ci * @param pParaStart will receive the index of the first character of the
14441cb0ef41Sopenharmony_ci *        paragraph in the text.
14451cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14461cb0ef41Sopenharmony_ci *        value is not necessary.
14471cb0ef41Sopenharmony_ci *
14481cb0ef41Sopenharmony_ci * @param pParaLimit will receive the limit of the paragraph.
14491cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14501cb0ef41Sopenharmony_ci *        value is not necessary.
14511cb0ef41Sopenharmony_ci *
14521cb0ef41Sopenharmony_ci * @param pParaLevel will receive the level of the paragraph.
14531cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
14541cb0ef41Sopenharmony_ci *        value is not necessary.
14551cb0ef41Sopenharmony_ci *
14561cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
14571cb0ef41Sopenharmony_ci *
14581cb0ef41Sopenharmony_ci * @stable ICU 3.4
14591cb0ef41Sopenharmony_ci */
14601cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
14611cb0ef41Sopenharmony_ciubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,
14621cb0ef41Sopenharmony_ci                          int32_t *pParaStart, int32_t *pParaLimit,
14631cb0ef41Sopenharmony_ci                          UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);
14641cb0ef41Sopenharmony_ci
14651cb0ef41Sopenharmony_ci/**
14661cb0ef41Sopenharmony_ci * Get the level for one character.
14671cb0ef41Sopenharmony_ci *
14681cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
14691cb0ef41Sopenharmony_ci *
14701cb0ef41Sopenharmony_ci * @param charIndex the index of a character. It must be in the range
14711cb0ef41Sopenharmony_ci *         [0..ubidi_getProcessedLength(pBiDi)].
14721cb0ef41Sopenharmony_ci *
14731cb0ef41Sopenharmony_ci * @return The level for the character at charIndex (0 if charIndex is not
14741cb0ef41Sopenharmony_ci *         in the valid range).
14751cb0ef41Sopenharmony_ci *
14761cb0ef41Sopenharmony_ci * @see UBiDiLevel
14771cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
14781cb0ef41Sopenharmony_ci * @stable ICU 2.0
14791cb0ef41Sopenharmony_ci */
14801cb0ef41Sopenharmony_ciU_CAPI UBiDiLevel U_EXPORT2
14811cb0ef41Sopenharmony_ciubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);
14821cb0ef41Sopenharmony_ci
14831cb0ef41Sopenharmony_ci/**
14841cb0ef41Sopenharmony_ci * Get an array of levels for each character.<p>
14851cb0ef41Sopenharmony_ci *
14861cb0ef41Sopenharmony_ci * Note that this function may allocate memory under some
14871cb0ef41Sopenharmony_ci * circumstances, unlike <code>ubidi_getLevelAt()</code>.
14881cb0ef41Sopenharmony_ci *
14891cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object, whose
14901cb0ef41Sopenharmony_ci *        text length must be strictly positive.
14911cb0ef41Sopenharmony_ci *
14921cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
14931cb0ef41Sopenharmony_ci *
14941cb0ef41Sopenharmony_ci * @return The levels array for the text,
14951cb0ef41Sopenharmony_ci *         or <code>NULL</code> if an error occurs.
14961cb0ef41Sopenharmony_ci *
14971cb0ef41Sopenharmony_ci * @see UBiDiLevel
14981cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
14991cb0ef41Sopenharmony_ci * @stable ICU 2.0
15001cb0ef41Sopenharmony_ci */
15011cb0ef41Sopenharmony_ciU_CAPI const UBiDiLevel * U_EXPORT2
15021cb0ef41Sopenharmony_ciubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);
15031cb0ef41Sopenharmony_ci
15041cb0ef41Sopenharmony_ci/**
15051cb0ef41Sopenharmony_ci * Get a logical run.
15061cb0ef41Sopenharmony_ci * This function returns information about a run and is used
15071cb0ef41Sopenharmony_ci * to retrieve runs in logical order.<p>
15081cb0ef41Sopenharmony_ci * This is especially useful for line-breaking on a paragraph.
15091cb0ef41Sopenharmony_ci *
15101cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
15111cb0ef41Sopenharmony_ci *
15121cb0ef41Sopenharmony_ci * @param logicalPosition is a logical position within the source text.
15131cb0ef41Sopenharmony_ci *
15141cb0ef41Sopenharmony_ci * @param pLogicalLimit will receive the limit of the corresponding run.
15151cb0ef41Sopenharmony_ci *        The l-value that you point to here may be the
15161cb0ef41Sopenharmony_ci *        same expression (variable) as the one for
15171cb0ef41Sopenharmony_ci *        <code>logicalPosition</code>.
15181cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
15191cb0ef41Sopenharmony_ci *        value is not necessary.
15201cb0ef41Sopenharmony_ci *
15211cb0ef41Sopenharmony_ci * @param pLevel will receive the level of the corresponding run.
15221cb0ef41Sopenharmony_ci *        This pointer can be <code>NULL</code> if this
15231cb0ef41Sopenharmony_ci *        value is not necessary.
15241cb0ef41Sopenharmony_ci *
15251cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
15261cb0ef41Sopenharmony_ci * @stable ICU 2.0
15271cb0ef41Sopenharmony_ci */
15281cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
15291cb0ef41Sopenharmony_ciubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,
15301cb0ef41Sopenharmony_ci                    int32_t *pLogicalLimit, UBiDiLevel *pLevel);
15311cb0ef41Sopenharmony_ci
15321cb0ef41Sopenharmony_ci/**
15331cb0ef41Sopenharmony_ci * Get the number of runs.
15341cb0ef41Sopenharmony_ci * This function may invoke the actual reordering on the
15351cb0ef41Sopenharmony_ci * <code>UBiDi</code> object, after <code>ubidi_setPara()</code>
15361cb0ef41Sopenharmony_ci * may have resolved only the levels of the text. Therefore,
15371cb0ef41Sopenharmony_ci * <code>ubidi_countRuns()</code> may have to allocate memory,
15381cb0ef41Sopenharmony_ci * and may fail doing so.
15391cb0ef41Sopenharmony_ci *
15401cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
15411cb0ef41Sopenharmony_ci *
15421cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
15431cb0ef41Sopenharmony_ci *
15441cb0ef41Sopenharmony_ci * @return The number of runs.
15451cb0ef41Sopenharmony_ci * @stable ICU 2.0
15461cb0ef41Sopenharmony_ci */
15471cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
15481cb0ef41Sopenharmony_ciubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
15491cb0ef41Sopenharmony_ci
15501cb0ef41Sopenharmony_ci/**
15511cb0ef41Sopenharmony_ci * Get one run's logical start, length, and directionality,
15521cb0ef41Sopenharmony_ci * which can be 0 for LTR or 1 for RTL.
15531cb0ef41Sopenharmony_ci * In an RTL run, the character at the logical start is
15541cb0ef41Sopenharmony_ci * visually on the right of the displayed run.
15551cb0ef41Sopenharmony_ci * The length is the number of characters in the run.<p>
15561cb0ef41Sopenharmony_ci * <code>ubidi_countRuns()</code> should be called
15571cb0ef41Sopenharmony_ci * before the runs are retrieved.
15581cb0ef41Sopenharmony_ci *
15591cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
15601cb0ef41Sopenharmony_ci *
15611cb0ef41Sopenharmony_ci * @param runIndex is the number of the run in visual order, in the
15621cb0ef41Sopenharmony_ci *        range <code>[0..ubidi_countRuns(pBiDi)-1]</code>.
15631cb0ef41Sopenharmony_ci *
15641cb0ef41Sopenharmony_ci * @param pLogicalStart is the first logical character index in the text.
15651cb0ef41Sopenharmony_ci *        The pointer may be <code>NULL</code> if this index is not needed.
15661cb0ef41Sopenharmony_ci *
15671cb0ef41Sopenharmony_ci * @param pLength is the number of characters (at least one) in the run.
15681cb0ef41Sopenharmony_ci *        The pointer may be <code>NULL</code> if this is not needed.
15691cb0ef41Sopenharmony_ci *
15701cb0ef41Sopenharmony_ci * @return the directionality of the run,
15711cb0ef41Sopenharmony_ci *         <code>UBIDI_LTR==0</code> or <code>UBIDI_RTL==1</code>,
15721cb0ef41Sopenharmony_ci *         never <code>UBIDI_MIXED</code>,
15731cb0ef41Sopenharmony_ci *         never <code>UBIDI_NEUTRAL</code>.
15741cb0ef41Sopenharmony_ci *
15751cb0ef41Sopenharmony_ci * @see ubidi_countRuns
15761cb0ef41Sopenharmony_ci *
15771cb0ef41Sopenharmony_ci * Example:
15781cb0ef41Sopenharmony_ci * <pre>
15791cb0ef41Sopenharmony_ci * \code
15801cb0ef41Sopenharmony_ci * int32_t i, count=ubidi_countRuns(pBiDi),
15811cb0ef41Sopenharmony_ci *         logicalStart, visualIndex=0, length;
15821cb0ef41Sopenharmony_ci * for(i=0; i<count; ++i) {
15831cb0ef41Sopenharmony_ci *    if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {
15841cb0ef41Sopenharmony_ci *         do { // LTR
15851cb0ef41Sopenharmony_ci *             show_char(text[logicalStart++], visualIndex++);
15861cb0ef41Sopenharmony_ci *         } while(--length>0);
15871cb0ef41Sopenharmony_ci *     } else {
15881cb0ef41Sopenharmony_ci *         logicalStart+=length;  // logicalLimit
15891cb0ef41Sopenharmony_ci *         do { // RTL
15901cb0ef41Sopenharmony_ci *             show_char(text[--logicalStart], visualIndex++);
15911cb0ef41Sopenharmony_ci *         } while(--length>0);
15921cb0ef41Sopenharmony_ci *     }
15931cb0ef41Sopenharmony_ci * }
15941cb0ef41Sopenharmony_ci *\endcode
15951cb0ef41Sopenharmony_ci * </pre>
15961cb0ef41Sopenharmony_ci *
15971cb0ef41Sopenharmony_ci * Note that in right-to-left runs, code like this places
15981cb0ef41Sopenharmony_ci * second surrogates before first ones (which is generally a bad idea)
15991cb0ef41Sopenharmony_ci * and combining characters before base characters.
16001cb0ef41Sopenharmony_ci * <p>
16011cb0ef41Sopenharmony_ci * Use of <code>ubidi_writeReordered()</code>, optionally with the
16021cb0ef41Sopenharmony_ci * <code>#UBIDI_KEEP_BASE_COMBINING</code> option, can be considered in order
16031cb0ef41Sopenharmony_ci * to avoid these issues.
16041cb0ef41Sopenharmony_ci * @stable ICU 2.0
16051cb0ef41Sopenharmony_ci */
16061cb0ef41Sopenharmony_ciU_CAPI UBiDiDirection U_EXPORT2
16071cb0ef41Sopenharmony_ciubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,
16081cb0ef41Sopenharmony_ci                   int32_t *pLogicalStart, int32_t *pLength);
16091cb0ef41Sopenharmony_ci
16101cb0ef41Sopenharmony_ci/**
16111cb0ef41Sopenharmony_ci * Get the visual position from a logical text position.
16121cb0ef41Sopenharmony_ci * If such a mapping is used many times on the same
16131cb0ef41Sopenharmony_ci * <code>UBiDi</code> object, then calling
16141cb0ef41Sopenharmony_ci * <code>ubidi_getLogicalMap()</code> is more efficient.<p>
16151cb0ef41Sopenharmony_ci *
16161cb0ef41Sopenharmony_ci * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
16171cb0ef41Sopenharmony_ci * visual position because the corresponding text character is a Bidi control
16181cb0ef41Sopenharmony_ci * removed from output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
16191cb0ef41Sopenharmony_ci * <p>
16201cb0ef41Sopenharmony_ci * When the visual output is altered by using options of
16211cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
16221cb0ef41Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
16231cb0ef41Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual position returned may not
16241cb0ef41Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
16251cb0ef41Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
16261cb0ef41Sopenharmony_ci * <p>
16271cb0ef41Sopenharmony_ci * Note that in right-to-left runs, this mapping places
16281cb0ef41Sopenharmony_ci * second surrogates before first ones (which is generally a bad idea)
16291cb0ef41Sopenharmony_ci * and combining characters before base characters.
16301cb0ef41Sopenharmony_ci * Use of <code>ubidi_writeReordered()</code>, optionally with the
16311cb0ef41Sopenharmony_ci * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
16321cb0ef41Sopenharmony_ci * of using the mapping, in order to avoid these issues.
16331cb0ef41Sopenharmony_ci *
16341cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
16351cb0ef41Sopenharmony_ci *
16361cb0ef41Sopenharmony_ci * @param logicalIndex is the index of a character in the text.
16371cb0ef41Sopenharmony_ci *
16381cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
16391cb0ef41Sopenharmony_ci *
16401cb0ef41Sopenharmony_ci * @return The visual position of this character.
16411cb0ef41Sopenharmony_ci *
16421cb0ef41Sopenharmony_ci * @see ubidi_getLogicalMap
16431cb0ef41Sopenharmony_ci * @see ubidi_getLogicalIndex
16441cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
16451cb0ef41Sopenharmony_ci * @stable ICU 2.0
16461cb0ef41Sopenharmony_ci */
16471cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
16481cb0ef41Sopenharmony_ciubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode);
16491cb0ef41Sopenharmony_ci
16501cb0ef41Sopenharmony_ci/**
16511cb0ef41Sopenharmony_ci * Get the logical text position from a visual position.
16521cb0ef41Sopenharmony_ci * If such a mapping is used many times on the same
16531cb0ef41Sopenharmony_ci * <code>UBiDi</code> object, then calling
16541cb0ef41Sopenharmony_ci * <code>ubidi_getVisualMap()</code> is more efficient.<p>
16551cb0ef41Sopenharmony_ci *
16561cb0ef41Sopenharmony_ci * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
16571cb0ef41Sopenharmony_ci * logical position because the corresponding text character is a Bidi mark
16581cb0ef41Sopenharmony_ci * inserted in the output by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
16591cb0ef41Sopenharmony_ci * <p>
16601cb0ef41Sopenharmony_ci * This is the inverse function to <code>ubidi_getVisualIndex()</code>.
16611cb0ef41Sopenharmony_ci * <p>
16621cb0ef41Sopenharmony_ci * When the visual output is altered by using options of
16631cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
16641cb0ef41Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
16651cb0ef41Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical position returned may not
16661cb0ef41Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
16671cb0ef41Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
16681cb0ef41Sopenharmony_ci *
16691cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
16701cb0ef41Sopenharmony_ci *
16711cb0ef41Sopenharmony_ci * @param visualIndex is the visual position of a character.
16721cb0ef41Sopenharmony_ci *
16731cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
16741cb0ef41Sopenharmony_ci *
16751cb0ef41Sopenharmony_ci * @return The index of this character in the text.
16761cb0ef41Sopenharmony_ci *
16771cb0ef41Sopenharmony_ci * @see ubidi_getVisualMap
16781cb0ef41Sopenharmony_ci * @see ubidi_getVisualIndex
16791cb0ef41Sopenharmony_ci * @see ubidi_getResultLength
16801cb0ef41Sopenharmony_ci * @stable ICU 2.0
16811cb0ef41Sopenharmony_ci */
16821cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
16831cb0ef41Sopenharmony_ciubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);
16841cb0ef41Sopenharmony_ci
16851cb0ef41Sopenharmony_ci/**
16861cb0ef41Sopenharmony_ci * Get a logical-to-visual index map (array) for the characters in the UBiDi
16871cb0ef41Sopenharmony_ci * (paragraph or line) object.
16881cb0ef41Sopenharmony_ci * <p>
16891cb0ef41Sopenharmony_ci * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
16901cb0ef41Sopenharmony_ci * corresponding text characters are Bidi controls removed from the visual
16911cb0ef41Sopenharmony_ci * output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
16921cb0ef41Sopenharmony_ci * <p>
16931cb0ef41Sopenharmony_ci * When the visual output is altered by using options of
16941cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
16951cb0ef41Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
16961cb0ef41Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual positions returned may not
16971cb0ef41Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
16981cb0ef41Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
16991cb0ef41Sopenharmony_ci * <p>
17001cb0ef41Sopenharmony_ci * Note that in right-to-left runs, this mapping places
17011cb0ef41Sopenharmony_ci * second surrogates before first ones (which is generally a bad idea)
17021cb0ef41Sopenharmony_ci * and combining characters before base characters.
17031cb0ef41Sopenharmony_ci * Use of <code>ubidi_writeReordered()</code>, optionally with the
17041cb0ef41Sopenharmony_ci * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
17051cb0ef41Sopenharmony_ci * of using the mapping, in order to avoid these issues.
17061cb0ef41Sopenharmony_ci *
17071cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
17081cb0ef41Sopenharmony_ci *
17091cb0ef41Sopenharmony_ci * @param indexMap is a pointer to an array of <code>ubidi_getProcessedLength()</code>
17101cb0ef41Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
17111cb0ef41Sopenharmony_ci *        If option <code>#UBIDI_OPTION_INSERT_MARKS</code> is set, the number
17121cb0ef41Sopenharmony_ci *        of elements allocated in <code>indexMap</code> must be no less than
17131cb0ef41Sopenharmony_ci *        <code>ubidi_getResultLength()</code>.
17141cb0ef41Sopenharmony_ci *        The array does not need to be initialized.<br><br>
17151cb0ef41Sopenharmony_ci *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
17161cb0ef41Sopenharmony_ci *
17171cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
17181cb0ef41Sopenharmony_ci *
17191cb0ef41Sopenharmony_ci * @see ubidi_getVisualMap
17201cb0ef41Sopenharmony_ci * @see ubidi_getVisualIndex
17211cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
17221cb0ef41Sopenharmony_ci * @see ubidi_getResultLength
17231cb0ef41Sopenharmony_ci * @stable ICU 2.0
17241cb0ef41Sopenharmony_ci */
17251cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
17261cb0ef41Sopenharmony_ciubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
17271cb0ef41Sopenharmony_ci
17281cb0ef41Sopenharmony_ci/**
17291cb0ef41Sopenharmony_ci * Get a visual-to-logical index map (array) for the characters in the UBiDi
17301cb0ef41Sopenharmony_ci * (paragraph or line) object.
17311cb0ef41Sopenharmony_ci * <p>
17321cb0ef41Sopenharmony_ci * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
17331cb0ef41Sopenharmony_ci * corresponding text characters are Bidi marks inserted in the visual output
17341cb0ef41Sopenharmony_ci * by the option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
17351cb0ef41Sopenharmony_ci * <p>
17361cb0ef41Sopenharmony_ci * When the visual output is altered by using options of
17371cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
17381cb0ef41Sopenharmony_ci * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
17391cb0ef41Sopenharmony_ci * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical positions returned may not
17401cb0ef41Sopenharmony_ci * be correct. It is advised to use, when possible, reordering options
17411cb0ef41Sopenharmony_ci * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
17421cb0ef41Sopenharmony_ci *
17431cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
17441cb0ef41Sopenharmony_ci *
17451cb0ef41Sopenharmony_ci * @param indexMap is a pointer to an array of <code>ubidi_getResultLength()</code>
17461cb0ef41Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
17471cb0ef41Sopenharmony_ci *        If option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is set, the number
17481cb0ef41Sopenharmony_ci *        of elements allocated in <code>indexMap</code> must be no less than
17491cb0ef41Sopenharmony_ci *        <code>ubidi_getProcessedLength()</code>.
17501cb0ef41Sopenharmony_ci *        The array does not need to be initialized.<br><br>
17511cb0ef41Sopenharmony_ci *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
17521cb0ef41Sopenharmony_ci *
17531cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
17541cb0ef41Sopenharmony_ci *
17551cb0ef41Sopenharmony_ci * @see ubidi_getLogicalMap
17561cb0ef41Sopenharmony_ci * @see ubidi_getLogicalIndex
17571cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
17581cb0ef41Sopenharmony_ci * @see ubidi_getResultLength
17591cb0ef41Sopenharmony_ci * @stable ICU 2.0
17601cb0ef41Sopenharmony_ci */
17611cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
17621cb0ef41Sopenharmony_ciubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
17631cb0ef41Sopenharmony_ci
17641cb0ef41Sopenharmony_ci/**
17651cb0ef41Sopenharmony_ci * This is a convenience function that does not use a UBiDi object.
17661cb0ef41Sopenharmony_ci * It is intended to be used for when an application has determined the levels
17671cb0ef41Sopenharmony_ci * of objects (character sequences) and just needs to have them reordered (L2).
17681cb0ef41Sopenharmony_ci * This is equivalent to using <code>ubidi_getLogicalMap()</code> on a
17691cb0ef41Sopenharmony_ci * <code>UBiDi</code> object.
17701cb0ef41Sopenharmony_ci *
17711cb0ef41Sopenharmony_ci * @param levels is an array with <code>length</code> levels that have been determined by
17721cb0ef41Sopenharmony_ci *        the application.
17731cb0ef41Sopenharmony_ci *
17741cb0ef41Sopenharmony_ci * @param length is the number of levels in the array, or, semantically,
17751cb0ef41Sopenharmony_ci *        the number of objects to be reordered.
17761cb0ef41Sopenharmony_ci *        It must be <code>length>0</code>.
17771cb0ef41Sopenharmony_ci *
17781cb0ef41Sopenharmony_ci * @param indexMap is a pointer to an array of <code>length</code>
17791cb0ef41Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
17801cb0ef41Sopenharmony_ci *        The array does not need to be initialized.<p>
17811cb0ef41Sopenharmony_ci *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
17821cb0ef41Sopenharmony_ci * @stable ICU 2.0
17831cb0ef41Sopenharmony_ci */
17841cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
17851cb0ef41Sopenharmony_ciubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
17861cb0ef41Sopenharmony_ci
17871cb0ef41Sopenharmony_ci/**
17881cb0ef41Sopenharmony_ci * This is a convenience function that does not use a UBiDi object.
17891cb0ef41Sopenharmony_ci * It is intended to be used for when an application has determined the levels
17901cb0ef41Sopenharmony_ci * of objects (character sequences) and just needs to have them reordered (L2).
17911cb0ef41Sopenharmony_ci * This is equivalent to using <code>ubidi_getVisualMap()</code> on a
17921cb0ef41Sopenharmony_ci * <code>UBiDi</code> object.
17931cb0ef41Sopenharmony_ci *
17941cb0ef41Sopenharmony_ci * @param levels is an array with <code>length</code> levels that have been determined by
17951cb0ef41Sopenharmony_ci *        the application.
17961cb0ef41Sopenharmony_ci *
17971cb0ef41Sopenharmony_ci * @param length is the number of levels in the array, or, semantically,
17981cb0ef41Sopenharmony_ci *        the number of objects to be reordered.
17991cb0ef41Sopenharmony_ci *        It must be <code>length>0</code>.
18001cb0ef41Sopenharmony_ci *
18011cb0ef41Sopenharmony_ci * @param indexMap is a pointer to an array of <code>length</code>
18021cb0ef41Sopenharmony_ci *        indexes which will reflect the reordering of the characters.
18031cb0ef41Sopenharmony_ci *        The array does not need to be initialized.<p>
18041cb0ef41Sopenharmony_ci *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
18051cb0ef41Sopenharmony_ci * @stable ICU 2.0
18061cb0ef41Sopenharmony_ci */
18071cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
18081cb0ef41Sopenharmony_ciubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
18091cb0ef41Sopenharmony_ci
18101cb0ef41Sopenharmony_ci/**
18111cb0ef41Sopenharmony_ci * Invert an index map.
18121cb0ef41Sopenharmony_ci * The index mapping of the first map is inverted and written to
18131cb0ef41Sopenharmony_ci * the second one.
18141cb0ef41Sopenharmony_ci *
18151cb0ef41Sopenharmony_ci * @param srcMap is an array with <code>length</code> elements
18161cb0ef41Sopenharmony_ci *        which defines the original mapping from a source array containing
18171cb0ef41Sopenharmony_ci *        <code>length</code> elements to a destination array.
18181cb0ef41Sopenharmony_ci *        Some elements of the source array may have no mapping in the
18191cb0ef41Sopenharmony_ci *        destination array. In that case, their value will be
18201cb0ef41Sopenharmony_ci *        the special value <code>UBIDI_MAP_NOWHERE</code>.
18211cb0ef41Sopenharmony_ci *        All elements must be >=0 or equal to <code>UBIDI_MAP_NOWHERE</code>.
18221cb0ef41Sopenharmony_ci *        Some elements may have a value >= <code>length</code>, if the
18231cb0ef41Sopenharmony_ci *        destination array has more elements than the source array.
18241cb0ef41Sopenharmony_ci *        There must be no duplicate indexes (two or more elements with the
18251cb0ef41Sopenharmony_ci *        same value except <code>UBIDI_MAP_NOWHERE</code>).
18261cb0ef41Sopenharmony_ci *
18271cb0ef41Sopenharmony_ci * @param destMap is an array with a number of elements equal to 1 + the highest
18281cb0ef41Sopenharmony_ci *        value in <code>srcMap</code>.
18291cb0ef41Sopenharmony_ci *        <code>destMap</code> will be filled with the inverse mapping.
18301cb0ef41Sopenharmony_ci *        If element with index i in <code>srcMap</code> has a value k different
18311cb0ef41Sopenharmony_ci *        from <code>UBIDI_MAP_NOWHERE</code>, this means that element i of
18321cb0ef41Sopenharmony_ci *        the source array maps to element k in the destination array.
18331cb0ef41Sopenharmony_ci *        The inverse map will have value i in its k-th element.
18341cb0ef41Sopenharmony_ci *        For all elements of the destination array which do not map to
18351cb0ef41Sopenharmony_ci *        an element in the source array, the corresponding element in the
18361cb0ef41Sopenharmony_ci *        inverse map will have a value equal to <code>UBIDI_MAP_NOWHERE</code>.
18371cb0ef41Sopenharmony_ci *
18381cb0ef41Sopenharmony_ci * @param length is the length of each array.
18391cb0ef41Sopenharmony_ci * @see UBIDI_MAP_NOWHERE
18401cb0ef41Sopenharmony_ci * @stable ICU 2.0
18411cb0ef41Sopenharmony_ci */
18421cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
18431cb0ef41Sopenharmony_ciubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);
18441cb0ef41Sopenharmony_ci
18451cb0ef41Sopenharmony_ci/** option flags for ubidi_writeReordered() */
18461cb0ef41Sopenharmony_ci
18471cb0ef41Sopenharmony_ci/**
18481cb0ef41Sopenharmony_ci * option bit for ubidi_writeReordered():
18491cb0ef41Sopenharmony_ci * keep combining characters after their base characters in RTL runs
18501cb0ef41Sopenharmony_ci *
18511cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
18521cb0ef41Sopenharmony_ci * @stable ICU 2.0
18531cb0ef41Sopenharmony_ci */
18541cb0ef41Sopenharmony_ci#define UBIDI_KEEP_BASE_COMBINING       1
18551cb0ef41Sopenharmony_ci
18561cb0ef41Sopenharmony_ci/**
18571cb0ef41Sopenharmony_ci * option bit for ubidi_writeReordered():
18581cb0ef41Sopenharmony_ci * replace characters with the "mirrored" property in RTL runs
18591cb0ef41Sopenharmony_ci * by their mirror-image mappings
18601cb0ef41Sopenharmony_ci *
18611cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
18621cb0ef41Sopenharmony_ci * @stable ICU 2.0
18631cb0ef41Sopenharmony_ci */
18641cb0ef41Sopenharmony_ci#define UBIDI_DO_MIRRORING              2
18651cb0ef41Sopenharmony_ci
18661cb0ef41Sopenharmony_ci/**
18671cb0ef41Sopenharmony_ci * option bit for ubidi_writeReordered():
18681cb0ef41Sopenharmony_ci * surround the run with LRMs if necessary;
18691cb0ef41Sopenharmony_ci * this is part of the approximate "inverse Bidi" algorithm
18701cb0ef41Sopenharmony_ci *
18711cb0ef41Sopenharmony_ci * <p>This option does not imply corresponding adjustment of the index
18721cb0ef41Sopenharmony_ci * mappings.</p>
18731cb0ef41Sopenharmony_ci *
18741cb0ef41Sopenharmony_ci * @see ubidi_setInverse
18751cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
18761cb0ef41Sopenharmony_ci * @stable ICU 2.0
18771cb0ef41Sopenharmony_ci */
18781cb0ef41Sopenharmony_ci#define UBIDI_INSERT_LRM_FOR_NUMERIC    4
18791cb0ef41Sopenharmony_ci
18801cb0ef41Sopenharmony_ci/**
18811cb0ef41Sopenharmony_ci * option bit for ubidi_writeReordered():
18821cb0ef41Sopenharmony_ci * remove Bidi control characters
18831cb0ef41Sopenharmony_ci * (this does not affect #UBIDI_INSERT_LRM_FOR_NUMERIC)
18841cb0ef41Sopenharmony_ci *
18851cb0ef41Sopenharmony_ci * <p>This option does not imply corresponding adjustment of the index
18861cb0ef41Sopenharmony_ci * mappings.</p>
18871cb0ef41Sopenharmony_ci *
18881cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
18891cb0ef41Sopenharmony_ci * @stable ICU 2.0
18901cb0ef41Sopenharmony_ci */
18911cb0ef41Sopenharmony_ci#define UBIDI_REMOVE_BIDI_CONTROLS      8
18921cb0ef41Sopenharmony_ci
18931cb0ef41Sopenharmony_ci/**
18941cb0ef41Sopenharmony_ci * option bit for ubidi_writeReordered():
18951cb0ef41Sopenharmony_ci * write the output in reverse order
18961cb0ef41Sopenharmony_ci *
18971cb0ef41Sopenharmony_ci * <p>This has the same effect as calling <code>ubidi_writeReordered()</code>
18981cb0ef41Sopenharmony_ci * first without this option, and then calling
18991cb0ef41Sopenharmony_ci * <code>ubidi_writeReverse()</code> without mirroring.
19001cb0ef41Sopenharmony_ci * Doing this in the same step is faster and avoids a temporary buffer.
19011cb0ef41Sopenharmony_ci * An example for using this option is output to a character terminal that
19021cb0ef41Sopenharmony_ci * is designed for RTL scripts and stores text in reverse order.</p>
19031cb0ef41Sopenharmony_ci *
19041cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
19051cb0ef41Sopenharmony_ci * @stable ICU 2.0
19061cb0ef41Sopenharmony_ci */
19071cb0ef41Sopenharmony_ci#define UBIDI_OUTPUT_REVERSE            16
19081cb0ef41Sopenharmony_ci
19091cb0ef41Sopenharmony_ci/**
19101cb0ef41Sopenharmony_ci * Get the length of the source text processed by the last call to
19111cb0ef41Sopenharmony_ci * <code>ubidi_setPara()</code>. This length may be different from the length
19121cb0ef41Sopenharmony_ci * of the source text if option <code>#UBIDI_OPTION_STREAMING</code>
19131cb0ef41Sopenharmony_ci * has been set.
19141cb0ef41Sopenharmony_ci * <br>
19151cb0ef41Sopenharmony_ci * Note that whenever the length of the text affects the execution or the
19161cb0ef41Sopenharmony_ci * result of a function, it is the processed length which must be considered,
19171cb0ef41Sopenharmony_ci * except for <code>ubidi_setPara</code> (which receives unprocessed source
19181cb0ef41Sopenharmony_ci * text) and <code>ubidi_getLength</code> (which returns the original length
19191cb0ef41Sopenharmony_ci * of the source text).<br>
19201cb0ef41Sopenharmony_ci * In particular, the processed length is the one to consider in the following
19211cb0ef41Sopenharmony_ci * cases:
19221cb0ef41Sopenharmony_ci * <ul>
19231cb0ef41Sopenharmony_ci * <li>maximum value of the <code>limit</code> argument of
19241cb0ef41Sopenharmony_ci * <code>ubidi_setLine</code></li>
19251cb0ef41Sopenharmony_ci * <li>maximum value of the <code>charIndex</code> argument of
19261cb0ef41Sopenharmony_ci * <code>ubidi_getParagraph</code></li>
19271cb0ef41Sopenharmony_ci * <li>maximum value of the <code>charIndex</code> argument of
19281cb0ef41Sopenharmony_ci * <code>ubidi_getLevelAt</code></li>
19291cb0ef41Sopenharmony_ci * <li>number of elements in the array returned by <code>ubidi_getLevels</code></li>
19301cb0ef41Sopenharmony_ci * <li>maximum value of the <code>logicalStart</code> argument of
19311cb0ef41Sopenharmony_ci * <code>ubidi_getLogicalRun</code></li>
19321cb0ef41Sopenharmony_ci * <li>maximum value of the <code>logicalIndex</code> argument of
19331cb0ef41Sopenharmony_ci * <code>ubidi_getVisualIndex</code></li>
19341cb0ef41Sopenharmony_ci * <li>number of elements filled in the <code>*indexMap</code> argument of
19351cb0ef41Sopenharmony_ci * <code>ubidi_getLogicalMap</code></li>
19361cb0ef41Sopenharmony_ci * <li>length of text processed by <code>ubidi_writeReordered</code></li>
19371cb0ef41Sopenharmony_ci * </ul>
19381cb0ef41Sopenharmony_ci *
19391cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
19401cb0ef41Sopenharmony_ci *
19411cb0ef41Sopenharmony_ci * @return The length of the part of the source text processed by
19421cb0ef41Sopenharmony_ci *         the last call to <code>ubidi_setPara</code>.
19431cb0ef41Sopenharmony_ci * @see ubidi_setPara
19441cb0ef41Sopenharmony_ci * @see UBIDI_OPTION_STREAMING
19451cb0ef41Sopenharmony_ci * @stable ICU 3.6
19461cb0ef41Sopenharmony_ci */
19471cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
19481cb0ef41Sopenharmony_ciubidi_getProcessedLength(const UBiDi *pBiDi);
19491cb0ef41Sopenharmony_ci
19501cb0ef41Sopenharmony_ci/**
19511cb0ef41Sopenharmony_ci * Get the length of the reordered text resulting from the last call to
19521cb0ef41Sopenharmony_ci * <code>ubidi_setPara()</code>. This length may be different from the length
19531cb0ef41Sopenharmony_ci * of the source text if option <code>#UBIDI_OPTION_INSERT_MARKS</code>
19541cb0ef41Sopenharmony_ci * or option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> has been set.
19551cb0ef41Sopenharmony_ci * <br>
19561cb0ef41Sopenharmony_ci * This resulting length is the one to consider in the following cases:
19571cb0ef41Sopenharmony_ci * <ul>
19581cb0ef41Sopenharmony_ci * <li>maximum value of the <code>visualIndex</code> argument of
19591cb0ef41Sopenharmony_ci * <code>ubidi_getLogicalIndex</code></li>
19601cb0ef41Sopenharmony_ci * <li>number of elements of the <code>*indexMap</code> argument of
19611cb0ef41Sopenharmony_ci * <code>ubidi_getVisualMap</code></li>
19621cb0ef41Sopenharmony_ci * </ul>
19631cb0ef41Sopenharmony_ci * Note that this length stays identical to the source text length if
19641cb0ef41Sopenharmony_ci * Bidi marks are inserted or removed using option bits of
19651cb0ef41Sopenharmony_ci * <code>ubidi_writeReordered</code>, or if option
19661cb0ef41Sopenharmony_ci * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> has been set.
19671cb0ef41Sopenharmony_ci *
19681cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
19691cb0ef41Sopenharmony_ci *
19701cb0ef41Sopenharmony_ci * @return The length of the reordered text resulting from
19711cb0ef41Sopenharmony_ci *         the last call to <code>ubidi_setPara</code>.
19721cb0ef41Sopenharmony_ci * @see ubidi_setPara
19731cb0ef41Sopenharmony_ci * @see UBIDI_OPTION_INSERT_MARKS
19741cb0ef41Sopenharmony_ci * @see UBIDI_OPTION_REMOVE_CONTROLS
19751cb0ef41Sopenharmony_ci * @stable ICU 3.6
19761cb0ef41Sopenharmony_ci */
19771cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
19781cb0ef41Sopenharmony_ciubidi_getResultLength(const UBiDi *pBiDi);
19791cb0ef41Sopenharmony_ci
19801cb0ef41Sopenharmony_ciU_CDECL_BEGIN
19811cb0ef41Sopenharmony_ci
19821cb0ef41Sopenharmony_ci#ifndef U_HIDE_DEPRECATED_API
19831cb0ef41Sopenharmony_ci/**
19841cb0ef41Sopenharmony_ci * Value returned by <code>UBiDiClassCallback</code> callbacks when
19851cb0ef41Sopenharmony_ci * there is no need to override the standard Bidi class for a given code point.
19861cb0ef41Sopenharmony_ci *
19871cb0ef41Sopenharmony_ci * This constant is deprecated; use u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1 instead.
19881cb0ef41Sopenharmony_ci *
19891cb0ef41Sopenharmony_ci * @see UBiDiClassCallback
19901cb0ef41Sopenharmony_ci * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
19911cb0ef41Sopenharmony_ci */
19921cb0ef41Sopenharmony_ci#define U_BIDI_CLASS_DEFAULT  U_CHAR_DIRECTION_COUNT
19931cb0ef41Sopenharmony_ci#endif  // U_HIDE_DEPRECATED_API
19941cb0ef41Sopenharmony_ci
19951cb0ef41Sopenharmony_ci/**
19961cb0ef41Sopenharmony_ci * Callback type declaration for overriding default Bidi class values with
19971cb0ef41Sopenharmony_ci * custom ones.
19981cb0ef41Sopenharmony_ci * <p>Usually, the function pointer will be propagated to a <code>UBiDi</code>
19991cb0ef41Sopenharmony_ci * object by calling the <code>ubidi_setClassCallback()</code> function;
20001cb0ef41Sopenharmony_ci * then the callback will be invoked by the UBA implementation any time the
20011cb0ef41Sopenharmony_ci * class of a character is to be determined.</p>
20021cb0ef41Sopenharmony_ci *
20031cb0ef41Sopenharmony_ci * @param context is a pointer to the callback private data.
20041cb0ef41Sopenharmony_ci *
20051cb0ef41Sopenharmony_ci * @param c       is the code point to get a Bidi class for.
20061cb0ef41Sopenharmony_ci *
20071cb0ef41Sopenharmony_ci * @return The directional property / Bidi class for the given code point
20081cb0ef41Sopenharmony_ci *         <code>c</code> if the default class has been overridden, or
20091cb0ef41Sopenharmony_ci *         <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>
20101cb0ef41Sopenharmony_ci *         if the standard Bidi class value for <code>c</code> is to be used.
20111cb0ef41Sopenharmony_ci * @see ubidi_setClassCallback
20121cb0ef41Sopenharmony_ci * @see ubidi_getClassCallback
20131cb0ef41Sopenharmony_ci * @stable ICU 3.6
20141cb0ef41Sopenharmony_ci */
20151cb0ef41Sopenharmony_citypedef UCharDirection U_CALLCONV
20161cb0ef41Sopenharmony_ciUBiDiClassCallback(const void *context, UChar32 c);
20171cb0ef41Sopenharmony_ci
20181cb0ef41Sopenharmony_ciU_CDECL_END
20191cb0ef41Sopenharmony_ci
20201cb0ef41Sopenharmony_ci/**
20211cb0ef41Sopenharmony_ci * Retrieve the Bidi class for a given code point.
20221cb0ef41Sopenharmony_ci * <p>If a <code>#UBiDiClassCallback</code> callback is defined and returns a
20231cb0ef41Sopenharmony_ci * value other than <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>,
20241cb0ef41Sopenharmony_ci * that value is used; otherwise the default class determination mechanism is invoked.</p>
20251cb0ef41Sopenharmony_ci *
20261cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
20271cb0ef41Sopenharmony_ci *
20281cb0ef41Sopenharmony_ci * @param c     is the code point whose Bidi class must be retrieved.
20291cb0ef41Sopenharmony_ci *
20301cb0ef41Sopenharmony_ci * @return The Bidi class for character <code>c</code> based
20311cb0ef41Sopenharmony_ci *         on the given <code>pBiDi</code> instance.
20321cb0ef41Sopenharmony_ci * @see UBiDiClassCallback
20331cb0ef41Sopenharmony_ci * @stable ICU 3.6
20341cb0ef41Sopenharmony_ci */
20351cb0ef41Sopenharmony_ciU_CAPI UCharDirection U_EXPORT2
20361cb0ef41Sopenharmony_ciubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c);
20371cb0ef41Sopenharmony_ci
20381cb0ef41Sopenharmony_ci/**
20391cb0ef41Sopenharmony_ci * Set the callback function and callback data used by the UBA
20401cb0ef41Sopenharmony_ci * implementation for Bidi class determination.
20411cb0ef41Sopenharmony_ci * <p>This may be useful for assigning Bidi classes to PUA characters, or
20421cb0ef41Sopenharmony_ci * for special application needs. For instance, an application may want to
20431cb0ef41Sopenharmony_ci * handle all spaces like L or R characters (according to the base direction)
20441cb0ef41Sopenharmony_ci * when creating the visual ordering of logical lines which are part of a report
20451cb0ef41Sopenharmony_ci * organized in columns: there should not be interaction between adjacent
20461cb0ef41Sopenharmony_ci * cells.<p>
20471cb0ef41Sopenharmony_ci *
20481cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
20491cb0ef41Sopenharmony_ci *
20501cb0ef41Sopenharmony_ci * @param newFn is the new callback function pointer.
20511cb0ef41Sopenharmony_ci *
20521cb0ef41Sopenharmony_ci * @param newContext is the new callback context pointer. This can be NULL.
20531cb0ef41Sopenharmony_ci *
20541cb0ef41Sopenharmony_ci * @param oldFn fillin: Returns the old callback function pointer. This can be
20551cb0ef41Sopenharmony_ci *                      NULL.
20561cb0ef41Sopenharmony_ci *
20571cb0ef41Sopenharmony_ci * @param oldContext fillin: Returns the old callback's context. This can be
20581cb0ef41Sopenharmony_ci *                           NULL.
20591cb0ef41Sopenharmony_ci *
20601cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
20611cb0ef41Sopenharmony_ci *
20621cb0ef41Sopenharmony_ci * @see ubidi_getClassCallback
20631cb0ef41Sopenharmony_ci * @stable ICU 3.6
20641cb0ef41Sopenharmony_ci */
20651cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
20661cb0ef41Sopenharmony_ciubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,
20671cb0ef41Sopenharmony_ci                       const void *newContext, UBiDiClassCallback **oldFn,
20681cb0ef41Sopenharmony_ci                       const void **oldContext, UErrorCode *pErrorCode);
20691cb0ef41Sopenharmony_ci
20701cb0ef41Sopenharmony_ci/**
20711cb0ef41Sopenharmony_ci * Get the current callback function used for Bidi class determination.
20721cb0ef41Sopenharmony_ci *
20731cb0ef41Sopenharmony_ci * @param pBiDi is the paragraph <code>UBiDi</code> object.
20741cb0ef41Sopenharmony_ci *
20751cb0ef41Sopenharmony_ci * @param fn fillin: Returns the callback function pointer.
20761cb0ef41Sopenharmony_ci *
20771cb0ef41Sopenharmony_ci * @param context fillin: Returns the callback's private context.
20781cb0ef41Sopenharmony_ci *
20791cb0ef41Sopenharmony_ci * @see ubidi_setClassCallback
20801cb0ef41Sopenharmony_ci * @stable ICU 3.6
20811cb0ef41Sopenharmony_ci */
20821cb0ef41Sopenharmony_ciU_CAPI void U_EXPORT2
20831cb0ef41Sopenharmony_ciubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context);
20841cb0ef41Sopenharmony_ci
20851cb0ef41Sopenharmony_ci/**
20861cb0ef41Sopenharmony_ci * Take a <code>UBiDi</code> object containing the reordering
20871cb0ef41Sopenharmony_ci * information for a piece of text (one or more paragraphs) set by
20881cb0ef41Sopenharmony_ci * <code>ubidi_setPara()</code> or for a line of text set by
20891cb0ef41Sopenharmony_ci * <code>ubidi_setLine()</code> and write a reordered string to the
20901cb0ef41Sopenharmony_ci * destination buffer.
20911cb0ef41Sopenharmony_ci *
20921cb0ef41Sopenharmony_ci * This function preserves the integrity of characters with multiple
20931cb0ef41Sopenharmony_ci * code units and (optionally) combining characters.
20941cb0ef41Sopenharmony_ci * Characters in RTL runs can be replaced by mirror-image characters
20951cb0ef41Sopenharmony_ci * in the destination buffer. Note that "real" mirroring has
20961cb0ef41Sopenharmony_ci * to be done in a rendering engine by glyph selection
20971cb0ef41Sopenharmony_ci * and that for many "mirrored" characters there are no
20981cb0ef41Sopenharmony_ci * Unicode characters as mirror-image equivalents.
20991cb0ef41Sopenharmony_ci * There are also options to insert or remove Bidi control
21001cb0ef41Sopenharmony_ci * characters; see the description of the <code>destSize</code>
21011cb0ef41Sopenharmony_ci * and <code>options</code> parameters and of the option bit flags.
21021cb0ef41Sopenharmony_ci *
21031cb0ef41Sopenharmony_ci * @param pBiDi A pointer to a <code>UBiDi</code> object that
21041cb0ef41Sopenharmony_ci *              is set by <code>ubidi_setPara()</code> or
21051cb0ef41Sopenharmony_ci *              <code>ubidi_setLine()</code> and contains the reordering
21061cb0ef41Sopenharmony_ci *              information for the text that it was defined for,
21071cb0ef41Sopenharmony_ci *              as well as a pointer to that text.<br><br>
21081cb0ef41Sopenharmony_ci *              The text was aliased (only the pointer was stored
21091cb0ef41Sopenharmony_ci *              without copying the contents) and must not have been modified
21101cb0ef41Sopenharmony_ci *              since the <code>ubidi_setPara()</code> call.
21111cb0ef41Sopenharmony_ci *
21121cb0ef41Sopenharmony_ci * @param dest A pointer to where the reordered text is to be copied.
21131cb0ef41Sopenharmony_ci *             The source text and <code>dest[destSize]</code>
21141cb0ef41Sopenharmony_ci *             must not overlap.
21151cb0ef41Sopenharmony_ci *
21161cb0ef41Sopenharmony_ci * @param destSize The size of the <code>dest</code> buffer,
21171cb0ef41Sopenharmony_ci *                 in number of UChars.
21181cb0ef41Sopenharmony_ci *                 If the <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>
21191cb0ef41Sopenharmony_ci *                 option is set, then the destination length could be
21201cb0ef41Sopenharmony_ci *                 as large as
21211cb0ef41Sopenharmony_ci *                 <code>ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)</code>.
21221cb0ef41Sopenharmony_ci *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
21231cb0ef41Sopenharmony_ci *                 is set, then the destination length may be less than
21241cb0ef41Sopenharmony_ci *                 <code>ubidi_getLength(pBiDi)</code>.
21251cb0ef41Sopenharmony_ci *                 If none of these options is set, then the destination length
21261cb0ef41Sopenharmony_ci *                 will be exactly <code>ubidi_getProcessedLength(pBiDi)</code>.
21271cb0ef41Sopenharmony_ci *
21281cb0ef41Sopenharmony_ci * @param options A bit set of options for the reordering that control
21291cb0ef41Sopenharmony_ci *                how the reordered text is written.
21301cb0ef41Sopenharmony_ci *                The options include mirroring the characters on a code
21311cb0ef41Sopenharmony_ci *                point basis and inserting LRM characters, which is used
21321cb0ef41Sopenharmony_ci *                especially for transforming visually stored text
21331cb0ef41Sopenharmony_ci *                to logically stored text (although this is still an
21341cb0ef41Sopenharmony_ci *                imperfect implementation of an "inverse Bidi" algorithm
21351cb0ef41Sopenharmony_ci *                because it uses the "forward Bidi" algorithm at its core).
21361cb0ef41Sopenharmony_ci *                The available options are:
21371cb0ef41Sopenharmony_ci *                <code>#UBIDI_DO_MIRRORING</code>,
21381cb0ef41Sopenharmony_ci *                <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
21391cb0ef41Sopenharmony_ci *                <code>#UBIDI_KEEP_BASE_COMBINING</code>,
21401cb0ef41Sopenharmony_ci *                <code>#UBIDI_OUTPUT_REVERSE</code>,
21411cb0ef41Sopenharmony_ci *                <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
21421cb0ef41Sopenharmony_ci *
21431cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
21441cb0ef41Sopenharmony_ci *
21451cb0ef41Sopenharmony_ci * @return The length of the output string.
21461cb0ef41Sopenharmony_ci *
21471cb0ef41Sopenharmony_ci * @see ubidi_getProcessedLength
21481cb0ef41Sopenharmony_ci * @stable ICU 2.0
21491cb0ef41Sopenharmony_ci */
21501cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
21511cb0ef41Sopenharmony_ciubidi_writeReordered(UBiDi *pBiDi,
21521cb0ef41Sopenharmony_ci                     UChar *dest, int32_t destSize,
21531cb0ef41Sopenharmony_ci                     uint16_t options,
21541cb0ef41Sopenharmony_ci                     UErrorCode *pErrorCode);
21551cb0ef41Sopenharmony_ci
21561cb0ef41Sopenharmony_ci/**
21571cb0ef41Sopenharmony_ci * Reverse a Right-To-Left run of Unicode text.
21581cb0ef41Sopenharmony_ci *
21591cb0ef41Sopenharmony_ci * This function preserves the integrity of characters with multiple
21601cb0ef41Sopenharmony_ci * code units and (optionally) combining characters.
21611cb0ef41Sopenharmony_ci * Characters can be replaced by mirror-image characters
21621cb0ef41Sopenharmony_ci * in the destination buffer. Note that "real" mirroring has
21631cb0ef41Sopenharmony_ci * to be done in a rendering engine by glyph selection
21641cb0ef41Sopenharmony_ci * and that for many "mirrored" characters there are no
21651cb0ef41Sopenharmony_ci * Unicode characters as mirror-image equivalents.
21661cb0ef41Sopenharmony_ci * There are also options to insert or remove Bidi control
21671cb0ef41Sopenharmony_ci * characters.
21681cb0ef41Sopenharmony_ci *
21691cb0ef41Sopenharmony_ci * This function is the implementation for reversing RTL runs as part
21701cb0ef41Sopenharmony_ci * of <code>ubidi_writeReordered()</code>. For detailed descriptions
21711cb0ef41Sopenharmony_ci * of the parameters, see there.
21721cb0ef41Sopenharmony_ci * Since no Bidi controls are inserted here, the output string length
21731cb0ef41Sopenharmony_ci * will never exceed <code>srcLength</code>.
21741cb0ef41Sopenharmony_ci *
21751cb0ef41Sopenharmony_ci * @see ubidi_writeReordered
21761cb0ef41Sopenharmony_ci *
21771cb0ef41Sopenharmony_ci * @param src A pointer to the RTL run text.
21781cb0ef41Sopenharmony_ci *
21791cb0ef41Sopenharmony_ci * @param srcLength The length of the RTL run.
21801cb0ef41Sopenharmony_ci *
21811cb0ef41Sopenharmony_ci * @param dest A pointer to where the reordered text is to be copied.
21821cb0ef41Sopenharmony_ci *             <code>src[srcLength]</code> and <code>dest[destSize]</code>
21831cb0ef41Sopenharmony_ci *             must not overlap.
21841cb0ef41Sopenharmony_ci *
21851cb0ef41Sopenharmony_ci * @param destSize The size of the <code>dest</code> buffer,
21861cb0ef41Sopenharmony_ci *                 in number of UChars.
21871cb0ef41Sopenharmony_ci *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
21881cb0ef41Sopenharmony_ci *                 is set, then the destination length may be less than
21891cb0ef41Sopenharmony_ci *                 <code>srcLength</code>.
21901cb0ef41Sopenharmony_ci *                 If this option is not set, then the destination length
21911cb0ef41Sopenharmony_ci *                 will be exactly <code>srcLength</code>.
21921cb0ef41Sopenharmony_ci *
21931cb0ef41Sopenharmony_ci * @param options A bit set of options for the reordering that control
21941cb0ef41Sopenharmony_ci *                how the reordered text is written.
21951cb0ef41Sopenharmony_ci *                See the <code>options</code> parameter in <code>ubidi_writeReordered()</code>.
21961cb0ef41Sopenharmony_ci *
21971cb0ef41Sopenharmony_ci * @param pErrorCode must be a valid pointer to an error code value.
21981cb0ef41Sopenharmony_ci *
21991cb0ef41Sopenharmony_ci * @return The length of the output string.
22001cb0ef41Sopenharmony_ci * @stable ICU 2.0
22011cb0ef41Sopenharmony_ci */
22021cb0ef41Sopenharmony_ciU_CAPI int32_t U_EXPORT2
22031cb0ef41Sopenharmony_ciubidi_writeReverse(const UChar *src, int32_t srcLength,
22041cb0ef41Sopenharmony_ci                   UChar *dest, int32_t destSize,
22051cb0ef41Sopenharmony_ci                   uint16_t options,
22061cb0ef41Sopenharmony_ci                   UErrorCode *pErrorCode);
22071cb0ef41Sopenharmony_ci
22081cb0ef41Sopenharmony_ci/*#define BIDI_SAMPLE_CODE*/
22091cb0ef41Sopenharmony_ci/*@}*/
22101cb0ef41Sopenharmony_ci
22111cb0ef41Sopenharmony_ci#endif
2212