michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 1999-2013, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * file name: ubidi.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 1999jul27 michael@0: * created by: Markus W. Scherer, updated by Matitiahu Allouche michael@0: */ michael@0: michael@0: #ifndef UBIDI_H michael@0: #define UBIDI_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: #include "unicode/uchar.h" michael@0: #include "unicode/localpointer.h" michael@0: michael@0: /** michael@0: *\file michael@0: * \brief C API: Bidi algorithm michael@0: * michael@0: *
michael@0: * michael@0: * Note: Libraries that perform a bidirectional algorithm and michael@0: * reorder strings accordingly are sometimes called "Storage Layout Engines". michael@0: * ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such michael@0: * "Storage Layout Engines". michael@0: * michael@0: *
pErrorCode
pointer must be valid
michael@0: * and the value that it points to must not indicate a failure before
michael@0: * the function call. Otherwise, the function returns immediately.
michael@0: * After the function call, the value indicates success or failure.michael@0: * michael@0: * The "limit" of a sequence of characters is the position just after their michael@0: * last character, i.e., one more than that position.
michael@0: * michael@0: * Some of the API functions provide access to "runs". michael@0: * Such a "run" is defined as a sequence of characters michael@0: * that are at the same embedding level michael@0: * after performing the Bidi algorithm.
michael@0: * michael@0: * @author Markus W. Scherer michael@0: * @version 1.0 michael@0: * michael@0: * michael@0: *
The basic assumptions are:
michael@0: *michael@0: * \code michael@0: *#include "unicode/ubidi.h" michael@0: * michael@0: *typedef enum { michael@0: * styleNormal=0, styleSelected=1, michael@0: * styleBold=2, styleItalics=4, michael@0: * styleSuper=8, styleSub=16 michael@0: *} Style; michael@0: * michael@0: *typedef struct { int32_t limit; Style style; } StyleRun; michael@0: * michael@0: *int getTextWidth(const UChar *text, int32_t start, int32_t limit, michael@0: * const StyleRun *styleRuns, int styleRunCount); michael@0: * michael@0: * // set *pLimit and *pStyleRunLimit for a line michael@0: * // from text[start] and from styleRuns[styleRunStart] michael@0: * // using ubidi_getLogicalRun(para, ...) michael@0: *void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit, michael@0: * UBiDi *para, michael@0: * const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit, michael@0: * int *pLineWidth); michael@0: * michael@0: * // render runs on a line sequentially, always from left to right michael@0: * michael@0: * // prepare rendering a new line michael@0: * void startLine(UBiDiDirection textDirection, int lineWidth); michael@0: * michael@0: * // render a run of text and advance to the right by the run width michael@0: * // the text[start..limit-1] is always in logical order michael@0: * void renderRun(const UChar *text, int32_t start, int32_t limit, michael@0: * UBiDiDirection textDirection, Style style); michael@0: * michael@0: * // We could compute a cross-product michael@0: * // from the style runs with the directional runs michael@0: * // and then reorder it. michael@0: * // Instead, here we iterate over each run type michael@0: * // and render the intersections - michael@0: * // with shortcuts in simple (and common) cases. michael@0: * // renderParagraph() is the main function. michael@0: * michael@0: * // render a directional run with michael@0: * // (possibly) multiple style runs intersecting with it michael@0: * void renderDirectionalRun(const UChar *text, michael@0: * int32_t start, int32_t limit, michael@0: * UBiDiDirection direction, michael@0: * const StyleRun *styleRuns, int styleRunCount) { michael@0: * int i; michael@0: * michael@0: * // iterate over style runs michael@0: * if(direction==UBIDI_LTR) { michael@0: * int styleLimit; michael@0: * michael@0: * for(i=0; imichael@0: */ michael@0: michael@0: /*DOCXX_TAG*/ michael@0: /*@{*/ michael@0: michael@0: /** michael@0: * UBiDiLevel is the type of the level values in this michael@0: * Bidi implementation. michael@0: * It holds an embedding level and indicates the visual direction michael@0: * by its bit 0 (even/odd value).limit) { styleLimit=limit; } michael@0: * renderRun(text, start, styleLimit, michael@0: * direction, styleRun[i].style); michael@0: * if(styleLimit==limit) { break; } michael@0: * start=styleLimit; michael@0: * } michael@0: * } michael@0: * } else { michael@0: * int styleStart; michael@0: * michael@0: * for(i=styleRunCount-1; i>=0; --i) { michael@0: * if(i>0) { michael@0: * styleStart=styleRun[i-1].limit; michael@0: * } else { michael@0: * styleStart=0; michael@0: * } michael@0: * if(limit>=styleStart) { michael@0: * if(styleStart =length michael@0: * michael@0: * width=getTextWidth(text, 0, length, styleRuns, styleRunCount); michael@0: * if(width<=lineWidth) { michael@0: * // everything fits onto one line michael@0: * michael@0: * // prepare rendering a new line from either left or right michael@0: * startLine(paraLevel, width); michael@0: * michael@0: * renderLine(para, text, 0, length, michael@0: * styleRuns, styleRunCount); michael@0: * } else { michael@0: * UBiDi *line; michael@0: * michael@0: * // we need to render several lines michael@0: * line=ubidi_openSized(length, 0, pErrorCode); michael@0: * if(line!=NULL) { michael@0: * int32_t start=0, limit; michael@0: * int styleRunStart=0, styleRunLimit; michael@0: * michael@0: * for(;;) { michael@0: * limit=length; michael@0: * styleRunLimit=styleRunCount; michael@0: * getLineBreak(text, start, &limit, para, michael@0: * styleRuns, styleRunStart, &styleRunLimit, michael@0: * &width); michael@0: * ubidi_setLine(para, start, limit, line, pErrorCode); michael@0: * if(U_SUCCESS(*pErrorCode)) { michael@0: * // prepare rendering a new line michael@0: * // from either left or right michael@0: * startLine(paraLevel, width); michael@0: * michael@0: * renderLine(line, text, start, limit, michael@0: * styleRuns+styleRunStart, michael@0: * styleRunLimit-styleRunStart); michael@0: * } michael@0: * if(limit==length) { break; } michael@0: * start=limit; michael@0: * styleRunStart=styleRunLimit-1; michael@0: * if(start>=styleRuns[styleRunStart].limit) { michael@0: * ++styleRunStart; michael@0: * } michael@0: * } michael@0: * michael@0: * ubidi_close(line); michael@0: * } michael@0: * } michael@0: * } michael@0: * michael@0: * ubidi_close(para); michael@0: *} michael@0: *\endcode michael@0: *
michael@0: *
michael@0: * It can also hold non-level values for the
michael@0: * paraLevel
and embeddingLevels
michael@0: * arguments of ubidi_setPara()
; there:
michael@0: *
embeddingLevels[]
michael@0: * value indicates whether the using application is
michael@0: * specifying the level of a character to override whatever the
michael@0: * Bidi implementation would resolve it to.paraLevel
can be set to the
michael@0: * pseudo-level values UBIDI_DEFAULT_LTR
michael@0: * and UBIDI_DEFAULT_RTL
.The related constants are not real, valid level values.
michael@0: * UBIDI_DEFAULT_XXX
can be used to specify
michael@0: * a default for the paragraph level for
michael@0: * when the ubidi_setPara()
function
michael@0: * shall determine it but there is no
michael@0: * strongly typed character in the input.
michael@0: *
michael@0: * Note that the value for UBIDI_DEFAULT_LTR
is even
michael@0: * and the one for UBIDI_DEFAULT_RTL
is odd,
michael@0: * just like with normal LTR and RTL level values -
michael@0: * these special values are designed that way. Also, the implementation
michael@0: * assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
michael@0: *
michael@0: * @see UBIDI_DEFAULT_LTR
michael@0: * @see UBIDI_DEFAULT_RTL
michael@0: * @see UBIDI_LEVEL_OVERRIDE
michael@0: * @see UBIDI_MAX_EXPLICIT_LEVEL
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: typedef uint8_t UBiDiLevel;
michael@0:
michael@0: /** Paragraph level setting.
michael@0: * michael@0: * Constant indicating that the base direction depends on the first strong michael@0: * directional character in the text according to the Unicode Bidirectional michael@0: * Algorithm. If no strong directional character is present, michael@0: * then set the paragraph level to 0 (left-to-right).
michael@0: *
michael@0: * If this value is used in conjunction with reordering modes
michael@0: * UBIDI_REORDER_INVERSE_LIKE_DIRECT
or
michael@0: * UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
, the text to reorder
michael@0: * is assumed to be visual LTR, and the text after reordering is required
michael@0: * to be the corresponding logical string with appropriate contextual
michael@0: * direction. The direction of the result string will be RTL if either
michael@0: * the righmost or leftmost strong character of the source text is RTL
michael@0: * or Arabic Letter, the direction will be LTR otherwise.
michael@0: *
michael@0: * If reordering option UBIDI_OPTION_INSERT_MARKS
is set, an RLM may
michael@0: * be added at the beginning of the result string to ensure round trip
michael@0: * (that the result string, when reordered back to visual, will produce
michael@0: * the original source text).
michael@0: * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
michael@0: * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define UBIDI_DEFAULT_LTR 0xfe
michael@0:
michael@0: /** Paragraph level setting.
michael@0: * michael@0: * Constant indicating that the base direction depends on the first strong michael@0: * directional character in the text according to the Unicode Bidirectional michael@0: * Algorithm. If no strong directional character is present, michael@0: * then set the paragraph level to 1 (right-to-left).
michael@0: *
michael@0: * If this value is used in conjunction with reordering modes
michael@0: * UBIDI_REORDER_INVERSE_LIKE_DIRECT
or
michael@0: * UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
, the text to reorder
michael@0: * is assumed to be visual LTR, and the text after reordering is required
michael@0: * to be the corresponding logical string with appropriate contextual
michael@0: * direction. The direction of the result string will be RTL if either
michael@0: * the righmost or leftmost strong character of the source text is RTL
michael@0: * or Arabic Letter, or if the text contains no strong character;
michael@0: * the direction will be LTR otherwise.
michael@0: *
michael@0: * If reordering option UBIDI_OPTION_INSERT_MARKS
is set, an RLM may
michael@0: * be added at the beginning of the result string to ensure round trip
michael@0: * (that the result string, when reordered back to visual, will produce
michael@0: * the original source text).
michael@0: * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
michael@0: * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define UBIDI_DEFAULT_RTL 0xff
michael@0:
michael@0: /**
michael@0: * Maximum explicit embedding level.
michael@0: * (The maximum resolved level can be up to UBIDI_MAX_EXPLICIT_LEVEL+1
).
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define UBIDI_MAX_EXPLICIT_LEVEL 125
michael@0:
michael@0: /** Bit flag for level input.
michael@0: * Overrides directional properties.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define UBIDI_LEVEL_OVERRIDE 0x80
michael@0:
michael@0: /**
michael@0: * Special value which can be returned by the mapping functions when a logical
michael@0: * index has no corresponding visual index or vice-versa. This may happen
michael@0: * for the logical-to-visual mapping of a Bidi control when option
michael@0: * #UBIDI_OPTION_REMOVE_CONTROLS
is specified. This can also happen
michael@0: * for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted
michael@0: * by option #UBIDI_OPTION_INSERT_MARKS
.
michael@0: * @see ubidi_getVisualIndex
michael@0: * @see ubidi_getVisualMap
michael@0: * @see ubidi_getLogicalIndex
michael@0: * @see ubidi_getLogicalMap
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: #define UBIDI_MAP_NOWHERE (-1)
michael@0:
michael@0: /**
michael@0: * UBiDiDirection
values indicate the text direction.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: enum UBiDiDirection {
michael@0: /** Left-to-right text. This is a 0 value.
michael@0: *
ubidi_getDirection()
, it means
michael@0: * that the source string contains no right-to-left characters, or
michael@0: * that the source string is empty and the paragraph level is even.
michael@0: * ubidi_getBaseDirection()
, it
michael@0: * means that the first strong character of the source string has
michael@0: * a left-to-right direction.
michael@0: * ubidi_getDirection()
, it means
michael@0: * that the source string contains no left-to-right characters, or
michael@0: * that the source string is empty and the paragraph level is odd.
michael@0: * ubidi_getBaseDirection()
, it
michael@0: * means that the first strong character of the source string has
michael@0: * a right-to-left direction.
michael@0: * As return value for ubidi_getDirection()
, it means
michael@0: * that the source string contains both left-to-right and
michael@0: * right-to-left characters.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: UBIDI_MIXED,
michael@0: /** No strongly directional text.
michael@0: *
As return value for ubidi_getBaseDirection()
, it means
michael@0: * that the source string is missing or empty, or contains neither left-to-right
michael@0: * nor right-to-left characters.
michael@0: * @stable ICU 4.6
michael@0: */
michael@0: UBIDI_NEUTRAL
michael@0: };
michael@0:
michael@0: /** @stable ICU 2.0 */
michael@0: typedef enum UBiDiDirection UBiDiDirection;
michael@0:
michael@0: /**
michael@0: * Forward declaration of the UBiDi
structure for the declaration of
michael@0: * the API functions. Its fields are implementation-specific.
michael@0: * This structure holds information about a paragraph (or multiple paragraphs) michael@0: * of text with Bidi-algorithm-related details, or about one line of michael@0: * such a paragraph.
michael@0: * Reordering can be done on a line, or on one or more paragraphs which are
michael@0: * then interpreted each as one single line.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: struct UBiDi;
michael@0:
michael@0: /** @stable ICU 2.0 */
michael@0: typedef struct UBiDi UBiDi;
michael@0:
michael@0: /**
michael@0: * Allocate a UBiDi
structure.
michael@0: * Such an object is initially empty. It is assigned
michael@0: * the Bidi properties of a piece of text containing one or more paragraphs
michael@0: * by ubidi_setPara()
michael@0: * or the Bidi properties of a line within a paragraph by
michael@0: * ubidi_setLine()
.
michael@0: * This object can be reused for as long as it is not deallocated
michael@0: * by calling ubidi_close()
.
michael@0: * ubidi_setPara()
and ubidi_setLine()
will allocate
michael@0: * additional memory for internal structures as necessary.
michael@0: *
michael@0: * @return An empty UBiDi
object.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UBiDi * U_EXPORT2
michael@0: ubidi_open(void);
michael@0:
michael@0: /**
michael@0: * Allocate a UBiDi
structure with preallocated memory
michael@0: * for internal structures.
michael@0: * This function provides a UBiDi
object like ubidi_open()
michael@0: * with no arguments, but it also preallocates memory for internal structures
michael@0: * according to the sizings supplied by the caller.
michael@0: * Subsequent functions will not allocate any more memory, and are thus michael@0: * guaranteed not to fail because of lack of memory.
michael@0: * The preallocation can be limited to some of the internal memory
michael@0: * by setting some values to 0 here. That means that if, e.g.,
michael@0: * maxRunCount
cannot be reasonably predetermined and should not
michael@0: * be set to maxLength
(the only failproof value) to avoid
michael@0: * wasting memory, then maxRunCount
could be set to 0 here
michael@0: * and the internal structures that are associated with it will be allocated
michael@0: * on demand, just like with ubidi_open()
.
michael@0: *
michael@0: * @param maxLength is the maximum text or line length that internal memory
michael@0: * will be preallocated for. An attempt to associate this object with a
michael@0: * longer text will fail, unless this value is 0, which leaves the allocation
michael@0: * up to the implementation.
michael@0: *
michael@0: * @param maxRunCount is the maximum anticipated number of same-level runs
michael@0: * that internal memory will be preallocated for. An attempt to access
michael@0: * visual runs on an object that was not preallocated for as many runs
michael@0: * as the text was actually resolved to will fail,
michael@0: * unless this value is 0, which leaves the allocation up to the implementation.
michael@0: * The number of runs depends on the actual text and maybe anywhere between
michael@0: * 1 and maxLength
. It is typically small.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return An empty UBiDi
object with preallocated memory.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UBiDi * U_EXPORT2
michael@0: ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * ubidi_close()
must be called to free the memory
michael@0: * associated with a UBiDi object.
michael@0: *
michael@0: * Important:
michael@0: * A parent UBiDi
object must not be destroyed or reused if
michael@0: * it still has children.
michael@0: * If a UBiDi
object has become the child
michael@0: * of another one (its parent) by calling
michael@0: * ubidi_setLine()
, then the child object must
michael@0: * be destroyed (closed) or reused (by calling
michael@0: * ubidi_setPara()
or ubidi_setLine()
)
michael@0: * before the parent object.
michael@0: *
michael@0: * @param pBiDi is a UBiDi
object.
michael@0: *
michael@0: * @see ubidi_setPara
michael@0: * @see ubidi_setLine
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_close(UBiDi *pBiDi);
michael@0:
michael@0: #if U_SHOW_CPLUSPLUS_API
michael@0:
michael@0: U_NAMESPACE_BEGIN
michael@0:
michael@0: /**
michael@0: * \class LocalUBiDiPointer
michael@0: * "Smart pointer" class, closes a UBiDi via ubidi_close().
michael@0: * For most methods see the LocalPointerBase base class.
michael@0: *
michael@0: * @see LocalPointerBase
michael@0: * @see LocalPointer
michael@0: * @stable ICU 4.4
michael@0: */
michael@0: U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);
michael@0:
michael@0: U_NAMESPACE_END
michael@0:
michael@0: #endif
michael@0:
michael@0: /**
michael@0: * Modify the operation of the Bidi algorithm such that it
michael@0: * approximates an "inverse Bidi" algorithm. This function
michael@0: * must be called before ubidi_setPara()
.
michael@0: *
michael@0: *
The normal operation of the Bidi algorithm as described michael@0: * in the Unicode Technical Report is to take text stored in logical michael@0: * (keyboard, typing) order and to determine the reordering of it for visual michael@0: * rendering. michael@0: * Some legacy systems store text in visual order, and for operations michael@0: * with standard, Unicode-based algorithms, the text needs to be transformed michael@0: * to logical order. This is effectively the inverse algorithm of the michael@0: * described Bidi algorithm. Note that there is no standard algorithm for michael@0: * this "inverse Bidi" and that the current implementation provides only an michael@0: * approximation of "inverse Bidi".
michael@0: * michael@0: *With isInverse
set to TRUE
,
michael@0: * this function changes the behavior of some of the subsequent functions
michael@0: * in a way that they can be used for the inverse Bidi algorithm.
michael@0: * Specifically, runs of text with numeric characters will be treated in a
michael@0: * special way and may need to be surrounded with LRM characters when they are
michael@0: * written in reordered sequence.
Output runs should be retrieved using ubidi_getVisualRun()
.
michael@0: * Since the actual input for "inverse Bidi" is visually ordered text and
michael@0: * ubidi_getVisualRun()
gets the reordered runs, these are actually
michael@0: * the runs of the logically ordered output.
Calling this function with argument isInverse
set to
michael@0: * TRUE
is equivalent to calling
michael@0: * ubidi_setReorderingMode
with argument
michael@0: * reorderingMode
michael@0: * set to #UBIDI_REORDER_INVERSE_NUMBERS_AS_L
.
michael@0: * Calling this function with argument isInverse
set to
michael@0: * FALSE
is equivalent to calling
michael@0: * ubidi_setReorderingMode
with argument
michael@0: * reorderingMode
michael@0: * set to #UBIDI_REORDER_DEFAULT
.
michael@0: *
michael@0: * @param pBiDi is a UBiDi
object.
michael@0: *
michael@0: * @param isInverse specifies "forward" or "inverse" Bidi operation.
michael@0: *
michael@0: * @see ubidi_setPara
michael@0: * @see ubidi_writeReordered
michael@0: * @see ubidi_setReorderingMode
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
michael@0:
michael@0: /**
michael@0: * Is this Bidi object set to perform the inverse Bidi algorithm?
michael@0: *
Note: calling this function after setting the reordering mode with
michael@0: * ubidi_setReorderingMode
will return TRUE
if the
michael@0: * reordering mode was set to #UBIDI_REORDER_INVERSE_NUMBERS_AS_L
,
michael@0: * FALSE
for all other values.
UBiDi
object.
michael@0: * @return TRUE if the Bidi object is set to perform the inverse Bidi algorithm
michael@0: * by handling numbers as L.
michael@0: *
michael@0: * @see ubidi_setInverse
michael@0: * @see ubidi_setReorderingMode
michael@0: * @stable ICU 2.0
michael@0: */
michael@0:
michael@0: U_STABLE UBool U_EXPORT2
michael@0: ubidi_isInverse(UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Specify whether block separators must be allocated level zero,
michael@0: * so that successive paragraphs will progress from left to right.
michael@0: * This function must be called before ubidi_setPara()
.
michael@0: * Paragraph separators (B) may appear in the text. Setting them to level zero
michael@0: * means that all paragraph separators (including one possibly appearing
michael@0: * in the last text position) are kept in the reordered text after the text
michael@0: * that they follow in the source text.
michael@0: * When this feature is not enabled, a paragraph separator at the last
michael@0: * position of the text before reordering will go to the first position
michael@0: * of the reordered text when the paragraph level is odd.
michael@0: *
michael@0: * @param pBiDi is a UBiDi
object.
michael@0: *
michael@0: * @param orderParagraphsLTR specifies whether paragraph separators (B) must
michael@0: * receive level 0, so that successive paragraphs progress from left to right.
michael@0: *
michael@0: * @see ubidi_setPara
michael@0: * @stable ICU 3.4
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);
michael@0:
michael@0: /**
michael@0: * Is this Bidi object set to allocate level 0 to block separators so that
michael@0: * successive paragraphs progress from left to right?
michael@0: *
michael@0: * @param pBiDi is a UBiDi
object.
michael@0: * @return TRUE if the Bidi object is set to allocate level 0 to block
michael@0: * separators.
michael@0: *
michael@0: * @see ubidi_orderParagraphsLTR
michael@0: * @stable ICU 3.4
michael@0: */
michael@0: U_STABLE UBool U_EXPORT2
michael@0: ubidi_isOrderParagraphsLTR(UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * UBiDiReorderingMode
values indicate which variant of the Bidi
michael@0: * algorithm to use.
michael@0: *
michael@0: * @see ubidi_setReorderingMode
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: typedef enum UBiDiReorderingMode {
michael@0: /** Regular Logical to Visual Bidi algorithm according to Unicode.
michael@0: * This is a 0 value.
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_DEFAULT = 0,
michael@0: /** Logical to Visual algorithm which handles numbers in a way which
michael@0: * mimicks the behavior of Windows XP.
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_NUMBERS_SPECIAL,
michael@0: /** Logical to Visual algorithm grouping numbers with adjacent R characters
michael@0: * (reversible algorithm).
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_GROUP_NUMBERS_WITH_R,
michael@0: /** Reorder runs only to transform a Logical LTR string to the Logical RTL
michael@0: * string with the same display, or vice-versa.#UBIDI_OPTION_INSERT_MARKS
, some Bidi controls in the source
michael@0: * text may be removed and other controls may be added to produce the
michael@0: * minimum combination which has the required display.
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_RUNS_ONLY,
michael@0: /** Visual to Logical algorithm which handles numbers like L
michael@0: * (same algorithm as selected by ubidi_setInverse(TRUE)
.
michael@0: * @see ubidi_setInverse
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_INVERSE_NUMBERS_AS_L,
michael@0: /** Visual to Logical algorithm equivalent to the regular Logical to Visual
michael@0: * algorithm.
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_INVERSE_LIKE_DIRECT,
michael@0: /** Inverse Bidi (Visual to Logical) algorithm for the
michael@0: * UBIDI_REORDER_NUMBERS_SPECIAL
Bidi algorithm.
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,
michael@0: /** Number of values for reordering mode.
michael@0: * @stable ICU 3.6 */
michael@0: UBIDI_REORDER_COUNT
michael@0: } UBiDiReorderingMode;
michael@0:
michael@0: /**
michael@0: * Modify the operation of the Bidi algorithm such that it implements some
michael@0: * variant to the basic Bidi algorithm or approximates an "inverse Bidi"
michael@0: * algorithm, depending on different values of the "reordering mode".
michael@0: * This function must be called before ubidi_setPara()
, and stays
michael@0: * in effect until called again with a different argument.
michael@0: *
michael@0: * The normal operation of the Bidi algorithm as described michael@0: * in the Unicode Standard Annex #9 is to take text stored in logical michael@0: * (keyboard, typing) order and to determine how to reorder it for visual michael@0: * rendering.
michael@0: * michael@0: *With the reordering mode set to a value other than
michael@0: * #UBIDI_REORDER_DEFAULT
, this function changes the behavior of
michael@0: * some of the subsequent functions in a way such that they implement an
michael@0: * inverse Bidi algorithm or some other algorithm variants.
Some legacy systems store text in visual order, and for operations michael@0: * with standard, Unicode-based algorithms, the text needs to be transformed michael@0: * into logical order. This is effectively the inverse algorithm of the michael@0: * described Bidi algorithm. Note that there is no standard algorithm for michael@0: * this "inverse Bidi", so a number of variants are implemented here.
michael@0: * michael@0: *In other cases, it may be desirable to emulate some variant of the michael@0: * Logical to Visual algorithm (e.g. one used in MS Windows), or perform a michael@0: * Logical to Logical transformation.
michael@0: * michael@0: *#UBIDI_REORDER_DEFAULT
,
michael@0: * the standard Bidi Logical to Visual algorithm is applied.#UBIDI_REORDER_NUMBERS_SPECIAL
,
michael@0: * the algorithm used to perform Bidi transformations when calling
michael@0: * ubidi_setPara
should approximate the algorithm used in
michael@0: * Microsoft Windows XP rather than strictly conform to the Unicode Bidi
michael@0: * algorithm.
michael@0: * #UBIDI_REORDER_GROUP_NUMBERS_WITH_R
,
michael@0: * numbers located between LTR text and RTL text are associated with the RTL
michael@0: * text. For instance, an LTR paragraph with content "abc 123 DEF" (where
michael@0: * upper case letters represent RTL characters) will be transformed to
michael@0: * "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed
michael@0: * to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".
michael@0: * This makes the algorithm reversible and makes it useful when round trip
michael@0: * (from visual to logical and back to visual) must be achieved without
michael@0: * adding LRM characters. However, this is a variation from the standard
michael@0: * Unicode Bidi algorithm.#UBIDI_REORDER_RUNS_ONLY
,
michael@0: * a "Logical to Logical" transformation must be performed:
michael@0: * paraLevel
michael@0: * in ubidi_setPara
) is even, the source text will be handled as
michael@0: * LTR logical text and will be transformed to the RTL logical text which has
michael@0: * the same LTR visual display.#UBIDI_REORDER_INVERSE_NUMBERS_AS_L
, an "inverse Bidi" algorithm
michael@0: * is applied.
michael@0: * Runs of text with numeric characters will be treated like LTR letters and
michael@0: * may need to be surrounded with LRM characters when they are written in
michael@0: * reordered sequence (the option #UBIDI_INSERT_LRM_FOR_NUMERIC
can
michael@0: * be used with function ubidi_writeReordered
to this end. This
michael@0: * mode is equivalent to calling ubidi_setInverse()
with
michael@0: * argument isInverse
set to TRUE
.#UBIDI_REORDER_INVERSE_LIKE_DIRECT
, the "direct" Logical to Visual
michael@0: * Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.
michael@0: * This mode is similar to mode #UBIDI_REORDER_INVERSE_NUMBERS_AS_L
michael@0: * but is closer to the regular Bidi algorithm.
michael@0: * UBIDI_REORDER_INVERSE_NUMBERS_AS_L
.#UBIDI_OPTION_INSERT_MARKS
, this mode generally
michael@0: * adds Bidi marks to the output significantly more sparingly than mode
michael@0: * #UBIDI_REORDER_INVERSE_NUMBERS_AS_L
with option
michael@0: * #UBIDI_INSERT_LRM_FOR_NUMERIC
in calls to
michael@0: * ubidi_writeReordered
.#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
, the Logical to Visual
michael@0: * Bidi algorithm used in Windows XP is used as an approximation of an "inverse Bidi" algorithm.
michael@0: * In all the reordering modes specifying an "inverse Bidi" algorithm
michael@0: * (i.e. those with a name starting with UBIDI_REORDER_INVERSE
),
michael@0: * output runs should be retrieved using
michael@0: * ubidi_getVisualRun()
, and the output text with
michael@0: * ubidi_writeReordered()
. The caller should keep in mind that in
michael@0: * "inverse Bidi" modes the input is actually visually ordered text and
michael@0: * reordered output returned by ubidi_getVisualRun()
or
michael@0: * ubidi_writeReordered()
are actually runs or character string
michael@0: * of logically ordered output.
michael@0: * For all the "inverse Bidi" modes, the source text should not contain
michael@0: * Bidi control characters other than LRM or RLM.
Note that option #UBIDI_OUTPUT_REVERSE
of
michael@0: * ubidi_writeReordered
has no useful meaning and should not be
michael@0: * used in conjunction with any value of the reordering mode specifying
michael@0: * "inverse Bidi" or with value UBIDI_REORDER_RUNS_ONLY
.
michael@0: *
michael@0: * @param pBiDi is a UBiDi
object.
michael@0: * @param reorderingMode specifies the required variant of the Bidi algorithm.
michael@0: *
michael@0: * @see UBiDiReorderingMode
michael@0: * @see ubidi_setInverse
michael@0: * @see ubidi_setPara
michael@0: * @see ubidi_writeReordered
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);
michael@0:
michael@0: /**
michael@0: * What is the requested reordering mode for a given Bidi object?
michael@0: *
michael@0: * @param pBiDi is a UBiDi
object.
michael@0: * @return the current reordering mode of the Bidi object
michael@0: * @see ubidi_setReorderingMode
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE UBiDiReorderingMode U_EXPORT2
michael@0: ubidi_getReorderingMode(UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * UBiDiReorderingOption
values indicate which options are
michael@0: * specified to affect the Bidi algorithm.
michael@0: *
michael@0: * @see ubidi_setReorderingOptions
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: typedef enum UBiDiReorderingOption {
michael@0: /**
michael@0: * option value for ubidi_setReorderingOptions
:
michael@0: * disable all the options which can be set with this function
michael@0: * @see ubidi_setReorderingOptions
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: UBIDI_OPTION_DEFAULT = 0,
michael@0:
michael@0: /**
michael@0: * option bit for ubidi_setReorderingOptions
:
michael@0: * insert Bidi marks (LRM or RLM) when needed to ensure correct result of
michael@0: * a reordering to a Logical order
michael@0: *
michael@0: *
This option must be set or reset before calling
michael@0: * ubidi_setPara
.
This option is significant only with reordering modes which generate michael@0: * a result with Logical order, specifically:
michael@0: *#UBIDI_REORDER_RUNS_ONLY
#UBIDI_REORDER_INVERSE_NUMBERS_AS_L
#UBIDI_REORDER_INVERSE_LIKE_DIRECT
#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
If this option is set in conjunction with reordering mode
michael@0: * #UBIDI_REORDER_INVERSE_NUMBERS_AS_L
or with calling
michael@0: * ubidi_setInverse(TRUE)
, it implies
michael@0: * option #UBIDI_INSERT_LRM_FOR_NUMERIC
michael@0: * in calls to function ubidi_writeReordered()
.
For other reordering modes, a minimum number of LRM or RLM characters
michael@0: * will be added to the source text after reordering it so as to ensure
michael@0: * round trip, i.e. when applying the inverse reordering mode on the
michael@0: * resulting logical text with removal of Bidi marks
michael@0: * (option #UBIDI_OPTION_REMOVE_CONTROLS
set before calling
michael@0: * ubidi_setPara()
or option #UBIDI_REMOVE_BIDI_CONTROLS
michael@0: * in ubidi_writeReordered
), the result will be identical to the
michael@0: * source text in the first transformation.
michael@0: *
michael@0: *
This option will be ignored if specified together with option
michael@0: * #UBIDI_OPTION_REMOVE_CONTROLS
. It inhibits option
michael@0: * UBIDI_REMOVE_BIDI_CONTROLS
in calls to function
michael@0: * ubidi_writeReordered()
and it implies option
michael@0: * #UBIDI_INSERT_LRM_FOR_NUMERIC
in calls to function
michael@0: * ubidi_writeReordered()
if the reordering mode is
michael@0: * #UBIDI_REORDER_INVERSE_NUMBERS_AS_L
.
ubidi_setReorderingOptions
:
michael@0: * remove Bidi control characters
michael@0: *
michael@0: * This option must be set or reset before calling
michael@0: * ubidi_setPara
.
This option nullifies option #UBIDI_OPTION_INSERT_MARKS
.
michael@0: * It inhibits option #UBIDI_INSERT_LRM_FOR_NUMERIC
in calls
michael@0: * to function ubidi_writeReordered()
and it implies option
michael@0: * #UBIDI_REMOVE_BIDI_CONTROLS
in calls to that function.
ubidi_setReorderingOptions
:
michael@0: * process the output as part of a stream to be continued
michael@0: *
michael@0: * This option must be set or reset before calling
michael@0: * ubidi_setPara
.
This option specifies that the caller is interested in processing large michael@0: * text object in parts. michael@0: * The results of the successive calls are expected to be concatenated by the michael@0: * caller. Only the call for the last part will have this option bit off.
michael@0: * michael@0: *When this option bit is on, ubidi_setPara()
may process
michael@0: * less than the full source text in order to truncate the text at a meaningful
michael@0: * boundary. The caller should call ubidi_getProcessedLength()
michael@0: * immediately after calling ubidi_setPara()
in order to
michael@0: * determine how much of the source text has been processed.
michael@0: * Source text beyond that length should be resubmitted in following calls to
michael@0: * ubidi_setPara
. The processed length may be less than
michael@0: * the length of the source text if a character preceding the last character of
michael@0: * the source text constitutes a reasonable boundary (like a block separator)
michael@0: * for text to be continued.
michael@0: * If the last character of the source text constitutes a reasonable
michael@0: * boundary, the whole text will be processed at once.
michael@0: * If nowhere in the source text there exists
michael@0: * such a reasonable boundary, the processed length will be zero.
michael@0: * The caller should check for such an occurrence and do one of the following:
michael@0: *
UBIDI_OPTION_STREAMING
.When the UBIDI_OPTION_STREAMING
option is used,
michael@0: * it is recommended to call ubidi_orderParagraphsLTR()
with
michael@0: * argument orderParagraphsLTR
set to TRUE
before
michael@0: * calling ubidi_setPara
so that later paragraphs may be
michael@0: * concatenated to previous paragraphs on the right.
UBiDi
object.
michael@0: * @param reorderingOptions is a combination of zero or more of the following
michael@0: * options:
michael@0: * #UBIDI_OPTION_DEFAULT
, #UBIDI_OPTION_INSERT_MARKS
,
michael@0: * #UBIDI_OPTION_REMOVE_CONTROLS
, #UBIDI_OPTION_STREAMING
.
michael@0: *
michael@0: * @see ubidi_getReorderingOptions
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);
michael@0:
michael@0: /**
michael@0: * What are the reordering options applied to a given Bidi object?
michael@0: *
michael@0: * @param pBiDi is a UBiDi
object.
michael@0: * @return the current reordering options of the Bidi object
michael@0: * @see ubidi_setReorderingOptions
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE uint32_t U_EXPORT2
michael@0: ubidi_getReorderingOptions(UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Set the context before a call to ubidi_setPara().michael@0: * michael@0: * ubidi_setPara() computes the left-right directionality for a given piece michael@0: * of text which is supplied as one of its arguments. Sometimes this piece michael@0: * of text (the "main text") should be considered in context, because text michael@0: * appearing before ("prologue") and/or after ("epilogue") the main text michael@0: * may affect the result of this computation.
michael@0: * michael@0: * This function specifies the prologue and/or the epilogue for the next michael@0: * call to ubidi_setPara(). The characters specified as prologue and michael@0: * epilogue should not be modified by the calling program until the call michael@0: * to ubidi_setPara() has returned. If successive calls to ubidi_setPara() michael@0: * all need specification of a context, ubidi_setContext() must be called michael@0: * before each call to ubidi_setPara(). In other words, a context is not michael@0: * "remembered" after the following successful call to ubidi_setPara().
michael@0: * michael@0: * If a call to ubidi_setPara() specifies UBIDI_DEFAULT_LTR or michael@0: * UBIDI_DEFAULT_RTL as paraLevel and is preceded by a call to michael@0: * ubidi_setContext() which specifies a prologue, the paragraph level will michael@0: * be computed taking in consideration the text in the prologue.
michael@0: * michael@0: * When ubidi_setPara() is called without a previous call to michael@0: * ubidi_setContext, the main text is handled as if preceded and followed michael@0: * by strong directional characters at the current paragraph level. michael@0: * Calling ubidi_setContext() with specification of a prologue will change michael@0: * this behavior by handling the main text as if preceded by the last michael@0: * strong character appearing in the prologue, if any. michael@0: * Calling ubidi_setContext() with specification of an epilogue will change michael@0: * the behavior of ubidi_setPara() by handling the main text as if followed michael@0: * by the first strong character or digit appearing in the epilogue, if any.
michael@0: *
michael@0: * Note 1: if ubidi_setContext
is called repeatedly without
michael@0: * calling ubidi_setPara
, the earlier calls have no effect,
michael@0: * only the last call will be remembered for the next call to
michael@0: * ubidi_setPara
.
michael@0: *
michael@0: * Note 2: calling ubidi_setContext(pBiDi, NULL, 0, NULL, 0, &errorCode)
michael@0: * cancels any previous setting of non-empty prologue or epilogue.
michael@0: * The next call to ubidi_setPara()
will process no
michael@0: * prologue or epilogue.
michael@0: *
michael@0: * Note 3: users must be aware that even after setting the context
michael@0: * before a call to ubidi_setPara() to perform e.g. a logical to visual
michael@0: * transformation, the resulting string may not be identical to what it
michael@0: * would have been if all the text, including prologue and epilogue, had
michael@0: * been processed together.
michael@0: * Example (upper case letters represent RTL characters):
michael@0: * prologue = "abc DE
"
michael@0: * epilogue = none
michael@0: * main text = "FGH xyz
"
michael@0: * paraLevel = UBIDI_LTR
michael@0: * display without prologue = "HGF xyz
"
michael@0: * ("HGF" is adjacent to "xyz")
michael@0: * display with prologue = "abc HGFED xyz
"
michael@0: * ("HGF" is not adjacent to "xyz")
michael@0: *
michael@0: * @param pBiDi is a paragraph UBiDi
object.
michael@0: *
michael@0: * @param prologue is a pointer to the text which precedes the text that
michael@0: * will be specified in a coming call to ubidi_setPara().
michael@0: * If there is no prologue to consider, then proLength
michael@0: * must be zero and this pointer can be NULL.
michael@0: *
michael@0: * @param proLength is the length of the prologue; if proLength==-1
michael@0: * then the prologue must be zero-terminated.
michael@0: * Otherwise proLength must be >= 0. If proLength==0
, it means
michael@0: * that there is no prologue to consider.
michael@0: *
michael@0: * @param epilogue is a pointer to the text which follows the text that
michael@0: * will be specified in a coming call to ubidi_setPara().
michael@0: * If there is no epilogue to consider, then epiLength
michael@0: * must be zero and this pointer can be NULL.
michael@0: *
michael@0: * @param epiLength is the length of the epilogue; if epiLength==-1
michael@0: * then the epilogue must be zero-terminated.
michael@0: * Otherwise epiLength must be >= 0. If epiLength==0
, it means
michael@0: * that there is no epilogue to consider.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @see ubidi_setPara
michael@0: * @stable ICU 4.8
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_setContext(UBiDi *pBiDi,
michael@0: const UChar *prologue, int32_t proLength,
michael@0: const UChar *epilogue, int32_t epiLength,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Perform the Unicode Bidi algorithm. It is defined in the
michael@0: * Unicode Standard Anned #9,
michael@0: * version 13,
michael@0: * also described in The Unicode Standard, Version 4.0 .
michael@0: * michael@0: * This function takes a piece of plain text containing one or more paragraphs, michael@0: * with or without externally specified embedding levels from styled michael@0: * text and computes the left-right-directionality of each character.
michael@0: *
michael@0: * If the entire text is all of the same directionality, then
michael@0: * the function may not perform all the steps described by the algorithm,
michael@0: * i.e., some levels may not be the same as if all steps were performed.
michael@0: * This is not relevant for unidirectional text.
michael@0: * For example, in pure LTR text with numbers the numbers would get
michael@0: * a resolved level of 2 higher than the surrounding text according to
michael@0: * the algorithm. This implementation may set all resolved levels to
michael@0: * the same value in such a case.
michael@0: *
michael@0: * The text can be composed of multiple paragraphs. Occurrence of a block
michael@0: * separator in the text terminates a paragraph, and whatever comes next starts
michael@0: * a new paragraph. The exception to this rule is when a Carriage Return (CR)
michael@0: * is followed by a Line Feed (LF). Both CR and LF are block separators, but
michael@0: * in that case, the pair of characters is considered as terminating the
michael@0: * preceding paragraph, and a new paragraph will be started by a character
michael@0: * coming after the LF.
michael@0: *
michael@0: * @param pBiDi A UBiDi
object allocated with ubidi_open()
michael@0: * which will be set to contain the reordering information,
michael@0: * especially the resolved levels for all the characters in text
.
michael@0: *
michael@0: * @param text is a pointer to the text that the Bidi algorithm will be performed on.
michael@0: * This pointer is stored in the UBiDi object and can be retrieved
michael@0: * with ubidi_getText()
.
michael@0: * Note: the text must be (at least) length
long.
michael@0: *
michael@0: * @param length is the length of the text; if length==-1
then
michael@0: * the text must be zero-terminated.
michael@0: *
michael@0: * @param paraLevel specifies the default level for the text;
michael@0: * it is typically 0 (LTR) or 1 (RTL).
michael@0: * If the function shall determine the paragraph level from the text,
michael@0: * then paraLevel
can be set to
michael@0: * either #UBIDI_DEFAULT_LTR
michael@0: * or #UBIDI_DEFAULT_RTL
; if the text contains multiple
michael@0: * paragraphs, the paragraph level shall be determined separately for
michael@0: * each paragraph; if a paragraph does not include any strongly typed
michael@0: * character, then the desired default is used (0 for LTR or 1 for RTL).
michael@0: * Any other value between 0 and #UBIDI_MAX_EXPLICIT_LEVEL
michael@0: * is also valid, with odd levels indicating RTL.
michael@0: *
michael@0: * @param embeddingLevels (in) may be used to preset the embedding and override levels,
michael@0: * ignoring characters like LRE and PDF in the text.
michael@0: * A level overrides the directional property of its corresponding
michael@0: * (same index) character if the level has the
michael@0: * #UBIDI_LEVEL_OVERRIDE
bit set.
michael@0: * Except for that bit, it must be
michael@0: * paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL
,
michael@0: * with one exception: a level of zero may be specified for a paragraph
michael@0: * separator even if paraLevel>0
when multiple paragraphs
michael@0: * are submitted in the same call to ubidi_setPara()
.
michael@0: * Caution: A copy of this pointer, not of the levels,
michael@0: * will be stored in the UBiDi
object;
michael@0: * the embeddingLevels
array must not be
michael@0: * deallocated before the UBiDi
structure is destroyed or reused,
michael@0: * and the embeddingLevels
michael@0: * should not be modified to avoid unexpected results on subsequent Bidi operations.
michael@0: * However, the ubidi_setPara()
and
michael@0: * ubidi_setLine()
functions may modify some or all of the levels.
michael@0: * After the UBiDi
object is reused or destroyed, the caller
michael@0: * must take care of the deallocation of the embeddingLevels
array.
michael@0: * Note: the embeddingLevels
array must be
michael@0: * at least length
long.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
michael@0: UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * ubidi_setLine()
sets a UBiDi
to
michael@0: * contain the reordering information, especially the resolved levels,
michael@0: * for all the characters in a line of text. This line of text is
michael@0: * specified by referring to a UBiDi
object representing
michael@0: * this information for a piece of text containing one or more paragraphs,
michael@0: * and by specifying a range of indexes in this text.
michael@0: * In the new line object, the indexes will range from 0 to limit-start-1
.
michael@0: *
michael@0: * This is used after calling ubidi_setPara()
michael@0: * for a piece of text, and after line-breaking on that text.
michael@0: * It is not necessary if each paragraph is treated as a single line.
michael@0: *
michael@0: * After line-breaking, rules (L1) and (L2) for the treatment of
michael@0: * trailing WS and for reordering are performed on
michael@0: * a UBiDi
object that represents a line.
michael@0: *
michael@0: * Important: pLineBiDi
shares data with
michael@0: * pParaBiDi
.
michael@0: * You must destroy or reuse pLineBiDi
before pParaBiDi
.
michael@0: * In other words, you must destroy or reuse the UBiDi
object for a line
michael@0: * before the object for its parent paragraph.
michael@0: *
michael@0: * The text pointer that was stored in
michael@0: *
michael@0: * @param pBiDi is the paragraph or line
michael@0: *
michael@0: * @param pBiDi is the paragraph
michael@0: *
michael@0: * Note that this function may allocate memory under some
michael@0: * circumstances, unlike
michael@0: * This is especially useful for line-breaking on a paragraph.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line
michael@0: *
michael@0: * Use of
michael@0: *
michael@0: * The value returned may be
michael@0: * When the visual output is altered by using options of
michael@0: *
michael@0: * Note that in right-to-left runs, this mapping places
michael@0: * second surrogates before first ones (which is generally a bad idea)
michael@0: * and combining characters before base characters.
michael@0: * Use of
michael@0: *
michael@0: * The value returned may be
michael@0: * This is the inverse function to
michael@0: * When the visual output is altered by using options of
michael@0: *
michael@0: * Some values in the map may be
michael@0: * When the visual output is altered by using options of
michael@0: *
michael@0: * Note that in right-to-left runs, this mapping places
michael@0: * second surrogates before first ones (which is generally a bad idea)
michael@0: * and combining characters before base characters.
michael@0: * Use of
michael@0: * Some values in the map may be
michael@0: * When the visual output is altered by using options of
michael@0: *
michael@0: * The index map will result in
michael@0: * The index map will result in This option does not imply corresponding adjustment of the index
michael@0: * mappings. This option does not imply corresponding adjustment of the index
michael@0: * mappings. This has the same effect as calling Usually, the function pointer will be propagated to a If a This may be useful for assigning Bidi classes to PUA characters, or
michael@0: * for special application needs. For instance, an application may want to
michael@0: * handle all spaces like L or R characters (according to the base direction)
michael@0: * when creating the visual ordering of logical lines which are part of a report
michael@0: * organized in columns: there should not be interaction between adjacent
michael@0: * cells.
michael@0: *
michael@0: * @param pBiDi is the paragraph pParaBiDi
is also copied,
michael@0: * and start
is added to it so that it points to the beginning of the
michael@0: * line for this object.
michael@0: *
michael@0: * @param pParaBiDi is the parent paragraph object. It must have been set
michael@0: * by a successful call to ubidi_setPara.
michael@0: *
michael@0: * @param start is the line's first index into the text.
michael@0: *
michael@0: * @param limit is just behind the line's last index into the text
michael@0: * (its last index +1).
michael@0: * It must be 0<=start
UBiDi
object.
michael@0: *
michael@0: * @return a value of UBIDI_LTR
, UBIDI_RTL
michael@0: * or UBIDI_MIXED
michael@0: * that indicates if the entire text
michael@0: * represented by this object is unidirectional,
michael@0: * and which direction, or if it is mixed-directional.
michael@0: * Note - The value UBIDI_NEUTRAL
is never returned from this method.
michael@0: *
michael@0: * @see UBiDiDirection
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UBiDiDirection U_EXPORT2
michael@0: ubidi_getDirection(const UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Gets the base direction of the text provided according
michael@0: * to the Unicode Bidirectional Algorithm. The base direction
michael@0: * is derived from the first character in the string with bidirectional
michael@0: * character type L, R, or AL. If the first such character has type L,
michael@0: * UBIDI_LTR
is returned. If the first such character has
michael@0: * type R or AL, UBIDI_RTL
is returned. If the string does
michael@0: * not contain any character of these types, then
michael@0: * UBIDI_NEUTRAL
is returned.
michael@0: *
michael@0: * This is a lightweight function for use when only the base direction
michael@0: * is needed and no further bidi processing of the text is needed.
michael@0: *
michael@0: * @param text is a pointer to the text whose base
michael@0: * direction is needed.
michael@0: * Note: the text must be (at least) @c length long.
michael@0: *
michael@0: * @param length is the length of the text;
michael@0: * if length==-1
then the text
michael@0: * must be zero-terminated.
michael@0: *
michael@0: * @return UBIDI_LTR
, UBIDI_RTL
,
michael@0: * UBIDI_NEUTRAL
michael@0: *
michael@0: * @see UBiDiDirection
michael@0: * @stable ICU 4.6
michael@0: */
michael@0: U_STABLE UBiDiDirection U_EXPORT2
michael@0: ubidi_getBaseDirection(const UChar *text, int32_t length );
michael@0:
michael@0: /**
michael@0: * Get the pointer to the text.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @return The pointer to the text that the UBiDi object was created for.
michael@0: *
michael@0: * @see ubidi_setPara
michael@0: * @see ubidi_setLine
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE const UChar * U_EXPORT2
michael@0: ubidi_getText(const UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Get the length of the text.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @return The length of the text that the UBiDi object was created for.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_getLength(const UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Get the paragraph level of the text.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @return The paragraph level. If there are multiple paragraphs, their
michael@0: * level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or
michael@0: * UBIDI_DEFAULT_RTL. In that case, the level of the first paragraph
michael@0: * is returned.
michael@0: *
michael@0: * @see UBiDiLevel
michael@0: * @see ubidi_getParagraph
michael@0: * @see ubidi_getParagraphByIndex
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UBiDiLevel U_EXPORT2
michael@0: ubidi_getParaLevel(const UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Get the number of paragraphs.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @return The number of paragraphs.
michael@0: * @stable ICU 3.4
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_countParagraphs(UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Get a paragraph, given a position within the text.
michael@0: * This function returns information about a paragraph.
michael@0: * Note: if the paragraph index is known, it is more efficient to
michael@0: * retrieve the paragraph information using ubidi_getParagraphByIndex().UBiDi
object.
michael@0: *
michael@0: * @param charIndex is the index of a character within the text, in the
michael@0: * range [0..ubidi_getProcessedLength(pBiDi)-1]
.
michael@0: *
michael@0: * @param pParaStart will receive the index of the first character of the
michael@0: * paragraph in the text.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pParaLimit will receive the limit of the paragraph.
michael@0: * The l-value that you point to here may be the
michael@0: * same expression (variable) as the one for
michael@0: * charIndex
.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pParaLevel will receive the level of the paragraph.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return The index of the paragraph containing the specified position.
michael@0: *
michael@0: * @see ubidi_getProcessedLength
michael@0: * @stable ICU 3.4
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,
michael@0: int32_t *pParaLimit, UBiDiLevel *pParaLevel,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get a paragraph, given the index of this paragraph.
michael@0: *
michael@0: * This function returns information about a paragraph.UBiDi
object.
michael@0: *
michael@0: * @param paraIndex is the number of the paragraph, in the
michael@0: * range [0..ubidi_countParagraphs(pBiDi)-1]
.
michael@0: *
michael@0: * @param pParaStart will receive the index of the first character of the
michael@0: * paragraph in the text.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pParaLimit will receive the limit of the paragraph.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pParaLevel will receive the level of the paragraph.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @stable ICU 3.4
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,
michael@0: int32_t *pParaStart, int32_t *pParaLimit,
michael@0: UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get the level for one character.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @param charIndex the index of a character. It must be in the range
michael@0: * [0..ubidi_getProcessedLength(pBiDi)].
michael@0: *
michael@0: * @return The level for the character at charIndex (0 if charIndex is not
michael@0: * in the valid range).
michael@0: *
michael@0: * @see UBiDiLevel
michael@0: * @see ubidi_getProcessedLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UBiDiLevel U_EXPORT2
michael@0: ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);
michael@0:
michael@0: /**
michael@0: * Get an array of levels for each character.ubidi_getLevelAt()
.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object, whose
michael@0: * text length must be strictly positive.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return The levels array for the text,
michael@0: * or NULL
if an error occurs.
michael@0: *
michael@0: * @see UBiDiLevel
michael@0: * @see ubidi_getProcessedLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE const UBiDiLevel * U_EXPORT2
michael@0: ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get a logical run.
michael@0: * This function returns information about a run and is used
michael@0: * to retrieve runs in logical order.UBiDi
object.
michael@0: *
michael@0: * @param logicalPosition is a logical position within the source text.
michael@0: *
michael@0: * @param pLogicalLimit will receive the limit of the corresponding run.
michael@0: * The l-value that you point to here may be the
michael@0: * same expression (variable) as the one for
michael@0: * logicalPosition
.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @param pLevel will receive the level of the corresponding run.
michael@0: * This pointer can be NULL
if this
michael@0: * value is not necessary.
michael@0: *
michael@0: * @see ubidi_getProcessedLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,
michael@0: int32_t *pLogicalLimit, UBiDiLevel *pLevel);
michael@0:
michael@0: /**
michael@0: * Get the number of runs.
michael@0: * This function may invoke the actual reordering on the
michael@0: * UBiDi
object, after ubidi_setPara()
michael@0: * may have resolved only the levels of the text. Therefore,
michael@0: * ubidi_countRuns()
may have to allocate memory,
michael@0: * and may fail doing so.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return The number of runs.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get one run's logical start, length, and directionality,
michael@0: * which can be 0 for LTR or 1 for RTL.
michael@0: * In an RTL run, the character at the logical start is
michael@0: * visually on the right of the displayed run.
michael@0: * The length is the number of characters in the run.ubidi_countRuns()
should be called
michael@0: * before the runs are retrieved.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @param runIndex is the number of the run in visual order, in the
michael@0: * range [0..ubidi_countRuns(pBiDi)-1]
.
michael@0: *
michael@0: * @param pLogicalStart is the first logical character index in the text.
michael@0: * The pointer may be NULL
if this index is not needed.
michael@0: *
michael@0: * @param pLength is the number of characters (at least one) in the run.
michael@0: * The pointer may be NULL
if this is not needed.
michael@0: *
michael@0: * @return the directionality of the run,
michael@0: * UBIDI_LTR==0
or UBIDI_RTL==1
,
michael@0: * never UBIDI_MIXED
,
michael@0: * never UBIDI_NEUTRAL
.
michael@0: *
michael@0: * @see ubidi_countRuns
michael@0: *
michael@0: * Example:
michael@0: *
michael@0: * \code
michael@0: * int32_t i, count=ubidi_countRuns(pBiDi),
michael@0: * logicalStart, visualIndex=0, length;
michael@0: * for(i=0; i
michael@0: *
michael@0: * Note that in right-to-left runs, code like this places
michael@0: * second surrogates before first ones (which is generally a bad idea)
michael@0: * and combining characters before base characters.
michael@0: * ubidi_writeReordered()
, optionally with the
michael@0: * #UBIDI_KEEP_BASE_COMBINING
option, can be considered in order
michael@0: * to avoid these issues.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE UBiDiDirection U_EXPORT2
michael@0: ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,
michael@0: int32_t *pLogicalStart, int32_t *pLength);
michael@0:
michael@0: /**
michael@0: * Get the visual position from a logical text position.
michael@0: * If such a mapping is used many times on the same
michael@0: * UBiDi
object, then calling
michael@0: * ubidi_getLogicalMap()
is more efficient.#UBIDI_MAP_NOWHERE
if there is no
michael@0: * visual position because the corresponding text character is a Bidi control
michael@0: * removed from output by the option #UBIDI_OPTION_REMOVE_CONTROLS
.
michael@0: * ubidi_writeReordered()
such as UBIDI_INSERT_LRM_FOR_NUMERIC
,
michael@0: * UBIDI_KEEP_BASE_COMBINING
, UBIDI_OUTPUT_REVERSE
,
michael@0: * UBIDI_REMOVE_BIDI_CONTROLS
, the visual position returned may not
michael@0: * be correct. It is advised to use, when possible, reordering options
michael@0: * such as UBIDI_OPTION_INSERT_MARKS
and UBIDI_OPTION_REMOVE_CONTROLS
.
michael@0: * ubidi_writeReordered()
, optionally with the
michael@0: * #UBIDI_KEEP_BASE_COMBINING
option can be considered instead
michael@0: * of using the mapping, in order to avoid these issues.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @param logicalIndex is the index of a character in the text.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return The visual position of this character.
michael@0: *
michael@0: * @see ubidi_getLogicalMap
michael@0: * @see ubidi_getLogicalIndex
michael@0: * @see ubidi_getProcessedLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get the logical text position from a visual position.
michael@0: * If such a mapping is used many times on the same
michael@0: * UBiDi
object, then calling
michael@0: * ubidi_getVisualMap()
is more efficient.#UBIDI_MAP_NOWHERE
if there is no
michael@0: * logical position because the corresponding text character is a Bidi mark
michael@0: * inserted in the output by option #UBIDI_OPTION_INSERT_MARKS
.
michael@0: * ubidi_getVisualIndex()
.
michael@0: * ubidi_writeReordered()
such as UBIDI_INSERT_LRM_FOR_NUMERIC
,
michael@0: * UBIDI_KEEP_BASE_COMBINING
, UBIDI_OUTPUT_REVERSE
,
michael@0: * UBIDI_REMOVE_BIDI_CONTROLS
, the logical position returned may not
michael@0: * be correct. It is advised to use, when possible, reordering options
michael@0: * such as UBIDI_OPTION_INSERT_MARKS
and UBIDI_OPTION_REMOVE_CONTROLS
.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @param visualIndex is the visual position of a character.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return The index of this character in the text.
michael@0: *
michael@0: * @see ubidi_getVisualMap
michael@0: * @see ubidi_getVisualIndex
michael@0: * @see ubidi_getResultLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get a logical-to-visual index map (array) for the characters in the UBiDi
michael@0: * (paragraph or line) object.
michael@0: * #UBIDI_MAP_NOWHERE
if the
michael@0: * corresponding text characters are Bidi controls removed from the visual
michael@0: * output by the option #UBIDI_OPTION_REMOVE_CONTROLS
.
michael@0: * ubidi_writeReordered()
such as UBIDI_INSERT_LRM_FOR_NUMERIC
,
michael@0: * UBIDI_KEEP_BASE_COMBINING
, UBIDI_OUTPUT_REVERSE
,
michael@0: * UBIDI_REMOVE_BIDI_CONTROLS
, the visual positions returned may not
michael@0: * be correct. It is advised to use, when possible, reordering options
michael@0: * such as UBIDI_OPTION_INSERT_MARKS
and UBIDI_OPTION_REMOVE_CONTROLS
.
michael@0: * ubidi_writeReordered()
, optionally with the
michael@0: * #UBIDI_KEEP_BASE_COMBINING
option can be considered instead
michael@0: * of using the mapping, in order to avoid these issues.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @param indexMap is a pointer to an array of ubidi_getProcessedLength()
michael@0: * indexes which will reflect the reordering of the characters.
michael@0: * If option #UBIDI_OPTION_INSERT_MARKS
is set, the number
michael@0: * of elements allocated in indexMap
must be no less than
michael@0: * ubidi_getResultLength()
.
michael@0: * The array does not need to be initialized.
michael@0: * The index map will result in indexMap[logicalIndex]==visualIndex
.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @see ubidi_getVisualMap
michael@0: * @see ubidi_getVisualIndex
michael@0: * @see ubidi_getProcessedLength
michael@0: * @see ubidi_getResultLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get a visual-to-logical index map (array) for the characters in the UBiDi
michael@0: * (paragraph or line) object.
michael@0: * #UBIDI_MAP_NOWHERE
if the
michael@0: * corresponding text characters are Bidi marks inserted in the visual output
michael@0: * by the option #UBIDI_OPTION_INSERT_MARKS
.
michael@0: * ubidi_writeReordered()
such as UBIDI_INSERT_LRM_FOR_NUMERIC
,
michael@0: * UBIDI_KEEP_BASE_COMBINING
, UBIDI_OUTPUT_REVERSE
,
michael@0: * UBIDI_REMOVE_BIDI_CONTROLS
, the logical positions returned may not
michael@0: * be correct. It is advised to use, when possible, reordering options
michael@0: * such as UBIDI_OPTION_INSERT_MARKS
and UBIDI_OPTION_REMOVE_CONTROLS
.
michael@0: *
michael@0: * @param pBiDi is the paragraph or line UBiDi
object.
michael@0: *
michael@0: * @param indexMap is a pointer to an array of ubidi_getResultLength()
michael@0: * indexes which will reflect the reordering of the characters.
michael@0: * If option #UBIDI_OPTION_REMOVE_CONTROLS
is set, the number
michael@0: * of elements allocated in indexMap
must be no less than
michael@0: * ubidi_getProcessedLength()
.
michael@0: * The array does not need to be initialized.
michael@0: * The index map will result in indexMap[visualIndex]==logicalIndex
.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @see ubidi_getLogicalMap
michael@0: * @see ubidi_getLogicalIndex
michael@0: * @see ubidi_getProcessedLength
michael@0: * @see ubidi_getResultLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * This is a convenience function that does not use a UBiDi object.
michael@0: * It is intended to be used for when an application has determined the levels
michael@0: * of objects (character sequences) and just needs to have them reordered (L2).
michael@0: * This is equivalent to using ubidi_getLogicalMap()
on a
michael@0: * UBiDi
object.
michael@0: *
michael@0: * @param levels is an array with length
levels that have been determined by
michael@0: * the application.
michael@0: *
michael@0: * @param length is the number of levels in the array, or, semantically,
michael@0: * the number of objects to be reordered.
michael@0: * It must be length>0
.
michael@0: *
michael@0: * @param indexMap is a pointer to an array of length
michael@0: * indexes which will reflect the reordering of the characters.
michael@0: * The array does not need to be initialized.indexMap[logicalIndex]==visualIndex
.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
michael@0:
michael@0: /**
michael@0: * This is a convenience function that does not use a UBiDi object.
michael@0: * It is intended to be used for when an application has determined the levels
michael@0: * of objects (character sequences) and just needs to have them reordered (L2).
michael@0: * This is equivalent to using ubidi_getVisualMap()
on a
michael@0: * UBiDi
object.
michael@0: *
michael@0: * @param levels is an array with length
levels that have been determined by
michael@0: * the application.
michael@0: *
michael@0: * @param length is the number of levels in the array, or, semantically,
michael@0: * the number of objects to be reordered.
michael@0: * It must be length>0
.
michael@0: *
michael@0: * @param indexMap is a pointer to an array of length
michael@0: * indexes which will reflect the reordering of the characters.
michael@0: * The array does not need to be initialized.indexMap[visualIndex]==logicalIndex
.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
michael@0:
michael@0: /**
michael@0: * Invert an index map.
michael@0: * The index mapping of the first map is inverted and written to
michael@0: * the second one.
michael@0: *
michael@0: * @param srcMap is an array with length
elements
michael@0: * which defines the original mapping from a source array containing
michael@0: * length
elements to a destination array.
michael@0: * Some elements of the source array may have no mapping in the
michael@0: * destination array. In that case, their value will be
michael@0: * the special value UBIDI_MAP_NOWHERE
.
michael@0: * All elements must be >=0 or equal to UBIDI_MAP_NOWHERE
.
michael@0: * Some elements may have a value >= length
, if the
michael@0: * destination array has more elements than the source array.
michael@0: * There must be no duplicate indexes (two or more elements with the
michael@0: * same value except UBIDI_MAP_NOWHERE
).
michael@0: *
michael@0: * @param destMap is an array with a number of elements equal to 1 + the highest
michael@0: * value in srcMap
.
michael@0: * destMap
will be filled with the inverse mapping.
michael@0: * If element with index i in srcMap
has a value k different
michael@0: * from UBIDI_MAP_NOWHERE
, this means that element i of
michael@0: * the source array maps to element k in the destination array.
michael@0: * The inverse map will have value i in its k-th element.
michael@0: * For all elements of the destination array which do not map to
michael@0: * an element in the source array, the corresponding element in the
michael@0: * inverse map will have a value equal to UBIDI_MAP_NOWHERE
.
michael@0: *
michael@0: * @param length is the length of each array.
michael@0: * @see UBIDI_MAP_NOWHERE
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);
michael@0:
michael@0: /** option flags for ubidi_writeReordered() */
michael@0:
michael@0: /**
michael@0: * option bit for ubidi_writeReordered():
michael@0: * keep combining characters after their base characters in RTL runs
michael@0: *
michael@0: * @see ubidi_writeReordered
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define UBIDI_KEEP_BASE_COMBINING 1
michael@0:
michael@0: /**
michael@0: * option bit for ubidi_writeReordered():
michael@0: * replace characters with the "mirrored" property in RTL runs
michael@0: * by their mirror-image mappings
michael@0: *
michael@0: * @see ubidi_writeReordered
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define UBIDI_DO_MIRRORING 2
michael@0:
michael@0: /**
michael@0: * option bit for ubidi_writeReordered():
michael@0: * surround the run with LRMs if necessary;
michael@0: * this is part of the approximate "inverse Bidi" algorithm
michael@0: *
michael@0: * ubidi_writeReordered()
michael@0: * first without this option, and then calling
michael@0: * ubidi_writeReverse()
without mirroring.
michael@0: * Doing this in the same step is faster and avoids a temporary buffer.
michael@0: * An example for using this option is output to a character terminal that
michael@0: * is designed for RTL scripts and stores text in reverse order.ubidi_setPara()
. This length may be different from the length
michael@0: * of the source text if option #UBIDI_OPTION_STREAMING
michael@0: * has been set.
michael@0: *
michael@0: * Note that whenever the length of the text affects the execution or the
michael@0: * result of a function, it is the processed length which must be considered,
michael@0: * except for ubidi_setPara
(which receives unprocessed source
michael@0: * text) and ubidi_getLength
(which returns the original length
michael@0: * of the source text).
michael@0: * In particular, the processed length is the one to consider in the following
michael@0: * cases:
michael@0: *
michael@0: *
michael@0: *
michael@0: * @param pBiDi is the paragraph limit
argument of
michael@0: * ubidi_setLine
charIndex
argument of
michael@0: * ubidi_getParagraph
charIndex
argument of
michael@0: * ubidi_getLevelAt
ubidi_getLevels
logicalStart
argument of
michael@0: * ubidi_getLogicalRun
logicalIndex
argument of
michael@0: * ubidi_getVisualIndex
*indexMap
argument of
michael@0: * ubidi_getLogicalMap
ubidi_writeReordered
UBiDi
object.
michael@0: *
michael@0: * @return The length of the part of the source text processed by
michael@0: * the last call to ubidi_setPara
.
michael@0: * @see ubidi_setPara
michael@0: * @see UBIDI_OPTION_STREAMING
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_getProcessedLength(const UBiDi *pBiDi);
michael@0:
michael@0: /**
michael@0: * Get the length of the reordered text resulting from the last call to
michael@0: * ubidi_setPara()
. This length may be different from the length
michael@0: * of the source text if option #UBIDI_OPTION_INSERT_MARKS
michael@0: * or option #UBIDI_OPTION_REMOVE_CONTROLS
has been set.
michael@0: *
michael@0: * This resulting length is the one to consider in the following cases:
michael@0: *
michael@0: *
michael@0: * Note that this length stays identical to the source text length if
michael@0: * Bidi marks are inserted or removed using option bits of
michael@0: * visualIndex
argument of
michael@0: * ubidi_getLogicalIndex
*indexMap
argument of
michael@0: * ubidi_getVisualMap
ubidi_writeReordered
, or if option
michael@0: * #UBIDI_REORDER_INVERSE_NUMBERS_AS_L
has been set.
michael@0: *
michael@0: * @param pBiDi is the paragraph UBiDi
object.
michael@0: *
michael@0: * @return The length of the reordered text resulting from
michael@0: * the last call to ubidi_setPara
.
michael@0: * @see ubidi_setPara
michael@0: * @see UBIDI_OPTION_INSERT_MARKS
michael@0: * @see UBIDI_OPTION_REMOVE_CONTROLS
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_getResultLength(const UBiDi *pBiDi);
michael@0:
michael@0: U_CDECL_BEGIN
michael@0: /**
michael@0: * value returned by UBiDiClassCallback
callbacks when
michael@0: * there is no need to override the standard Bidi class for a given code point.
michael@0: * @see UBiDiClassCallback
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: #define U_BIDI_CLASS_DEFAULT U_CHAR_DIRECTION_COUNT
michael@0:
michael@0: /**
michael@0: * Callback type declaration for overriding default Bidi class values with
michael@0: * custom ones.
michael@0: * UBiDi
michael@0: * object by calling the ubidi_setClassCallback()
function;
michael@0: * then the callback will be invoked by the UBA implementation any time the
michael@0: * class of a character is to be determined.c
if the default class has been overridden, or
michael@0: * #U_BIDI_CLASS_DEFAULT
if the standard Bidi class value
michael@0: * for c
is to be used.
michael@0: * @see ubidi_setClassCallback
michael@0: * @see ubidi_getClassCallback
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: typedef UCharDirection U_CALLCONV
michael@0: UBiDiClassCallback(const void *context, UChar32 c);
michael@0:
michael@0: U_CDECL_END
michael@0:
michael@0: /**
michael@0: * Retrieve the Bidi class for a given code point.
michael@0: * #UBiDiClassCallback
callback is defined and returns a
michael@0: * value other than #U_BIDI_CLASS_DEFAULT
, that value is used;
michael@0: * otherwise the default class determination mechanism is invoked.UBiDi
object.
michael@0: *
michael@0: * @param c is the code point whose Bidi class must be retrieved.
michael@0: *
michael@0: * @return The Bidi class for character c
based
michael@0: * on the given pBiDi
instance.
michael@0: * @see UBiDiClassCallback
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE UCharDirection U_EXPORT2
michael@0: ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c);
michael@0:
michael@0: /**
michael@0: * Set the callback function and callback data used by the UBA
michael@0: * implementation for Bidi class determination.
michael@0: * UBiDi
object.
michael@0: *
michael@0: * @param newFn is the new callback function pointer.
michael@0: *
michael@0: * @param newContext is the new callback context pointer. This can be NULL.
michael@0: *
michael@0: * @param oldFn fillin: Returns the old callback function pointer. This can be
michael@0: * NULL.
michael@0: *
michael@0: * @param oldContext fillin: Returns the old callback's context. This can be
michael@0: * NULL.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @see ubidi_getClassCallback
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,
michael@0: const void *newContext, UBiDiClassCallback **oldFn,
michael@0: const void **oldContext, UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Get the current callback function used for Bidi class determination.
michael@0: *
michael@0: * @param pBiDi is the paragraph UBiDi
object.
michael@0: *
michael@0: * @param fn fillin: Returns the callback function pointer.
michael@0: *
michael@0: * @param context fillin: Returns the callback's private context.
michael@0: *
michael@0: * @see ubidi_setClassCallback
michael@0: * @stable ICU 3.6
michael@0: */
michael@0: U_STABLE void U_EXPORT2
michael@0: ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context);
michael@0:
michael@0: /**
michael@0: * Take a UBiDi
object containing the reordering
michael@0: * information for a piece of text (one or more paragraphs) set by
michael@0: * ubidi_setPara()
or for a line of text set by
michael@0: * ubidi_setLine()
and write a reordered string to the
michael@0: * destination buffer.
michael@0: *
michael@0: * This function preserves the integrity of characters with multiple
michael@0: * code units and (optionally) combining characters.
michael@0: * Characters in RTL runs can be replaced by mirror-image characters
michael@0: * in the destination buffer. Note that "real" mirroring has
michael@0: * to be done in a rendering engine by glyph selection
michael@0: * and that for many "mirrored" characters there are no
michael@0: * Unicode characters as mirror-image equivalents.
michael@0: * There are also options to insert or remove Bidi control
michael@0: * characters; see the description of the destSize
michael@0: * and options
parameters and of the option bit flags.
michael@0: *
michael@0: * @param pBiDi A pointer to a UBiDi
object that
michael@0: * is set by ubidi_setPara()
or
michael@0: * ubidi_setLine()
and contains the reordering
michael@0: * information for the text that it was defined for,
michael@0: * as well as a pointer to that text.
michael@0: * The text was aliased (only the pointer was stored
michael@0: * without copying the contents) and must not have been modified
michael@0: * since the ubidi_setPara()
call.
michael@0: *
michael@0: * @param dest A pointer to where the reordered text is to be copied.
michael@0: * The source text and dest[destSize]
michael@0: * must not overlap.
michael@0: *
michael@0: * @param destSize The size of the dest
buffer,
michael@0: * in number of UChars.
michael@0: * If the UBIDI_INSERT_LRM_FOR_NUMERIC
michael@0: * option is set, then the destination length could be
michael@0: * as large as
michael@0: * ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)
.
michael@0: * If the UBIDI_REMOVE_BIDI_CONTROLS
option
michael@0: * is set, then the destination length may be less than
michael@0: * ubidi_getLength(pBiDi)
.
michael@0: * If none of these options is set, then the destination length
michael@0: * will be exactly ubidi_getProcessedLength(pBiDi)
.
michael@0: *
michael@0: * @param options A bit set of options for the reordering that control
michael@0: * how the reordered text is written.
michael@0: * The options include mirroring the characters on a code
michael@0: * point basis and inserting LRM characters, which is used
michael@0: * especially for transforming visually stored text
michael@0: * to logically stored text (although this is still an
michael@0: * imperfect implementation of an "inverse Bidi" algorithm
michael@0: * because it uses the "forward Bidi" algorithm at its core).
michael@0: * The available options are:
michael@0: * #UBIDI_DO_MIRRORING
,
michael@0: * #UBIDI_INSERT_LRM_FOR_NUMERIC
,
michael@0: * #UBIDI_KEEP_BASE_COMBINING
,
michael@0: * #UBIDI_OUTPUT_REVERSE
,
michael@0: * #UBIDI_REMOVE_BIDI_CONTROLS
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return The length of the output string.
michael@0: *
michael@0: * @see ubidi_getProcessedLength
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_writeReordered(UBiDi *pBiDi,
michael@0: UChar *dest, int32_t destSize,
michael@0: uint16_t options,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Reverse a Right-To-Left run of Unicode text.
michael@0: *
michael@0: * This function preserves the integrity of characters with multiple
michael@0: * code units and (optionally) combining characters.
michael@0: * Characters can be replaced by mirror-image characters
michael@0: * in the destination buffer. Note that "real" mirroring has
michael@0: * to be done in a rendering engine by glyph selection
michael@0: * and that for many "mirrored" characters there are no
michael@0: * Unicode characters as mirror-image equivalents.
michael@0: * There are also options to insert or remove Bidi control
michael@0: * characters.
michael@0: *
michael@0: * This function is the implementation for reversing RTL runs as part
michael@0: * of ubidi_writeReordered()
. For detailed descriptions
michael@0: * of the parameters, see there.
michael@0: * Since no Bidi controls are inserted here, the output string length
michael@0: * will never exceed srcLength
.
michael@0: *
michael@0: * @see ubidi_writeReordered
michael@0: *
michael@0: * @param src A pointer to the RTL run text.
michael@0: *
michael@0: * @param srcLength The length of the RTL run.
michael@0: *
michael@0: * @param dest A pointer to where the reordered text is to be copied.
michael@0: * src[srcLength]
and dest[destSize]
michael@0: * must not overlap.
michael@0: *
michael@0: * @param destSize The size of the dest
buffer,
michael@0: * in number of UChars.
michael@0: * If the UBIDI_REMOVE_BIDI_CONTROLS
option
michael@0: * is set, then the destination length may be less than
michael@0: * srcLength
.
michael@0: * If this option is not set, then the destination length
michael@0: * will be exactly srcLength
.
michael@0: *
michael@0: * @param options A bit set of options for the reordering that control
michael@0: * how the reordered text is written.
michael@0: * See the options
parameter in ubidi_writeReordered()
.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value.
michael@0: *
michael@0: * @return The length of the output string.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: ubidi_writeReverse(const UChar *src, int32_t srcLength,
michael@0: UChar *dest, int32_t destSize,
michael@0: uint16_t options,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /*#define BIDI_SAMPLE_CODE*/
michael@0: /*@}*/
michael@0:
michael@0: #endif