Logo Search packages:      
Sourcecode: icu version File versions  Download package

U_STABLE UBiDiDirection U_EXPORT2 ubidi_getVisualRun ( UBiDi pBiDi,
int32_t  runIndex,
int32_t *  pLogicalStart,
int32_t *  pLength 
)

Get one run's logical start, length, and directionality, which can be 0 for LTR or 1 for RTL. 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.

Parameters:
pBiDi is the paragraph or line UBiDi object.
runIndex is the number of the run in visual order, in the range [0..ubidi_countRuns(pBiDi)-1].
pLogicalStart is the first logical character index in the text. The pointer may be NULL if this index is not needed.
pLength is the number of characters (at least one) in the run. The pointer may be NULL if this is not needed.
Returns:
the directionality of the run, UBIDI_LTR==0 or UBIDI_RTL==1, never UBIDI_MIXED.
See also:
ubidi_countRuns
Example:
 
 int32_t i, count=ubidi_countRuns(pBiDi),
         logicalStart, visualIndex=0, length;
 for(i=0; i<count; ++i) {
    if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {
         do { // LTR
             show_char(text[logicalStart++], visualIndex++);
         } while(--length>0);
     } else {
         logicalStart+=length;  // logicalLimit
         do { // RTL
             show_char(text[--logicalStart], visualIndex++);
         } while(--length>0);
     }
 }
 *

Note that in right-to-left runs, code like this places second surrogates before first ones (which is generally a bad idea) and combining characters before base characters.

Use of ubidi_writeReordered(), optionally with the UBIDI_KEEP_BASE_COMBINING option, can be considered in order to avoid these issues. ICU 2.0

Definition at line 361 of file ubidiln.c.

References NULL, U_FAILURE, U_ZERO_ERROR, and UBIDI_LTR.

{
    int32_t start;
    UErrorCode errorCode = U_ZERO_ERROR;
    RETURN_IF_NOT_VALID_PARA_OR_LINE(pBiDi, errorCode, UBIDI_LTR);
    ubidi_getRuns(pBiDi, &errorCode);
    if(U_FAILURE(errorCode)) {
        return UBIDI_LTR;
    }
    RETURN_IF_BAD_RANGE(runIndex, 0, pBiDi->runCount, errorCode, UBIDI_LTR);

    start=pBiDi->runs[runIndex].logicalStart;
    if(pLogicalStart!=NULL) {
        *pLogicalStart=GET_INDEX(start);
    }
    if(pLength!=NULL) {
        if(runIndex>0) {
            *pLength=pBiDi->runs[runIndex].visualLimit-
                     pBiDi->runs[runIndex-1].visualLimit;
        } else {
            *pLength=pBiDi->runs[0].visualLimit;
        }
    }
    return (UBiDiDirection)GET_ODD_BIT(start);
}


Generated by  Doxygen 1.6.0   Back to index