/* ****************************************************************************** * * Copyright (C) 1999-2004, International Business Machines * Corporation and others. All Rights Reserved. * ****************************************************************************** * file name: ubidi.h * encoding: US-ASCII * tab size: 8 (not used) * indentation:4 * * created on: 1999jul27 * created by: Markus W. Scherer */ #ifndef UBIDI_H #define UBIDI_H #include "unicode/utypes.h" #include "unicode/uchar.h" /* * javadoc-style comments are intended to be transformed into HTML * using DOC++ - see * http://www.zib.de/Visual/software/doc++/index.html . * * The HTML documentation is created with * doc++ -H ubidi.h * * The following #define trick allows us to do it all in one file * and still be able to compile it. */ /*#define DOCXX_TAG*/ /*#define BIDI_SAMPLE_CODE*/ /** *\file * \brief C API: BIDI algorithm * *
* * 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". * *
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 * * *
The basic assumptions are:
** \code *#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*/ /*DOCXX_TAG*/ /*@{*/ /** * 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).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 =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); *} *\endcode *
*
* It can also hold non-level values for the
* paraLevel
and embeddingLevels
* arguments of ubidi_setPara()
; there:
*
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
.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 UBIDI_DEFAULT_LTR
* @see UBIDI_DEFAULT_RTL
* @see UBIDI_LEVEL_OVERRIDE
* @see UBIDI_MAX_EXPLICIT_LEVEL
* @stable ICU 2.0
*/
typedef uint8_t UBiDiLevel;
/** Paragraph level setting.
* If there is no strong character, then set the paragraph level to 0 (left-to-right).
* @stable ICU 2.0
*/
#define UBIDI_DEFAULT_LTR 0xfe
/** Paragraph level setting.
* If there is no strong character, then set the paragraph level to 1 (right-to-left).
* @stable ICU 2.0
*/
#define UBIDI_DEFAULT_RTL 0xff
/**
* Maximum explicit embedding level.
* (The maximum resolved level can be up to UBIDI_MAX_EXPLICIT_LEVEL+1
).
* @stable ICU 2.0
*/
#define UBIDI_MAX_EXPLICIT_LEVEL 61
/** Bit flag for level input.
* Overrides directional properties.
* @stable ICU 2.0
*/
#define UBIDI_LEVEL_OVERRIDE 0x80
/**
* UBiDiDirection
values indicate the text direction.
* @stable ICU 2.0
*/
enum UBiDiDirection {
/** All left-to-right text. This is a 0 value. @stable ICU 2.0 */
UBIDI_LTR,
/** All right-to-left text. This is a 1 value. @stable ICU 2.0 */
UBIDI_RTL,
/** Mixed-directional text. @stable ICU 2.0 */
UBIDI_MIXED
};
/** @stable ICU 2.0 */
typedef enum UBiDiDirection UBiDiDirection;
/**
* Forward declaration of the UBiDi
structure for the declaration of
* the API functions. Its fields are implementation-specific.
* This structure holds information about a paragraph of text * with BiDi-algorithm-related details, or about one line of * such a paragraph.
* Reordering can be done on a line, or on a paragraph which is
* then interpreted as one single line.
* @stable ICU 2.0
*/
struct UBiDi;
/** @stable ICU 2.0 */
typedef struct UBiDi UBiDi;
/**
* Allocate a UBiDi
structure.
* Such an object is initially empty. It is assigned
* the BiDi properties of a paragraph by ubidi_setPara()
* or the BiDi properties of a line of a paragraph by
* ubidi_setLine()
.
* This object can be reused for as long as it is not deallocated
* by calling ubidi_close()
.
* ubidi_setPara()
and ubidi_setLine()
will allocate
* additional memory for internal structures as necessary.
*
* @return An empty UBiDi
object.
* @stable ICU 2.0
*/
U_STABLE UBiDi * U_EXPORT2
ubidi_open(void);
/**
* Allocate a UBiDi
structure with preallocated memory
* for internal structures.
* This function provides a UBiDi
object like ubidi_open()
* with no arguments, but it also preallocates memory for internal structures
* according to the sizings supplied by the caller.
* Subsequent functions will not allocate any more memory, and are thus * guaranteed not to fail because of lack of memory.
* The preallocation can be limited to some of the internal memory
* by setting some values to 0 here. That means that if, e.g.,
* maxRunCount
cannot be reasonably predetermined and should not
* be set to maxLength
(the only failproof value) to avoid
* wasting memory, then maxRunCount
could be set to 0 here
* and the internal structures that are associated with it will be allocated
* on demand, just like with ubidi_open()
.
*
* @param maxLength is the maximum paragraph or line length that internal memory
* will be preallocated for. An attempt to associate this object with a
* longer text will fail, unless this value is 0, which leaves the allocation
* up to the implementation.
*
* @param maxRunCount is the maximum anticipated number of same-level runs
* that internal memory will be preallocated for. An attempt to access
* visual runs on an object that was not preallocated for as many runs
* as the text was actually resolved to will fail,
* unless this value is 0, which leaves the allocation up to the implementation.
* The number of runs depends on the actual text and maybe anywhere between
* 1 and maxLength
. It is typically small.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return An empty UBiDi
object with preallocated memory.
* @stable ICU 2.0
*/
U_STABLE UBiDi * U_EXPORT2
ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
/**
* 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 is the child
* of another one (its parent), after calling
* ubidi_setLine()
, then the child object must
* be destroyed (closed) or reused (by calling
* ubidi_setPara()
or ubidi_setLine()
)
* before the parent object.
*
* @param pBiDi is a UBiDi
object.
*
* @see ubidi_setPara
* @see ubidi_setLine
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_close(UBiDi *pBiDi);
/**
* Modify the operation of the BiDi algorithm such that it
* approximates an "inverse BiDi" algorithm. This function
* must be called before ubidi_setPara()
.
*
*
The normal operation of the BiDi algorithm as described * in the Unicode Technical Report is to take text stored in logical * (keyboard, typing) order and to determine the reordering of it for visual * rendering. * Some legacy systems store text in visual order, and for operations * with standard, Unicode-based algorithms, the text needs to be transformed * to logical order. This is effectively the inverse algorithm of the * described BiDi algorithm. Note that there is no standard algorithm for * this "inverse BiDi" and that the current implementation provides only an * approximation of "inverse BiDi".
* *With isInverse
set to TRUE
,
* this function changes the behavior of some of the subsequent functions
* in a way that they can be used for the inverse BiDi algorithm.
* Specifically, runs of text with numeric characters will be treated in a
* special way and may need to be surrounded with LRM characters when they are
* written in reordered sequence.
Output runs should be retrieved using ubidi_getVisualRun()
.
* Since the actual input for "inverse BiDi" is visually ordered text and
* ubidi_getVisualRun()
gets the reordered runs, these are actually
* the runs of the logically ordered output.
UBiDi
object.
*
* @param isInverse specifies "forward" or "inverse" BiDi operation
*
* @see ubidi_setPara
* @see ubidi_writeReordered
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
/**
* Is this BiDi object set to perform the inverse BiDi algorithm?
*
* @param pBiDi is a UBiDi
object.
* @return TRUE if the BiDi object is set to perform the inverse BiDi algorithm
*
* @see ubidi_setInverse
* @stable ICU 2.0
*/
U_STABLE UBool U_EXPORT2
ubidi_isInverse(UBiDi *pBiDi);
/**
* Specify whether block separators must be allocated level zero,
* so that successive paragraphs will progress from left to right.
* This function must be called before ubidi_setPara()
.
* Paragraph separators (B) may appear in the text. Setting them to level zero
* means that all paragraph separators (including one possibly appearing
* in the last text position) are kept in the reordered text after the text
* that they follow in the source text.
* When this feature is not enabled, a paragraph separator at the last
* position of the text before reordering will go to the first position
* of the reordered text when the paragraph level is odd.
*
* @param pBiDi is a UBiDi
object.
*
* @param isOrderParagraphLTR specifies whether paragraph separators (B) must
* receive level 0, so that successive paragraphs progress from left to right.
*
* @see ubidi_setPara
* @stable ICU 3.4
*/
U_STABLE void U_EXPORT2
ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool isOrderParagraphLTR);
/**
* Is this BiDi object set to allocate level 0 to block separators so that
* successive paragraphs progress from left to right?
*
* @param pBiDi is a UBiDi
object.
* @return TRUE if the BiDi object is set to allocate level 0 to block
* separators.
*
* @see ubidi_setMultiPara
* @stable ICU 3.4
*/
U_STABLE UBool U_EXPORT2
ubidi_isOrderParagraphsLTR(UBiDi *pBiDi);
/**
* Perform the Unicode BiDi algorithm. It is defined in the
* Unicode Standard Anned #9,
* version 13,
* also described in The Unicode Standard, Version 4.0 .* * This function takes a single plain text paragraph with or without * externally specified embedding levels from styled text * and computes the left-right-directionality of each character.
*
* If the entire paragraph consists of text of only one direction, then
* the function may not perform all the steps described by the algorithm,
* i.e., some levels may not be the same as if all steps were performed.
* This is not relevant for unidirectional text.
* For example, in pure LTR text with numbers the numbers would get
* a resolved level of 2 higher than the surrounding text according to
* the algorithm. This implementation may set all resolved levels to
* the same value in such a case.
*
* The text can be composed of multiple paragraphs. Occurrence of a block
* separator in the text terminates a paragraph, and whatever comes next starts
* a new paragraph. The exception to this rule is when a Carriage Return (CR)
* is followed by a Line Feed (LF). Both CR and LF are block separators, but
* in that case, the pair of characters is considered as terminating the
* preceding paragraph, and a new paragraph will be started by a character
* coming after the LF.
*
* @param pBiDi A UBiDi
object allocated with ubidi_open()
* which will be set to contain the reordering information,
* especially the resolved levels for all the characters in text
.
*
* @param text is a pointer to the text that the
* BiDi algorithm will be performed on
* (step (P1) of the algorithm must be performed externally if paraLevel
* is specified as UBIDI_DEFAULT_LTR
or
* UBIDI_DEFAULT_RTL
).
* The text must be (at least) length
long.
* This pointer is stored in the UBiDi object and can be retrieved
* with ubidi_getText()
.
*
* @param length is the length of the text; if length==-1
then
* the text must be zero-terminated.
*
* @param paraLevel specifies the default level for the paragraph;
* it is typically 0 (LTR) or 1 (RTL).
* If the function shall determine the paragraph level from the text,
* then paraLevel
can be set to
* either UBIDI_DEFAULT_LTR
* or UBIDI_DEFAULT_RTL
;
* if there is no strongly typed character, then
* the desired default is used (0 for LTR or 1 for RTL).
* Any other value between 0 and UBIDI_MAX_EXPLICIT_LEVEL
is also valid,
* with odd levels indicating RTL.
*
* @param embeddingLevels (in) may be used to preset the embedding and override levels,
* ignoring characters like LRE and PDF in the text.
* A level overrides the directional property of its corresponding
* (same index) character if the level has the
* UBIDI_LEVEL_OVERRIDE
bit set.
* Except for that bit, it must be
* paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL
,
* with one exception: a level of zero may be specified for a paragraph
* separator even if paraLevel>0
when multiple paragraphs
* are submitted in the same call to ubidi_setPara()
.
* Caution: A copy of this pointer, not of the levels,
* will be stored in the UBiDi
object;
* the embeddingLevels
array must not be
* deallocated before the UBiDi
structure is destroyed or reused,
* and the embeddingLevels
* should not be modified to avoid unexpected results on subsequent BiDi operations.
* However, the ubidi_setPara()
and
* ubidi_setLine()
functions may modify some or all of the levels.
* After the UBiDi
object is reused or destroyed, the caller
* must take care of the deallocation of the embeddingLevels
array.
* The embeddingLevels
array must be
* at least length
long.
*
* @param pErrorCode must be a valid pointer to an error code value.
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
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. This line of text is
* specified by referring to a UBiDi
object representing
* this information for a paragraph of text, and by specifying
* a range of indexes in this paragraph.
* In the new line object, the indexes will range from 0 to limit-start-1
.
*
* This is used after calling ubidi_setPara()
* for a paragraph, and after line-breaking on that paragraph.
* It is not necessary if the paragraph is treated as a single line.
*
* After line-breaking, rules (L1) and (L2) for the treatment of
* trailing WS and for reordering are performed on
* a UBiDi
object that represents a line.
*
* Important: pLineBiDi
shares data with
* pParaBiDi
.
* You must destroy or reuse pLineBiDi
before pParaBiDi
.
* In other words, you must destroy or reuse the UBiDi
object for a line
* before the object for its parent paragraph.
*
* The text pointer that was stored in pParaBiDi
is also copied,
* and start
is added to it so that it points to the beginning of the
* line for this object.
*
* @param pParaBiDi is the parent paragraph object. It must have been set
* by a successful call to ubidi_setPara.
*
* @param start is the line's first index into the paragraph text.
*
* @param limit is just behind the line's last index into the paragraph text
* (its last index +1).
* It must be 0<=start<=limit<=
paragraph length.
*
* @param pLineBiDi is the object that will now represent a line of the paragraph.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @see ubidi_setPara
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_setLine(const UBiDi *pParaBiDi,
int32_t start, int32_t limit,
UBiDi *pLineBiDi,
UErrorCode *pErrorCode);
/**
* Get the directionality of the text.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @return A UBIDI_XXX
value that indicates if the entire text
* represented by this object is unidirectional,
* and which direction, or if it is mixed-directional.
*
* @see UBiDiDirection
* @stable ICU 2.0
*/
U_STABLE UBiDiDirection U_EXPORT2
ubidi_getDirection(const UBiDi *pBiDi);
/**
* Get the pointer to the text.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @return The pointer to the text that the UBiDi object was created for.
*
* @see ubidi_setPara
* @see ubidi_setLine
* @stable ICU 2.0
*/
U_STABLE const UChar * U_EXPORT2
ubidi_getText(const UBiDi *pBiDi);
/**
* Get the length of the text.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @return The length of the text that the UBiDi object was created for.
* @stable ICU 2.0
*/
U_STABLE int32_t U_EXPORT2
ubidi_getLength(const UBiDi *pBiDi);
/**
* Get the paragraph level of the text.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @return The paragraph level. If there are multiple paragraphs, their
* level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or
* UBIDI_DEFAULT_RTL. In that case, the level of the first paragraph
* is returned.
*
* @see UBiDiLevel
* @see ubidi_getParagraph
* @see ubidi_getParagraphByIndex
* @stable ICU 2.0
*/
U_STABLE UBiDiLevel U_EXPORT2
ubidi_getParaLevel(const UBiDi *pBiDi);
/**
* Get the number of paragraphs.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @return The number of paragraphs.
* @stable ICU 3.4
*/
U_STABLE int32_t U_EXPORT2
ubidi_countParagraphs(UBiDi *pBiDi);
/**
* Get a paragraph, given a position within the paragraph.
* This function returns information about a paragraph.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param charIndex is the index of a character within the text, in the
* range [0..ubidi_getLength(pBiDi)-1]
.
*
* @param pParaStart will receive the index of the first character in
* the paragraph.
* This pointer can be NULL
if this
* value is not necessary.
*
* @param pParaLimit will receive the limit of the paragraph.
* The l-value that you point to here may be the
* same expression (variable) as the one for
* charIndex
.
* This pointer can be NULL
if this
* value is not necessary.
*
* @param pParaLevel will receive the level of the paragraph.
* This pointer can be NULL
if this
* value is not necessary.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return The index of the paragraph containing the specified position.
* @stable ICU 3.4
*/
U_STABLE int32_t U_EXPORT2
ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,
int32_t *pParaLimit, UBiDiLevel *pParaLevel,
UErrorCode *pErrorCode);
/**
* Get a paragraph, given the index of this paragraph.
*
* This function returns information about a paragraph.
*
* @param pBiDi is the paragraph UBiDi
object.
*
* @param paraIndex is the number of the paragraph, in the
* range [0..ubidi_countParagraphs(pBiDi)-1]
.
*
* @param pParaStart will receive the index of the first character in
* the paragraph.
* This pointer can be NULL
if this
* value is not necessary.
*
* @param pParaLimit will receive the limit of the paragraph.
* This pointer can be NULL
if this
* value is not necessary.
*
* @param pParaLevel will receive the level of the paragraph.
* This pointer can be NULL
if this
* value is not necessary.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @stable ICU 3.4
*/
U_STABLE void U_EXPORT2
ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,
int32_t *pParaStart, int32_t *pParaLimit,
UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);
/**
* Get the level for one character.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param charIndex the index of a character.
*
* @return The level for the character at charIndex.
*
* @see UBiDiLevel
* @stable ICU 2.0
*/
U_STABLE UBiDiLevel U_EXPORT2
ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);
/**
* Get an array of levels for each character.
*
* Note that this function may allocate memory under some
* circumstances, unlike ubidi_getLevelAt()
.
*
* @param pBiDi is the paragraph or line UBiDi
object, whose
* text length must be strictly positive.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return The levels array for the text,
* or NULL
if an error occurs.
*
* @see UBiDiLevel
* @stable ICU 2.0
*/
U_STABLE const UBiDiLevel * U_EXPORT2
ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);
/**
* Get a logical run.
* This function returns information about a run and is used
* to retrieve runs in logical order.
* This is especially useful for line-breaking on a paragraph.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param logicalStart is the first character of the run.
*
* @param pLogicalLimit will receive the limit of the run.
* The l-value that you point to here may be the
* same expression (variable) as the one for
* logicalStart
.
* This pointer can be NULL
if this
* value is not necessary.
*
* @param pLevel will receive the level of the run.
* This pointer can be NULL
if this
* value is not necessary.
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalStart,
int32_t *pLogicalLimit, UBiDiLevel *pLevel);
/**
* 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.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return The number of runs.
* @stable ICU 2.0
*/
U_STABLE int32_t U_EXPORT2
ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
/**
* Get one run's logical start, length, and directionality,
* which can be 0 for LTR or 1 for RTL.
* In an RTL run, the character at the logical start is
* visually on the right of the displayed run.
* The length is the number of characters in the run.
* ubidi_countRuns()
should be called
* before the runs are retrieved.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param runIndex is the number of the run in visual order, in the
* range [0..ubidi_countRuns(pBiDi)-1]
.
*
* @param pLogicalStart is the first logical character index in the text.
* The pointer may be NULL
if this index is not needed.
*
* @param pLength is the number of characters (at least one) in the run.
* The pointer may be NULL
if this is not needed.
*
* @return the directionality of the run,
* UBIDI_LTR==0
or UBIDI_RTL==1
,
* never UBIDI_MIXED
.
*
* @see ubidi_countRuns
*
* Example:
*
* \code * int32_t i, count=ubidi_countRuns(pBiDi), * logicalStart, visualIndex=0, length; * for(i=0; i* * Note that in right-to-left runs, code like this places * modifier letters before base characters and second surrogates * before first ones. * @stable ICU 2.0 */ U_STABLE UBiDiDirection U_EXPORT2 ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex, int32_t *pLogicalStart, int32_t *pLength); /** * Get the visual position from a logical text position. * If such a mapping is used many times on the same *0); * } else { * logicalStart+=length; // logicalLimit * do { // RTL * show_char(text[--logicalStart], visualIndex++); * } while(--length>0); * } * } *\endcode *
UBiDi
object, then calling
* ubidi_getLogicalMap()
is more efficient.
*
* Note that in right-to-left runs, this mapping places
* modifier letters before base characters and second surrogates
* before first ones.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param logicalIndex is the index of a character in the text.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return The visual position of this character.
*
* @see ubidi_getLogicalMap
* @see ubidi_getLogicalIndex
* @stable ICU 2.0
*/
U_STABLE int32_t U_EXPORT2
ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, 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.
*
* This is the inverse function to ubidi_getVisualIndex()
.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param visualIndex is the visual position of a character.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return The index of this character in the text.
*
* @see ubidi_getVisualMap
* @see ubidi_getVisualIndex
* @stable ICU 2.0
*/
U_STABLE int32_t U_EXPORT2
ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);
/**
* Get a logical-to-visual index map (array) for the characters in the UBiDi
* (paragraph or line) object.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param indexMap is a pointer to an array of ubidi_getLength()
* indexes which will reflect the reordering of the characters.
* The array does not need to be initialized.
* The index map will result in indexMap[logicalIndex]==visualIndex
.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @see ubidi_getVisualMap
* @see ubidi_getVisualIndex
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_getLogicalMap(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.
*
* @param pBiDi is the paragraph or line UBiDi
object.
*
* @param indexMap is a pointer to an array of ubidi_getLength()
* indexes which will reflect the reordering of the characters.
* The array does not need to be initialized.
* The index map will result in indexMap[visualIndex]==logicalIndex
.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @see ubidi_getLogicalMap
* @see ubidi_getLogicalIndex
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
/**
* This is a convenience function that does not use a UBiDi object.
* It is intended to be used for when an application has determined the levels
* of objects (character sequences) and just needs to have them reordered (L2).
* This is equivalent to using ubidi_getLogicalMap
on a
* UBiDi
object.
*
* @param levels is an array with length
levels that have been determined by
* the application.
*
* @param length is the number of levels in the array, or, semantically,
* the number of objects to be reordered.
* It must be length>0
.
*
* @param indexMap is a pointer to an array of length
* indexes which will reflect the reordering of the characters.
* The array does not need to be initialized.
* The index map will result in indexMap[logicalIndex]==visualIndex
.
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
/**
* This is a convenience function that does not use a UBiDi object.
* It is intended to be used for when an application has determined the levels
* of objects (character sequences) and just needs to have them reordered (L2).
* This is equivalent to using ubidi_getVisualMap
on a
* UBiDi
object.
*
* @param levels is an array with length
levels that have been determined by
* the application.
*
* @param length is the number of levels in the array, or, semantically,
* the number of objects to be reordered.
* It must be length>0
.
*
* @param indexMap is a pointer to an array of length
* indexes which will reflect the reordering of the characters.
* The array does not need to be initialized.
* The index map will result in indexMap[visualIndex]==logicalIndex
.
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
/**
* Invert an index map.
* The one-to-one index mapping of the first map is inverted and written to
* the second one.
*
* @param srcMap is an array with length
indexes
* which define the original mapping.
*
* @param destMap is an array with length
indexes
* which will be filled with the inverse mapping.
*
* @param length is the length of each array.
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);
/** option flags for ubidi_writeReordered() */
/**
* option bit for ubidi_writeReordered():
* keep combining characters after their base characters in RTL runs
*
* @see ubidi_writeReordered
* @stable ICU 2.0
*/
#define UBIDI_KEEP_BASE_COMBINING 1
/**
* option bit for ubidi_writeReordered():
* replace characters with the "mirrored" property in RTL runs
* by their mirror-image mappings
*
* @see ubidi_writeReordered
* @stable ICU 2.0
*/
#define UBIDI_DO_MIRRORING 2
/**
* option bit for ubidi_writeReordered():
* surround the run with LRMs if necessary;
* this is part of the approximate "inverse BiDi" algorithm
*
* @see ubidi_setInverse
* @see ubidi_writeReordered
* @stable ICU 2.0
*/
#define UBIDI_INSERT_LRM_FOR_NUMERIC 4
/**
* option bit for ubidi_writeReordered():
* remove BiDi control characters
* (this does not affect UBIDI_INSERT_LRM_FOR_NUMERIC)
*
* @see ubidi_writeReordered
* @stable ICU 2.0
*/
#define UBIDI_REMOVE_BIDI_CONTROLS 8
/**
* 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.
UBiDi
object containing the reordering
* information for one paragraph or line of text as set by
* ubidi_setPara()
or ubidi_setLine()
and
* write a reordered string to the destination buffer.
*
* This function preserves the integrity of characters with multiple
* code units and (optionally) modifier letters.
* Characters in RTL runs can be replaced by mirror-image characters
* in the destination buffer. Note that "real" mirroring has
* to be done in a rendering engine by glyph selection
* and that for many "mirrored" characters there are no
* Unicode characters as mirror-image equivalents.
* There are also options to insert or remove BiDi control
* characters; see the description of the destSize
* and options
parameters and of the option bit flags.
*
* @see UBIDI_DO_MIRRORING
* @see UBIDI_INSERT_LRM_FOR_NUMERIC
* @see UBIDI_KEEP_BASE_COMBINING
* @see UBIDI_OUTPUT_REVERSE
* @see UBIDI_REMOVE_BIDI_CONTROLS
*
* @param pBiDi A pointer to a UBiDi
object that
* is set by ubidi_setPara()
or
* ubidi_setLine()
and contains the reordering
* information for the text that it was defined for,
* as well as a pointer to that text.
* The text was aliased (only the pointer was stored
* without copying the contents) and must not have been modified
* since the ubidi_setPara()
call.
dest[destSize]
* must not overlap.
*
* @param destSize The size of the dest
buffer,
* in number of UChars.
* If the UBIDI_INSERT_LRM_FOR_NUMERIC
* option is set, then the destination length could be
* as large as
* ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)
.
* If the UBIDI_REMOVE_BIDI_CONTROLS
option
* is set, then the destination length may be less than
* ubidi_getLength(pBiDi)
.
* If none of these options is set, then the destination length
* will be exactly ubidi_getLength(pBiDi)
.
*
* @param options A bit set of options for the reordering that control
* how the reordered text is written.
* The options include mirroring the characters on a code
* point basis and inserting LRM characters, which is used
* especially for transforming visually stored text
* to logically stored text (although this is still an
* imperfect implementation of an "inverse BiDi" algorithm
* because it uses the "forward BiDi" algorithm at its core).
* The available options are:
* #UBIDI_DO_MIRRORING
,
* #UBIDI_INSERT_LRM_FOR_NUMERIC
,
* #UBIDI_KEEP_BASE_COMBINING
,
* #UBIDI_OUTPUT_REVERSE
,
* #UBIDI_REMOVE_BIDI_CONTROLS
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return The length of the output string.
* @stable ICU 2.0
*/
U_STABLE int32_t U_EXPORT2
ubidi_writeReordered(UBiDi *pBiDi,
UChar *dest, int32_t destSize,
uint16_t options,
UErrorCode *pErrorCode);
/**
* Reverse a Right-To-Left run of Unicode text.
*
* This function preserves the integrity of characters with multiple
* code units and (optionally) modifier letters.
* Characters can be replaced by mirror-image characters
* in the destination buffer. Note that "real" mirroring has
* to be done in a rendering engine by glyph selection
* and that for many "mirrored" characters there are no
* Unicode characters as mirror-image equivalents.
* There are also options to insert or remove BiDi control
* characters.
*
* This function is the implementation for reversing RTL runs as part
* of ubidi_writeReordered()
. For detailed descriptions
* of the parameters, see there.
* Since no BiDi controls are inserted here, the output string length
* will never exceed srcLength
.
*
* @see ubidi_writeReordered
*
* @param src A pointer to the RTL run text.
*
* @param srcLength The length of the RTL run.
*
* @param dest A pointer to where the reordered text is to be copied.
* src[srcLength]
and dest[destSize]
* must not overlap.
*
* @param destSize The size of the dest
buffer,
* in number of UChars.
* If the UBIDI_REMOVE_BIDI_CONTROLS
option
* is set, then the destination length may be less than
* srcLength
.
* If this option is not set, then the destination length
* will be exactly srcLength
.
*
* @param options A bit set of options for the reordering that control
* how the reordered text is written.
* See the options
parameter in ubidi_writeReordered()
.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return The length of the output string.
* @stable ICU 2.0
*/
U_STABLE int32_t U_EXPORT2
ubidi_writeReverse(const UChar *src, int32_t srcLength,
UChar *dest, int32_t destSize,
uint16_t options,
UErrorCode *pErrorCode);
/*#define BIDI_SAMPLE_CODE*/
/*@}*/
#endif