Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/ubidi.h
38827 views
/*1******************************************************************************2*3* Copyright (C) 1999-2013, International Business Machines4* Corporation and others. All Rights Reserved.5*6******************************************************************************7* file name: ubidi.h8* encoding: US-ASCII9* tab size: 8 (not used)10* indentation:411*12* created on: 1999jul2713* created by: Markus W. Scherer, updated by Matitiahu Allouche14*/1516#ifndef UBIDI_H17#define UBIDI_H1819#include "unicode/utypes.h"20#include "unicode/uchar.h"21#include "unicode/localpointer.h"2223/**24*\file25* \brief C API: Bidi algorithm26*27* <h2>Bidi algorithm for ICU</h2>28*29* This is an implementation of the Unicode Bidirectional Algorithm.30* The algorithm is defined in the31* <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.<p>32*33* Note: Libraries that perform a bidirectional algorithm and34* reorder strings accordingly are sometimes called "Storage Layout Engines".35* ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such36* "Storage Layout Engines".37*38* <h3>General remarks about the API:</h3>39*40* In functions with an error code parameter,41* the <code>pErrorCode</code> pointer must be valid42* and the value that it points to must not indicate a failure before43* the function call. Otherwise, the function returns immediately.44* After the function call, the value indicates success or failure.<p>45*46* The "limit" of a sequence of characters is the position just after their47* last character, i.e., one more than that position.<p>48*49* Some of the API functions provide access to "runs".50* Such a "run" is defined as a sequence of characters51* that are at the same embedding level52* after performing the Bidi algorithm.<p>53*54* @author Markus W. Scherer55* @version 1.056*57*58* <h4> Sample code for the ICU Bidi API </h4>59*60* <h5>Rendering a paragraph with the ICU Bidi API</h5>61*62* This is (hypothetical) sample code that illustrates63* how the ICU Bidi API could be used to render a paragraph of text.64* Rendering code depends highly on the graphics system,65* therefore this sample code must make a lot of assumptions,66* which may or may not match any existing graphics system's properties.67*68* <p>The basic assumptions are:</p>69* <ul>70* <li>Rendering is done from left to right on a horizontal line.</li>71* <li>A run of single-style, unidirectional text can be rendered at once.</li>72* <li>Such a run of text is passed to the graphics system with73* characters (code units) in logical order.</li>74* <li>The line-breaking algorithm is very complicated75* and Locale-dependent -76* and therefore its implementation omitted from this sample code.</li>77* </ul>78*79* <pre>80* \code81*#include "unicode/ubidi.h"82*83*typedef enum {84* styleNormal=0, styleSelected=1,85* styleBold=2, styleItalics=4,86* styleSuper=8, styleSub=1687*} Style;88*89*typedef struct { int32_t limit; Style style; } StyleRun;90*91*int getTextWidth(const UChar *text, int32_t start, int32_t limit,92* const StyleRun *styleRuns, int styleRunCount);93*94* // set *pLimit and *pStyleRunLimit for a line95* // from text[start] and from styleRuns[styleRunStart]96* // using ubidi_getLogicalRun(para, ...)97*void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,98* UBiDi *para,99* const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,100* int *pLineWidth);101*102* // render runs on a line sequentially, always from left to right103*104* // prepare rendering a new line105* void startLine(UBiDiDirection textDirection, int lineWidth);106*107* // render a run of text and advance to the right by the run width108* // the text[start..limit-1] is always in logical order109* void renderRun(const UChar *text, int32_t start, int32_t limit,110* UBiDiDirection textDirection, Style style);111*112* // We could compute a cross-product113* // from the style runs with the directional runs114* // and then reorder it.115* // Instead, here we iterate over each run type116* // and render the intersections -117* // with shortcuts in simple (and common) cases.118* // renderParagraph() is the main function.119*120* // render a directional run with121* // (possibly) multiple style runs intersecting with it122* void renderDirectionalRun(const UChar *text,123* int32_t start, int32_t limit,124* UBiDiDirection direction,125* const StyleRun *styleRuns, int styleRunCount) {126* int i;127*128* // iterate over style runs129* if(direction==UBIDI_LTR) {130* int styleLimit;131*132* for(i=0; i<styleRunCount; ++i) {133* styleLimit=styleRun[i].limit;134* if(start<styleLimit) {135* if(styleLimit>limit) { styleLimit=limit; }136* renderRun(text, start, styleLimit,137* direction, styleRun[i].style);138* if(styleLimit==limit) { break; }139* start=styleLimit;140* }141* }142* } else {143* int styleStart;144*145* for(i=styleRunCount-1; i>=0; --i) {146* if(i>0) {147* styleStart=styleRun[i-1].limit;148* } else {149* styleStart=0;150* }151* if(limit>=styleStart) {152* if(styleStart<start) { styleStart=start; }153* renderRun(text, styleStart, limit,154* direction, styleRun[i].style);155* if(styleStart==start) { break; }156* limit=styleStart;157* }158* }159* }160* }161*162* // the line object represents text[start..limit-1]163* void renderLine(UBiDi *line, const UChar *text,164* int32_t start, int32_t limit,165* const StyleRun *styleRuns, int styleRunCount) {166* UBiDiDirection direction=ubidi_getDirection(line);167* if(direction!=UBIDI_MIXED) {168* // unidirectional169* if(styleRunCount<=1) {170* renderRun(text, start, limit, direction, styleRuns[0].style);171* } else {172* renderDirectionalRun(text, start, limit,173* direction, styleRuns, styleRunCount);174* }175* } else {176* // mixed-directional177* int32_t count, i, length;178* UBiDiLevel level;179*180* count=ubidi_countRuns(para, pErrorCode);181* if(U_SUCCESS(*pErrorCode)) {182* if(styleRunCount<=1) {183* Style style=styleRuns[0].style;184*185* // iterate over directional runs186* for(i=0; i<count; ++i) {187* direction=ubidi_getVisualRun(para, i, &start, &length);188* renderRun(text, start, start+length, direction, style);189* }190* } else {191* int32_t j;192*193* // iterate over both directional and style runs194* for(i=0; i<count; ++i) {195* direction=ubidi_getVisualRun(line, i, &start, &length);196* renderDirectionalRun(text, start, start+length,197* direction, styleRuns, styleRunCount);198* }199* }200* }201* }202* }203*204*void renderParagraph(const UChar *text, int32_t length,205* UBiDiDirection textDirection,206* const StyleRun *styleRuns, int styleRunCount,207* int lineWidth,208* UErrorCode *pErrorCode) {209* UBiDi *para;210*211* if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {212* return;213* }214*215* para=ubidi_openSized(length, 0, pErrorCode);216* if(para==NULL) { return; }217*218* ubidi_setPara(para, text, length,219* textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,220* NULL, pErrorCode);221* if(U_SUCCESS(*pErrorCode)) {222* UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);223* StyleRun styleRun={ length, styleNormal };224* int width;225*226* if(styleRuns==NULL || styleRunCount<=0) {227* styleRunCount=1;228* styleRuns=&styleRun;229* }230*231* // assume styleRuns[styleRunCount-1].limit>=length232*233* width=getTextWidth(text, 0, length, styleRuns, styleRunCount);234* if(width<=lineWidth) {235* // everything fits onto one line236*237* // prepare rendering a new line from either left or right238* startLine(paraLevel, width);239*240* renderLine(para, text, 0, length,241* styleRuns, styleRunCount);242* } else {243* UBiDi *line;244*245* // we need to render several lines246* line=ubidi_openSized(length, 0, pErrorCode);247* if(line!=NULL) {248* int32_t start=0, limit;249* int styleRunStart=0, styleRunLimit;250*251* for(;;) {252* limit=length;253* styleRunLimit=styleRunCount;254* getLineBreak(text, start, &limit, para,255* styleRuns, styleRunStart, &styleRunLimit,256* &width);257* ubidi_setLine(para, start, limit, line, pErrorCode);258* if(U_SUCCESS(*pErrorCode)) {259* // prepare rendering a new line260* // from either left or right261* startLine(paraLevel, width);262*263* renderLine(line, text, start, limit,264* styleRuns+styleRunStart,265* styleRunLimit-styleRunStart);266* }267* if(limit==length) { break; }268* start=limit;269* styleRunStart=styleRunLimit-1;270* if(start>=styleRuns[styleRunStart].limit) {271* ++styleRunStart;272* }273* }274*275* ubidi_close(line);276* }277* }278* }279*280* ubidi_close(para);281*}282*\endcode283* </pre>284*/285286/*DOCXX_TAG*/287/*@{*/288289/**290* UBiDiLevel is the type of the level values in this291* Bidi implementation.292* It holds an embedding level and indicates the visual direction293* by its bit 0 (even/odd value).<p>294*295* It can also hold non-level values for the296* <code>paraLevel</code> and <code>embeddingLevels</code>297* arguments of <code>ubidi_setPara()</code>; there:298* <ul>299* <li>bit 7 of an <code>embeddingLevels[]</code>300* value indicates whether the using application is301* specifying the level of a character to <i>override</i> whatever the302* Bidi implementation would resolve it to.</li>303* <li><code>paraLevel</code> can be set to the304* pseudo-level values <code>UBIDI_DEFAULT_LTR</code>305* and <code>UBIDI_DEFAULT_RTL</code>.</li>306* </ul>307*308* @see ubidi_setPara309*310* <p>The related constants are not real, valid level values.311* <code>UBIDI_DEFAULT_XXX</code> can be used to specify312* a default for the paragraph level for313* when the <code>ubidi_setPara()</code> function314* shall determine it but there is no315* strongly typed character in the input.<p>316*317* Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even318* and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,319* just like with normal LTR and RTL level values -320* these special values are designed that way. Also, the implementation321* assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.322*323* @see UBIDI_DEFAULT_LTR324* @see UBIDI_DEFAULT_RTL325* @see UBIDI_LEVEL_OVERRIDE326* @see UBIDI_MAX_EXPLICIT_LEVEL327* @stable ICU 2.0328*/329typedef uint8_t UBiDiLevel;330331/** Paragraph level setting.<p>332*333* Constant indicating that the base direction depends on the first strong334* directional character in the text according to the Unicode Bidirectional335* Algorithm. If no strong directional character is present,336* then set the paragraph level to 0 (left-to-right).<p>337*338* If this value is used in conjunction with reordering modes339* <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or340* <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder341* is assumed to be visual LTR, and the text after reordering is required342* to be the corresponding logical string with appropriate contextual343* direction. The direction of the result string will be RTL if either344* the righmost or leftmost strong character of the source text is RTL345* or Arabic Letter, the direction will be LTR otherwise.<p>346*347* If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may348* be added at the beginning of the result string to ensure round trip349* (that the result string, when reordered back to visual, will produce350* the original source text).351* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT352* @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL353* @stable ICU 2.0354*/355#define UBIDI_DEFAULT_LTR 0xfe356357/** Paragraph level setting.<p>358*359* Constant indicating that the base direction depends on the first strong360* directional character in the text according to the Unicode Bidirectional361* Algorithm. If no strong directional character is present,362* then set the paragraph level to 1 (right-to-left).<p>363*364* If this value is used in conjunction with reordering modes365* <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or366* <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder367* is assumed to be visual LTR, and the text after reordering is required368* to be the corresponding logical string with appropriate contextual369* direction. The direction of the result string will be RTL if either370* the righmost or leftmost strong character of the source text is RTL371* or Arabic Letter, or if the text contains no strong character;372* the direction will be LTR otherwise.<p>373*374* If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may375* be added at the beginning of the result string to ensure round trip376* (that the result string, when reordered back to visual, will produce377* the original source text).378* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT379* @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL380* @stable ICU 2.0381*/382#define UBIDI_DEFAULT_RTL 0xff383384/**385* Maximum explicit embedding level.386* (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).387* @stable ICU 2.0388*/389#define UBIDI_MAX_EXPLICIT_LEVEL 125390391/** Bit flag for level input.392* Overrides directional properties.393* @stable ICU 2.0394*/395#define UBIDI_LEVEL_OVERRIDE 0x80396397/**398* Special value which can be returned by the mapping functions when a logical399* index has no corresponding visual index or vice-versa. This may happen400* for the logical-to-visual mapping of a Bidi control when option401* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is specified. This can also happen402* for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted403* by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.404* @see ubidi_getVisualIndex405* @see ubidi_getVisualMap406* @see ubidi_getLogicalIndex407* @see ubidi_getLogicalMap408* @stable ICU 3.6409*/410#define UBIDI_MAP_NOWHERE (-1)411412/**413* <code>UBiDiDirection</code> values indicate the text direction.414* @stable ICU 2.0415*/416enum UBiDiDirection {417/** Left-to-right text. This is a 0 value.418* <ul>419* <li>As return value for <code>ubidi_getDirection()</code>, it means420* that the source string contains no right-to-left characters, or421* that the source string is empty and the paragraph level is even.422* <li> As return value for <code>ubidi_getBaseDirection()</code>, it423* means that the first strong character of the source string has424* a left-to-right direction.425* </ul>426* @stable ICU 2.0427*/428UBIDI_LTR,429/** Right-to-left text. This is a 1 value.430* <ul>431* <li>As return value for <code>ubidi_getDirection()</code>, it means432* that the source string contains no left-to-right characters, or433* that the source string is empty and the paragraph level is odd.434* <li> As return value for <code>ubidi_getBaseDirection()</code>, it435* means that the first strong character of the source string has436* a right-to-left direction.437* </ul>438* @stable ICU 2.0439*/440UBIDI_RTL,441/** Mixed-directional text.442* <p>As return value for <code>ubidi_getDirection()</code>, it means443* that the source string contains both left-to-right and444* right-to-left characters.445* @stable ICU 2.0446*/447UBIDI_MIXED,448/** No strongly directional text.449* <p>As return value for <code>ubidi_getBaseDirection()</code>, it means450* that the source string is missing or empty, or contains neither left-to-right451* nor right-to-left characters.452* @stable ICU 4.6453*/454UBIDI_NEUTRAL455};456457/** @stable ICU 2.0 */458typedef enum UBiDiDirection UBiDiDirection;459460/**461* Forward declaration of the <code>UBiDi</code> structure for the declaration of462* the API functions. Its fields are implementation-specific.<p>463* This structure holds information about a paragraph (or multiple paragraphs)464* of text with Bidi-algorithm-related details, or about one line of465* such a paragraph.<p>466* Reordering can be done on a line, or on one or more paragraphs which are467* then interpreted each as one single line.468* @stable ICU 2.0469*/470struct UBiDi;471472/** @stable ICU 2.0 */473typedef struct UBiDi UBiDi;474475/**476* Allocate a <code>UBiDi</code> structure.477* Such an object is initially empty. It is assigned478* the Bidi properties of a piece of text containing one or more paragraphs479* by <code>ubidi_setPara()</code>480* or the Bidi properties of a line within a paragraph by481* <code>ubidi_setLine()</code>.<p>482* This object can be reused for as long as it is not deallocated483* by calling <code>ubidi_close()</code>.<p>484* <code>ubidi_setPara()</code> and <code>ubidi_setLine()</code> will allocate485* additional memory for internal structures as necessary.486*487* @return An empty <code>UBiDi</code> object.488* @stable ICU 2.0489*/490U_STABLE UBiDi * U_EXPORT2491ubidi_open(void);492493/**494* Allocate a <code>UBiDi</code> structure with preallocated memory495* for internal structures.496* This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>497* with no arguments, but it also preallocates memory for internal structures498* according to the sizings supplied by the caller.<p>499* Subsequent functions will not allocate any more memory, and are thus500* guaranteed not to fail because of lack of memory.<p>501* The preallocation can be limited to some of the internal memory502* by setting some values to 0 here. That means that if, e.g.,503* <code>maxRunCount</code> cannot be reasonably predetermined and should not504* be set to <code>maxLength</code> (the only failproof value) to avoid505* wasting memory, then <code>maxRunCount</code> could be set to 0 here506* and the internal structures that are associated with it will be allocated507* on demand, just like with <code>ubidi_open()</code>.508*509* @param maxLength is the maximum text or line length that internal memory510* will be preallocated for. An attempt to associate this object with a511* longer text will fail, unless this value is 0, which leaves the allocation512* up to the implementation.513*514* @param maxRunCount is the maximum anticipated number of same-level runs515* that internal memory will be preallocated for. An attempt to access516* visual runs on an object that was not preallocated for as many runs517* as the text was actually resolved to will fail,518* unless this value is 0, which leaves the allocation up to the implementation.<br><br>519* The number of runs depends on the actual text and maybe anywhere between520* 1 and <code>maxLength</code>. It is typically small.521*522* @param pErrorCode must be a valid pointer to an error code value.523*524* @return An empty <code>UBiDi</code> object with preallocated memory.525* @stable ICU 2.0526*/527U_STABLE UBiDi * U_EXPORT2528ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);529530/**531* <code>ubidi_close()</code> must be called to free the memory532* associated with a UBiDi object.<p>533*534* <strong>Important: </strong>535* A parent <code>UBiDi</code> object must not be destroyed or reused if536* it still has children.537* If a <code>UBiDi</code> object has become the <i>child</i>538* of another one (its <i>parent</i>) by calling539* <code>ubidi_setLine()</code>, then the child object must540* be destroyed (closed) or reused (by calling541* <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)542* before the parent object.543*544* @param pBiDi is a <code>UBiDi</code> object.545*546* @see ubidi_setPara547* @see ubidi_setLine548* @stable ICU 2.0549*/550U_STABLE void U_EXPORT2551ubidi_close(UBiDi *pBiDi);552553#if U_SHOW_CPLUSPLUS_API554555U_NAMESPACE_BEGIN556557/**558* \class LocalUBiDiPointer559* "Smart pointer" class, closes a UBiDi via ubidi_close().560* For most methods see the LocalPointerBase base class.561*562* @see LocalPointerBase563* @see LocalPointer564* @stable ICU 4.4565*/566U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);567568U_NAMESPACE_END569570#endif571572/**573* Modify the operation of the Bidi algorithm such that it574* approximates an "inverse Bidi" algorithm. This function575* must be called before <code>ubidi_setPara()</code>.576*577* <p>The normal operation of the Bidi algorithm as described578* in the Unicode Technical Report is to take text stored in logical579* (keyboard, typing) order and to determine the reordering of it for visual580* rendering.581* Some legacy systems store text in visual order, and for operations582* with standard, Unicode-based algorithms, the text needs to be transformed583* to logical order. This is effectively the inverse algorithm of the584* described Bidi algorithm. Note that there is no standard algorithm for585* this "inverse Bidi" and that the current implementation provides only an586* approximation of "inverse Bidi".</p>587*588* <p>With <code>isInverse</code> set to <code>TRUE</code>,589* this function changes the behavior of some of the subsequent functions590* in a way that they can be used for the inverse Bidi algorithm.591* Specifically, runs of text with numeric characters will be treated in a592* special way and may need to be surrounded with LRM characters when they are593* written in reordered sequence.</p>594*595* <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.596* Since the actual input for "inverse Bidi" is visually ordered text and597* <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually598* the runs of the logically ordered output.</p>599*600* <p>Calling this function with argument <code>isInverse</code> set to601* <code>TRUE</code> is equivalent to calling602* <code>ubidi_setReorderingMode</code> with argument603* <code>reorderingMode</code>604* set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>605* Calling this function with argument <code>isInverse</code> set to606* <code>FALSE</code> is equivalent to calling607* <code>ubidi_setReorderingMode</code> with argument608* <code>reorderingMode</code>609* set to <code>#UBIDI_REORDER_DEFAULT</code>.610*611* @param pBiDi is a <code>UBiDi</code> object.612*613* @param isInverse specifies "forward" or "inverse" Bidi operation.614*615* @see ubidi_setPara616* @see ubidi_writeReordered617* @see ubidi_setReorderingMode618* @stable ICU 2.0619*/620U_STABLE void U_EXPORT2621ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);622623/**624* Is this Bidi object set to perform the inverse Bidi algorithm?625* <p>Note: calling this function after setting the reordering mode with626* <code>ubidi_setReorderingMode</code> will return <code>TRUE</code> if the627* reordering mode was set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>,628* <code>FALSE</code> for all other values.</p>629*630* @param pBiDi is a <code>UBiDi</code> object.631* @return TRUE if the Bidi object is set to perform the inverse Bidi algorithm632* by handling numbers as L.633*634* @see ubidi_setInverse635* @see ubidi_setReorderingMode636* @stable ICU 2.0637*/638639U_STABLE UBool U_EXPORT2640ubidi_isInverse(UBiDi *pBiDi);641642/**643* Specify whether block separators must be allocated level zero,644* so that successive paragraphs will progress from left to right.645* This function must be called before <code>ubidi_setPara()</code>.646* Paragraph separators (B) may appear in the text. Setting them to level zero647* means that all paragraph separators (including one possibly appearing648* in the last text position) are kept in the reordered text after the text649* that they follow in the source text.650* When this feature is not enabled, a paragraph separator at the last651* position of the text before reordering will go to the first position652* of the reordered text when the paragraph level is odd.653*654* @param pBiDi is a <code>UBiDi</code> object.655*656* @param orderParagraphsLTR specifies whether paragraph separators (B) must657* receive level 0, so that successive paragraphs progress from left to right.658*659* @see ubidi_setPara660* @stable ICU 3.4661*/662U_STABLE void U_EXPORT2663ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);664665/**666* Is this Bidi object set to allocate level 0 to block separators so that667* successive paragraphs progress from left to right?668*669* @param pBiDi is a <code>UBiDi</code> object.670* @return TRUE if the Bidi object is set to allocate level 0 to block671* separators.672*673* @see ubidi_orderParagraphsLTR674* @stable ICU 3.4675*/676U_STABLE UBool U_EXPORT2677ubidi_isOrderParagraphsLTR(UBiDi *pBiDi);678679/**680* <code>UBiDiReorderingMode</code> values indicate which variant of the Bidi681* algorithm to use.682*683* @see ubidi_setReorderingMode684* @stable ICU 3.6685*/686typedef enum UBiDiReorderingMode {687/** Regular Logical to Visual Bidi algorithm according to Unicode.688* This is a 0 value.689* @stable ICU 3.6 */690UBIDI_REORDER_DEFAULT = 0,691/** Logical to Visual algorithm which handles numbers in a way which692* mimicks the behavior of Windows XP.693* @stable ICU 3.6 */694UBIDI_REORDER_NUMBERS_SPECIAL,695/** Logical to Visual algorithm grouping numbers with adjacent R characters696* (reversible algorithm).697* @stable ICU 3.6 */698UBIDI_REORDER_GROUP_NUMBERS_WITH_R,699/** Reorder runs only to transform a Logical LTR string to the Logical RTL700* string with the same display, or vice-versa.<br>701* If this mode is set together with option702* <code>#UBIDI_OPTION_INSERT_MARKS</code>, some Bidi controls in the source703* text may be removed and other controls may be added to produce the704* minimum combination which has the required display.705* @stable ICU 3.6 */706UBIDI_REORDER_RUNS_ONLY,707/** Visual to Logical algorithm which handles numbers like L708* (same algorithm as selected by <code>ubidi_setInverse(TRUE)</code>.709* @see ubidi_setInverse710* @stable ICU 3.6 */711UBIDI_REORDER_INVERSE_NUMBERS_AS_L,712/** Visual to Logical algorithm equivalent to the regular Logical to Visual713* algorithm.714* @stable ICU 3.6 */715UBIDI_REORDER_INVERSE_LIKE_DIRECT,716/** Inverse Bidi (Visual to Logical) algorithm for the717* <code>UBIDI_REORDER_NUMBERS_SPECIAL</code> Bidi algorithm.718* @stable ICU 3.6 */719UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,720/** Number of values for reordering mode.721* @stable ICU 3.6 */722UBIDI_REORDER_COUNT723} UBiDiReorderingMode;724725/**726* Modify the operation of the Bidi algorithm such that it implements some727* variant to the basic Bidi algorithm or approximates an "inverse Bidi"728* algorithm, depending on different values of the "reordering mode".729* This function must be called before <code>ubidi_setPara()</code>, and stays730* in effect until called again with a different argument.731*732* <p>The normal operation of the Bidi algorithm as described733* in the Unicode Standard Annex #9 is to take text stored in logical734* (keyboard, typing) order and to determine how to reorder it for visual735* rendering.</p>736*737* <p>With the reordering mode set to a value other than738* <code>#UBIDI_REORDER_DEFAULT</code>, this function changes the behavior of739* some of the subsequent functions in a way such that they implement an740* inverse Bidi algorithm or some other algorithm variants.</p>741*742* <p>Some legacy systems store text in visual order, and for operations743* with standard, Unicode-based algorithms, the text needs to be transformed744* into logical order. This is effectively the inverse algorithm of the745* described Bidi algorithm. Note that there is no standard algorithm for746* this "inverse Bidi", so a number of variants are implemented here.</p>747*748* <p>In other cases, it may be desirable to emulate some variant of the749* Logical to Visual algorithm (e.g. one used in MS Windows), or perform a750* Logical to Logical transformation.</p>751*752* <ul>753* <li>When the reordering mode is set to <code>#UBIDI_REORDER_DEFAULT</code>,754* the standard Bidi Logical to Visual algorithm is applied.</li>755*756* <li>When the reordering mode is set to757* <code>#UBIDI_REORDER_NUMBERS_SPECIAL</code>,758* the algorithm used to perform Bidi transformations when calling759* <code>ubidi_setPara</code> should approximate the algorithm used in760* Microsoft Windows XP rather than strictly conform to the Unicode Bidi761* algorithm.762* <br>763* The differences between the basic algorithm and the algorithm addressed764* by this option are as follows:765* <ul>766* <li>Within text at an even embedding level, the sequence "123AB"767* (where AB represent R or AL letters) is transformed to "123BA" by the768* Unicode algorithm and to "BA123" by the Windows algorithm.</li>769* <li>Arabic-Indic numbers (AN) are handled by the Windows algorithm just770* like regular numbers (EN).</li>771* </ul></li>772*773* <li>When the reordering mode is set to774* <code>#UBIDI_REORDER_GROUP_NUMBERS_WITH_R</code>,775* numbers located between LTR text and RTL text are associated with the RTL776* text. For instance, an LTR paragraph with content "abc 123 DEF" (where777* upper case letters represent RTL characters) will be transformed to778* "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed779* to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".780* This makes the algorithm reversible and makes it useful when round trip781* (from visual to logical and back to visual) must be achieved without782* adding LRM characters. However, this is a variation from the standard783* Unicode Bidi algorithm.<br>784* The source text should not contain Bidi control characters other than LRM785* or RLM.</li>786*787* <li>When the reordering mode is set to788* <code>#UBIDI_REORDER_RUNS_ONLY</code>,789* a "Logical to Logical" transformation must be performed:790* <ul>791* <li>If the default text level of the source text (argument <code>paraLevel</code>792* in <code>ubidi_setPara</code>) is even, the source text will be handled as793* LTR logical text and will be transformed to the RTL logical text which has794* the same LTR visual display.</li>795* <li>If the default level of the source text is odd, the source text796* will be handled as RTL logical text and will be transformed to the797* LTR logical text which has the same LTR visual display.</li>798* </ul>799* This mode may be needed when logical text which is basically Arabic or800* Hebrew, with possible included numbers or phrases in English, has to be801* displayed as if it had an even embedding level (this can happen if the802* displaying application treats all text as if it was basically LTR).803* <br>804* This mode may also be needed in the reverse case, when logical text which is805* basically English, with possible included phrases in Arabic or Hebrew, has to806* be displayed as if it had an odd embedding level.807* <br>808* Both cases could be handled by adding LRE or RLE at the head of the text,809* if the display subsystem supports these formatting controls. If it does not,810* the problem may be handled by transforming the source text in this mode811* before displaying it, so that it will be displayed properly.<br>812* The source text should not contain Bidi control characters other than LRM813* or RLM.</li>814*815* <li>When the reordering mode is set to816* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>, an "inverse Bidi" algorithm817* is applied.818* Runs of text with numeric characters will be treated like LTR letters and819* may need to be surrounded with LRM characters when they are written in820* reordered sequence (the option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> can821* be used with function <code>ubidi_writeReordered</code> to this end. This822* mode is equivalent to calling <code>ubidi_setInverse()</code> with823* argument <code>isInverse</code> set to <code>TRUE</code>.</li>824*825* <li>When the reordering mode is set to826* <code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code>, the "direct" Logical to Visual827* Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.828* This mode is similar to mode <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>829* but is closer to the regular Bidi algorithm.830* <br>831* For example, an LTR paragraph with the content "FED 123 456 CBA" (where832* upper case represents RTL characters) will be transformed to833* "ABC 456 123 DEF", as opposed to "DEF 123 456 ABC"834* with mode <code>UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>835* When used in conjunction with option836* <code>#UBIDI_OPTION_INSERT_MARKS</code>, this mode generally837* adds Bidi marks to the output significantly more sparingly than mode838* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> with option839* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to840* <code>ubidi_writeReordered</code>.</li>841*842* <li>When the reordering mode is set to843* <code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the Logical to Visual844* Bidi algorithm used in Windows XP is used as an approximation of an "inverse Bidi" algorithm.845* <br>846* For example, an LTR paragraph with the content "abc FED123" (where847* upper case represents RTL characters) will be transformed to "abc 123DEF."</li>848* </ul>849*850* <p>In all the reordering modes specifying an "inverse Bidi" algorithm851* (i.e. those with a name starting with <code>UBIDI_REORDER_INVERSE</code>),852* output runs should be retrieved using853* <code>ubidi_getVisualRun()</code>, and the output text with854* <code>ubidi_writeReordered()</code>. The caller should keep in mind that in855* "inverse Bidi" modes the input is actually visually ordered text and856* reordered output returned by <code>ubidi_getVisualRun()</code> or857* <code>ubidi_writeReordered()</code> are actually runs or character string858* of logically ordered output.<br>859* For all the "inverse Bidi" modes, the source text should not contain860* Bidi control characters other than LRM or RLM.</p>861*862* <p>Note that option <code>#UBIDI_OUTPUT_REVERSE</code> of863* <code>ubidi_writeReordered</code> has no useful meaning and should not be864* used in conjunction with any value of the reordering mode specifying865* "inverse Bidi" or with value <code>UBIDI_REORDER_RUNS_ONLY</code>.866*867* @param pBiDi is a <code>UBiDi</code> object.868* @param reorderingMode specifies the required variant of the Bidi algorithm.869*870* @see UBiDiReorderingMode871* @see ubidi_setInverse872* @see ubidi_setPara873* @see ubidi_writeReordered874* @stable ICU 3.6875*/876U_STABLE void U_EXPORT2877ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);878879/**880* What is the requested reordering mode for a given Bidi object?881*882* @param pBiDi is a <code>UBiDi</code> object.883* @return the current reordering mode of the Bidi object884* @see ubidi_setReorderingMode885* @stable ICU 3.6886*/887U_STABLE UBiDiReorderingMode U_EXPORT2888ubidi_getReorderingMode(UBiDi *pBiDi);889890/**891* <code>UBiDiReorderingOption</code> values indicate which options are892* specified to affect the Bidi algorithm.893*894* @see ubidi_setReorderingOptions895* @stable ICU 3.6896*/897typedef enum UBiDiReorderingOption {898/**899* option value for <code>ubidi_setReorderingOptions</code>:900* disable all the options which can be set with this function901* @see ubidi_setReorderingOptions902* @stable ICU 3.6903*/904UBIDI_OPTION_DEFAULT = 0,905906/**907* option bit for <code>ubidi_setReorderingOptions</code>:908* insert Bidi marks (LRM or RLM) when needed to ensure correct result of909* a reordering to a Logical order910*911* <p>This option must be set or reset before calling912* <code>ubidi_setPara</code>.</p>913*914* <p>This option is significant only with reordering modes which generate915* a result with Logical order, specifically:</p>916* <ul>917* <li><code>#UBIDI_REORDER_RUNS_ONLY</code></li>918* <li><code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code></li>919* <li><code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code></li>920* <li><code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code></li>921* </ul>922*923* <p>If this option is set in conjunction with reordering mode924* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> or with calling925* <code>ubidi_setInverse(TRUE)</code>, it implies926* option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>927* in calls to function <code>ubidi_writeReordered()</code>.</p>928*929* <p>For other reordering modes, a minimum number of LRM or RLM characters930* will be added to the source text after reordering it so as to ensure931* round trip, i.e. when applying the inverse reordering mode on the932* resulting logical text with removal of Bidi marks933* (option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> set before calling934* <code>ubidi_setPara()</code> or option <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>935* in <code>ubidi_writeReordered</code>), the result will be identical to the936* source text in the first transformation.937*938* <p>This option will be ignored if specified together with option939* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>. It inhibits option940* <code>UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to function941* <code>ubidi_writeReordered()</code> and it implies option942* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to function943* <code>ubidi_writeReordered()</code> if the reordering mode is944* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.</p>945*946* @see ubidi_setReorderingMode947* @see ubidi_setReorderingOptions948* @stable ICU 3.6949*/950UBIDI_OPTION_INSERT_MARKS = 1,951952/**953* option bit for <code>ubidi_setReorderingOptions</code>:954* remove Bidi control characters955*956* <p>This option must be set or reset before calling957* <code>ubidi_setPara</code>.</p>958*959* <p>This option nullifies option <code>#UBIDI_OPTION_INSERT_MARKS</code>.960* It inhibits option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls961* to function <code>ubidi_writeReordered()</code> and it implies option962* <code>#UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to that function.</p>963*964* @see ubidi_setReorderingMode965* @see ubidi_setReorderingOptions966* @stable ICU 3.6967*/968UBIDI_OPTION_REMOVE_CONTROLS = 2,969970/**971* option bit for <code>ubidi_setReorderingOptions</code>:972* process the output as part of a stream to be continued973*974* <p>This option must be set or reset before calling975* <code>ubidi_setPara</code>.</p>976*977* <p>This option specifies that the caller is interested in processing large978* text object in parts.979* The results of the successive calls are expected to be concatenated by the980* caller. Only the call for the last part will have this option bit off.</p>981*982* <p>When this option bit is on, <code>ubidi_setPara()</code> may process983* less than the full source text in order to truncate the text at a meaningful984* boundary. The caller should call <code>ubidi_getProcessedLength()</code>985* immediately after calling <code>ubidi_setPara()</code> in order to986* determine how much of the source text has been processed.987* Source text beyond that length should be resubmitted in following calls to988* <code>ubidi_setPara</code>. The processed length may be less than989* the length of the source text if a character preceding the last character of990* the source text constitutes a reasonable boundary (like a block separator)991* for text to be continued.<br>992* If the last character of the source text constitutes a reasonable993* boundary, the whole text will be processed at once.<br>994* If nowhere in the source text there exists995* such a reasonable boundary, the processed length will be zero.<br>996* The caller should check for such an occurrence and do one of the following:997* <ul><li>submit a larger amount of text with a better chance to include998* a reasonable boundary.</li>999* <li>resubmit the same text after turning off option1000* <code>UBIDI_OPTION_STREAMING</code>.</li></ul>1001* In all cases, this option should be turned off before processing the last1002* part of the text.</p>1003*1004* <p>When the <code>UBIDI_OPTION_STREAMING</code> option is used,1005* it is recommended to call <code>ubidi_orderParagraphsLTR()</code> with1006* argument <code>orderParagraphsLTR</code> set to <code>TRUE</code> before1007* calling <code>ubidi_setPara</code> so that later paragraphs may be1008* concatenated to previous paragraphs on the right.</p>1009*1010* @see ubidi_setReorderingMode1011* @see ubidi_setReorderingOptions1012* @see ubidi_getProcessedLength1013* @see ubidi_orderParagraphsLTR1014* @stable ICU 3.61015*/1016UBIDI_OPTION_STREAMING = 41017} UBiDiReorderingOption;10181019/**1020* Specify which of the reordering options1021* should be applied during Bidi transformations.1022*1023* @param pBiDi is a <code>UBiDi</code> object.1024* @param reorderingOptions is a combination of zero or more of the following1025* options:1026* <code>#UBIDI_OPTION_DEFAULT</code>, <code>#UBIDI_OPTION_INSERT_MARKS</code>,1027* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>, <code>#UBIDI_OPTION_STREAMING</code>.1028*1029* @see ubidi_getReorderingOptions1030* @stable ICU 3.61031*/1032U_STABLE void U_EXPORT21033ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);10341035/**1036* What are the reordering options applied to a given Bidi object?1037*1038* @param pBiDi is a <code>UBiDi</code> object.1039* @return the current reordering options of the Bidi object1040* @see ubidi_setReorderingOptions1041* @stable ICU 3.61042*/1043U_STABLE uint32_t U_EXPORT21044ubidi_getReorderingOptions(UBiDi *pBiDi);10451046/**1047* Set the context before a call to ubidi_setPara().<p>1048*1049* ubidi_setPara() computes the left-right directionality for a given piece1050* of text which is supplied as one of its arguments. Sometimes this piece1051* of text (the "main text") should be considered in context, because text1052* appearing before ("prologue") and/or after ("epilogue") the main text1053* may affect the result of this computation.<p>1054*1055* This function specifies the prologue and/or the epilogue for the next1056* call to ubidi_setPara(). The characters specified as prologue and1057* epilogue should not be modified by the calling program until the call1058* to ubidi_setPara() has returned. If successive calls to ubidi_setPara()1059* all need specification of a context, ubidi_setContext() must be called1060* before each call to ubidi_setPara(). In other words, a context is not1061* "remembered" after the following successful call to ubidi_setPara().<p>1062*1063* If a call to ubidi_setPara() specifies UBIDI_DEFAULT_LTR or1064* UBIDI_DEFAULT_RTL as paraLevel and is preceded by a call to1065* ubidi_setContext() which specifies a prologue, the paragraph level will1066* be computed taking in consideration the text in the prologue.<p>1067*1068* When ubidi_setPara() is called without a previous call to1069* ubidi_setContext, the main text is handled as if preceded and followed1070* by strong directional characters at the current paragraph level.1071* Calling ubidi_setContext() with specification of a prologue will change1072* this behavior by handling the main text as if preceded by the last1073* strong character appearing in the prologue, if any.1074* Calling ubidi_setContext() with specification of an epilogue will change1075* the behavior of ubidi_setPara() by handling the main text as if followed1076* by the first strong character or digit appearing in the epilogue, if any.<p>1077*1078* Note 1: if <code>ubidi_setContext</code> is called repeatedly without1079* calling <code>ubidi_setPara</code>, the earlier calls have no effect,1080* only the last call will be remembered for the next call to1081* <code>ubidi_setPara</code>.<p>1082*1083* Note 2: calling <code>ubidi_setContext(pBiDi, NULL, 0, NULL, 0, &errorCode)</code>1084* cancels any previous setting of non-empty prologue or epilogue.1085* The next call to <code>ubidi_setPara()</code> will process no1086* prologue or epilogue.<p>1087*1088* Note 3: users must be aware that even after setting the context1089* before a call to ubidi_setPara() to perform e.g. a logical to visual1090* transformation, the resulting string may not be identical to what it1091* would have been if all the text, including prologue and epilogue, had1092* been processed together.<br>1093* Example (upper case letters represent RTL characters):<br>1094* prologue = "<code>abc DE</code>"<br>1095* epilogue = none<br>1096* main text = "<code>FGH xyz</code>"<br>1097* paraLevel = UBIDI_LTR<br>1098* display without prologue = "<code>HGF xyz</code>"1099* ("HGF" is adjacent to "xyz")<br>1100* display with prologue = "<code>abc HGFED xyz</code>"1101* ("HGF" is not adjacent to "xyz")<br>1102*1103* @param pBiDi is a paragraph <code>UBiDi</code> object.1104*1105* @param prologue is a pointer to the text which precedes the text that1106* will be specified in a coming call to ubidi_setPara().1107* If there is no prologue to consider, then <code>proLength</code>1108* must be zero and this pointer can be NULL.1109*1110* @param proLength is the length of the prologue; if <code>proLength==-1</code>1111* then the prologue must be zero-terminated.1112* Otherwise proLength must be >= 0. If <code>proLength==0</code>, it means1113* that there is no prologue to consider.1114*1115* @param epilogue is a pointer to the text which follows the text that1116* will be specified in a coming call to ubidi_setPara().1117* If there is no epilogue to consider, then <code>epiLength</code>1118* must be zero and this pointer can be NULL.1119*1120* @param epiLength is the length of the epilogue; if <code>epiLength==-1</code>1121* then the epilogue must be zero-terminated.1122* Otherwise epiLength must be >= 0. If <code>epiLength==0</code>, it means1123* that there is no epilogue to consider.1124*1125* @param pErrorCode must be a valid pointer to an error code value.1126*1127* @see ubidi_setPara1128* @stable ICU 4.81129*/1130U_STABLE void U_EXPORT21131ubidi_setContext(UBiDi *pBiDi,1132const UChar *prologue, int32_t proLength,1133const UChar *epilogue, int32_t epiLength,1134UErrorCode *pErrorCode);11351136/**1137* Perform the Unicode Bidi algorithm. It is defined in the1138* <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Anned #9</a>,1139* version 13,1140* also described in The Unicode Standard, Version 4.0 .<p>1141*1142* This function takes a piece of plain text containing one or more paragraphs,1143* with or without externally specified embedding levels from <i>styled</i>1144* text and computes the left-right-directionality of each character.<p>1145*1146* If the entire text is all of the same directionality, then1147* the function may not perform all the steps described by the algorithm,1148* i.e., some levels may not be the same as if all steps were performed.1149* This is not relevant for unidirectional text.<br>1150* For example, in pure LTR text with numbers the numbers would get1151* a resolved level of 2 higher than the surrounding text according to1152* the algorithm. This implementation may set all resolved levels to1153* the same value in such a case.<p>1154*1155* The text can be composed of multiple paragraphs. Occurrence of a block1156* separator in the text terminates a paragraph, and whatever comes next starts1157* a new paragraph. The exception to this rule is when a Carriage Return (CR)1158* is followed by a Line Feed (LF). Both CR and LF are block separators, but1159* in that case, the pair of characters is considered as terminating the1160* preceding paragraph, and a new paragraph will be started by a character1161* coming after the LF.1162*1163* @param pBiDi A <code>UBiDi</code> object allocated with <code>ubidi_open()</code>1164* which will be set to contain the reordering information,1165* especially the resolved levels for all the characters in <code>text</code>.1166*1167* @param text is a pointer to the text that the Bidi algorithm will be performed on.1168* This pointer is stored in the UBiDi object and can be retrieved1169* with <code>ubidi_getText()</code>.<br>1170* <strong>Note:</strong> the text must be (at least) <code>length</code> long.1171*1172* @param length is the length of the text; if <code>length==-1</code> then1173* the text must be zero-terminated.1174*1175* @param paraLevel specifies the default level for the text;1176* it is typically 0 (LTR) or 1 (RTL).1177* If the function shall determine the paragraph level from the text,1178* then <code>paraLevel</code> can be set to1179* either <code>#UBIDI_DEFAULT_LTR</code>1180* or <code>#UBIDI_DEFAULT_RTL</code>; if the text contains multiple1181* paragraphs, the paragraph level shall be determined separately for1182* each paragraph; if a paragraph does not include any strongly typed1183* character, then the desired default is used (0 for LTR or 1 for RTL).1184* Any other value between 0 and <code>#UBIDI_MAX_EXPLICIT_LEVEL</code>1185* is also valid, with odd levels indicating RTL.1186*1187* @param embeddingLevels (in) may be used to preset the embedding and override levels,1188* ignoring characters like LRE and PDF in the text.1189* A level overrides the directional property of its corresponding1190* (same index) character if the level has the1191* <code>#UBIDI_LEVEL_OVERRIDE</code> bit set.<br><br>1192* Except for that bit, it must be1193* <code>paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL</code>,1194* with one exception: a level of zero may be specified for a paragraph1195* separator even if <code>paraLevel>0</code> when multiple paragraphs1196* are submitted in the same call to <code>ubidi_setPara()</code>.<br><br>1197* <strong>Caution: </strong>A copy of this pointer, not of the levels,1198* will be stored in the <code>UBiDi</code> object;1199* the <code>embeddingLevels</code> array must not be1200* deallocated before the <code>UBiDi</code> structure is destroyed or reused,1201* and the <code>embeddingLevels</code>1202* should not be modified to avoid unexpected results on subsequent Bidi operations.1203* However, the <code>ubidi_setPara()</code> and1204* <code>ubidi_setLine()</code> functions may modify some or all of the levels.<br><br>1205* After the <code>UBiDi</code> object is reused or destroyed, the caller1206* must take care of the deallocation of the <code>embeddingLevels</code> array.<br><br>1207* <strong>Note:</strong> the <code>embeddingLevels</code> array must be1208* at least <code>length</code> long.1209* This pointer can be <code>NULL</code> if this1210* value is not necessary.1211*1212* @param pErrorCode must be a valid pointer to an error code value.1213* @stable ICU 2.01214*/1215U_STABLE void U_EXPORT21216ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,1217UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,1218UErrorCode *pErrorCode);12191220/**1221* <code>ubidi_setLine()</code> sets a <code>UBiDi</code> to1222* contain the reordering information, especially the resolved levels,1223* for all the characters in a line of text. This line of text is1224* specified by referring to a <code>UBiDi</code> object representing1225* this information for a piece of text containing one or more paragraphs,1226* and by specifying a range of indexes in this text.<p>1227* In the new line object, the indexes will range from 0 to <code>limit-start-1</code>.<p>1228*1229* This is used after calling <code>ubidi_setPara()</code>1230* for a piece of text, and after line-breaking on that text.1231* It is not necessary if each paragraph is treated as a single line.<p>1232*1233* After line-breaking, rules (L1) and (L2) for the treatment of1234* trailing WS and for reordering are performed on1235* a <code>UBiDi</code> object that represents a line.<p>1236*1237* <strong>Important: </strong><code>pLineBiDi</code> shares data with1238* <code>pParaBiDi</code>.1239* You must destroy or reuse <code>pLineBiDi</code> before <code>pParaBiDi</code>.1240* In other words, you must destroy or reuse the <code>UBiDi</code> object for a line1241* before the object for its parent paragraph.<p>1242*1243* The text pointer that was stored in <code>pParaBiDi</code> is also copied,1244* and <code>start</code> is added to it so that it points to the beginning of the1245* line for this object.1246*1247* @param pParaBiDi is the parent paragraph object. It must have been set1248* by a successful call to ubidi_setPara.1249*1250* @param start is the line's first index into the text.1251*1252* @param limit is just behind the line's last index into the text1253* (its last index +1).<br>1254* It must be <code>0<=start<limit<=</code>containing paragraph limit.1255* If the specified line crosses a paragraph boundary, the function1256* will terminate with error code U_ILLEGAL_ARGUMENT_ERROR.1257*1258* @param pLineBiDi is the object that will now represent a line of the text.1259*1260* @param pErrorCode must be a valid pointer to an error code value.1261*1262* @see ubidi_setPara1263* @see ubidi_getProcessedLength1264* @stable ICU 2.01265*/1266U_STABLE void U_EXPORT21267ubidi_setLine(const UBiDi *pParaBiDi,1268int32_t start, int32_t limit,1269UBiDi *pLineBiDi,1270UErrorCode *pErrorCode);12711272/**1273* Get the directionality of the text.1274*1275* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1276*1277* @return a value of <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>1278* or <code>UBIDI_MIXED</code>1279* that indicates if the entire text1280* represented by this object is unidirectional,1281* and which direction, or if it is mixed-directional.1282* Note - The value <code>UBIDI_NEUTRAL</code> is never returned from this method.1283*1284* @see UBiDiDirection1285* @stable ICU 2.01286*/1287U_STABLE UBiDiDirection U_EXPORT21288ubidi_getDirection(const UBiDi *pBiDi);12891290/**1291* Gets the base direction of the text provided according1292* to the Unicode Bidirectional Algorithm. The base direction1293* is derived from the first character in the string with bidirectional1294* character type L, R, or AL. If the first such character has type L,1295* <code>UBIDI_LTR</code> is returned. If the first such character has1296* type R or AL, <code>UBIDI_RTL</code> is returned. If the string does1297* not contain any character of these types, then1298* <code>UBIDI_NEUTRAL</code> is returned.1299*1300* This is a lightweight function for use when only the base direction1301* is needed and no further bidi processing of the text is needed.1302*1303* @param text is a pointer to the text whose base1304* direction is needed.1305* Note: the text must be (at least) @c length long.1306*1307* @param length is the length of the text;1308* if <code>length==-1</code> then the text1309* must be zero-terminated.1310*1311* @return <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>,1312* <code>UBIDI_NEUTRAL</code>1313*1314* @see UBiDiDirection1315* @stable ICU 4.61316*/1317U_STABLE UBiDiDirection U_EXPORT21318ubidi_getBaseDirection(const UChar *text, int32_t length );13191320/**1321* Get the pointer to the text.1322*1323* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1324*1325* @return The pointer to the text that the UBiDi object was created for.1326*1327* @see ubidi_setPara1328* @see ubidi_setLine1329* @stable ICU 2.01330*/1331U_STABLE const UChar * U_EXPORT21332ubidi_getText(const UBiDi *pBiDi);13331334/**1335* Get the length of the text.1336*1337* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1338*1339* @return The length of the text that the UBiDi object was created for.1340* @stable ICU 2.01341*/1342U_STABLE int32_t U_EXPORT21343ubidi_getLength(const UBiDi *pBiDi);13441345/**1346* Get the paragraph level of the text.1347*1348* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1349*1350* @return The paragraph level. If there are multiple paragraphs, their1351* level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or1352* UBIDI_DEFAULT_RTL. In that case, the level of the first paragraph1353* is returned.1354*1355* @see UBiDiLevel1356* @see ubidi_getParagraph1357* @see ubidi_getParagraphByIndex1358* @stable ICU 2.01359*/1360U_STABLE UBiDiLevel U_EXPORT21361ubidi_getParaLevel(const UBiDi *pBiDi);13621363/**1364* Get the number of paragraphs.1365*1366* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1367*1368* @return The number of paragraphs.1369* @stable ICU 3.41370*/1371U_STABLE int32_t U_EXPORT21372ubidi_countParagraphs(UBiDi *pBiDi);13731374/**1375* Get a paragraph, given a position within the text.1376* This function returns information about a paragraph.<br>1377* Note: if the paragraph index is known, it is more efficient to1378* retrieve the paragraph information using ubidi_getParagraphByIndex().<p>1379*1380* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1381*1382* @param charIndex is the index of a character within the text, in the1383* range <code>[0..ubidi_getProcessedLength(pBiDi)-1]</code>.1384*1385* @param pParaStart will receive the index of the first character of the1386* paragraph in the text.1387* This pointer can be <code>NULL</code> if this1388* value is not necessary.1389*1390* @param pParaLimit will receive the limit of the paragraph.1391* The l-value that you point to here may be the1392* same expression (variable) as the one for1393* <code>charIndex</code>.1394* This pointer can be <code>NULL</code> if this1395* value is not necessary.1396*1397* @param pParaLevel will receive the level of the paragraph.1398* This pointer can be <code>NULL</code> if this1399* value is not necessary.1400*1401* @param pErrorCode must be a valid pointer to an error code value.1402*1403* @return The index of the paragraph containing the specified position.1404*1405* @see ubidi_getProcessedLength1406* @stable ICU 3.41407*/1408U_STABLE int32_t U_EXPORT21409ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,1410int32_t *pParaLimit, UBiDiLevel *pParaLevel,1411UErrorCode *pErrorCode);14121413/**1414* Get a paragraph, given the index of this paragraph.1415*1416* This function returns information about a paragraph.<p>1417*1418* @param pBiDi is the paragraph <code>UBiDi</code> object.1419*1420* @param paraIndex is the number of the paragraph, in the1421* range <code>[0..ubidi_countParagraphs(pBiDi)-1]</code>.1422*1423* @param pParaStart will receive the index of the first character of the1424* paragraph in the text.1425* This pointer can be <code>NULL</code> if this1426* value is not necessary.1427*1428* @param pParaLimit will receive the limit of the paragraph.1429* This pointer can be <code>NULL</code> if this1430* value is not necessary.1431*1432* @param pParaLevel will receive the level of the paragraph.1433* This pointer can be <code>NULL</code> if this1434* value is not necessary.1435*1436* @param pErrorCode must be a valid pointer to an error code value.1437*1438* @stable ICU 3.41439*/1440U_STABLE void U_EXPORT21441ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,1442int32_t *pParaStart, int32_t *pParaLimit,1443UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);14441445/**1446* Get the level for one character.1447*1448* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1449*1450* @param charIndex the index of a character. It must be in the range1451* [0..ubidi_getProcessedLength(pBiDi)].1452*1453* @return The level for the character at charIndex (0 if charIndex is not1454* in the valid range).1455*1456* @see UBiDiLevel1457* @see ubidi_getProcessedLength1458* @stable ICU 2.01459*/1460U_STABLE UBiDiLevel U_EXPORT21461ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);14621463/**1464* Get an array of levels for each character.<p>1465*1466* Note that this function may allocate memory under some1467* circumstances, unlike <code>ubidi_getLevelAt()</code>.1468*1469* @param pBiDi is the paragraph or line <code>UBiDi</code> object, whose1470* text length must be strictly positive.1471*1472* @param pErrorCode must be a valid pointer to an error code value.1473*1474* @return The levels array for the text,1475* or <code>NULL</code> if an error occurs.1476*1477* @see UBiDiLevel1478* @see ubidi_getProcessedLength1479* @stable ICU 2.01480*/1481U_STABLE const UBiDiLevel * U_EXPORT21482ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);14831484/**1485* Get a logical run.1486* This function returns information about a run and is used1487* to retrieve runs in logical order.<p>1488* This is especially useful for line-breaking on a paragraph.1489*1490* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1491*1492* @param logicalPosition is a logical position within the source text.1493*1494* @param pLogicalLimit will receive the limit of the corresponding run.1495* The l-value that you point to here may be the1496* same expression (variable) as the one for1497* <code>logicalPosition</code>.1498* This pointer can be <code>NULL</code> if this1499* value is not necessary.1500*1501* @param pLevel will receive the level of the corresponding run.1502* This pointer can be <code>NULL</code> if this1503* value is not necessary.1504*1505* @see ubidi_getProcessedLength1506* @stable ICU 2.01507*/1508U_STABLE void U_EXPORT21509ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,1510int32_t *pLogicalLimit, UBiDiLevel *pLevel);15111512/**1513* Get the number of runs.1514* This function may invoke the actual reordering on the1515* <code>UBiDi</code> object, after <code>ubidi_setPara()</code>1516* may have resolved only the levels of the text. Therefore,1517* <code>ubidi_countRuns()</code> may have to allocate memory,1518* and may fail doing so.1519*1520* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1521*1522* @param pErrorCode must be a valid pointer to an error code value.1523*1524* @return The number of runs.1525* @stable ICU 2.01526*/1527U_STABLE int32_t U_EXPORT21528ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);15291530/**1531* Get one run's logical start, length, and directionality,1532* which can be 0 for LTR or 1 for RTL.1533* In an RTL run, the character at the logical start is1534* visually on the right of the displayed run.1535* The length is the number of characters in the run.<p>1536* <code>ubidi_countRuns()</code> should be called1537* before the runs are retrieved.1538*1539* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1540*1541* @param runIndex is the number of the run in visual order, in the1542* range <code>[0..ubidi_countRuns(pBiDi)-1]</code>.1543*1544* @param pLogicalStart is the first logical character index in the text.1545* The pointer may be <code>NULL</code> if this index is not needed.1546*1547* @param pLength is the number of characters (at least one) in the run.1548* The pointer may be <code>NULL</code> if this is not needed.1549*1550* @return the directionality of the run,1551* <code>UBIDI_LTR==0</code> or <code>UBIDI_RTL==1</code>,1552* never <code>UBIDI_MIXED</code>,1553* never <code>UBIDI_NEUTRAL</code>.1554*1555* @see ubidi_countRuns1556*1557* Example:1558* <pre>1559* \code1560* int32_t i, count=ubidi_countRuns(pBiDi),1561* logicalStart, visualIndex=0, length;1562* for(i=0; i<count; ++i) {1563* if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {1564* do { // LTR1565* show_char(text[logicalStart++], visualIndex++);1566* } while(--length>0);1567* } else {1568* logicalStart+=length; // logicalLimit1569* do { // RTL1570* show_char(text[--logicalStart], visualIndex++);1571* } while(--length>0);1572* }1573* }1574*\endcode1575* </pre>1576*1577* Note that in right-to-left runs, code like this places1578* second surrogates before first ones (which is generally a bad idea)1579* and combining characters before base characters.1580* <p>1581* Use of <code>ubidi_writeReordered()</code>, optionally with the1582* <code>#UBIDI_KEEP_BASE_COMBINING</code> option, can be considered in order1583* to avoid these issues.1584* @stable ICU 2.01585*/1586U_STABLE UBiDiDirection U_EXPORT21587ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,1588int32_t *pLogicalStart, int32_t *pLength);15891590/**1591* Get the visual position from a logical text position.1592* If such a mapping is used many times on the same1593* <code>UBiDi</code> object, then calling1594* <code>ubidi_getLogicalMap()</code> is more efficient.<p>1595*1596* The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no1597* visual position because the corresponding text character is a Bidi control1598* removed from output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.1599* <p>1600* When the visual output is altered by using options of1601* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1602* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1603* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual position returned may not1604* be correct. It is advised to use, when possible, reordering options1605* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1606* <p>1607* Note that in right-to-left runs, this mapping places1608* second surrogates before first ones (which is generally a bad idea)1609* and combining characters before base characters.1610* Use of <code>ubidi_writeReordered()</code>, optionally with the1611* <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead1612* of using the mapping, in order to avoid these issues.1613*1614* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1615*1616* @param logicalIndex is the index of a character in the text.1617*1618* @param pErrorCode must be a valid pointer to an error code value.1619*1620* @return The visual position of this character.1621*1622* @see ubidi_getLogicalMap1623* @see ubidi_getLogicalIndex1624* @see ubidi_getProcessedLength1625* @stable ICU 2.01626*/1627U_STABLE int32_t U_EXPORT21628ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode);16291630/**1631* Get the logical text position from a visual position.1632* If such a mapping is used many times on the same1633* <code>UBiDi</code> object, then calling1634* <code>ubidi_getVisualMap()</code> is more efficient.<p>1635*1636* The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no1637* logical position because the corresponding text character is a Bidi mark1638* inserted in the output by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.1639* <p>1640* This is the inverse function to <code>ubidi_getVisualIndex()</code>.1641* <p>1642* When the visual output is altered by using options of1643* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1644* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1645* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical position returned may not1646* be correct. It is advised to use, when possible, reordering options1647* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1648*1649* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1650*1651* @param visualIndex is the visual position of a character.1652*1653* @param pErrorCode must be a valid pointer to an error code value.1654*1655* @return The index of this character in the text.1656*1657* @see ubidi_getVisualMap1658* @see ubidi_getVisualIndex1659* @see ubidi_getResultLength1660* @stable ICU 2.01661*/1662U_STABLE int32_t U_EXPORT21663ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);16641665/**1666* Get a logical-to-visual index map (array) for the characters in the UBiDi1667* (paragraph or line) object.1668* <p>1669* Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the1670* corresponding text characters are Bidi controls removed from the visual1671* output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.1672* <p>1673* When the visual output is altered by using options of1674* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1675* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1676* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual positions returned may not1677* be correct. It is advised to use, when possible, reordering options1678* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1679* <p>1680* Note that in right-to-left runs, this mapping places1681* second surrogates before first ones (which is generally a bad idea)1682* and combining characters before base characters.1683* Use of <code>ubidi_writeReordered()</code>, optionally with the1684* <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead1685* of using the mapping, in order to avoid these issues.1686*1687* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1688*1689* @param indexMap is a pointer to an array of <code>ubidi_getProcessedLength()</code>1690* indexes which will reflect the reordering of the characters.1691* If option <code>#UBIDI_OPTION_INSERT_MARKS</code> is set, the number1692* of elements allocated in <code>indexMap</code> must be no less than1693* <code>ubidi_getResultLength()</code>.1694* The array does not need to be initialized.<br><br>1695* The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.1696*1697* @param pErrorCode must be a valid pointer to an error code value.1698*1699* @see ubidi_getVisualMap1700* @see ubidi_getVisualIndex1701* @see ubidi_getProcessedLength1702* @see ubidi_getResultLength1703* @stable ICU 2.01704*/1705U_STABLE void U_EXPORT21706ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);17071708/**1709* Get a visual-to-logical index map (array) for the characters in the UBiDi1710* (paragraph or line) object.1711* <p>1712* Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the1713* corresponding text characters are Bidi marks inserted in the visual output1714* by the option <code>#UBIDI_OPTION_INSERT_MARKS</code>.1715* <p>1716* When the visual output is altered by using options of1717* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1718* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1719* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical positions returned may not1720* be correct. It is advised to use, when possible, reordering options1721* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1722*1723* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1724*1725* @param indexMap is a pointer to an array of <code>ubidi_getResultLength()</code>1726* indexes which will reflect the reordering of the characters.1727* If option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is set, the number1728* of elements allocated in <code>indexMap</code> must be no less than1729* <code>ubidi_getProcessedLength()</code>.1730* The array does not need to be initialized.<br><br>1731* The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.1732*1733* @param pErrorCode must be a valid pointer to an error code value.1734*1735* @see ubidi_getLogicalMap1736* @see ubidi_getLogicalIndex1737* @see ubidi_getProcessedLength1738* @see ubidi_getResultLength1739* @stable ICU 2.01740*/1741U_STABLE void U_EXPORT21742ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);17431744/**1745* This is a convenience function that does not use a UBiDi object.1746* It is intended to be used for when an application has determined the levels1747* of objects (character sequences) and just needs to have them reordered (L2).1748* This is equivalent to using <code>ubidi_getLogicalMap()</code> on a1749* <code>UBiDi</code> object.1750*1751* @param levels is an array with <code>length</code> levels that have been determined by1752* the application.1753*1754* @param length is the number of levels in the array, or, semantically,1755* the number of objects to be reordered.1756* It must be <code>length>0</code>.1757*1758* @param indexMap is a pointer to an array of <code>length</code>1759* indexes which will reflect the reordering of the characters.1760* The array does not need to be initialized.<p>1761* The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.1762* @stable ICU 2.01763*/1764U_STABLE void U_EXPORT21765ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);17661767/**1768* This is a convenience function that does not use a UBiDi object.1769* It is intended to be used for when an application has determined the levels1770* of objects (character sequences) and just needs to have them reordered (L2).1771* This is equivalent to using <code>ubidi_getVisualMap()</code> on a1772* <code>UBiDi</code> object.1773*1774* @param levels is an array with <code>length</code> levels that have been determined by1775* the application.1776*1777* @param length is the number of levels in the array, or, semantically,1778* the number of objects to be reordered.1779* It must be <code>length>0</code>.1780*1781* @param indexMap is a pointer to an array of <code>length</code>1782* indexes which will reflect the reordering of the characters.1783* The array does not need to be initialized.<p>1784* The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.1785* @stable ICU 2.01786*/1787U_STABLE void U_EXPORT21788ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);17891790/**1791* Invert an index map.1792* The index mapping of the first map is inverted and written to1793* the second one.1794*1795* @param srcMap is an array with <code>length</code> elements1796* which defines the original mapping from a source array containing1797* <code>length</code> elements to a destination array.1798* Some elements of the source array may have no mapping in the1799* destination array. In that case, their value will be1800* the special value <code>UBIDI_MAP_NOWHERE</code>.1801* All elements must be >=0 or equal to <code>UBIDI_MAP_NOWHERE</code>.1802* Some elements may have a value >= <code>length</code>, if the1803* destination array has more elements than the source array.1804* There must be no duplicate indexes (two or more elements with the1805* same value except <code>UBIDI_MAP_NOWHERE</code>).1806*1807* @param destMap is an array with a number of elements equal to 1 + the highest1808* value in <code>srcMap</code>.1809* <code>destMap</code> will be filled with the inverse mapping.1810* If element with index i in <code>srcMap</code> has a value k different1811* from <code>UBIDI_MAP_NOWHERE</code>, this means that element i of1812* the source array maps to element k in the destination array.1813* The inverse map will have value i in its k-th element.1814* For all elements of the destination array which do not map to1815* an element in the source array, the corresponding element in the1816* inverse map will have a value equal to <code>UBIDI_MAP_NOWHERE</code>.1817*1818* @param length is the length of each array.1819* @see UBIDI_MAP_NOWHERE1820* @stable ICU 2.01821*/1822U_STABLE void U_EXPORT21823ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);18241825/** option flags for ubidi_writeReordered() */18261827/**1828* option bit for ubidi_writeReordered():1829* keep combining characters after their base characters in RTL runs1830*1831* @see ubidi_writeReordered1832* @stable ICU 2.01833*/1834#define UBIDI_KEEP_BASE_COMBINING 118351836/**1837* option bit for ubidi_writeReordered():1838* replace characters with the "mirrored" property in RTL runs1839* by their mirror-image mappings1840*1841* @see ubidi_writeReordered1842* @stable ICU 2.01843*/1844#define UBIDI_DO_MIRRORING 218451846/**1847* option bit for ubidi_writeReordered():1848* surround the run with LRMs if necessary;1849* this is part of the approximate "inverse Bidi" algorithm1850*1851* <p>This option does not imply corresponding adjustment of the index1852* mappings.</p>1853*1854* @see ubidi_setInverse1855* @see ubidi_writeReordered1856* @stable ICU 2.01857*/1858#define UBIDI_INSERT_LRM_FOR_NUMERIC 418591860/**1861* option bit for ubidi_writeReordered():1862* remove Bidi control characters1863* (this does not affect #UBIDI_INSERT_LRM_FOR_NUMERIC)1864*1865* <p>This option does not imply corresponding adjustment of the index1866* mappings.</p>1867*1868* @see ubidi_writeReordered1869* @stable ICU 2.01870*/1871#define UBIDI_REMOVE_BIDI_CONTROLS 818721873/**1874* option bit for ubidi_writeReordered():1875* write the output in reverse order1876*1877* <p>This has the same effect as calling <code>ubidi_writeReordered()</code>1878* first without this option, and then calling1879* <code>ubidi_writeReverse()</code> without mirroring.1880* Doing this in the same step is faster and avoids a temporary buffer.1881* An example for using this option is output to a character terminal that1882* is designed for RTL scripts and stores text in reverse order.</p>1883*1884* @see ubidi_writeReordered1885* @stable ICU 2.01886*/1887#define UBIDI_OUTPUT_REVERSE 1618881889/**1890* Get the length of the source text processed by the last call to1891* <code>ubidi_setPara()</code>. This length may be different from the length1892* of the source text if option <code>#UBIDI_OPTION_STREAMING</code>1893* has been set.1894* <br>1895* Note that whenever the length of the text affects the execution or the1896* result of a function, it is the processed length which must be considered,1897* except for <code>ubidi_setPara</code> (which receives unprocessed source1898* text) and <code>ubidi_getLength</code> (which returns the original length1899* of the source text).<br>1900* In particular, the processed length is the one to consider in the following1901* cases:1902* <ul>1903* <li>maximum value of the <code>limit</code> argument of1904* <code>ubidi_setLine</code></li>1905* <li>maximum value of the <code>charIndex</code> argument of1906* <code>ubidi_getParagraph</code></li>1907* <li>maximum value of the <code>charIndex</code> argument of1908* <code>ubidi_getLevelAt</code></li>1909* <li>number of elements in the array returned by <code>ubidi_getLevels</code></li>1910* <li>maximum value of the <code>logicalStart</code> argument of1911* <code>ubidi_getLogicalRun</code></li>1912* <li>maximum value of the <code>logicalIndex</code> argument of1913* <code>ubidi_getVisualIndex</code></li>1914* <li>number of elements filled in the <code>*indexMap</code> argument of1915* <code>ubidi_getLogicalMap</code></li>1916* <li>length of text processed by <code>ubidi_writeReordered</code></li>1917* </ul>1918*1919* @param pBiDi is the paragraph <code>UBiDi</code> object.1920*1921* @return The length of the part of the source text processed by1922* the last call to <code>ubidi_setPara</code>.1923* @see ubidi_setPara1924* @see UBIDI_OPTION_STREAMING1925* @stable ICU 3.61926*/1927U_STABLE int32_t U_EXPORT21928ubidi_getProcessedLength(const UBiDi *pBiDi);19291930/**1931* Get the length of the reordered text resulting from the last call to1932* <code>ubidi_setPara()</code>. This length may be different from the length1933* of the source text if option <code>#UBIDI_OPTION_INSERT_MARKS</code>1934* or option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> has been set.1935* <br>1936* This resulting length is the one to consider in the following cases:1937* <ul>1938* <li>maximum value of the <code>visualIndex</code> argument of1939* <code>ubidi_getLogicalIndex</code></li>1940* <li>number of elements of the <code>*indexMap</code> argument of1941* <code>ubidi_getVisualMap</code></li>1942* </ul>1943* Note that this length stays identical to the source text length if1944* Bidi marks are inserted or removed using option bits of1945* <code>ubidi_writeReordered</code>, or if option1946* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> has been set.1947*1948* @param pBiDi is the paragraph <code>UBiDi</code> object.1949*1950* @return The length of the reordered text resulting from1951* the last call to <code>ubidi_setPara</code>.1952* @see ubidi_setPara1953* @see UBIDI_OPTION_INSERT_MARKS1954* @see UBIDI_OPTION_REMOVE_CONTROLS1955* @stable ICU 3.61956*/1957U_STABLE int32_t U_EXPORT21958ubidi_getResultLength(const UBiDi *pBiDi);19591960U_CDECL_BEGIN1961/**1962* value returned by <code>UBiDiClassCallback</code> callbacks when1963* there is no need to override the standard Bidi class for a given code point.1964* @see UBiDiClassCallback1965* @stable ICU 3.61966*/1967#define U_BIDI_CLASS_DEFAULT U_CHAR_DIRECTION_COUNT19681969/**1970* Callback type declaration for overriding default Bidi class values with1971* custom ones.1972* <p>Usually, the function pointer will be propagated to a <code>UBiDi</code>1973* object by calling the <code>ubidi_setClassCallback()</code> function;1974* then the callback will be invoked by the UBA implementation any time the1975* class of a character is to be determined.</p>1976*1977* @param context is a pointer to the callback private data.1978*1979* @param c is the code point to get a Bidi class for.1980*1981* @return The directional property / Bidi class for the given code point1982* <code>c</code> if the default class has been overridden, or1983* <code>#U_BIDI_CLASS_DEFAULT</code> if the standard Bidi class value1984* for <code>c</code> is to be used.1985* @see ubidi_setClassCallback1986* @see ubidi_getClassCallback1987* @stable ICU 3.61988*/1989typedef UCharDirection U_CALLCONV1990UBiDiClassCallback(const void *context, UChar32 c);19911992U_CDECL_END19931994/**1995* Retrieve the Bidi class for a given code point.1996* <p>If a <code>#UBiDiClassCallback</code> callback is defined and returns a1997* value other than <code>#U_BIDI_CLASS_DEFAULT</code>, that value is used;1998* otherwise the default class determination mechanism is invoked.</p>1999*2000* @param pBiDi is the paragraph <code>UBiDi</code> object.2001*2002* @param c is the code point whose Bidi class must be retrieved.2003*2004* @return The Bidi class for character <code>c</code> based2005* on the given <code>pBiDi</code> instance.2006* @see UBiDiClassCallback2007* @stable ICU 3.62008*/2009U_STABLE UCharDirection U_EXPORT22010ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c);20112012/**2013* Set the callback function and callback data used by the UBA2014* implementation for Bidi class determination.2015* <p>This may be useful for assigning Bidi classes to PUA characters, or2016* for special application needs. For instance, an application may want to2017* handle all spaces like L or R characters (according to the base direction)2018* when creating the visual ordering of logical lines which are part of a report2019* organized in columns: there should not be interaction between adjacent2020* cells.<p>2021*2022* @param pBiDi is the paragraph <code>UBiDi</code> object.2023*2024* @param newFn is the new callback function pointer.2025*2026* @param newContext is the new callback context pointer. This can be NULL.2027*2028* @param oldFn fillin: Returns the old callback function pointer. This can be2029* NULL.2030*2031* @param oldContext fillin: Returns the old callback's context. This can be2032* NULL.2033*2034* @param pErrorCode must be a valid pointer to an error code value.2035*2036* @see ubidi_getClassCallback2037* @stable ICU 3.62038*/2039U_STABLE void U_EXPORT22040ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,2041const void *newContext, UBiDiClassCallback **oldFn,2042const void **oldContext, UErrorCode *pErrorCode);20432044/**2045* Get the current callback function used for Bidi class determination.2046*2047* @param pBiDi is the paragraph <code>UBiDi</code> object.2048*2049* @param fn fillin: Returns the callback function pointer.2050*2051* @param context fillin: Returns the callback's private context.2052*2053* @see ubidi_setClassCallback2054* @stable ICU 3.62055*/2056U_STABLE void U_EXPORT22057ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context);20582059/**2060* Take a <code>UBiDi</code> object containing the reordering2061* information for a piece of text (one or more paragraphs) set by2062* <code>ubidi_setPara()</code> or for a line of text set by2063* <code>ubidi_setLine()</code> and write a reordered string to the2064* destination buffer.2065*2066* This function preserves the integrity of characters with multiple2067* code units and (optionally) combining characters.2068* Characters in RTL runs can be replaced by mirror-image characters2069* in the destination buffer. Note that "real" mirroring has2070* to be done in a rendering engine by glyph selection2071* and that for many "mirrored" characters there are no2072* Unicode characters as mirror-image equivalents.2073* There are also options to insert or remove Bidi control2074* characters; see the description of the <code>destSize</code>2075* and <code>options</code> parameters and of the option bit flags.2076*2077* @param pBiDi A pointer to a <code>UBiDi</code> object that2078* is set by <code>ubidi_setPara()</code> or2079* <code>ubidi_setLine()</code> and contains the reordering2080* information for the text that it was defined for,2081* as well as a pointer to that text.<br><br>2082* The text was aliased (only the pointer was stored2083* without copying the contents) and must not have been modified2084* since the <code>ubidi_setPara()</code> call.2085*2086* @param dest A pointer to where the reordered text is to be copied.2087* The source text and <code>dest[destSize]</code>2088* must not overlap.2089*2090* @param destSize The size of the <code>dest</code> buffer,2091* in number of UChars.2092* If the <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>2093* option is set, then the destination length could be2094* as large as2095* <code>ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)</code>.2096* If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option2097* is set, then the destination length may be less than2098* <code>ubidi_getLength(pBiDi)</code>.2099* If none of these options is set, then the destination length2100* will be exactly <code>ubidi_getProcessedLength(pBiDi)</code>.2101*2102* @param options A bit set of options for the reordering that control2103* how the reordered text is written.2104* The options include mirroring the characters on a code2105* point basis and inserting LRM characters, which is used2106* especially for transforming visually stored text2107* to logically stored text (although this is still an2108* imperfect implementation of an "inverse Bidi" algorithm2109* because it uses the "forward Bidi" algorithm at its core).2110* The available options are:2111* <code>#UBIDI_DO_MIRRORING</code>,2112* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>,2113* <code>#UBIDI_KEEP_BASE_COMBINING</code>,2114* <code>#UBIDI_OUTPUT_REVERSE</code>,2115* <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>2116*2117* @param pErrorCode must be a valid pointer to an error code value.2118*2119* @return The length of the output string.2120*2121* @see ubidi_getProcessedLength2122* @stable ICU 2.02123*/2124U_STABLE int32_t U_EXPORT22125ubidi_writeReordered(UBiDi *pBiDi,2126UChar *dest, int32_t destSize,2127uint16_t options,2128UErrorCode *pErrorCode);21292130/**2131* Reverse a Right-To-Left run of Unicode text.2132*2133* This function preserves the integrity of characters with multiple2134* code units and (optionally) combining characters.2135* Characters can be replaced by mirror-image characters2136* in the destination buffer. Note that "real" mirroring has2137* to be done in a rendering engine by glyph selection2138* and that for many "mirrored" characters there are no2139* Unicode characters as mirror-image equivalents.2140* There are also options to insert or remove Bidi control2141* characters.2142*2143* This function is the implementation for reversing RTL runs as part2144* of <code>ubidi_writeReordered()</code>. For detailed descriptions2145* of the parameters, see there.2146* Since no Bidi controls are inserted here, the output string length2147* will never exceed <code>srcLength</code>.2148*2149* @see ubidi_writeReordered2150*2151* @param src A pointer to the RTL run text.2152*2153* @param srcLength The length of the RTL run.2154*2155* @param dest A pointer to where the reordered text is to be copied.2156* <code>src[srcLength]</code> and <code>dest[destSize]</code>2157* must not overlap.2158*2159* @param destSize The size of the <code>dest</code> buffer,2160* in number of UChars.2161* If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option2162* is set, then the destination length may be less than2163* <code>srcLength</code>.2164* If this option is not set, then the destination length2165* will be exactly <code>srcLength</code>.2166*2167* @param options A bit set of options for the reordering that control2168* how the reordered text is written.2169* See the <code>options</code> parameter in <code>ubidi_writeReordered()</code>.2170*2171* @param pErrorCode must be a valid pointer to an error code value.2172*2173* @return The length of the output string.2174* @stable ICU 2.02175*/2176U_STABLE int32_t U_EXPORT22177ubidi_writeReverse(const UChar *src, int32_t srcLength,2178UChar *dest, int32_t destSize,2179uint16_t options,2180UErrorCode *pErrorCode);21812182/*#define BIDI_SAMPLE_CODE*/2183/*@}*/21842185#endif218621872188