Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/ubidi.h
48729 views
// © 2016 and later: Unicode, Inc. and others.1// License & terms of use: http://www.unicode.org/copyright.html2/*3******************************************************************************4*5* Copyright (C) 1999-2013, International Business Machines6* Corporation and others. All Rights Reserved.7*8******************************************************************************9* file name: ubidi.h10* encoding: UTF-811* tab size: 8 (not used)12* indentation:413*14* created on: 1999jul2715* created by: Markus W. Scherer, updated by Matitiahu Allouche16*/1718#ifndef UBIDI_H19#define UBIDI_H2021#include "unicode/utypes.h"22#include "unicode/uchar.h"23#include "unicode/localpointer.h"2425/**26*\file27* \brief C API: Bidi algorithm28*29* <h2>Bidi algorithm for ICU</h2>30*31* This is an implementation of the Unicode Bidirectional Algorithm.32* The algorithm is defined in the33* <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.<p>34*35* Note: Libraries that perform a bidirectional algorithm and36* reorder strings accordingly are sometimes called "Storage Layout Engines".37* ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such38* "Storage Layout Engines".39*40* <h3>General remarks about the API:</h3>41*42* In functions with an error code parameter,43* the <code>pErrorCode</code> pointer must be valid44* and the value that it points to must not indicate a failure before45* the function call. Otherwise, the function returns immediately.46* After the function call, the value indicates success or failure.<p>47*48* The "limit" of a sequence of characters is the position just after their49* last character, i.e., one more than that position.<p>50*51* Some of the API functions provide access to "runs".52* Such a "run" is defined as a sequence of characters53* that are at the same embedding level54* after performing the Bidi algorithm.<p>55*56* @author Markus W. Scherer57* @version 1.058*59*60* <h4> Sample code for the ICU Bidi API </h4>61*62* <h5>Rendering a paragraph with the ICU Bidi API</h5>63*64* This is (hypothetical) sample code that illustrates65* how the ICU Bidi API could be used to render a paragraph of text.66* Rendering code depends highly on the graphics system,67* therefore this sample code must make a lot of assumptions,68* which may or may not match any existing graphics system's properties.69*70* <p>The basic assumptions are:</p>71* <ul>72* <li>Rendering is done from left to right on a horizontal line.</li>73* <li>A run of single-style, unidirectional text can be rendered at once.</li>74* <li>Such a run of text is passed to the graphics system with75* characters (code units) in logical order.</li>76* <li>The line-breaking algorithm is very complicated77* and Locale-dependent -78* and therefore its implementation omitted from this sample code.</li>79* </ul>80*81* <pre>82* \code83*#include "unicode/ubidi.h"84*85*typedef enum {86* styleNormal=0, styleSelected=1,87* styleBold=2, styleItalics=4,88* styleSuper=8, styleSub=1689*} Style;90*91*typedef struct { int32_t limit; Style style; } StyleRun;92*93*int getTextWidth(const UChar *text, int32_t start, int32_t limit,94* const StyleRun *styleRuns, int styleRunCount);95*96* // set *pLimit and *pStyleRunLimit for a line97* // from text[start] and from styleRuns[styleRunStart]98* // using ubidi_getLogicalRun(para, ...)99*void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,100* UBiDi *para,101* const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,102* int *pLineWidth);103*104* // render runs on a line sequentially, always from left to right105*106* // prepare rendering a new line107* void startLine(UBiDiDirection textDirection, int lineWidth);108*109* // render a run of text and advance to the right by the run width110* // the text[start..limit-1] is always in logical order111* void renderRun(const UChar *text, int32_t start, int32_t limit,112* UBiDiDirection textDirection, Style style);113*114* // We could compute a cross-product115* // from the style runs with the directional runs116* // and then reorder it.117* // Instead, here we iterate over each run type118* // and render the intersections -119* // with shortcuts in simple (and common) cases.120* // renderParagraph() is the main function.121*122* // render a directional run with123* // (possibly) multiple style runs intersecting with it124* void renderDirectionalRun(const UChar *text,125* int32_t start, int32_t limit,126* UBiDiDirection direction,127* const StyleRun *styleRuns, int styleRunCount) {128* int i;129*130* // iterate over style runs131* if(direction==UBIDI_LTR) {132* int styleLimit;133*134* for(i=0; i<styleRunCount; ++i) {135* styleLimit=styleRun[i].limit;136* if(start<styleLimit) {137* if(styleLimit>limit) { styleLimit=limit; }138* renderRun(text, start, styleLimit,139* direction, styleRun[i].style);140* if(styleLimit==limit) { break; }141* start=styleLimit;142* }143* }144* } else {145* int styleStart;146*147* for(i=styleRunCount-1; i>=0; --i) {148* if(i>0) {149* styleStart=styleRun[i-1].limit;150* } else {151* styleStart=0;152* }153* if(limit>=styleStart) {154* if(styleStart<start) { styleStart=start; }155* renderRun(text, styleStart, limit,156* direction, styleRun[i].style);157* if(styleStart==start) { break; }158* limit=styleStart;159* }160* }161* }162* }163*164* // the line object represents text[start..limit-1]165* void renderLine(UBiDi *line, const UChar *text,166* int32_t start, int32_t limit,167* const StyleRun *styleRuns, int styleRunCount) {168* UBiDiDirection direction=ubidi_getDirection(line);169* if(direction!=UBIDI_MIXED) {170* // unidirectional171* if(styleRunCount<=1) {172* renderRun(text, start, limit, direction, styleRuns[0].style);173* } else {174* renderDirectionalRun(text, start, limit,175* direction, styleRuns, styleRunCount);176* }177* } else {178* // mixed-directional179* int32_t count, i, length;180* UBiDiLevel level;181*182* count=ubidi_countRuns(para, pErrorCode);183* if(U_SUCCESS(*pErrorCode)) {184* if(styleRunCount<=1) {185* Style style=styleRuns[0].style;186*187* // iterate over directional runs188* for(i=0; i<count; ++i) {189* direction=ubidi_getVisualRun(para, i, &start, &length);190* renderRun(text, start, start+length, direction, style);191* }192* } else {193* int32_t j;194*195* // iterate over both directional and style runs196* for(i=0; i<count; ++i) {197* direction=ubidi_getVisualRun(line, i, &start, &length);198* renderDirectionalRun(text, start, start+length,199* direction, styleRuns, styleRunCount);200* }201* }202* }203* }204* }205*206*void renderParagraph(const UChar *text, int32_t length,207* UBiDiDirection textDirection,208* const StyleRun *styleRuns, int styleRunCount,209* int lineWidth,210* UErrorCode *pErrorCode) {211* UBiDi *para;212*213* if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {214* return;215* }216*217* para=ubidi_openSized(length, 0, pErrorCode);218* if(para==NULL) { return; }219*220* ubidi_setPara(para, text, length,221* textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,222* NULL, pErrorCode);223* if(U_SUCCESS(*pErrorCode)) {224* UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);225* StyleRun styleRun={ length, styleNormal };226* int width;227*228* if(styleRuns==NULL || styleRunCount<=0) {229* styleRunCount=1;230* styleRuns=&styleRun;231* }232*233* // assume styleRuns[styleRunCount-1].limit>=length234*235* width=getTextWidth(text, 0, length, styleRuns, styleRunCount);236* if(width<=lineWidth) {237* // everything fits onto one line238*239* // prepare rendering a new line from either left or right240* startLine(paraLevel, width);241*242* renderLine(para, text, 0, length,243* styleRuns, styleRunCount);244* } else {245* UBiDi *line;246*247* // we need to render several lines248* line=ubidi_openSized(length, 0, pErrorCode);249* if(line!=NULL) {250* int32_t start=0, limit;251* int styleRunStart=0, styleRunLimit;252*253* for(;;) {254* limit=length;255* styleRunLimit=styleRunCount;256* getLineBreak(text, start, &limit, para,257* styleRuns, styleRunStart, &styleRunLimit,258* &width);259* ubidi_setLine(para, start, limit, line, pErrorCode);260* if(U_SUCCESS(*pErrorCode)) {261* // prepare rendering a new line262* // from either left or right263* startLine(paraLevel, width);264*265* renderLine(line, text, start, limit,266* styleRuns+styleRunStart,267* styleRunLimit-styleRunStart);268* }269* if(limit==length) { break; }270* start=limit;271* styleRunStart=styleRunLimit-1;272* if(start>=styleRuns[styleRunStart].limit) {273* ++styleRunStart;274* }275* }276*277* ubidi_close(line);278* }279* }280* }281*282* ubidi_close(para);283*}284*\endcode285* </pre>286*/287288/*DOCXX_TAG*/289/*@{*/290291/**292* UBiDiLevel is the type of the level values in this293* Bidi implementation.294* It holds an embedding level and indicates the visual direction295* by its bit 0 (even/odd value).<p>296*297* It can also hold non-level values for the298* <code>paraLevel</code> and <code>embeddingLevels</code>299* arguments of <code>ubidi_setPara()</code>; there:300* <ul>301* <li>bit 7 of an <code>embeddingLevels[]</code>302* value indicates whether the using application is303* specifying the level of a character to <i>override</i> whatever the304* Bidi implementation would resolve it to.</li>305* <li><code>paraLevel</code> can be set to the306* pseudo-level values <code>UBIDI_DEFAULT_LTR</code>307* and <code>UBIDI_DEFAULT_RTL</code>.</li>308* </ul>309*310* @see ubidi_setPara311*312* <p>The related constants are not real, valid level values.313* <code>UBIDI_DEFAULT_XXX</code> can be used to specify314* a default for the paragraph level for315* when the <code>ubidi_setPara()</code> function316* shall determine it but there is no317* strongly typed character in the input.<p>318*319* Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even320* and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,321* just like with normal LTR and RTL level values -322* these special values are designed that way. Also, the implementation323* assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.324*325* Note: The numeric values of the related constants will not change:326* They are tied to the use of 7-bit byte values (plus the override bit)327* and of the UBiDiLevel=uint8_t data type in this API.328*329* @see UBIDI_DEFAULT_LTR330* @see UBIDI_DEFAULT_RTL331* @see UBIDI_LEVEL_OVERRIDE332* @see UBIDI_MAX_EXPLICIT_LEVEL333* @stable ICU 2.0334*/335typedef uint8_t UBiDiLevel;336337/** Paragraph level setting.<p>338*339* Constant indicating that the base direction depends on the first strong340* directional character in the text according to the Unicode Bidirectional341* Algorithm. If no strong directional character is present,342* then set the paragraph level to 0 (left-to-right).<p>343*344* If this value is used in conjunction with reordering modes345* <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or346* <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder347* is assumed to be visual LTR, and the text after reordering is required348* to be the corresponding logical string with appropriate contextual349* direction. The direction of the result string will be RTL if either350* the righmost or leftmost strong character of the source text is RTL351* or Arabic Letter, the direction will be LTR otherwise.<p>352*353* If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may354* be added at the beginning of the result string to ensure round trip355* (that the result string, when reordered back to visual, will produce356* the original source text).357* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT358* @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL359* @stable ICU 2.0360*/361#define UBIDI_DEFAULT_LTR 0xfe362363/** Paragraph level setting.<p>364*365* Constant indicating that the base direction depends on the first strong366* directional character in the text according to the Unicode Bidirectional367* Algorithm. If no strong directional character is present,368* then set the paragraph level to 1 (right-to-left).<p>369*370* If this value is used in conjunction with reordering modes371* <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or372* <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder373* is assumed to be visual LTR, and the text after reordering is required374* to be the corresponding logical string with appropriate contextual375* direction. The direction of the result string will be RTL if either376* the righmost or leftmost strong character of the source text is RTL377* or Arabic Letter, or if the text contains no strong character;378* the direction will be LTR otherwise.<p>379*380* If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may381* be added at the beginning of the result string to ensure round trip382* (that the result string, when reordered back to visual, will produce383* the original source text).384* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT385* @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL386* @stable ICU 2.0387*/388#define UBIDI_DEFAULT_RTL 0xff389390/**391* Maximum explicit embedding level.392* Same as the max_depth value in the393* <a href="http://www.unicode.org/reports/tr9/#BD2">Unicode Bidirectional Algorithm</a>.394* (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).395* @stable ICU 2.0396*/397#define UBIDI_MAX_EXPLICIT_LEVEL 125398399/** Bit flag for level input.400* Overrides directional properties.401* @stable ICU 2.0402*/403#define UBIDI_LEVEL_OVERRIDE 0x80404405/**406* Special value which can be returned by the mapping functions when a logical407* index has no corresponding visual index or vice-versa. This may happen408* for the logical-to-visual mapping of a Bidi control when option409* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is specified. This can also happen410* for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted411* by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.412* @see ubidi_getVisualIndex413* @see ubidi_getVisualMap414* @see ubidi_getLogicalIndex415* @see ubidi_getLogicalMap416* @stable ICU 3.6417*/418#define UBIDI_MAP_NOWHERE (-1)419420/**421* <code>UBiDiDirection</code> values indicate the text direction.422* @stable ICU 2.0423*/424enum UBiDiDirection {425/** Left-to-right text. This is a 0 value.426* <ul>427* <li>As return value for <code>ubidi_getDirection()</code>, it means428* that the source string contains no right-to-left characters, or429* that the source string is empty and the paragraph level is even.430* <li> As return value for <code>ubidi_getBaseDirection()</code>, it431* means that the first strong character of the source string has432* a left-to-right direction.433* </ul>434* @stable ICU 2.0435*/436UBIDI_LTR,437/** Right-to-left text. This is a 1 value.438* <ul>439* <li>As return value for <code>ubidi_getDirection()</code>, it means440* that the source string contains no left-to-right characters, or441* that the source string is empty and the paragraph level is odd.442* <li> As return value for <code>ubidi_getBaseDirection()</code>, it443* means that the first strong character of the source string has444* a right-to-left direction.445* </ul>446* @stable ICU 2.0447*/448UBIDI_RTL,449/** Mixed-directional text.450* <p>As return value for <code>ubidi_getDirection()</code>, it means451* that the source string contains both left-to-right and452* right-to-left characters.453* @stable ICU 2.0454*/455UBIDI_MIXED,456/** No strongly directional text.457* <p>As return value for <code>ubidi_getBaseDirection()</code>, it means458* that the source string is missing or empty, or contains neither left-to-right459* nor right-to-left characters.460* @stable ICU 4.6461*/462UBIDI_NEUTRAL463};464465/** @stable ICU 2.0 */466typedef enum UBiDiDirection UBiDiDirection;467468/**469* Forward declaration of the <code>UBiDi</code> structure for the declaration of470* the API functions. Its fields are implementation-specific.<p>471* This structure holds information about a paragraph (or multiple paragraphs)472* of text with Bidi-algorithm-related details, or about one line of473* such a paragraph.<p>474* Reordering can be done on a line, or on one or more paragraphs which are475* then interpreted each as one single line.476* @stable ICU 2.0477*/478struct UBiDi;479480/** @stable ICU 2.0 */481typedef struct UBiDi UBiDi;482483/**484* Allocate a <code>UBiDi</code> structure.485* Such an object is initially empty. It is assigned486* the Bidi properties of a piece of text containing one or more paragraphs487* by <code>ubidi_setPara()</code>488* or the Bidi properties of a line within a paragraph by489* <code>ubidi_setLine()</code>.<p>490* This object can be reused for as long as it is not deallocated491* by calling <code>ubidi_close()</code>.<p>492* <code>ubidi_setPara()</code> and <code>ubidi_setLine()</code> will allocate493* additional memory for internal structures as necessary.494*495* @return An empty <code>UBiDi</code> object.496* @stable ICU 2.0497*/498U_STABLE UBiDi * U_EXPORT2499ubidi_open(void);500501/**502* Allocate a <code>UBiDi</code> structure with preallocated memory503* for internal structures.504* This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>505* with no arguments, but it also preallocates memory for internal structures506* according to the sizings supplied by the caller.<p>507* Subsequent functions will not allocate any more memory, and are thus508* guaranteed not to fail because of lack of memory.<p>509* The preallocation can be limited to some of the internal memory510* by setting some values to 0 here. That means that if, e.g.,511* <code>maxRunCount</code> cannot be reasonably predetermined and should not512* be set to <code>maxLength</code> (the only failproof value) to avoid513* wasting memory, then <code>maxRunCount</code> could be set to 0 here514* and the internal structures that are associated with it will be allocated515* on demand, just like with <code>ubidi_open()</code>.516*517* @param maxLength is the maximum text or line length that internal memory518* will be preallocated for. An attempt to associate this object with a519* longer text will fail, unless this value is 0, which leaves the allocation520* up to the implementation.521*522* @param maxRunCount is the maximum anticipated number of same-level runs523* that internal memory will be preallocated for. An attempt to access524* visual runs on an object that was not preallocated for as many runs525* as the text was actually resolved to will fail,526* unless this value is 0, which leaves the allocation up to the implementation.<br><br>527* The number of runs depends on the actual text and maybe anywhere between528* 1 and <code>maxLength</code>. It is typically small.529*530* @param pErrorCode must be a valid pointer to an error code value.531*532* @return An empty <code>UBiDi</code> object with preallocated memory.533* @stable ICU 2.0534*/535U_STABLE UBiDi * U_EXPORT2536ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);537538/**539* <code>ubidi_close()</code> must be called to free the memory540* associated with a UBiDi object.<p>541*542* <strong>Important: </strong>543* A parent <code>UBiDi</code> object must not be destroyed or reused if544* it still has children.545* If a <code>UBiDi</code> object has become the <i>child</i>546* of another one (its <i>parent</i>) by calling547* <code>ubidi_setLine()</code>, then the child object must548* be destroyed (closed) or reused (by calling549* <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)550* before the parent object.551*552* @param pBiDi is a <code>UBiDi</code> object.553*554* @see ubidi_setPara555* @see ubidi_setLine556* @stable ICU 2.0557*/558U_STABLE void U_EXPORT2559ubidi_close(UBiDi *pBiDi);560561#if U_SHOW_CPLUSPLUS_API562563U_NAMESPACE_BEGIN564565/**566* \class LocalUBiDiPointer567* "Smart pointer" class, closes a UBiDi via ubidi_close().568* For most methods see the LocalPointerBase base class.569*570* @see LocalPointerBase571* @see LocalPointer572* @stable ICU 4.4573*/574U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);575576U_NAMESPACE_END577578#endif579580/**581* Modify the operation of the Bidi algorithm such that it582* approximates an "inverse Bidi" algorithm. This function583* must be called before <code>ubidi_setPara()</code>.584*585* <p>The normal operation of the Bidi algorithm as described586* in the Unicode Technical Report is to take text stored in logical587* (keyboard, typing) order and to determine the reordering of it for visual588* rendering.589* Some legacy systems store text in visual order, and for operations590* with standard, Unicode-based algorithms, the text needs to be transformed591* to logical order. This is effectively the inverse algorithm of the592* described Bidi algorithm. Note that there is no standard algorithm for593* this "inverse Bidi" and that the current implementation provides only an594* approximation of "inverse Bidi".</p>595*596* <p>With <code>isInverse</code> set to <code>TRUE</code>,597* this function changes the behavior of some of the subsequent functions598* in a way that they can be used for the inverse Bidi algorithm.599* Specifically, runs of text with numeric characters will be treated in a600* special way and may need to be surrounded with LRM characters when they are601* written in reordered sequence.</p>602*603* <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.604* Since the actual input for "inverse Bidi" is visually ordered text and605* <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually606* the runs of the logically ordered output.</p>607*608* <p>Calling this function with argument <code>isInverse</code> set to609* <code>TRUE</code> is equivalent to calling610* <code>ubidi_setReorderingMode</code> with argument611* <code>reorderingMode</code>612* set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>613* Calling this function with argument <code>isInverse</code> set to614* <code>FALSE</code> is equivalent to calling615* <code>ubidi_setReorderingMode</code> with argument616* <code>reorderingMode</code>617* set to <code>#UBIDI_REORDER_DEFAULT</code>.618*619* @param pBiDi is a <code>UBiDi</code> object.620*621* @param isInverse specifies "forward" or "inverse" Bidi operation.622*623* @see ubidi_setPara624* @see ubidi_writeReordered625* @see ubidi_setReorderingMode626* @stable ICU 2.0627*/628U_STABLE void U_EXPORT2629ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);630631/**632* Is this Bidi object set to perform the inverse Bidi algorithm?633* <p>Note: calling this function after setting the reordering mode with634* <code>ubidi_setReorderingMode</code> will return <code>TRUE</code> if the635* reordering mode was set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>,636* <code>FALSE</code> for all other values.</p>637*638* @param pBiDi is a <code>UBiDi</code> object.639* @return TRUE if the Bidi object is set to perform the inverse Bidi algorithm640* by handling numbers as L.641*642* @see ubidi_setInverse643* @see ubidi_setReorderingMode644* @stable ICU 2.0645*/646647U_STABLE UBool U_EXPORT2648ubidi_isInverse(UBiDi *pBiDi);649650/**651* Specify whether block separators must be allocated level zero,652* so that successive paragraphs will progress from left to right.653* This function must be called before <code>ubidi_setPara()</code>.654* Paragraph separators (B) may appear in the text. Setting them to level zero655* means that all paragraph separators (including one possibly appearing656* in the last text position) are kept in the reordered text after the text657* that they follow in the source text.658* When this feature is not enabled, a paragraph separator at the last659* position of the text before reordering will go to the first position660* of the reordered text when the paragraph level is odd.661*662* @param pBiDi is a <code>UBiDi</code> object.663*664* @param orderParagraphsLTR specifies whether paragraph separators (B) must665* receive level 0, so that successive paragraphs progress from left to right.666*667* @see ubidi_setPara668* @stable ICU 3.4669*/670U_STABLE void U_EXPORT2671ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);672673/**674* Is this Bidi object set to allocate level 0 to block separators so that675* successive paragraphs progress from left to right?676*677* @param pBiDi is a <code>UBiDi</code> object.678* @return TRUE if the Bidi object is set to allocate level 0 to block679* separators.680*681* @see ubidi_orderParagraphsLTR682* @stable ICU 3.4683*/684U_STABLE UBool U_EXPORT2685ubidi_isOrderParagraphsLTR(UBiDi *pBiDi);686687/**688* <code>UBiDiReorderingMode</code> values indicate which variant of the Bidi689* algorithm to use.690*691* @see ubidi_setReorderingMode692* @stable ICU 3.6693*/694typedef enum UBiDiReorderingMode {695/** Regular Logical to Visual Bidi algorithm according to Unicode.696* This is a 0 value.697* @stable ICU 3.6 */698UBIDI_REORDER_DEFAULT = 0,699/** Logical to Visual algorithm which handles numbers in a way which700* mimics the behavior of Windows XP.701* @stable ICU 3.6 */702UBIDI_REORDER_NUMBERS_SPECIAL,703/** Logical to Visual algorithm grouping numbers with adjacent R characters704* (reversible algorithm).705* @stable ICU 3.6 */706UBIDI_REORDER_GROUP_NUMBERS_WITH_R,707/** Reorder runs only to transform a Logical LTR string to the Logical RTL708* string with the same display, or vice-versa.<br>709* If this mode is set together with option710* <code>#UBIDI_OPTION_INSERT_MARKS</code>, some Bidi controls in the source711* text may be removed and other controls may be added to produce the712* minimum combination which has the required display.713* @stable ICU 3.6 */714UBIDI_REORDER_RUNS_ONLY,715/** Visual to Logical algorithm which handles numbers like L716* (same algorithm as selected by <code>ubidi_setInverse(TRUE)</code>.717* @see ubidi_setInverse718* @stable ICU 3.6 */719UBIDI_REORDER_INVERSE_NUMBERS_AS_L,720/** Visual to Logical algorithm equivalent to the regular Logical to Visual721* algorithm.722* @stable ICU 3.6 */723UBIDI_REORDER_INVERSE_LIKE_DIRECT,724/** Inverse Bidi (Visual to Logical) algorithm for the725* <code>UBIDI_REORDER_NUMBERS_SPECIAL</code> Bidi algorithm.726* @stable ICU 3.6 */727UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,728#ifndef U_HIDE_DEPRECATED_API729/**730* Number of values for reordering mode.731* @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.732*/733UBIDI_REORDER_COUNT734#endif // U_HIDE_DEPRECATED_API735} UBiDiReorderingMode;736737/**738* Modify the operation of the Bidi algorithm such that it implements some739* variant to the basic Bidi algorithm or approximates an "inverse Bidi"740* algorithm, depending on different values of the "reordering mode".741* This function must be called before <code>ubidi_setPara()</code>, and stays742* in effect until called again with a different argument.743*744* <p>The normal operation of the Bidi algorithm as described745* in the Unicode Standard Annex #9 is to take text stored in logical746* (keyboard, typing) order and to determine how to reorder it for visual747* rendering.</p>748*749* <p>With the reordering mode set to a value other than750* <code>#UBIDI_REORDER_DEFAULT</code>, this function changes the behavior of751* some of the subsequent functions in a way such that they implement an752* inverse Bidi algorithm or some other algorithm variants.</p>753*754* <p>Some legacy systems store text in visual order, and for operations755* with standard, Unicode-based algorithms, the text needs to be transformed756* into logical order. This is effectively the inverse algorithm of the757* described Bidi algorithm. Note that there is no standard algorithm for758* this "inverse Bidi", so a number of variants are implemented here.</p>759*760* <p>In other cases, it may be desirable to emulate some variant of the761* Logical to Visual algorithm (e.g. one used in MS Windows), or perform a762* Logical to Logical transformation.</p>763*764* <ul>765* <li>When the reordering mode is set to <code>#UBIDI_REORDER_DEFAULT</code>,766* the standard Bidi Logical to Visual algorithm is applied.</li>767*768* <li>When the reordering mode is set to769* <code>#UBIDI_REORDER_NUMBERS_SPECIAL</code>,770* the algorithm used to perform Bidi transformations when calling771* <code>ubidi_setPara</code> should approximate the algorithm used in772* Microsoft Windows XP rather than strictly conform to the Unicode Bidi773* algorithm.774* <br>775* The differences between the basic algorithm and the algorithm addressed776* by this option are as follows:777* <ul>778* <li>Within text at an even embedding level, the sequence "123AB"779* (where AB represent R or AL letters) is transformed to "123BA" by the780* Unicode algorithm and to "BA123" by the Windows algorithm.</li>781* <li>Arabic-Indic numbers (AN) are handled by the Windows algorithm just782* like regular numbers (EN).</li>783* </ul></li>784*785* <li>When the reordering mode is set to786* <code>#UBIDI_REORDER_GROUP_NUMBERS_WITH_R</code>,787* numbers located between LTR text and RTL text are associated with the RTL788* text. For instance, an LTR paragraph with content "abc 123 DEF" (where789* upper case letters represent RTL characters) will be transformed to790* "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed791* to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".792* This makes the algorithm reversible and makes it useful when round trip793* (from visual to logical and back to visual) must be achieved without794* adding LRM characters. However, this is a variation from the standard795* Unicode Bidi algorithm.<br>796* The source text should not contain Bidi control characters other than LRM797* or RLM.</li>798*799* <li>When the reordering mode is set to800* <code>#UBIDI_REORDER_RUNS_ONLY</code>,801* a "Logical to Logical" transformation must be performed:802* <ul>803* <li>If the default text level of the source text (argument <code>paraLevel</code>804* in <code>ubidi_setPara</code>) is even, the source text will be handled as805* LTR logical text and will be transformed to the RTL logical text which has806* the same LTR visual display.</li>807* <li>If the default level of the source text is odd, the source text808* will be handled as RTL logical text and will be transformed to the809* LTR logical text which has the same LTR visual display.</li>810* </ul>811* This mode may be needed when logical text which is basically Arabic or812* Hebrew, with possible included numbers or phrases in English, has to be813* displayed as if it had an even embedding level (this can happen if the814* displaying application treats all text as if it was basically LTR).815* <br>816* This mode may also be needed in the reverse case, when logical text which is817* basically English, with possible included phrases in Arabic or Hebrew, has to818* be displayed as if it had an odd embedding level.819* <br>820* Both cases could be handled by adding LRE or RLE at the head of the text,821* if the display subsystem supports these formatting controls. If it does not,822* the problem may be handled by transforming the source text in this mode823* before displaying it, so that it will be displayed properly.<br>824* The source text should not contain Bidi control characters other than LRM825* or RLM.</li>826*827* <li>When the reordering mode is set to828* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>, an "inverse Bidi" algorithm829* is applied.830* Runs of text with numeric characters will be treated like LTR letters and831* may need to be surrounded with LRM characters when they are written in832* reordered sequence (the option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> can833* be used with function <code>ubidi_writeReordered</code> to this end. This834* mode is equivalent to calling <code>ubidi_setInverse()</code> with835* argument <code>isInverse</code> set to <code>TRUE</code>.</li>836*837* <li>When the reordering mode is set to838* <code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code>, the "direct" Logical to Visual839* Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.840* This mode is similar to mode <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>841* but is closer to the regular Bidi algorithm.842* <br>843* For example, an LTR paragraph with the content "FED 123 456 CBA" (where844* upper case represents RTL characters) will be transformed to845* "ABC 456 123 DEF", as opposed to "DEF 123 456 ABC"846* with mode <code>UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>847* When used in conjunction with option848* <code>#UBIDI_OPTION_INSERT_MARKS</code>, this mode generally849* adds Bidi marks to the output significantly more sparingly than mode850* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> with option851* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to852* <code>ubidi_writeReordered</code>.</li>853*854* <li>When the reordering mode is set to855* <code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the Logical to Visual856* Bidi algorithm used in Windows XP is used as an approximation of an "inverse Bidi" algorithm.857* <br>858* For example, an LTR paragraph with the content "abc FED123" (where859* upper case represents RTL characters) will be transformed to "abc 123DEF."</li>860* </ul>861*862* <p>In all the reordering modes specifying an "inverse Bidi" algorithm863* (i.e. those with a name starting with <code>UBIDI_REORDER_INVERSE</code>),864* output runs should be retrieved using865* <code>ubidi_getVisualRun()</code>, and the output text with866* <code>ubidi_writeReordered()</code>. The caller should keep in mind that in867* "inverse Bidi" modes the input is actually visually ordered text and868* reordered output returned by <code>ubidi_getVisualRun()</code> or869* <code>ubidi_writeReordered()</code> are actually runs or character string870* of logically ordered output.<br>871* For all the "inverse Bidi" modes, the source text should not contain872* Bidi control characters other than LRM or RLM.</p>873*874* <p>Note that option <code>#UBIDI_OUTPUT_REVERSE</code> of875* <code>ubidi_writeReordered</code> has no useful meaning and should not be876* used in conjunction with any value of the reordering mode specifying877* "inverse Bidi" or with value <code>UBIDI_REORDER_RUNS_ONLY</code>.878*879* @param pBiDi is a <code>UBiDi</code> object.880* @param reorderingMode specifies the required variant of the Bidi algorithm.881*882* @see UBiDiReorderingMode883* @see ubidi_setInverse884* @see ubidi_setPara885* @see ubidi_writeReordered886* @stable ICU 3.6887*/888U_STABLE void U_EXPORT2889ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);890891/**892* What is the requested reordering mode for a given Bidi object?893*894* @param pBiDi is a <code>UBiDi</code> object.895* @return the current reordering mode of the Bidi object896* @see ubidi_setReorderingMode897* @stable ICU 3.6898*/899U_STABLE UBiDiReorderingMode U_EXPORT2900ubidi_getReorderingMode(UBiDi *pBiDi);901902/**903* <code>UBiDiReorderingOption</code> values indicate which options are904* specified to affect the Bidi algorithm.905*906* @see ubidi_setReorderingOptions907* @stable ICU 3.6908*/909typedef enum UBiDiReorderingOption {910/**911* option value for <code>ubidi_setReorderingOptions</code>:912* disable all the options which can be set with this function913* @see ubidi_setReorderingOptions914* @stable ICU 3.6915*/916UBIDI_OPTION_DEFAULT = 0,917918/**919* option bit for <code>ubidi_setReorderingOptions</code>:920* insert Bidi marks (LRM or RLM) when needed to ensure correct result of921* a reordering to a Logical order922*923* <p>This option must be set or reset before calling924* <code>ubidi_setPara</code>.</p>925*926* <p>This option is significant only with reordering modes which generate927* a result with Logical order, specifically:</p>928* <ul>929* <li><code>#UBIDI_REORDER_RUNS_ONLY</code></li>930* <li><code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code></li>931* <li><code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code></li>932* <li><code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code></li>933* </ul>934*935* <p>If this option is set in conjunction with reordering mode936* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> or with calling937* <code>ubidi_setInverse(TRUE)</code>, it implies938* option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>939* in calls to function <code>ubidi_writeReordered()</code>.</p>940*941* <p>For other reordering modes, a minimum number of LRM or RLM characters942* will be added to the source text after reordering it so as to ensure943* round trip, i.e. when applying the inverse reordering mode on the944* resulting logical text with removal of Bidi marks945* (option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> set before calling946* <code>ubidi_setPara()</code> or option <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>947* in <code>ubidi_writeReordered</code>), the result will be identical to the948* source text in the first transformation.949*950* <p>This option will be ignored if specified together with option951* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>. It inhibits option952* <code>UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to function953* <code>ubidi_writeReordered()</code> and it implies option954* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to function955* <code>ubidi_writeReordered()</code> if the reordering mode is956* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.</p>957*958* @see ubidi_setReorderingMode959* @see ubidi_setReorderingOptions960* @stable ICU 3.6961*/962UBIDI_OPTION_INSERT_MARKS = 1,963964/**965* option bit for <code>ubidi_setReorderingOptions</code>:966* remove Bidi control characters967*968* <p>This option must be set or reset before calling969* <code>ubidi_setPara</code>.</p>970*971* <p>This option nullifies option <code>#UBIDI_OPTION_INSERT_MARKS</code>.972* It inhibits option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls973* to function <code>ubidi_writeReordered()</code> and it implies option974* <code>#UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to that function.</p>975*976* @see ubidi_setReorderingMode977* @see ubidi_setReorderingOptions978* @stable ICU 3.6979*/980UBIDI_OPTION_REMOVE_CONTROLS = 2,981982/**983* option bit for <code>ubidi_setReorderingOptions</code>:984* process the output as part of a stream to be continued985*986* <p>This option must be set or reset before calling987* <code>ubidi_setPara</code>.</p>988*989* <p>This option specifies that the caller is interested in processing large990* text object in parts.991* The results of the successive calls are expected to be concatenated by the992* caller. Only the call for the last part will have this option bit off.</p>993*994* <p>When this option bit is on, <code>ubidi_setPara()</code> may process995* less than the full source text in order to truncate the text at a meaningful996* boundary. The caller should call <code>ubidi_getProcessedLength()</code>997* immediately after calling <code>ubidi_setPara()</code> in order to998* determine how much of the source text has been processed.999* Source text beyond that length should be resubmitted in following calls to1000* <code>ubidi_setPara</code>. The processed length may be less than1001* the length of the source text if a character preceding the last character of1002* the source text constitutes a reasonable boundary (like a block separator)1003* for text to be continued.<br>1004* If the last character of the source text constitutes a reasonable1005* boundary, the whole text will be processed at once.<br>1006* If nowhere in the source text there exists1007* such a reasonable boundary, the processed length will be zero.<br>1008* The caller should check for such an occurrence and do one of the following:1009* <ul><li>submit a larger amount of text with a better chance to include1010* a reasonable boundary.</li>1011* <li>resubmit the same text after turning off option1012* <code>UBIDI_OPTION_STREAMING</code>.</li></ul>1013* In all cases, this option should be turned off before processing the last1014* part of the text.</p>1015*1016* <p>When the <code>UBIDI_OPTION_STREAMING</code> option is used,1017* it is recommended to call <code>ubidi_orderParagraphsLTR()</code> with1018* argument <code>orderParagraphsLTR</code> set to <code>TRUE</code> before1019* calling <code>ubidi_setPara</code> so that later paragraphs may be1020* concatenated to previous paragraphs on the right.</p>1021*1022* @see ubidi_setReorderingMode1023* @see ubidi_setReorderingOptions1024* @see ubidi_getProcessedLength1025* @see ubidi_orderParagraphsLTR1026* @stable ICU 3.61027*/1028UBIDI_OPTION_STREAMING = 41029} UBiDiReorderingOption;10301031/**1032* Specify which of the reordering options1033* should be applied during Bidi transformations.1034*1035* @param pBiDi is a <code>UBiDi</code> object.1036* @param reorderingOptions is a combination of zero or more of the following1037* options:1038* <code>#UBIDI_OPTION_DEFAULT</code>, <code>#UBIDI_OPTION_INSERT_MARKS</code>,1039* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>, <code>#UBIDI_OPTION_STREAMING</code>.1040*1041* @see ubidi_getReorderingOptions1042* @stable ICU 3.61043*/1044U_STABLE void U_EXPORT21045ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);10461047/**1048* What are the reordering options applied to a given Bidi object?1049*1050* @param pBiDi is a <code>UBiDi</code> object.1051* @return the current reordering options of the Bidi object1052* @see ubidi_setReorderingOptions1053* @stable ICU 3.61054*/1055U_STABLE uint32_t U_EXPORT21056ubidi_getReorderingOptions(UBiDi *pBiDi);10571058/**1059* Set the context before a call to ubidi_setPara().<p>1060*1061* ubidi_setPara() computes the left-right directionality for a given piece1062* of text which is supplied as one of its arguments. Sometimes this piece1063* of text (the "main text") should be considered in context, because text1064* appearing before ("prologue") and/or after ("epilogue") the main text1065* may affect the result of this computation.<p>1066*1067* This function specifies the prologue and/or the epilogue for the next1068* call to ubidi_setPara(). The characters specified as prologue and1069* epilogue should not be modified by the calling program until the call1070* to ubidi_setPara() has returned. If successive calls to ubidi_setPara()1071* all need specification of a context, ubidi_setContext() must be called1072* before each call to ubidi_setPara(). In other words, a context is not1073* "remembered" after the following successful call to ubidi_setPara().<p>1074*1075* If a call to ubidi_setPara() specifies UBIDI_DEFAULT_LTR or1076* UBIDI_DEFAULT_RTL as paraLevel and is preceded by a call to1077* ubidi_setContext() which specifies a prologue, the paragraph level will1078* be computed taking in consideration the text in the prologue.<p>1079*1080* When ubidi_setPara() is called without a previous call to1081* ubidi_setContext, the main text is handled as if preceded and followed1082* by strong directional characters at the current paragraph level.1083* Calling ubidi_setContext() with specification of a prologue will change1084* this behavior by handling the main text as if preceded by the last1085* strong character appearing in the prologue, if any.1086* Calling ubidi_setContext() with specification of an epilogue will change1087* the behavior of ubidi_setPara() by handling the main text as if followed1088* by the first strong character or digit appearing in the epilogue, if any.<p>1089*1090* Note 1: if <code>ubidi_setContext</code> is called repeatedly without1091* calling <code>ubidi_setPara</code>, the earlier calls have no effect,1092* only the last call will be remembered for the next call to1093* <code>ubidi_setPara</code>.<p>1094*1095* Note 2: calling <code>ubidi_setContext(pBiDi, NULL, 0, NULL, 0, &errorCode)</code>1096* cancels any previous setting of non-empty prologue or epilogue.1097* The next call to <code>ubidi_setPara()</code> will process no1098* prologue or epilogue.<p>1099*1100* Note 3: users must be aware that even after setting the context1101* before a call to ubidi_setPara() to perform e.g. a logical to visual1102* transformation, the resulting string may not be identical to what it1103* would have been if all the text, including prologue and epilogue, had1104* been processed together.<br>1105* Example (upper case letters represent RTL characters):<br>1106* prologue = "<code>abc DE</code>"<br>1107* epilogue = none<br>1108* main text = "<code>FGH xyz</code>"<br>1109* paraLevel = UBIDI_LTR<br>1110* display without prologue = "<code>HGF xyz</code>"1111* ("HGF" is adjacent to "xyz")<br>1112* display with prologue = "<code>abc HGFED xyz</code>"1113* ("HGF" is not adjacent to "xyz")<br>1114*1115* @param pBiDi is a paragraph <code>UBiDi</code> object.1116*1117* @param prologue is a pointer to the text which precedes the text that1118* will be specified in a coming call to ubidi_setPara().1119* If there is no prologue to consider, then <code>proLength</code>1120* must be zero and this pointer can be NULL.1121*1122* @param proLength is the length of the prologue; if <code>proLength==-1</code>1123* then the prologue must be zero-terminated.1124* Otherwise proLength must be >= 0. If <code>proLength==0</code>, it means1125* that there is no prologue to consider.1126*1127* @param epilogue is a pointer to the text which follows the text that1128* will be specified in a coming call to ubidi_setPara().1129* If there is no epilogue to consider, then <code>epiLength</code>1130* must be zero and this pointer can be NULL.1131*1132* @param epiLength is the length of the epilogue; if <code>epiLength==-1</code>1133* then the epilogue must be zero-terminated.1134* Otherwise epiLength must be >= 0. If <code>epiLength==0</code>, it means1135* that there is no epilogue to consider.1136*1137* @param pErrorCode must be a valid pointer to an error code value.1138*1139* @see ubidi_setPara1140* @stable ICU 4.81141*/1142U_STABLE void U_EXPORT21143ubidi_setContext(UBiDi *pBiDi,1144const UChar *prologue, int32_t proLength,1145const UChar *epilogue, int32_t epiLength,1146UErrorCode *pErrorCode);11471148/**1149* Perform the Unicode Bidi algorithm. It is defined in the1150* <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,1151* version 13,1152* also described in The Unicode Standard, Version 4.0 .<p>1153*1154* This function takes a piece of plain text containing one or more paragraphs,1155* with or without externally specified embedding levels from <i>styled</i>1156* text and computes the left-right-directionality of each character.<p>1157*1158* If the entire text is all of the same directionality, then1159* the function may not perform all the steps described by the algorithm,1160* i.e., some levels may not be the same as if all steps were performed.1161* This is not relevant for unidirectional text.<br>1162* For example, in pure LTR text with numbers the numbers would get1163* a resolved level of 2 higher than the surrounding text according to1164* the algorithm. This implementation may set all resolved levels to1165* the same value in such a case.<p>1166*1167* The text can be composed of multiple paragraphs. Occurrence of a block1168* separator in the text terminates a paragraph, and whatever comes next starts1169* a new paragraph. The exception to this rule is when a Carriage Return (CR)1170* is followed by a Line Feed (LF). Both CR and LF are block separators, but1171* in that case, the pair of characters is considered as terminating the1172* preceding paragraph, and a new paragraph will be started by a character1173* coming after the LF.1174*1175* @param pBiDi A <code>UBiDi</code> object allocated with <code>ubidi_open()</code>1176* which will be set to contain the reordering information,1177* especially the resolved levels for all the characters in <code>text</code>.1178*1179* @param text is a pointer to the text that the Bidi algorithm will be performed on.1180* This pointer is stored in the UBiDi object and can be retrieved1181* with <code>ubidi_getText()</code>.<br>1182* <strong>Note:</strong> the text must be (at least) <code>length</code> long.1183*1184* @param length is the length of the text; if <code>length==-1</code> then1185* the text must be zero-terminated.1186*1187* @param paraLevel specifies the default level for the text;1188* it is typically 0 (LTR) or 1 (RTL).1189* If the function shall determine the paragraph level from the text,1190* then <code>paraLevel</code> can be set to1191* either <code>#UBIDI_DEFAULT_LTR</code>1192* or <code>#UBIDI_DEFAULT_RTL</code>; if the text contains multiple1193* paragraphs, the paragraph level shall be determined separately for1194* each paragraph; if a paragraph does not include any strongly typed1195* character, then the desired default is used (0 for LTR or 1 for RTL).1196* Any other value between 0 and <code>#UBIDI_MAX_EXPLICIT_LEVEL</code>1197* is also valid, with odd levels indicating RTL.1198*1199* @param embeddingLevels (in) may be used to preset the embedding and override levels,1200* ignoring characters like LRE and PDF in the text.1201* A level overrides the directional property of its corresponding1202* (same index) character if the level has the1203* <code>#UBIDI_LEVEL_OVERRIDE</code> bit set.<br><br>1204* Aside from that bit, it must be1205* <code>paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL</code>,1206* except that level 0 is always allowed.1207* Level 0 for a paragraph separator prevents reordering of paragraphs;1208* this only works reliably if <code>#UBIDI_LEVEL_OVERRIDE</code>1209* is also set for paragraph separators.1210* Level 0 for other characters is treated as a wildcard1211* and is lifted up to the resolved level of the surrounding paragraph.<br><br>1212* <strong>Caution: </strong>A copy of this pointer, not of the levels,1213* will be stored in the <code>UBiDi</code> object;1214* the <code>embeddingLevels</code> array must not be1215* deallocated before the <code>UBiDi</code> structure is destroyed or reused,1216* and the <code>embeddingLevels</code>1217* should not be modified to avoid unexpected results on subsequent Bidi operations.1218* However, the <code>ubidi_setPara()</code> and1219* <code>ubidi_setLine()</code> functions may modify some or all of the levels.<br><br>1220* After the <code>UBiDi</code> object is reused or destroyed, the caller1221* must take care of the deallocation of the <code>embeddingLevels</code> array.<br><br>1222* <strong>Note:</strong> the <code>embeddingLevels</code> array must be1223* at least <code>length</code> long.1224* This pointer can be <code>NULL</code> if this1225* value is not necessary.1226*1227* @param pErrorCode must be a valid pointer to an error code value.1228* @stable ICU 2.01229*/1230U_STABLE void U_EXPORT21231ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,1232UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,1233UErrorCode *pErrorCode);12341235/**1236* <code>ubidi_setLine()</code> sets a <code>UBiDi</code> to1237* contain the reordering information, especially the resolved levels,1238* for all the characters in a line of text. This line of text is1239* specified by referring to a <code>UBiDi</code> object representing1240* this information for a piece of text containing one or more paragraphs,1241* and by specifying a range of indexes in this text.<p>1242* In the new line object, the indexes will range from 0 to <code>limit-start-1</code>.<p>1243*1244* This is used after calling <code>ubidi_setPara()</code>1245* for a piece of text, and after line-breaking on that text.1246* It is not necessary if each paragraph is treated as a single line.<p>1247*1248* After line-breaking, rules (L1) and (L2) for the treatment of1249* trailing WS and for reordering are performed on1250* a <code>UBiDi</code> object that represents a line.<p>1251*1252* <strong>Important: </strong><code>pLineBiDi</code> shares data with1253* <code>pParaBiDi</code>.1254* You must destroy or reuse <code>pLineBiDi</code> before <code>pParaBiDi</code>.1255* In other words, you must destroy or reuse the <code>UBiDi</code> object for a line1256* before the object for its parent paragraph.<p>1257*1258* The text pointer that was stored in <code>pParaBiDi</code> is also copied,1259* and <code>start</code> is added to it so that it points to the beginning of the1260* line for this object.1261*1262* @param pParaBiDi is the parent paragraph object. It must have been set1263* by a successful call to ubidi_setPara.1264*1265* @param start is the line's first index into the text.1266*1267* @param limit is just behind the line's last index into the text1268* (its last index +1).<br>1269* It must be <code>0<=start<limit<=</code>containing paragraph limit.1270* If the specified line crosses a paragraph boundary, the function1271* will terminate with error code U_ILLEGAL_ARGUMENT_ERROR.1272*1273* @param pLineBiDi is the object that will now represent a line of the text.1274*1275* @param pErrorCode must be a valid pointer to an error code value.1276*1277* @see ubidi_setPara1278* @see ubidi_getProcessedLength1279* @stable ICU 2.01280*/1281U_STABLE void U_EXPORT21282ubidi_setLine(const UBiDi *pParaBiDi,1283int32_t start, int32_t limit,1284UBiDi *pLineBiDi,1285UErrorCode *pErrorCode);12861287/**1288* Get the directionality of the text.1289*1290* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1291*1292* @return a value of <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>1293* or <code>UBIDI_MIXED</code>1294* that indicates if the entire text1295* represented by this object is unidirectional,1296* and which direction, or if it is mixed-directional.1297* Note - The value <code>UBIDI_NEUTRAL</code> is never returned from this method.1298*1299* @see UBiDiDirection1300* @stable ICU 2.01301*/1302U_STABLE UBiDiDirection U_EXPORT21303ubidi_getDirection(const UBiDi *pBiDi);13041305/**1306* Gets the base direction of the text provided according1307* to the Unicode Bidirectional Algorithm. The base direction1308* is derived from the first character in the string with bidirectional1309* character type L, R, or AL. If the first such character has type L,1310* <code>UBIDI_LTR</code> is returned. If the first such character has1311* type R or AL, <code>UBIDI_RTL</code> is returned. If the string does1312* not contain any character of these types, then1313* <code>UBIDI_NEUTRAL</code> is returned.1314*1315* This is a lightweight function for use when only the base direction1316* is needed and no further bidi processing of the text is needed.1317*1318* @param text is a pointer to the text whose base1319* direction is needed.1320* Note: the text must be (at least) @c length long.1321*1322* @param length is the length of the text;1323* if <code>length==-1</code> then the text1324* must be zero-terminated.1325*1326* @return <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>,1327* <code>UBIDI_NEUTRAL</code>1328*1329* @see UBiDiDirection1330* @stable ICU 4.61331*/1332U_STABLE UBiDiDirection U_EXPORT21333ubidi_getBaseDirection(const UChar *text, int32_t length );13341335/**1336* Get the pointer to the text.1337*1338* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1339*1340* @return The pointer to the text that the UBiDi object was created for.1341*1342* @see ubidi_setPara1343* @see ubidi_setLine1344* @stable ICU 2.01345*/1346U_STABLE const UChar * U_EXPORT21347ubidi_getText(const UBiDi *pBiDi);13481349/**1350* Get the length of the text.1351*1352* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1353*1354* @return The length of the text that the UBiDi object was created for.1355* @stable ICU 2.01356*/1357U_STABLE int32_t U_EXPORT21358ubidi_getLength(const UBiDi *pBiDi);13591360/**1361* Get the paragraph level of the text.1362*1363* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1364*1365* @return The paragraph level. If there are multiple paragraphs, their1366* level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or1367* UBIDI_DEFAULT_RTL. In that case, the level of the first paragraph1368* is returned.1369*1370* @see UBiDiLevel1371* @see ubidi_getParagraph1372* @see ubidi_getParagraphByIndex1373* @stable ICU 2.01374*/1375U_STABLE UBiDiLevel U_EXPORT21376ubidi_getParaLevel(const UBiDi *pBiDi);13771378/**1379* Get the number of paragraphs.1380*1381* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1382*1383* @return The number of paragraphs.1384* @stable ICU 3.41385*/1386U_STABLE int32_t U_EXPORT21387ubidi_countParagraphs(UBiDi *pBiDi);13881389/**1390* Get a paragraph, given a position within the text.1391* This function returns information about a paragraph.<br>1392* Note: if the paragraph index is known, it is more efficient to1393* retrieve the paragraph information using ubidi_getParagraphByIndex().<p>1394*1395* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1396*1397* @param charIndex is the index of a character within the text, in the1398* range <code>[0..ubidi_getProcessedLength(pBiDi)-1]</code>.1399*1400* @param pParaStart will receive the index of the first character of the1401* paragraph in the text.1402* This pointer can be <code>NULL</code> if this1403* value is not necessary.1404*1405* @param pParaLimit will receive the limit of the paragraph.1406* The l-value that you point to here may be the1407* same expression (variable) as the one for1408* <code>charIndex</code>.1409* This pointer can be <code>NULL</code> if this1410* value is not necessary.1411*1412* @param pParaLevel will receive the level of the paragraph.1413* This pointer can be <code>NULL</code> if this1414* value is not necessary.1415*1416* @param pErrorCode must be a valid pointer to an error code value.1417*1418* @return The index of the paragraph containing the specified position.1419*1420* @see ubidi_getProcessedLength1421* @stable ICU 3.41422*/1423U_STABLE int32_t U_EXPORT21424ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,1425int32_t *pParaLimit, UBiDiLevel *pParaLevel,1426UErrorCode *pErrorCode);14271428/**1429* Get a paragraph, given the index of this paragraph.1430*1431* This function returns information about a paragraph.<p>1432*1433* @param pBiDi is the paragraph <code>UBiDi</code> object.1434*1435* @param paraIndex is the number of the paragraph, in the1436* range <code>[0..ubidi_countParagraphs(pBiDi)-1]</code>.1437*1438* @param pParaStart will receive the index of the first character of the1439* paragraph in the text.1440* This pointer can be <code>NULL</code> if this1441* value is not necessary.1442*1443* @param pParaLimit will receive the limit of the paragraph.1444* This pointer can be <code>NULL</code> if this1445* value is not necessary.1446*1447* @param pParaLevel will receive the level of the paragraph.1448* This pointer can be <code>NULL</code> if this1449* value is not necessary.1450*1451* @param pErrorCode must be a valid pointer to an error code value.1452*1453* @stable ICU 3.41454*/1455U_STABLE void U_EXPORT21456ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,1457int32_t *pParaStart, int32_t *pParaLimit,1458UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);14591460/**1461* Get the level for one character.1462*1463* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1464*1465* @param charIndex the index of a character. It must be in the range1466* [0..ubidi_getProcessedLength(pBiDi)].1467*1468* @return The level for the character at charIndex (0 if charIndex is not1469* in the valid range).1470*1471* @see UBiDiLevel1472* @see ubidi_getProcessedLength1473* @stable ICU 2.01474*/1475U_STABLE UBiDiLevel U_EXPORT21476ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);14771478/**1479* Get an array of levels for each character.<p>1480*1481* Note that this function may allocate memory under some1482* circumstances, unlike <code>ubidi_getLevelAt()</code>.1483*1484* @param pBiDi is the paragraph or line <code>UBiDi</code> object, whose1485* text length must be strictly positive.1486*1487* @param pErrorCode must be a valid pointer to an error code value.1488*1489* @return The levels array for the text,1490* or <code>NULL</code> if an error occurs.1491*1492* @see UBiDiLevel1493* @see ubidi_getProcessedLength1494* @stable ICU 2.01495*/1496U_STABLE const UBiDiLevel * U_EXPORT21497ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);14981499/**1500* Get a logical run.1501* This function returns information about a run and is used1502* to retrieve runs in logical order.<p>1503* This is especially useful for line-breaking on a paragraph.1504*1505* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1506*1507* @param logicalPosition is a logical position within the source text.1508*1509* @param pLogicalLimit will receive the limit of the corresponding run.1510* The l-value that you point to here may be the1511* same expression (variable) as the one for1512* <code>logicalPosition</code>.1513* This pointer can be <code>NULL</code> if this1514* value is not necessary.1515*1516* @param pLevel will receive the level of the corresponding run.1517* This pointer can be <code>NULL</code> if this1518* value is not necessary.1519*1520* @see ubidi_getProcessedLength1521* @stable ICU 2.01522*/1523U_STABLE void U_EXPORT21524ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,1525int32_t *pLogicalLimit, UBiDiLevel *pLevel);15261527/**1528* Get the number of runs.1529* This function may invoke the actual reordering on the1530* <code>UBiDi</code> object, after <code>ubidi_setPara()</code>1531* may have resolved only the levels of the text. Therefore,1532* <code>ubidi_countRuns()</code> may have to allocate memory,1533* and may fail doing so.1534*1535* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1536*1537* @param pErrorCode must be a valid pointer to an error code value.1538*1539* @return The number of runs.1540* @stable ICU 2.01541*/1542U_STABLE int32_t U_EXPORT21543ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);15441545/**1546* Get one run's logical start, length, and directionality,1547* which can be 0 for LTR or 1 for RTL.1548* In an RTL run, the character at the logical start is1549* visually on the right of the displayed run.1550* The length is the number of characters in the run.<p>1551* <code>ubidi_countRuns()</code> should be called1552* before the runs are retrieved.1553*1554* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1555*1556* @param runIndex is the number of the run in visual order, in the1557* range <code>[0..ubidi_countRuns(pBiDi)-1]</code>.1558*1559* @param pLogicalStart is the first logical character index in the text.1560* The pointer may be <code>NULL</code> if this index is not needed.1561*1562* @param pLength is the number of characters (at least one) in the run.1563* The pointer may be <code>NULL</code> if this is not needed.1564*1565* @return the directionality of the run,1566* <code>UBIDI_LTR==0</code> or <code>UBIDI_RTL==1</code>,1567* never <code>UBIDI_MIXED</code>,1568* never <code>UBIDI_NEUTRAL</code>.1569*1570* @see ubidi_countRuns1571*1572* Example:1573* <pre>1574* \code1575* int32_t i, count=ubidi_countRuns(pBiDi),1576* logicalStart, visualIndex=0, length;1577* for(i=0; i<count; ++i) {1578* if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {1579* do { // LTR1580* show_char(text[logicalStart++], visualIndex++);1581* } while(--length>0);1582* } else {1583* logicalStart+=length; // logicalLimit1584* do { // RTL1585* show_char(text[--logicalStart], visualIndex++);1586* } while(--length>0);1587* }1588* }1589*\endcode1590* </pre>1591*1592* Note that in right-to-left runs, code like this places1593* second surrogates before first ones (which is generally a bad idea)1594* and combining characters before base characters.1595* <p>1596* Use of <code>ubidi_writeReordered()</code>, optionally with the1597* <code>#UBIDI_KEEP_BASE_COMBINING</code> option, can be considered in order1598* to avoid these issues.1599* @stable ICU 2.01600*/1601U_STABLE UBiDiDirection U_EXPORT21602ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,1603int32_t *pLogicalStart, int32_t *pLength);16041605/**1606* Get the visual position from a logical text position.1607* If such a mapping is used many times on the same1608* <code>UBiDi</code> object, then calling1609* <code>ubidi_getLogicalMap()</code> is more efficient.<p>1610*1611* The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no1612* visual position because the corresponding text character is a Bidi control1613* removed from output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.1614* <p>1615* When the visual output is altered by using options of1616* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1617* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1618* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual position returned may not1619* be correct. It is advised to use, when possible, reordering options1620* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1621* <p>1622* Note that in right-to-left runs, this mapping places1623* second surrogates before first ones (which is generally a bad idea)1624* and combining characters before base characters.1625* Use of <code>ubidi_writeReordered()</code>, optionally with the1626* <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead1627* of using the mapping, in order to avoid these issues.1628*1629* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1630*1631* @param logicalIndex is the index of a character in the text.1632*1633* @param pErrorCode must be a valid pointer to an error code value.1634*1635* @return The visual position of this character.1636*1637* @see ubidi_getLogicalMap1638* @see ubidi_getLogicalIndex1639* @see ubidi_getProcessedLength1640* @stable ICU 2.01641*/1642U_STABLE int32_t U_EXPORT21643ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode);16441645/**1646* Get the logical text position from a visual position.1647* If such a mapping is used many times on the same1648* <code>UBiDi</code> object, then calling1649* <code>ubidi_getVisualMap()</code> is more efficient.<p>1650*1651* The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no1652* logical position because the corresponding text character is a Bidi mark1653* inserted in the output by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.1654* <p>1655* This is the inverse function to <code>ubidi_getVisualIndex()</code>.1656* <p>1657* When the visual output is altered by using options of1658* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1659* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1660* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical position returned may not1661* be correct. It is advised to use, when possible, reordering options1662* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1663*1664* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1665*1666* @param visualIndex is the visual position of a character.1667*1668* @param pErrorCode must be a valid pointer to an error code value.1669*1670* @return The index of this character in the text.1671*1672* @see ubidi_getVisualMap1673* @see ubidi_getVisualIndex1674* @see ubidi_getResultLength1675* @stable ICU 2.01676*/1677U_STABLE int32_t U_EXPORT21678ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);16791680/**1681* Get a logical-to-visual index map (array) for the characters in the UBiDi1682* (paragraph or line) object.1683* <p>1684* Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the1685* corresponding text characters are Bidi controls removed from the visual1686* output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.1687* <p>1688* When the visual output is altered by using options of1689* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1690* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1691* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual positions returned may not1692* be correct. It is advised to use, when possible, reordering options1693* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1694* <p>1695* Note that in right-to-left runs, this mapping places1696* second surrogates before first ones (which is generally a bad idea)1697* and combining characters before base characters.1698* Use of <code>ubidi_writeReordered()</code>, optionally with the1699* <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead1700* of using the mapping, in order to avoid these issues.1701*1702* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1703*1704* @param indexMap is a pointer to an array of <code>ubidi_getProcessedLength()</code>1705* indexes which will reflect the reordering of the characters.1706* If option <code>#UBIDI_OPTION_INSERT_MARKS</code> is set, the number1707* of elements allocated in <code>indexMap</code> must be no less than1708* <code>ubidi_getResultLength()</code>.1709* The array does not need to be initialized.<br><br>1710* The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.1711*1712* @param pErrorCode must be a valid pointer to an error code value.1713*1714* @see ubidi_getVisualMap1715* @see ubidi_getVisualIndex1716* @see ubidi_getProcessedLength1717* @see ubidi_getResultLength1718* @stable ICU 2.01719*/1720U_STABLE void U_EXPORT21721ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);17221723/**1724* Get a visual-to-logical index map (array) for the characters in the UBiDi1725* (paragraph or line) object.1726* <p>1727* Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the1728* corresponding text characters are Bidi marks inserted in the visual output1729* by the option <code>#UBIDI_OPTION_INSERT_MARKS</code>.1730* <p>1731* When the visual output is altered by using options of1732* <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,1733* <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,1734* <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical positions returned may not1735* be correct. It is advised to use, when possible, reordering options1736* such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.1737*1738* @param pBiDi is the paragraph or line <code>UBiDi</code> object.1739*1740* @param indexMap is a pointer to an array of <code>ubidi_getResultLength()</code>1741* indexes which will reflect the reordering of the characters.1742* If option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is set, the number1743* of elements allocated in <code>indexMap</code> must be no less than1744* <code>ubidi_getProcessedLength()</code>.1745* The array does not need to be initialized.<br><br>1746* The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.1747*1748* @param pErrorCode must be a valid pointer to an error code value.1749*1750* @see ubidi_getLogicalMap1751* @see ubidi_getLogicalIndex1752* @see ubidi_getProcessedLength1753* @see ubidi_getResultLength1754* @stable ICU 2.01755*/1756U_STABLE void U_EXPORT21757ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);17581759/**1760* This is a convenience function that does not use a UBiDi object.1761* It is intended to be used for when an application has determined the levels1762* of objects (character sequences) and just needs to have them reordered (L2).1763* This is equivalent to using <code>ubidi_getLogicalMap()</code> on a1764* <code>UBiDi</code> object.1765*1766* @param levels is an array with <code>length</code> levels that have been determined by1767* the application.1768*1769* @param length is the number of levels in the array, or, semantically,1770* the number of objects to be reordered.1771* It must be <code>length>0</code>.1772*1773* @param indexMap is a pointer to an array of <code>length</code>1774* indexes which will reflect the reordering of the characters.1775* The array does not need to be initialized.<p>1776* The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.1777* @stable ICU 2.01778*/1779U_STABLE void U_EXPORT21780ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);17811782/**1783* This is a convenience function that does not use a UBiDi object.1784* It is intended to be used for when an application has determined the levels1785* of objects (character sequences) and just needs to have them reordered (L2).1786* This is equivalent to using <code>ubidi_getVisualMap()</code> on a1787* <code>UBiDi</code> object.1788*1789* @param levels is an array with <code>length</code> levels that have been determined by1790* the application.1791*1792* @param length is the number of levels in the array, or, semantically,1793* the number of objects to be reordered.1794* It must be <code>length>0</code>.1795*1796* @param indexMap is a pointer to an array of <code>length</code>1797* indexes which will reflect the reordering of the characters.1798* The array does not need to be initialized.<p>1799* The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.1800* @stable ICU 2.01801*/1802U_STABLE void U_EXPORT21803ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);18041805/**1806* Invert an index map.1807* The index mapping of the first map is inverted and written to1808* the second one.1809*1810* @param srcMap is an array with <code>length</code> elements1811* which defines the original mapping from a source array containing1812* <code>length</code> elements to a destination array.1813* Some elements of the source array may have no mapping in the1814* destination array. In that case, their value will be1815* the special value <code>UBIDI_MAP_NOWHERE</code>.1816* All elements must be >=0 or equal to <code>UBIDI_MAP_NOWHERE</code>.1817* Some elements may have a value >= <code>length</code>, if the1818* destination array has more elements than the source array.1819* There must be no duplicate indexes (two or more elements with the1820* same value except <code>UBIDI_MAP_NOWHERE</code>).1821*1822* @param destMap is an array with a number of elements equal to 1 + the highest1823* value in <code>srcMap</code>.1824* <code>destMap</code> will be filled with the inverse mapping.1825* If element with index i in <code>srcMap</code> has a value k different1826* from <code>UBIDI_MAP_NOWHERE</code>, this means that element i of1827* the source array maps to element k in the destination array.1828* The inverse map will have value i in its k-th element.1829* For all elements of the destination array which do not map to1830* an element in the source array, the corresponding element in the1831* inverse map will have a value equal to <code>UBIDI_MAP_NOWHERE</code>.1832*1833* @param length is the length of each array.1834* @see UBIDI_MAP_NOWHERE1835* @stable ICU 2.01836*/1837U_STABLE void U_EXPORT21838ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);18391840/** option flags for ubidi_writeReordered() */18411842/**1843* option bit for ubidi_writeReordered():1844* keep combining characters after their base characters in RTL runs1845*1846* @see ubidi_writeReordered1847* @stable ICU 2.01848*/1849#define UBIDI_KEEP_BASE_COMBINING 118501851/**1852* option bit for ubidi_writeReordered():1853* replace characters with the "mirrored" property in RTL runs1854* by their mirror-image mappings1855*1856* @see ubidi_writeReordered1857* @stable ICU 2.01858*/1859#define UBIDI_DO_MIRRORING 218601861/**1862* option bit for ubidi_writeReordered():1863* surround the run with LRMs if necessary;1864* this is part of the approximate "inverse Bidi" algorithm1865*1866* <p>This option does not imply corresponding adjustment of the index1867* mappings.</p>1868*1869* @see ubidi_setInverse1870* @see ubidi_writeReordered1871* @stable ICU 2.01872*/1873#define UBIDI_INSERT_LRM_FOR_NUMERIC 418741875/**1876* option bit for ubidi_writeReordered():1877* remove Bidi control characters1878* (this does not affect #UBIDI_INSERT_LRM_FOR_NUMERIC)1879*1880* <p>This option does not imply corresponding adjustment of the index1881* mappings.</p>1882*1883* @see ubidi_writeReordered1884* @stable ICU 2.01885*/1886#define UBIDI_REMOVE_BIDI_CONTROLS 818871888/**1889* option bit for ubidi_writeReordered():1890* write the output in reverse order1891*1892* <p>This has the same effect as calling <code>ubidi_writeReordered()</code>1893* first without this option, and then calling1894* <code>ubidi_writeReverse()</code> without mirroring.1895* Doing this in the same step is faster and avoids a temporary buffer.1896* An example for using this option is output to a character terminal that1897* is designed for RTL scripts and stores text in reverse order.</p>1898*1899* @see ubidi_writeReordered1900* @stable ICU 2.01901*/1902#define UBIDI_OUTPUT_REVERSE 1619031904/**1905* Get the length of the source text processed by the last call to1906* <code>ubidi_setPara()</code>. This length may be different from the length1907* of the source text if option <code>#UBIDI_OPTION_STREAMING</code>1908* has been set.1909* <br>1910* Note that whenever the length of the text affects the execution or the1911* result of a function, it is the processed length which must be considered,1912* except for <code>ubidi_setPara</code> (which receives unprocessed source1913* text) and <code>ubidi_getLength</code> (which returns the original length1914* of the source text).<br>1915* In particular, the processed length is the one to consider in the following1916* cases:1917* <ul>1918* <li>maximum value of the <code>limit</code> argument of1919* <code>ubidi_setLine</code></li>1920* <li>maximum value of the <code>charIndex</code> argument of1921* <code>ubidi_getParagraph</code></li>1922* <li>maximum value of the <code>charIndex</code> argument of1923* <code>ubidi_getLevelAt</code></li>1924* <li>number of elements in the array returned by <code>ubidi_getLevels</code></li>1925* <li>maximum value of the <code>logicalStart</code> argument of1926* <code>ubidi_getLogicalRun</code></li>1927* <li>maximum value of the <code>logicalIndex</code> argument of1928* <code>ubidi_getVisualIndex</code></li>1929* <li>number of elements filled in the <code>*indexMap</code> argument of1930* <code>ubidi_getLogicalMap</code></li>1931* <li>length of text processed by <code>ubidi_writeReordered</code></li>1932* </ul>1933*1934* @param pBiDi is the paragraph <code>UBiDi</code> object.1935*1936* @return The length of the part of the source text processed by1937* the last call to <code>ubidi_setPara</code>.1938* @see ubidi_setPara1939* @see UBIDI_OPTION_STREAMING1940* @stable ICU 3.61941*/1942U_STABLE int32_t U_EXPORT21943ubidi_getProcessedLength(const UBiDi *pBiDi);19441945/**1946* Get the length of the reordered text resulting from the last call to1947* <code>ubidi_setPara()</code>. This length may be different from the length1948* of the source text if option <code>#UBIDI_OPTION_INSERT_MARKS</code>1949* or option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> has been set.1950* <br>1951* This resulting length is the one to consider in the following cases:1952* <ul>1953* <li>maximum value of the <code>visualIndex</code> argument of1954* <code>ubidi_getLogicalIndex</code></li>1955* <li>number of elements of the <code>*indexMap</code> argument of1956* <code>ubidi_getVisualMap</code></li>1957* </ul>1958* Note that this length stays identical to the source text length if1959* Bidi marks are inserted or removed using option bits of1960* <code>ubidi_writeReordered</code>, or if option1961* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> has been set.1962*1963* @param pBiDi is the paragraph <code>UBiDi</code> object.1964*1965* @return The length of the reordered text resulting from1966* the last call to <code>ubidi_setPara</code>.1967* @see ubidi_setPara1968* @see UBIDI_OPTION_INSERT_MARKS1969* @see UBIDI_OPTION_REMOVE_CONTROLS1970* @stable ICU 3.61971*/1972U_STABLE int32_t U_EXPORT21973ubidi_getResultLength(const UBiDi *pBiDi);19741975U_CDECL_BEGIN19761977#ifndef U_HIDE_DEPRECATED_API1978/**1979* Value returned by <code>UBiDiClassCallback</code> callbacks when1980* there is no need to override the standard Bidi class for a given code point.1981*1982* This constant is deprecated; use u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1 instead.1983*1984* @see UBiDiClassCallback1985* @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.1986*/1987#define U_BIDI_CLASS_DEFAULT U_CHAR_DIRECTION_COUNT1988#endif // U_HIDE_DEPRECATED_API19891990/**1991* Callback type declaration for overriding default Bidi class values with1992* custom ones.1993* <p>Usually, the function pointer will be propagated to a <code>UBiDi</code>1994* object by calling the <code>ubidi_setClassCallback()</code> function;1995* then the callback will be invoked by the UBA implementation any time the1996* class of a character is to be determined.</p>1997*1998* @param context is a pointer to the callback private data.1999*2000* @param c is the code point to get a Bidi class for.2001*2002* @return The directional property / Bidi class for the given code point2003* <code>c</code> if the default class has been overridden, or2004* <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>2005* if the standard Bidi class value for <code>c</code> is to be used.2006* @see ubidi_setClassCallback2007* @see ubidi_getClassCallback2008* @stable ICU 3.62009*/2010typedef UCharDirection U_CALLCONV2011UBiDiClassCallback(const void *context, UChar32 c);20122013U_CDECL_END20142015/**2016* Retrieve the Bidi class for a given code point.2017* <p>If a <code>#UBiDiClassCallback</code> callback is defined and returns a2018* value other than <code>u_getIntPropertyMaxValue(UCHAR_BIDI_CLASS)+1</code>,2019* that value is used; otherwise the default class determination mechanism is invoked.</p>2020*2021* @param pBiDi is the paragraph <code>UBiDi</code> object.2022*2023* @param c is the code point whose Bidi class must be retrieved.2024*2025* @return The Bidi class for character <code>c</code> based2026* on the given <code>pBiDi</code> instance.2027* @see UBiDiClassCallback2028* @stable ICU 3.62029*/2030U_STABLE UCharDirection U_EXPORT22031ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c);20322033/**2034* Set the callback function and callback data used by the UBA2035* implementation for Bidi class determination.2036* <p>This may be useful for assigning Bidi classes to PUA characters, or2037* for special application needs. For instance, an application may want to2038* handle all spaces like L or R characters (according to the base direction)2039* when creating the visual ordering of logical lines which are part of a report2040* organized in columns: there should not be interaction between adjacent2041* cells.<p>2042*2043* @param pBiDi is the paragraph <code>UBiDi</code> object.2044*2045* @param newFn is the new callback function pointer.2046*2047* @param newContext is the new callback context pointer. This can be NULL.2048*2049* @param oldFn fillin: Returns the old callback function pointer. This can be2050* NULL.2051*2052* @param oldContext fillin: Returns the old callback's context. This can be2053* NULL.2054*2055* @param pErrorCode must be a valid pointer to an error code value.2056*2057* @see ubidi_getClassCallback2058* @stable ICU 3.62059*/2060U_STABLE void U_EXPORT22061ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,2062const void *newContext, UBiDiClassCallback **oldFn,2063const void **oldContext, UErrorCode *pErrorCode);20642065/**2066* Get the current callback function used for Bidi class determination.2067*2068* @param pBiDi is the paragraph <code>UBiDi</code> object.2069*2070* @param fn fillin: Returns the callback function pointer.2071*2072* @param context fillin: Returns the callback's private context.2073*2074* @see ubidi_setClassCallback2075* @stable ICU 3.62076*/2077U_STABLE void U_EXPORT22078ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context);20792080/**2081* Take a <code>UBiDi</code> object containing the reordering2082* information for a piece of text (one or more paragraphs) set by2083* <code>ubidi_setPara()</code> or for a line of text set by2084* <code>ubidi_setLine()</code> and write a reordered string to the2085* destination buffer.2086*2087* This function preserves the integrity of characters with multiple2088* code units and (optionally) combining characters.2089* Characters in RTL runs can be replaced by mirror-image characters2090* in the destination buffer. Note that "real" mirroring has2091* to be done in a rendering engine by glyph selection2092* and that for many "mirrored" characters there are no2093* Unicode characters as mirror-image equivalents.2094* There are also options to insert or remove Bidi control2095* characters; see the description of the <code>destSize</code>2096* and <code>options</code> parameters and of the option bit flags.2097*2098* @param pBiDi A pointer to a <code>UBiDi</code> object that2099* is set by <code>ubidi_setPara()</code> or2100* <code>ubidi_setLine()</code> and contains the reordering2101* information for the text that it was defined for,2102* as well as a pointer to that text.<br><br>2103* The text was aliased (only the pointer was stored2104* without copying the contents) and must not have been modified2105* since the <code>ubidi_setPara()</code> call.2106*2107* @param dest A pointer to where the reordered text is to be copied.2108* The source text and <code>dest[destSize]</code>2109* must not overlap.2110*2111* @param destSize The size of the <code>dest</code> buffer,2112* in number of UChars.2113* If the <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>2114* option is set, then the destination length could be2115* as large as2116* <code>ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)</code>.2117* If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option2118* is set, then the destination length may be less than2119* <code>ubidi_getLength(pBiDi)</code>.2120* If none of these options is set, then the destination length2121* will be exactly <code>ubidi_getProcessedLength(pBiDi)</code>.2122*2123* @param options A bit set of options for the reordering that control2124* how the reordered text is written.2125* The options include mirroring the characters on a code2126* point basis and inserting LRM characters, which is used2127* especially for transforming visually stored text2128* to logically stored text (although this is still an2129* imperfect implementation of an "inverse Bidi" algorithm2130* because it uses the "forward Bidi" algorithm at its core).2131* The available options are:2132* <code>#UBIDI_DO_MIRRORING</code>,2133* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>,2134* <code>#UBIDI_KEEP_BASE_COMBINING</code>,2135* <code>#UBIDI_OUTPUT_REVERSE</code>,2136* <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>2137*2138* @param pErrorCode must be a valid pointer to an error code value.2139*2140* @return The length of the output string.2141*2142* @see ubidi_getProcessedLength2143* @stable ICU 2.02144*/2145U_STABLE int32_t U_EXPORT22146ubidi_writeReordered(UBiDi *pBiDi,2147UChar *dest, int32_t destSize,2148uint16_t options,2149UErrorCode *pErrorCode);21502151/**2152* Reverse a Right-To-Left run of Unicode text.2153*2154* This function preserves the integrity of characters with multiple2155* code units and (optionally) combining characters.2156* Characters can be replaced by mirror-image characters2157* in the destination buffer. Note that "real" mirroring has2158* to be done in a rendering engine by glyph selection2159* and that for many "mirrored" characters there are no2160* Unicode characters as mirror-image equivalents.2161* There are also options to insert or remove Bidi control2162* characters.2163*2164* This function is the implementation for reversing RTL runs as part2165* of <code>ubidi_writeReordered()</code>. For detailed descriptions2166* of the parameters, see there.2167* Since no Bidi controls are inserted here, the output string length2168* will never exceed <code>srcLength</code>.2169*2170* @see ubidi_writeReordered2171*2172* @param src A pointer to the RTL run text.2173*2174* @param srcLength The length of the RTL run.2175*2176* @param dest A pointer to where the reordered text is to be copied.2177* <code>src[srcLength]</code> and <code>dest[destSize]</code>2178* must not overlap.2179*2180* @param destSize The size of the <code>dest</code> buffer,2181* in number of UChars.2182* If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option2183* is set, then the destination length may be less than2184* <code>srcLength</code>.2185* If this option is not set, then the destination length2186* will be exactly <code>srcLength</code>.2187*2188* @param options A bit set of options for the reordering that control2189* how the reordered text is written.2190* See the <code>options</code> parameter in <code>ubidi_writeReordered()</code>.2191*2192* @param pErrorCode must be a valid pointer to an error code value.2193*2194* @return The length of the output string.2195* @stable ICU 2.02196*/2197U_STABLE int32_t U_EXPORT22198ubidi_writeReverse(const UChar *src, int32_t srcLength,2199UChar *dest, int32_t destSize,2200uint16_t options,2201UErrorCode *pErrorCode);22022203/*#define BIDI_SAMPLE_CODE*/2204/*@}*/22052206#endif220722082209