ubidi.h File Reference

C API: Bidi algorithm. More...

#include "unicode/utypes.h"
#include "unicode/uchar.h"

Go to the source code of this file.
#define UBIDI_DEFAULT_LTR   0xfe
 Paragraph level setting.
#define UBIDI_DEFAULT_RTL   0xff
 Paragraph level setting.
#define UBIDI_MAX_EXPLICIT_LEVEL   61
 Maximum explicit embedding level.
#define UBIDI_LEVEL_OVERRIDE   0x80
 Bit flag for level input.
#define UBIDI_MAP_NOWHERE   (-1)
 Special value which can be returned by the mapping functions when a logical index has no corresponding visual index or vice-versa.
#define UBIDI_KEEP_BASE_COMBINING   1
 option flags for ubidi_writeReordered()
#define UBIDI_DO_MIRRORING   2
 option bit for ubidi_writeReordered(): replace characters with the "mirrored" property in RTL runs by their mirror-image mappings
#define UBIDI_INSERT_LRM_FOR_NUMERIC   4
 option bit for ubidi_writeReordered(): surround the run with LRMs if necessary; this is part of the approximate "inverse Bidi" algorithm
#define UBIDI_REMOVE_BIDI_CONTROLS   8
 option bit for ubidi_writeReordered(): remove Bidi control characters (this does not affect UBIDI_INSERT_LRM_FOR_NUMERIC)
#define UBIDI_OUTPUT_REVERSE   16
 option bit for ubidi_writeReordered(): write the output in reverse order
#define U_BIDI_CLASS_DEFAULT   U_CHAR_DIRECTION_COUNT
 value returned by UBiDiClassCallback callbacks when there is no need to override the standard Bidi class for a given code point.
enum  UBiDiDirection { UBIDI_LTR, UBIDI_RTL, UBIDI_MIXED }
 UBiDiDirection values indicate the text direction. More...
enum  UBiDiReorderingMode {
  UBIDI_REORDER_DEFAULT = 0, UBIDI_REORDER_NUMBERS_SPECIAL, UBIDI_REORDER_GROUP_NUMBERS_WITH_R, UBIDI_REORDER_RUNS_ONLY,
  UBIDI_REORDER_INVERSE_NUMBERS_AS_L, UBIDI_REORDER_INVERSE_LIKE_DIRECT, UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL, UBIDI_REORDER_COUNT
}
 UBiDiReorderingMode values indicate which variant of the Bidi algorithm to use. More...
enum  UBiDiReorderingOption { UBIDI_OPTION_DEFAULT = 0, UBIDI_OPTION_INSERT_MARKS = 1, UBIDI_OPTION_REMOVE_CONTROLS = 2, UBIDI_OPTION_STREAMING = 4 }
 UBiDiReorderingOption values indicate which options are specified to affect the Bidi algorithm. More...
typedef uint8_t UBiDiLevel
 UBiDiLevel is the type of the level values in this Bidi implementation.
typedef struct UBiDi UBiDi
typedef UCharDirection U_CALLCONV UBiDiClassCallback (const void *context, UChar32 c)
 Callback type declaration for overriding default Bidi class values with custom ones.
UBiDiubidi_open (void)
 Allocate a UBiDi structure.
UBiDiubidi_openSized (int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode)
 Allocate a UBiDi structure with preallocated memory for internal structures.
void ubidi_close (UBiDi *pBiDi)
 ubidi_close() must be called to free the memory associated with a UBiDi object.
void ubidi_setInverse (UBiDi *pBiDi, UBool isInverse)
 Modify the operation of the Bidi algorithm such that it approximates an "inverse Bidi" algorithm.
UBool ubidi_isInverse (UBiDi *pBiDi)
 Is this Bidi object set to perform the inverse Bidi algorithm?
void ubidi_orderParagraphsLTR (UBiDi *pBiDi, UBool orderParagraphsLTR)
 Specify whether block separators must be allocated level zero, so that successive paragraphs will progress from left to right.
UBool ubidi_isOrderParagraphsLTR (UBiDi *pBiDi)
 Is this Bidi object set to allocate level 0 to block separators so that successive paragraphs progress from left to right?
void ubidi_setReorderingMode (UBiDi *pBiDi, UBiDiReorderingMode reorderingMode)
 Modify the operation of the Bidi algorithm such that it implements some variant to the basic Bidi algorithm or approximates an "inverse Bidi" algorithm, depending on different values of the "reordering mode".
UBiDiReorderingMode ubidi_getReorderingMode (UBiDi *pBiDi)
 What is the requested reordering mode for a given Bidi object?
void ubidi_setReorderingOptions (UBiDi *pBiDi, uint32_t reorderingOptions)
 Specify which of the reordering options should be applied during Bidi transformations.
uint32_t ubidi_getReorderingOptions (UBiDi *pBiDi)
 What are the reordering options applied to a given Bidi object?
void ubidi_setPara (UBiDi *pBiDi, const UChar *text, int32_t length, UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels, UErrorCode *pErrorCode)
 Perform the Unicode Bidi algorithm.
void ubidi_setLine (const UBiDi *pParaBiDi, int32_t start, int32_t limit, UBiDi *pLineBiDi, UErrorCode *pErrorCode)
 ubidi_setLine() sets a UBiDi to contain the reordering information, especially the resolved levels, for all the characters in a line of text.
UBiDiDirection ubidi_getDirection (const UBiDi *pBiDi)
 Get the directionality of the text.
const UChar * ubidi_getText (const UBiDi *pBiDi)
 Get the pointer to the text.
int32_t ubidi_getLength (const UBiDi *pBiDi)
 Get the length of the text.
UBiDiLevel ubidi_getParaLevel (const UBiDi *pBiDi)
 Get the paragraph level of the text.
int32_t ubidi_countParagraphs (UBiDi *pBiDi)
 Get the number of paragraphs.
int32_t ubidi_getParagraph (const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart, int32_t *pParaLimit, UBiDiLevel *pParaLevel, UErrorCode *pErrorCode)
 Get a paragraph, given a position within the text.
void ubidi_getParagraphByIndex (const UBiDi *pBiDi, int32_t paraIndex, int32_t *pParaStart, int32_t *pParaLimit, UBiDiLevel *pParaLevel, UErrorCode *pErrorCode)
 Get a paragraph, given the index of this paragraph.
UBiDiLevel ubidi_getLevelAt (const UBiDi *pBiDi, int32_t charIndex)
 Get the level for one character.
const UBiDiLevelubidi_getLevels (UBiDi *pBiDi, UErrorCode *pErrorCode)
 Get an array of levels for each character.
void ubidi_getLogicalRun (const UBiDi *pBiDi, int32_t logicalPosition, int32_t *pLogicalLimit, UBiDiLevel *pLevel)
 Get a logical run.
int32_t ubidi_countRuns (UBiDi *pBiDi, UErrorCode *pErrorCode)
 Get the number of runs.
UBiDiDirection ubidi_getVisualRun (UBiDi *pBiDi, int32_t runIndex, int32_t *pLogicalStart, int32_t *pLength)
 Get one run's logical start, length, and directionality, which can be 0 for LTR or 1 for RTL.
int32_t ubidi_getVisualIndex (UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode)
 Get the visual position from a logical text position.
int32_t ubidi_getLogicalIndex (UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode)
 Get the logical text position from a visual position.
void ubidi_getLogicalMap (UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode)
 Get a logical-to-visual index map (array) for the characters in the UBiDi (paragraph or line) object.
void ubidi_getVisualMap (UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode)
 Get a visual-to-logical index map (array) for the characters in the UBiDi (paragraph or line) object.
void ubidi_reorderLogical (const UBiDiLevel *levels, int32_t length, int32_t *indexMap)
 This is a convenience function that does not use a UBiDi object.
void ubidi_reorderVisual (const UBiDiLevel *levels, int32_t length, int32_t *indexMap)
 This is a convenience function that does not use a UBiDi object.
void ubidi_invertMap (const int32_t *srcMap, int32_t *destMap, int32_t length)
 Invert an index map.
int32_t ubidi_getProcessedLength (const UBiDi *pBiDi)
 Get the length of the source text processed by the last call to ubidi_setPara().
int32_t ubidi_getResultLength (const UBiDi *pBiDi)
 Get the length of the reordered text resulting from the last call to ubidi_setPara().
U_CDECL_END UCharDirection ubidi_getCustomizedClass (UBiDi *pBiDi, UChar32 c)
 Retrieve the Bidi class for a given code point.
void ubidi_setClassCallback (UBiDi *pBiDi, UBiDiClassCallback *newFn, const void *newContext, UBiDiClassCallback **oldFn, const void **oldContext, UErrorCode *pErrorCode)
 Set the callback function and callback data used by the UBA implementation for Bidi class determination.
void ubidi_getClassCallback (UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context)
 Get the current callback function used for Bidi class determination.
int32_t ubidi_writeReordered (UBiDi *pBiDi, UChar *dest, int32_t destSize, uint16_t options, UErrorCode *pErrorCode)
 Take a UBiDi object containing the reordering information for a piece of text (one or more paragraphs) set by ubidi_setPara() or for a line of text set by ubidi_setLine() and write a reordered string to the destination buffer.
int32_t ubidi_writeReverse (const UChar *src, int32_t srcLength, UChar *dest, int32_t destSize, uint16_t options, UErrorCode *pErrorCode)
 Reverse a Right-To-Left run of Unicode text.


Detailed Description

C API: Bidi algorithm.

Bidi algorithm for ICU

This is an implementation of the Unicode Bidirectional algorithm. The algorithm is defined in the Unicode Standard Annex #9, version 13, also described in The Unicode Standard, Version 4.0 .

Note: Libraries that perform a bidirectional algorithm and reorder strings accordingly are sometimes called "Storage Layout Engines". ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such "Storage Layout Engines".

General remarks about the API:

In functions with an error code parameter, the pErrorCode pointer must be valid and the value that it points to must not indicate a failure before the function call. Otherwise, the function returns immediately. After the function call, the value indicates success or failure.

The "limit" of a sequence of characters is the position just after their last character, i.e., one more than that position.

Some of the API functions provide access to "runs". Such a "run" is defined as a sequence of characters that are at the same embedding level after performing the Bidi algorithm.

Author:
Markus W. Scherer
Version:
1.0

Sample code for the ICU Bidi API

Rendering a paragraph with the ICU Bidi API

This is (hypothetical) sample code that illustrates how the ICU Bidi API could be used to render a paragraph of text. Rendering code depends highly on the graphics system, therefore this sample code must make a lot of assumptions, which may or may not match any existing graphics system's properties.

The basic assumptions are:

 
 *#include "unicode/ubidi.h"

 *typedef enum {
     styleNormal=0, styleSelected=1,
     styleBold=2, styleItalics=4,
     styleSuper=8, styleSub=16
 *} Style;

 *typedef struct { int32_t limit; Style style; } StyleRun;

 *int getTextWidth(const UChar *text, int32_t start, int32_t limit,
                  const StyleRun *styleRuns, int styleRunCount);

 // set *pLimit and *pStyleRunLimit for a line
 // from text[start] and from styleRuns[styleRunStart]
 // using ubidi_getLogicalRun(para, ...)
 *void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,
                  UBiDi *para,
                  const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,
                  int *pLineWidth);

 // render runs on a line sequentially, always from left to right

 // prepare rendering a new line
 void startLine(UBiDiDirection textDirection, int lineWidth);

 // render a run of text and advance to the right by the run width
 // the text[start..limit-1] is always in logical order
 void renderRun(const UChar *text, int32_t start, int32_t limit,
               UBiDiDirection textDirection, Style style);

 // We could compute a cross-product
 // from the style runs with the directional runs
 // and then reorder it.
 // Instead, here we iterate over each run type
 // and render the intersections -
 // with shortcuts in simple (and common) cases.
 // renderParagraph() is the main function.

 // render a directional run with
 // (possibly) multiple style runs intersecting with it
 void renderDirectionalRun(const UChar *text,
                           int32_t start, int32_t limit,
                           UBiDiDirection direction,
                           const StyleRun *styleRuns, int styleRunCount) {
     int i;

     // iterate over style runs
     if(direction==UBIDI_LTR) {
         int styleLimit;

         for(i=0; i<styleRunCount; ++i) {
             styleLimit=styleRun[i].limit;
             if(start<styleLimit) {
                 if(styleLimit>limit) { styleLimit=limit; }
                 renderRun(text, start, styleLimit,
                           direction, styleRun[i].style);
                 if(styleLimit==limit) { break; }
                 start=styleLimit;
             }
         }
     } else {
         int styleStart;

         for(i=styleRunCount-1; i>=0; --i) {
             if(i>0) {
                 styleStart=styleRun[i-1].limit;
             } else {
                 styleStart=0;
             }
             if(limit>=styleStart) {
                 if(styleStart<start) { styleStart=start; }
                 renderRun(text, styleStart, limit,
                           direction, styleRun[i].style);
                 if(styleStart==start) { break; }
                 limit=styleStart;
             }
         }
     }
 }

 // the line object represents text[start..limit-1]
 void renderLine(UBiDi *line, const UChar *text,
                 int32_t start, int32_t limit,
                 const StyleRun *styleRuns, int styleRunCount) {
     UBiDiDirection direction=ubidi_getDirection(line);
     if(direction!=UBIDI_MIXED) {
         // unidirectional
         if(styleRunCount<=1) {
             renderRun(text, start, limit, direction, styleRuns[0].style);
         } else {
             renderDirectionalRun(text, start, limit,
                                  direction, styleRuns, styleRunCount);
         }
     } else {
         // mixed-directional
         int32_t count, i, length;
         UBiDiLevel level;

         count=ubidi_countRuns(para, pErrorCode);
         if(U_SUCCESS(*pErrorCode)) {
             if(styleRunCount<=1) {
                 Style style=styleRuns[0].style;

                 // iterate over directional runs
                for(i=0; i<count; ++i) {
                    direction=ubidi_getVisualRun(para, i, &start, &length);
                     renderRun(text, start, start+length, direction, style);
                }
             } else {
                 int32_t j;

                 // iterate over both directional and style runs
                 for(i=0; i<count; ++i) {
                     direction=ubidi_getVisualRun(line, i, &start, &length);
                     renderDirectionalRun(text, start, start+length,
                                          direction, styleRuns, styleRunCount);
                 }
             }
         }
     }
 }

 *void renderParagraph(const UChar *text, int32_t length,
                     UBiDiDirection textDirection,
                      const StyleRun *styleRuns, int styleRunCount,
                      int lineWidth,
                      UErrorCode *pErrorCode) {
     UBiDi *para;

     if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {
         return;
     }

     para=ubidi_openSized(length, 0, pErrorCode);
     if(para==NULL) { return; }

     ubidi_setPara(para, text, length,
                   textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
                   NULL, pErrorCode);
     if(U_SUCCESS(*pErrorCode)) {
         UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);
         StyleRun styleRun={ length, styleNormal };
         int width;

         if(styleRuns==NULL || styleRunCount<=0) {
            styleRunCount=1;
             styleRuns=&styleRun;
         }

        // assume styleRuns[styleRunCount-1].limit>=length

         width=getTextWidth(text, 0, length, styleRuns, styleRunCount);
         if(width<=lineWidth) {
             // everything fits onto one line

            // prepare rendering a new line from either left or right
             startLine(paraLevel, width);

             renderLine(para, text, 0, length,
                        styleRuns, styleRunCount);
         } else {
             UBiDi *line;

             // we need to render several lines
             line=ubidi_openSized(length, 0, pErrorCode);
             if(line!=NULL) {
                 int32_t start=0, limit;
                 int styleRunStart=0, styleRunLimit;

                 for(;;) {
                     limit=length;
                     styleRunLimit=styleRunCount;
                     getLineBreak(text, start, &limit, para,
                                  styleRuns, styleRunStart, &styleRunLimit,
                                 &width);
                     ubidi_setLine(para, start, limit, line, pErrorCode);
                     if(U_SUCCESS(*pErrorCode)) {
                         // prepare rendering a new line
                         // from either left or right
                         startLine(paraLevel, width);

                         renderLine(line, text, start, limit,
                                    styleRuns+styleRunStart,
                                    styleRunLimit-styleRunStart);
                     }
                     if(limit==length) { break; }
                     start=limit;
                     styleRunStart=styleRunLimit-1;
                     if(start>=styleRuns[styleRunStart].limit) {
                         ++styleRunStart;
                     }
                 }

                 ubidi_close(line);
             }
        }
    }

     ubidi_close(para);
 *}
 *

Definition in file ubidi.h.


Define Documentation

#define U_BIDI_CLASS_DEFAULT   U_CHAR_DIRECTION_COUNT

value returned by UBiDiClassCallback callbacks when there is no need to override the standard Bidi class for a given code point.

See also:
UBiDiClassCallback
Stable:
ICU 3.6

Definition at line 1795 of file ubidi.h.

#define UBIDI_DEFAULT_LTR   0xfe

Paragraph level setting.

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, then set the paragraph level to 0 (left-to-right).

If this value is used in conjunction with reordering modes UBIDI_REORDER_INVERSE_LIKE_DIRECT or UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL, the text to reorder is assumed to be visual LTR, and the text after reordering is required to be the corresponding logical string with appropriate contextual direction. The direction of the result string will be RTL if either the righmost or leftmost strong character of the source text is RTL or Arabic Letter, the direction will be LTR otherwise.

If reordering option UBIDI_OPTION_INSERT_MARKS is set, an RLM may be added at the beginning of the result string to ensure round trip (that the result string, when reordered back to visual, will produce the original source text).

See also:
UBIDI_REORDER_INVERSE_LIKE_DIRECT

UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL

Stable:
ICU 2.0

Definition at line 356 of file ubidi.h.

#define UBIDI_DEFAULT_RTL   0xff

Paragraph level setting.

Constant indicating that the base direction depends on the first strong directional character in the text according to the Unicode Bidirectional Algorithm. If no strong directional character is present, then set the paragraph level to 1 (right-to-left).

If this value is used in conjunction with reordering modes UBIDI_REORDER_INVERSE_LIKE_DIRECT or UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL, the text to reorder is assumed to be visual LTR, and the text after reordering is required to be the corresponding logical string with appropriate contextual direction. The direction of the result string will be RTL if either the righmost or leftmost strong character of the source text is RTL or Arabic Letter, or if the text contains no strong character; the direction will be LTR otherwise.

If reordering option UBIDI_OPTION_INSERT_MARKS is set, an RLM may be added at the beginning of the result string to ensure round trip (that the result string, when reordered back to visual, will produce the original source text).

See also:
UBIDI_REORDER_INVERSE_LIKE_DIRECT

UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL

Stable:
ICU 2.0

Definition at line 383 of file ubidi.h.

#define UBIDI_DO_MIRRORING   2

option bit for ubidi_writeReordered(): replace characters with the "mirrored" property in RTL runs by their mirror-image mappings

See also:
ubidi_writeReordered
Stable:
ICU 2.0

Definition at line 1672 of file ubidi.h.

#define UBIDI_INSERT_LRM_FOR_NUMERIC   4

option bit for ubidi_writeReordered(): surround the run with LRMs if necessary; this is part of the approximate "inverse Bidi" algorithm

This option does not imply corresponding adjustment of the index mappings.

See also:
ubidi_setInverse

ubidi_writeReordered

Stable:
ICU 2.0

Definition at line 1686 of file ubidi.h.

#define UBIDI_KEEP_BASE_COMBINING   1

option flags for ubidi_writeReordered()

option bit for ubidi_writeReordered(): keep combining characters after their base characters in RTL runs

See also:
ubidi_writeReordered
Stable:
ICU 2.0

Definition at line 1662 of file ubidi.h.

#define UBIDI_LEVEL_OVERRIDE   0x80

Bit flag for level input.

Overrides directional properties.

Stable:
ICU 2.0

Definition at line 396 of file ubidi.h.

#define UBIDI_MAP_NOWHERE   (-1)

Special value which can be returned by the mapping functions when a logical index has no corresponding visual index or vice-versa.

This may happen for the logical-to-visual mapping of a Bidi control when option UBIDI_OPTION_REMOVE_CONTROLS is specified. This can also happen for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted by option UBIDI_OPTION_INSERT_MARKS.

See also:
ubidi_getVisualIndex

ubidi_getVisualMap

ubidi_getLogicalIndex

ubidi_getLogicalMap

Stable:
ICU 3.6

Definition at line 411 of file ubidi.h.

#define UBIDI_MAX_EXPLICIT_LEVEL   61

Maximum explicit embedding level.

(The maximum resolved level can be up to UBIDI_MAX_EXPLICIT_LEVEL+1).

Stable:
ICU 2.0

Definition at line 390 of file ubidi.h.

#define UBIDI_OUTPUT_REVERSE   16

option bit for ubidi_writeReordered(): write the output in reverse order

This has the same effect as calling ubidi_writeReordered() first without this option, and then calling ubidi_writeReverse() without mirroring. Doing this in the same step is faster and avoids a temporary buffer. An example for using this option is output to a character terminal that is designed for RTL scripts and stores text in reverse order.

See also:
ubidi_writeReordered
Stable:
ICU 2.0

Definition at line 1715 of file ubidi.h.

#define UBIDI_REMOVE_BIDI_CONTROLS   8

option bit for ubidi_writeReordered(): remove Bidi control characters (this does not affect UBIDI_INSERT_LRM_FOR_NUMERIC)

This option does not imply corresponding adjustment of the index mappings.

See also:
ubidi_writeReordered
Stable:
ICU 2.0

Definition at line 1699 of file ubidi.h.


Typedef Documentation

typedef struct UBiDi UBiDi

Stable:
ICU 2.0

Definition at line 442 of file ubidi.h.

typedef UCharDirection U_CALLCONV UBiDiClassCallback(const void *context, UChar32 c)

Callback type declaration for overriding default Bidi class values with custom ones.

Usually, the function pointer will be propagated to a UBiDi object by calling the ubidi_setClassCallback() function; then the callback will be invoked by the UBA implementation any time the class of a character is to be determined.

Parameters:
context is a pointer to the callback private data.
c is the code point to get a Bidi class for.
Returns:
The directional property / Bidi class for the given code point c if the default class has been overridden, or U_BIDI_CLASS_DEFAULT if the standard Bidi class value for c is to be used.
See also:
ubidi_setClassCallback

ubidi_getClassCallback

Stable:
ICU 3.6

Definition at line 1818 of file ubidi.h.

typedef uint8_t UBiDiLevel

UBiDiLevel is the type of the level values in this Bidi implementation.

It holds an embedding level and indicates the visual direction by its bit 0 (even/odd value).

It can also hold non-level values for the paraLevel and embeddingLevels arguments of ubidi_setPara(); there:

  • bit 7 of an embeddingLevels[] value indicates whether the using application is specifying the level of a character to override whatever the Bidi implementation would resolve it to.
  • paraLevel can be set to the pseudo-level values UBIDI_DEFAULT_LTR and UBIDI_DEFAULT_RTL.

See also:
ubidi_setPara

The related constants are not real, valid level values. UBIDI_DEFAULT_XXX can be used to specify a default for the paragraph level for when the ubidi_setPara() function shall determine it but there is no strongly typed character in the input.

Note that the value for UBIDI_DEFAULT_LTR is even and the one for UBIDI_DEFAULT_RTL is odd, just like with normal LTR and RTL level values - these special values are designed that way. Also, the implementation assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.

See also:
UBIDI_DEFAULT_LTR

UBIDI_DEFAULT_RTL

UBIDI_LEVEL_OVERRIDE

UBIDI_MAX_EXPLICIT_LEVEL

Stable:
ICU 2.0

Definition at line 330 of file ubidi.h.


Enumeration Type Documentation

enum typedef enum UBiDiDirection UBiDiDirection

UBiDiDirection values indicate the text direction.

Stable:
ICU 2.0
Stable:
ICU 2.0
Enumerator:
UBIDI_LTR  All left-to-right text.

This is a 0 value.

Stable:
ICU 2.0
UBIDI_RTL  All right-to-left text.

This is a 1 value.

Stable:
ICU 2.0
UBIDI_MIXED  Mixed-directional text.

Stable:
ICU 2.0

Definition at line 417 of file ubidi.h.

UBiDiReorderingMode values indicate which variant of the Bidi algorithm to use.

See also:
ubidi_setReorderingMode
Stable:
ICU 3.6
Enumerator:
UBIDI_REORDER_DEFAULT  Regular Logical to Visual Bidi algorithm according to Unicode.

This is a 0 value.

Stable:
ICU 3.6
UBIDI_REORDER_NUMBERS_SPECIAL  Logical to Visual algorithm which handles numbers in a way which mimicks the behavior of Windows XP.

Stable:
ICU 3.6
UBIDI_REORDER_GROUP_NUMBERS_WITH_R  Logical to Visual algorithm grouping numbers with adjacent R characters (reversible algorithm).

Stable:
ICU 3.6
UBIDI_REORDER_RUNS_ONLY  Reorder runs only to transform a Logical LTR string to the Logical RTL string with the same display, or vice-versa.


If this mode is set together with option UBIDI_OPTION_INSERT_MARKS, some Bidi controls in the source text may be removed and other controls may be added to produce the minimum combination which has the required display.

Stable:
ICU 3.6
UBIDI_REORDER_INVERSE_NUMBERS_AS_L  Visual to Logical algorithm which handles numbers like L (same algorithm as selected by ubidi_setInverse(TRUE).

See also:
ubidi_setInverse
Stable:
ICU 3.6
UBIDI_REORDER_INVERSE_LIKE_DIRECT  Visual to Logical algorithm equivalent to the regular Logical to Visual algorithm.

Stable:
ICU 3.6
UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL  Inverse Bidi (Visual to Logical) algorithm for the UBIDI_REORDER_NUMBERS_SPECIAL Bidi algorithm.

Stable:
ICU 3.6
UBIDI_REORDER_COUNT  Number of values for reordering mode.

Stable:
ICU 3.6

Definition at line 636 of file ubidi.h.

UBiDiReorderingOption values indicate which options are specified to affect the Bidi algorithm.

See also:
ubidi_setReorderingOptions
Stable:
ICU 3.6
Enumerator:
UBIDI_OPTION_DEFAULT  option value for ubidi_setReorderingOptions: disable all the options which can be set with this function

See also:
ubidi_setReorderingOptions
Stable:
ICU 3.6
UBIDI_OPTION_INSERT_MARKS  option bit for ubidi_setReorderingOptions: insert Bidi marks (LRM or RLM) when needed to ensure correct result of a reordering to a Logical order

This option must be set or reset before calling ubidi_setPara.

This option is significant only with reordering modes which generate a result with Logical order, specifically:

If this option is set in conjunction with reordering mode UBIDI_REORDER_INVERSE_NUMBERS_AS_L or with calling ubidi_setInverse(TRUE), it implies option UBIDI_INSERT_LRM_FOR_NUMERIC in calls to function ubidi_writeReordered().

For other reordering modes, a minimum number of LRM or RLM characters will be added to the source text after reordering it so as to ensure round trip, i.e. when applying the inverse reordering mode on the resulting logical text with removal of Bidi marks (option UBIDI_OPTION_REMOVE_CONTROLS set before calling ubidi_setPara() or option UBIDI_REMOVE_BIDI_CONTROLS in ubidi_writeReordered), the result will be identical to the source text in the first transformation.

This option will be ignored if specified together with option UBIDI_OPTION_REMOVE_CONTROLS. It inhibits option UBIDI_REMOVE_BIDI_CONTROLS in calls to function ubidi_writeReordered() and it implies option UBIDI_INSERT_LRM_FOR_NUMERIC in calls to function ubidi_writeReordered() if the reordering mode is UBIDI_REORDER_INVERSE_NUMBERS_AS_L.

See also:
ubidi_setReorderingMode

ubidi_setReorderingOptions

Stable:
ICU 3.6
UBIDI_OPTION_REMOVE_CONTROLS  option bit for ubidi_setReorderingOptions: remove Bidi control characters

This option must be set or reset before calling ubidi_setPara.

This option nullifies option UBIDI_OPTION_INSERT_MARKS. It inhibits option UBIDI_INSERT_LRM_FOR_NUMERIC in calls to function ubidi_writeReordered() and it implies option UBIDI_REMOVE_BIDI_CONTROLS in calls to that function.

See also:
ubidi_setReorderingMode

ubidi_setReorderingOptions

Stable:
ICU 3.6
UBIDI_OPTION_STREAMING  option bit for ubidi_setReorderingOptions: process the output as part of a stream to be continued

This option must be set or reset before calling ubidi_setPara.

This option specifies that the caller is interested in processing large text object in parts. The results of the successive calls are expected to be concatenated by the caller. Only the call for the last part will have this option bit off.

When this option bit is on, ubidi_setPara() may process less than the full source text in order to truncate the text at a meaningful boundary. The caller should call ubidi_getProcessedLength() immediately after calling ubidi_setPara() in order to determine how much of the source text has been processed. Source text beyond that length should be resubmitted in following calls to ubidi_setPara. The processed length may be less than the length of the source text if a character preceding the last character of the source text constitutes a reasonable boundary (like a block separator) for text to be continued.
If the last character of the source text constitutes a reasonable boundary, the whole text will be processed at once.
If nowhere in the source text there exists such a reasonable boundary, the processed length will be zero.
The caller should check for such an occurrence and do one of the following:

  • submit a larger amount of text with a better chance to include a reasonable boundary.
  • resubmit the same text after turning off option UBIDI_OPTION_STREAMING.
In all cases, this option should be turned off before processing the last part of the text.

When the UBIDI_OPTION_STREAMING option is used, it is recommended to call ubidi_orderParagraphsLTR() with argument orderParagraphsLTR set to TRUE before calling ubidi_setPara so that later paragraphs may be concatenated to previous paragraphs on the right.

See also:
ubidi_setReorderingMode

ubidi_setReorderingOptions

ubidi_getProcessedLength

ubidi_orderParagraphsLTR

Stable:
ICU 3.6

Definition at line 849 of file ubidi.h.


Function Documentation

void ubidi_close ( UBiDi pBiDi  ) 

ubidi_close() must be called to free the memory associated with a UBiDi object.

Important: A parent UBiDi object must not be destroyed or reused if it still has children. If a UBiDi object has become the child of another one (its parent) by calling ubidi_setLine(), then the child object must be destroyed (closed) or reused (by calling ubidi_setPara() or ubidi_setLine()) before the parent object.

Parameters:
pBiDi is a UBiDi object.
See also:
ubidi_setPara

ubidi_setLine

Stable:
ICU 2.0

int32_t ubidi_countParagraphs ( UBiDi pBiDi  ) 

Get the number of paragraphs.

Parameters:
pBiDi is the paragraph or line UBiDi object.
Returns:
The number of paragraphs.
Stable:
ICU 3.4

int32_t ubidi_countRuns ( UBiDi pBiDi,
UErrorCode pErrorCode 
)

Get the number of runs.

This function may invoke the actual reordering on the UBiDi object, after ubidi_setPara() may have resolved only the levels of the text. Therefore, ubidi_countRuns() may have to allocate memory, and may fail doing so.

Parameters:
pBiDi is the paragraph or line UBiDi object.
pErrorCode must be a valid pointer to an error code value.
Returns:
The number of runs.
Stable:
ICU 2.0

void ubidi_getClassCallback ( UBiDi pBiDi,
UBiDiClassCallback **  fn,
const void **  context 
)

Get the current callback function used for Bidi class determination.

Parameters:
pBiDi is the paragraph UBiDi object.
fn fillin: Returns the callback function pointer.
context fillin: Returns the callback's private context.
See also:
ubidi_setClassCallback
Stable:
ICU 3.6

U_CDECL_END UCharDirection ubidi_getCustomizedClass ( UBiDi pBiDi,
UChar32  c 
)

Retrieve the Bidi class for a given code point.

If a UBiDiClassCallback callback is defined and returns a value other than U_BIDI_CLASS_DEFAULT, that value is used; otherwise the default class determination mechanism is invoked.

Parameters:
pBiDi is the paragraph UBiDi object.
c is the code point whose Bidi class must be retrieved.
Returns:
The Bidi class for character c based on the given pBiDi instance.
See also:
UBiDiClassCallback
Stable:
ICU 3.6

UBiDiDirection ubidi_getDirection ( const UBiDi pBiDi  ) 

Get the directionality of the text.

Parameters:
pBiDi is the paragraph or line UBiDi object.
Returns:
a value of UBIDI_LTR, UBIDI_RTL or UBIDI_MIXED that indicates if the entire text represented by this object is unidirectional, and which direction, or if it is mixed-directional.
See also:
UBiDiDirection
Stable:
ICU 2.0

Referenced by ParagraphLayout::getTextDirection().

int32_t ubidi_getLength ( const UBiDi pBiDi  ) 

Get the length of the text.

Parameters:
pBiDi is the paragraph or line UBiDi object.
Returns:
The length of the text that the UBiDi object was created for.
Stable:
ICU 2.0

UBiDiLevel ubidi_getLevelAt ( const UBiDi pBiDi,
int32_t  charIndex 
)

Get the level for one character.

Parameters:
pBiDi is the paragraph or line UBiDi object.
charIndex the index of a character. It must be in the range [0..ubidi_getProcessedLength(pBiDi)].
Returns:
The level for the character at charIndex (0 if charIndex is not in the valid range).
See also:
UBiDiLevel

ubidi_getProcessedLength

Stable:
ICU 2.0

const UBiDiLevel* ubidi_getLevels ( UBiDi pBiDi,
UErrorCode pErrorCode 
)

Get an array of levels for each character.

Note that this function may allocate memory under some circumstances, unlike ubidi_getLevelAt().

Parameters:
pBiDi is the paragraph or line UBiDi object, whose text length must be strictly positive.
pErrorCode must be a valid pointer to an error code value.
Returns:
The levels array for the text, or NULL if an error occurs.
See also:
UBiDiLevel

ubidi_getProcessedLength

Stable:
ICU 2.0

int32_t ubidi_getLogicalIndex ( UBiDi pBiDi,
int32_t  visualIndex,
UErrorCode pErrorCode 
)

Get the logical text position from a visual position.

If such a mapping is used many times on the same UBiDi object, then calling ubidi_getVisualMap() is more efficient.

The value returned may be UBIDI_MAP_NOWHERE if there is no logical position because the corresponding text character is a Bidi mark inserted in the output by option UBIDI_OPTION_INSERT_MARKS.

This is the inverse function to ubidi_getVisualIndex().

When the visual output is altered by using options of ubidi_writeReordered() such as UBIDI_INSERT_LRM_FOR_NUMERIC, UBIDI_KEEP_BASE_COMBINING, UBIDI_OUTPUT_REVERSE, UBIDI_REMOVE_BIDI_CONTROLS, the logical position returned may not be correct. It is advised to use, when possible, reordering options such as UBIDI_OPTION_INSERT_MARKS and UBIDI_OPTION_REMOVE_CONTROLS.

Parameters:
pBiDi is the paragraph or line UBiDi object.
visualIndex is the visual position of a character.
pErrorCode must be a valid pointer to an error code value.
Returns:
The index of this character in the text.
See also:
ubidi_getVisualMap

ubidi_getVisualIndex

ubidi_getResultLength

Stable:
ICU 2.0

void ubidi_getLogicalMap ( UBiDi pBiDi,
int32_t *  indexMap,
UErrorCode pErrorCode 
)

Get a logical-to-visual index map (array) for the characters in the UBiDi (paragraph or line) object.

Some values in the map may be UBIDI_MAP_NOWHERE if the corresponding text characters are Bidi controls removed from the visual output by the option UBIDI_OPTION_REMOVE_CONTROLS.

When the visual output is altered by using options of ubidi_writeReordered() such as UBIDI_INSERT_LRM_FOR_NUMERIC, UBIDI_KEEP_BASE_COMBINING, UBIDI_OUTPUT_REVERSE, UBIDI_REMOVE_BIDI_CONTROLS, the visual positions returned may not be correct. It is advised to use, when possible, reordering options such as UBIDI_OPTION_INSERT_MARKS and UBIDI_OPTION_REMOVE_CONTROLS.

Note that in right-to-left runs, this mapping places second surrogates before first ones (which is generally a bad idea) and combining characters before base characters. Use of ubidi_writeReordered(), optionally with the UBIDI_KEEP_BASE_COMBINING option can be considered instead of using the mapping, in order to avoid these issues.

Parameters:
pBiDi is the paragraph or line UBiDi object.
indexMap is a pointer to an array of ubidi_getProcessedLength() indexes which will reflect the reordering of the characters. If option UBIDI_OPTION_INSERT_MARKS is set, the number of elements allocated in indexMap must be no less than ubidi_getResultLength(). The array does not need to be initialized.

The index map will result in indexMap[logicalIndex]==visualIndex.
pErrorCode must be a valid pointer to an error code value.
See also:
ubidi_getVisualMap

ubidi_getVisualIndex

ubidi_getProcessedLength

ubidi_getResultLength

Stable:
ICU 2.0

void ubidi_getLogicalRun ( const UBiDi pBiDi,
int32_t  logicalPosition,
int32_t *  pLogicalLimit,