intl/icu/source/common/unicode/ubidi.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1999-2013, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 ******************************************************************************
michael@0 8 * file name: ubidi.h
michael@0 9 * encoding: US-ASCII
michael@0 10 * tab size: 8 (not used)
michael@0 11 * indentation:4
michael@0 12 *
michael@0 13 * created on: 1999jul27
michael@0 14 * created by: Markus W. Scherer, updated by Matitiahu Allouche
michael@0 15 */
michael@0 16
michael@0 17 #ifndef UBIDI_H
michael@0 18 #define UBIDI_H
michael@0 19
michael@0 20 #include "unicode/utypes.h"
michael@0 21 #include "unicode/uchar.h"
michael@0 22 #include "unicode/localpointer.h"
michael@0 23
michael@0 24 /**
michael@0 25 *\file
michael@0 26 * \brief C API: Bidi algorithm
michael@0 27 *
michael@0 28 * <h2>Bidi algorithm for ICU</h2>
michael@0 29 *
michael@0 30 * This is an implementation of the Unicode Bidirectional Algorithm.
michael@0 31 * The algorithm is defined in the
michael@0 32 * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>.<p>
michael@0 33 *
michael@0 34 * Note: Libraries that perform a bidirectional algorithm and
michael@0 35 * reorder strings accordingly are sometimes called "Storage Layout Engines".
michael@0 36 * ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such
michael@0 37 * "Storage Layout Engines".
michael@0 38 *
michael@0 39 * <h3>General remarks about the API:</h3>
michael@0 40 *
michael@0 41 * In functions with an error code parameter,
michael@0 42 * the <code>pErrorCode</code> pointer must be valid
michael@0 43 * and the value that it points to must not indicate a failure before
michael@0 44 * the function call. Otherwise, the function returns immediately.
michael@0 45 * After the function call, the value indicates success or failure.<p>
michael@0 46 *
michael@0 47 * The &quot;limit&quot; of a sequence of characters is the position just after their
michael@0 48 * last character, i.e., one more than that position.<p>
michael@0 49 *
michael@0 50 * Some of the API functions provide access to &quot;runs&quot;.
michael@0 51 * Such a &quot;run&quot; is defined as a sequence of characters
michael@0 52 * that are at the same embedding level
michael@0 53 * after performing the Bidi algorithm.<p>
michael@0 54 *
michael@0 55 * @author Markus W. Scherer
michael@0 56 * @version 1.0
michael@0 57 *
michael@0 58 *
michael@0 59 * <h4> Sample code for the ICU Bidi API </h4>
michael@0 60 *
michael@0 61 * <h5>Rendering a paragraph with the ICU Bidi API</h5>
michael@0 62 *
michael@0 63 * This is (hypothetical) sample code that illustrates
michael@0 64 * how the ICU Bidi API could be used to render a paragraph of text.
michael@0 65 * Rendering code depends highly on the graphics system,
michael@0 66 * therefore this sample code must make a lot of assumptions,
michael@0 67 * which may or may not match any existing graphics system's properties.
michael@0 68 *
michael@0 69 * <p>The basic assumptions are:</p>
michael@0 70 * <ul>
michael@0 71 * <li>Rendering is done from left to right on a horizontal line.</li>
michael@0 72 * <li>A run of single-style, unidirectional text can be rendered at once.</li>
michael@0 73 * <li>Such a run of text is passed to the graphics system with
michael@0 74 * characters (code units) in logical order.</li>
michael@0 75 * <li>The line-breaking algorithm is very complicated
michael@0 76 * and Locale-dependent -
michael@0 77 * and therefore its implementation omitted from this sample code.</li>
michael@0 78 * </ul>
michael@0 79 *
michael@0 80 * <pre>
michael@0 81 * \code
michael@0 82 *#include "unicode/ubidi.h"
michael@0 83 *
michael@0 84 *typedef enum {
michael@0 85 * styleNormal=0, styleSelected=1,
michael@0 86 * styleBold=2, styleItalics=4,
michael@0 87 * styleSuper=8, styleSub=16
michael@0 88 *} Style;
michael@0 89 *
michael@0 90 *typedef struct { int32_t limit; Style style; } StyleRun;
michael@0 91 *
michael@0 92 *int getTextWidth(const UChar *text, int32_t start, int32_t limit,
michael@0 93 * const StyleRun *styleRuns, int styleRunCount);
michael@0 94 *
michael@0 95 * // set *pLimit and *pStyleRunLimit for a line
michael@0 96 * // from text[start] and from styleRuns[styleRunStart]
michael@0 97 * // using ubidi_getLogicalRun(para, ...)
michael@0 98 *void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,
michael@0 99 * UBiDi *para,
michael@0 100 * const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,
michael@0 101 * int *pLineWidth);
michael@0 102 *
michael@0 103 * // render runs on a line sequentially, always from left to right
michael@0 104 *
michael@0 105 * // prepare rendering a new line
michael@0 106 * void startLine(UBiDiDirection textDirection, int lineWidth);
michael@0 107 *
michael@0 108 * // render a run of text and advance to the right by the run width
michael@0 109 * // the text[start..limit-1] is always in logical order
michael@0 110 * void renderRun(const UChar *text, int32_t start, int32_t limit,
michael@0 111 * UBiDiDirection textDirection, Style style);
michael@0 112 *
michael@0 113 * // We could compute a cross-product
michael@0 114 * // from the style runs with the directional runs
michael@0 115 * // and then reorder it.
michael@0 116 * // Instead, here we iterate over each run type
michael@0 117 * // and render the intersections -
michael@0 118 * // with shortcuts in simple (and common) cases.
michael@0 119 * // renderParagraph() is the main function.
michael@0 120 *
michael@0 121 * // render a directional run with
michael@0 122 * // (possibly) multiple style runs intersecting with it
michael@0 123 * void renderDirectionalRun(const UChar *text,
michael@0 124 * int32_t start, int32_t limit,
michael@0 125 * UBiDiDirection direction,
michael@0 126 * const StyleRun *styleRuns, int styleRunCount) {
michael@0 127 * int i;
michael@0 128 *
michael@0 129 * // iterate over style runs
michael@0 130 * if(direction==UBIDI_LTR) {
michael@0 131 * int styleLimit;
michael@0 132 *
michael@0 133 * for(i=0; i<styleRunCount; ++i) {
michael@0 134 * styleLimit=styleRun[i].limit;
michael@0 135 * if(start<styleLimit) {
michael@0 136 * if(styleLimit>limit) { styleLimit=limit; }
michael@0 137 * renderRun(text, start, styleLimit,
michael@0 138 * direction, styleRun[i].style);
michael@0 139 * if(styleLimit==limit) { break; }
michael@0 140 * start=styleLimit;
michael@0 141 * }
michael@0 142 * }
michael@0 143 * } else {
michael@0 144 * int styleStart;
michael@0 145 *
michael@0 146 * for(i=styleRunCount-1; i>=0; --i) {
michael@0 147 * if(i>0) {
michael@0 148 * styleStart=styleRun[i-1].limit;
michael@0 149 * } else {
michael@0 150 * styleStart=0;
michael@0 151 * }
michael@0 152 * if(limit>=styleStart) {
michael@0 153 * if(styleStart<start) { styleStart=start; }
michael@0 154 * renderRun(text, styleStart, limit,
michael@0 155 * direction, styleRun[i].style);
michael@0 156 * if(styleStart==start) { break; }
michael@0 157 * limit=styleStart;
michael@0 158 * }
michael@0 159 * }
michael@0 160 * }
michael@0 161 * }
michael@0 162 *
michael@0 163 * // the line object represents text[start..limit-1]
michael@0 164 * void renderLine(UBiDi *line, const UChar *text,
michael@0 165 * int32_t start, int32_t limit,
michael@0 166 * const StyleRun *styleRuns, int styleRunCount) {
michael@0 167 * UBiDiDirection direction=ubidi_getDirection(line);
michael@0 168 * if(direction!=UBIDI_MIXED) {
michael@0 169 * // unidirectional
michael@0 170 * if(styleRunCount<=1) {
michael@0 171 * renderRun(text, start, limit, direction, styleRuns[0].style);
michael@0 172 * } else {
michael@0 173 * renderDirectionalRun(text, start, limit,
michael@0 174 * direction, styleRuns, styleRunCount);
michael@0 175 * }
michael@0 176 * } else {
michael@0 177 * // mixed-directional
michael@0 178 * int32_t count, i, length;
michael@0 179 * UBiDiLevel level;
michael@0 180 *
michael@0 181 * count=ubidi_countRuns(para, pErrorCode);
michael@0 182 * if(U_SUCCESS(*pErrorCode)) {
michael@0 183 * if(styleRunCount<=1) {
michael@0 184 * Style style=styleRuns[0].style;
michael@0 185 *
michael@0 186 * // iterate over directional runs
michael@0 187 * for(i=0; i<count; ++i) {
michael@0 188 * direction=ubidi_getVisualRun(para, i, &start, &length);
michael@0 189 * renderRun(text, start, start+length, direction, style);
michael@0 190 * }
michael@0 191 * } else {
michael@0 192 * int32_t j;
michael@0 193 *
michael@0 194 * // iterate over both directional and style runs
michael@0 195 * for(i=0; i<count; ++i) {
michael@0 196 * direction=ubidi_getVisualRun(line, i, &start, &length);
michael@0 197 * renderDirectionalRun(text, start, start+length,
michael@0 198 * direction, styleRuns, styleRunCount);
michael@0 199 * }
michael@0 200 * }
michael@0 201 * }
michael@0 202 * }
michael@0 203 * }
michael@0 204 *
michael@0 205 *void renderParagraph(const UChar *text, int32_t length,
michael@0 206 * UBiDiDirection textDirection,
michael@0 207 * const StyleRun *styleRuns, int styleRunCount,
michael@0 208 * int lineWidth,
michael@0 209 * UErrorCode *pErrorCode) {
michael@0 210 * UBiDi *para;
michael@0 211 *
michael@0 212 * if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {
michael@0 213 * return;
michael@0 214 * }
michael@0 215 *
michael@0 216 * para=ubidi_openSized(length, 0, pErrorCode);
michael@0 217 * if(para==NULL) { return; }
michael@0 218 *
michael@0 219 * ubidi_setPara(para, text, length,
michael@0 220 * textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
michael@0 221 * NULL, pErrorCode);
michael@0 222 * if(U_SUCCESS(*pErrorCode)) {
michael@0 223 * UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);
michael@0 224 * StyleRun styleRun={ length, styleNormal };
michael@0 225 * int width;
michael@0 226 *
michael@0 227 * if(styleRuns==NULL || styleRunCount<=0) {
michael@0 228 * styleRunCount=1;
michael@0 229 * styleRuns=&styleRun;
michael@0 230 * }
michael@0 231 *
michael@0 232 * // assume styleRuns[styleRunCount-1].limit>=length
michael@0 233 *
michael@0 234 * width=getTextWidth(text, 0, length, styleRuns, styleRunCount);
michael@0 235 * if(width<=lineWidth) {
michael@0 236 * // everything fits onto one line
michael@0 237 *
michael@0 238 * // prepare rendering a new line from either left or right
michael@0 239 * startLine(paraLevel, width);
michael@0 240 *
michael@0 241 * renderLine(para, text, 0, length,
michael@0 242 * styleRuns, styleRunCount);
michael@0 243 * } else {
michael@0 244 * UBiDi *line;
michael@0 245 *
michael@0 246 * // we need to render several lines
michael@0 247 * line=ubidi_openSized(length, 0, pErrorCode);
michael@0 248 * if(line!=NULL) {
michael@0 249 * int32_t start=0, limit;
michael@0 250 * int styleRunStart=0, styleRunLimit;
michael@0 251 *
michael@0 252 * for(;;) {
michael@0 253 * limit=length;
michael@0 254 * styleRunLimit=styleRunCount;
michael@0 255 * getLineBreak(text, start, &limit, para,
michael@0 256 * styleRuns, styleRunStart, &styleRunLimit,
michael@0 257 * &width);
michael@0 258 * ubidi_setLine(para, start, limit, line, pErrorCode);
michael@0 259 * if(U_SUCCESS(*pErrorCode)) {
michael@0 260 * // prepare rendering a new line
michael@0 261 * // from either left or right
michael@0 262 * startLine(paraLevel, width);
michael@0 263 *
michael@0 264 * renderLine(line, text, start, limit,
michael@0 265 * styleRuns+styleRunStart,
michael@0 266 * styleRunLimit-styleRunStart);
michael@0 267 * }
michael@0 268 * if(limit==length) { break; }
michael@0 269 * start=limit;
michael@0 270 * styleRunStart=styleRunLimit-1;
michael@0 271 * if(start>=styleRuns[styleRunStart].limit) {
michael@0 272 * ++styleRunStart;
michael@0 273 * }
michael@0 274 * }
michael@0 275 *
michael@0 276 * ubidi_close(line);
michael@0 277 * }
michael@0 278 * }
michael@0 279 * }
michael@0 280 *
michael@0 281 * ubidi_close(para);
michael@0 282 *}
michael@0 283 *\endcode
michael@0 284 * </pre>
michael@0 285 */
michael@0 286
michael@0 287 /*DOCXX_TAG*/
michael@0 288 /*@{*/
michael@0 289
michael@0 290 /**
michael@0 291 * UBiDiLevel is the type of the level values in this
michael@0 292 * Bidi implementation.
michael@0 293 * It holds an embedding level and indicates the visual direction
michael@0 294 * by its bit&nbsp;0 (even/odd value).<p>
michael@0 295 *
michael@0 296 * It can also hold non-level values for the
michael@0 297 * <code>paraLevel</code> and <code>embeddingLevels</code>
michael@0 298 * arguments of <code>ubidi_setPara()</code>; there:
michael@0 299 * <ul>
michael@0 300 * <li>bit&nbsp;7 of an <code>embeddingLevels[]</code>
michael@0 301 * value indicates whether the using application is
michael@0 302 * specifying the level of a character to <i>override</i> whatever the
michael@0 303 * Bidi implementation would resolve it to.</li>
michael@0 304 * <li><code>paraLevel</code> can be set to the
michael@0 305 * pseudo-level values <code>UBIDI_DEFAULT_LTR</code>
michael@0 306 * and <code>UBIDI_DEFAULT_RTL</code>.</li>
michael@0 307 * </ul>
michael@0 308 *
michael@0 309 * @see ubidi_setPara
michael@0 310 *
michael@0 311 * <p>The related constants are not real, valid level values.
michael@0 312 * <code>UBIDI_DEFAULT_XXX</code> can be used to specify
michael@0 313 * a default for the paragraph level for
michael@0 314 * when the <code>ubidi_setPara()</code> function
michael@0 315 * shall determine it but there is no
michael@0 316 * strongly typed character in the input.<p>
michael@0 317 *
michael@0 318 * Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even
michael@0 319 * and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,
michael@0 320 * just like with normal LTR and RTL level values -
michael@0 321 * these special values are designed that way. Also, the implementation
michael@0 322 * assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
michael@0 323 *
michael@0 324 * @see UBIDI_DEFAULT_LTR
michael@0 325 * @see UBIDI_DEFAULT_RTL
michael@0 326 * @see UBIDI_LEVEL_OVERRIDE
michael@0 327 * @see UBIDI_MAX_EXPLICIT_LEVEL
michael@0 328 * @stable ICU 2.0
michael@0 329 */
michael@0 330 typedef uint8_t UBiDiLevel;
michael@0 331
michael@0 332 /** Paragraph level setting.<p>
michael@0 333 *
michael@0 334 * Constant indicating that the base direction depends on the first strong
michael@0 335 * directional character in the text according to the Unicode Bidirectional
michael@0 336 * Algorithm. If no strong directional character is present,
michael@0 337 * then set the paragraph level to 0 (left-to-right).<p>
michael@0 338 *
michael@0 339 * If this value is used in conjunction with reordering modes
michael@0 340 * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
michael@0 341 * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
michael@0 342 * is assumed to be visual LTR, and the text after reordering is required
michael@0 343 * to be the corresponding logical string with appropriate contextual
michael@0 344 * direction. The direction of the result string will be RTL if either
michael@0 345 * the righmost or leftmost strong character of the source text is RTL
michael@0 346 * or Arabic Letter, the direction will be LTR otherwise.<p>
michael@0 347 *
michael@0 348 * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
michael@0 349 * be added at the beginning of the result string to ensure round trip
michael@0 350 * (that the result string, when reordered back to visual, will produce
michael@0 351 * the original source text).
michael@0 352 * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
michael@0 353 * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
michael@0 354 * @stable ICU 2.0
michael@0 355 */
michael@0 356 #define UBIDI_DEFAULT_LTR 0xfe
michael@0 357
michael@0 358 /** Paragraph level setting.<p>
michael@0 359 *
michael@0 360 * Constant indicating that the base direction depends on the first strong
michael@0 361 * directional character in the text according to the Unicode Bidirectional
michael@0 362 * Algorithm. If no strong directional character is present,
michael@0 363 * then set the paragraph level to 1 (right-to-left).<p>
michael@0 364 *
michael@0 365 * If this value is used in conjunction with reordering modes
michael@0 366 * <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
michael@0 367 * <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
michael@0 368 * is assumed to be visual LTR, and the text after reordering is required
michael@0 369 * to be the corresponding logical string with appropriate contextual
michael@0 370 * direction. The direction of the result string will be RTL if either
michael@0 371 * the righmost or leftmost strong character of the source text is RTL
michael@0 372 * or Arabic Letter, or if the text contains no strong character;
michael@0 373 * the direction will be LTR otherwise.<p>
michael@0 374 *
michael@0 375 * If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
michael@0 376 * be added at the beginning of the result string to ensure round trip
michael@0 377 * (that the result string, when reordered back to visual, will produce
michael@0 378 * the original source text).
michael@0 379 * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
michael@0 380 * @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
michael@0 381 * @stable ICU 2.0
michael@0 382 */
michael@0 383 #define UBIDI_DEFAULT_RTL 0xff
michael@0 384
michael@0 385 /**
michael@0 386 * Maximum explicit embedding level.
michael@0 387 * (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).
michael@0 388 * @stable ICU 2.0
michael@0 389 */
michael@0 390 #define UBIDI_MAX_EXPLICIT_LEVEL 125
michael@0 391
michael@0 392 /** Bit flag for level input.
michael@0 393 * Overrides directional properties.
michael@0 394 * @stable ICU 2.0
michael@0 395 */
michael@0 396 #define UBIDI_LEVEL_OVERRIDE 0x80
michael@0 397
michael@0 398 /**
michael@0 399 * Special value which can be returned by the mapping functions when a logical
michael@0 400 * index has no corresponding visual index or vice-versa. This may happen
michael@0 401 * for the logical-to-visual mapping of a Bidi control when option
michael@0 402 * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is specified. This can also happen
michael@0 403 * for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted
michael@0 404 * by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
michael@0 405 * @see ubidi_getVisualIndex
michael@0 406 * @see ubidi_getVisualMap
michael@0 407 * @see ubidi_getLogicalIndex
michael@0 408 * @see ubidi_getLogicalMap
michael@0 409 * @stable ICU 3.6
michael@0 410 */
michael@0 411 #define UBIDI_MAP_NOWHERE (-1)
michael@0 412
michael@0 413 /**
michael@0 414 * <code>UBiDiDirection</code> values indicate the text direction.
michael@0 415 * @stable ICU 2.0
michael@0 416 */
michael@0 417 enum UBiDiDirection {
michael@0 418 /** Left-to-right text. This is a 0 value.
michael@0 419 * <ul>
michael@0 420 * <li>As return value for <code>ubidi_getDirection()</code>, it means
michael@0 421 * that the source string contains no right-to-left characters, or
michael@0 422 * that the source string is empty and the paragraph level is even.
michael@0 423 * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
michael@0 424 * means that the first strong character of the source string has
michael@0 425 * a left-to-right direction.
michael@0 426 * </ul>
michael@0 427 * @stable ICU 2.0
michael@0 428 */
michael@0 429 UBIDI_LTR,
michael@0 430 /** Right-to-left text. This is a 1 value.
michael@0 431 * <ul>
michael@0 432 * <li>As return value for <code>ubidi_getDirection()</code>, it means
michael@0 433 * that the source string contains no left-to-right characters, or
michael@0 434 * that the source string is empty and the paragraph level is odd.
michael@0 435 * <li> As return value for <code>ubidi_getBaseDirection()</code>, it
michael@0 436 * means that the first strong character of the source string has
michael@0 437 * a right-to-left direction.
michael@0 438 * </ul>
michael@0 439 * @stable ICU 2.0
michael@0 440 */
michael@0 441 UBIDI_RTL,
michael@0 442 /** Mixed-directional text.
michael@0 443 * <p>As return value for <code>ubidi_getDirection()</code>, it means
michael@0 444 * that the source string contains both left-to-right and
michael@0 445 * right-to-left characters.
michael@0 446 * @stable ICU 2.0
michael@0 447 */
michael@0 448 UBIDI_MIXED,
michael@0 449 /** No strongly directional text.
michael@0 450 * <p>As return value for <code>ubidi_getBaseDirection()</code>, it means
michael@0 451 * that the source string is missing or empty, or contains neither left-to-right
michael@0 452 * nor right-to-left characters.
michael@0 453 * @stable ICU 4.6
michael@0 454 */
michael@0 455 UBIDI_NEUTRAL
michael@0 456 };
michael@0 457
michael@0 458 /** @stable ICU 2.0 */
michael@0 459 typedef enum UBiDiDirection UBiDiDirection;
michael@0 460
michael@0 461 /**
michael@0 462 * Forward declaration of the <code>UBiDi</code> structure for the declaration of
michael@0 463 * the API functions. Its fields are implementation-specific.<p>
michael@0 464 * This structure holds information about a paragraph (or multiple paragraphs)
michael@0 465 * of text with Bidi-algorithm-related details, or about one line of
michael@0 466 * such a paragraph.<p>
michael@0 467 * Reordering can be done on a line, or on one or more paragraphs which are
michael@0 468 * then interpreted each as one single line.
michael@0 469 * @stable ICU 2.0
michael@0 470 */
michael@0 471 struct UBiDi;
michael@0 472
michael@0 473 /** @stable ICU 2.0 */
michael@0 474 typedef struct UBiDi UBiDi;
michael@0 475
michael@0 476 /**
michael@0 477 * Allocate a <code>UBiDi</code> structure.
michael@0 478 * Such an object is initially empty. It is assigned
michael@0 479 * the Bidi properties of a piece of text containing one or more paragraphs
michael@0 480 * by <code>ubidi_setPara()</code>
michael@0 481 * or the Bidi properties of a line within a paragraph by
michael@0 482 * <code>ubidi_setLine()</code>.<p>
michael@0 483 * This object can be reused for as long as it is not deallocated
michael@0 484 * by calling <code>ubidi_close()</code>.<p>
michael@0 485 * <code>ubidi_setPara()</code> and <code>ubidi_setLine()</code> will allocate
michael@0 486 * additional memory for internal structures as necessary.
michael@0 487 *
michael@0 488 * @return An empty <code>UBiDi</code> object.
michael@0 489 * @stable ICU 2.0
michael@0 490 */
michael@0 491 U_STABLE UBiDi * U_EXPORT2
michael@0 492 ubidi_open(void);
michael@0 493
michael@0 494 /**
michael@0 495 * Allocate a <code>UBiDi</code> structure with preallocated memory
michael@0 496 * for internal structures.
michael@0 497 * This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>
michael@0 498 * with no arguments, but it also preallocates memory for internal structures
michael@0 499 * according to the sizings supplied by the caller.<p>
michael@0 500 * Subsequent functions will not allocate any more memory, and are thus
michael@0 501 * guaranteed not to fail because of lack of memory.<p>
michael@0 502 * The preallocation can be limited to some of the internal memory
michael@0 503 * by setting some values to 0 here. That means that if, e.g.,
michael@0 504 * <code>maxRunCount</code> cannot be reasonably predetermined and should not
michael@0 505 * be set to <code>maxLength</code> (the only failproof value) to avoid
michael@0 506 * wasting memory, then <code>maxRunCount</code> could be set to 0 here
michael@0 507 * and the internal structures that are associated with it will be allocated
michael@0 508 * on demand, just like with <code>ubidi_open()</code>.
michael@0 509 *
michael@0 510 * @param maxLength is the maximum text or line length that internal memory
michael@0 511 * will be preallocated for. An attempt to associate this object with a
michael@0 512 * longer text will fail, unless this value is 0, which leaves the allocation
michael@0 513 * up to the implementation.
michael@0 514 *
michael@0 515 * @param maxRunCount is the maximum anticipated number of same-level runs
michael@0 516 * that internal memory will be preallocated for. An attempt to access
michael@0 517 * visual runs on an object that was not preallocated for as many runs
michael@0 518 * as the text was actually resolved to will fail,
michael@0 519 * unless this value is 0, which leaves the allocation up to the implementation.<br><br>
michael@0 520 * The number of runs depends on the actual text and maybe anywhere between
michael@0 521 * 1 and <code>maxLength</code>. It is typically small.
michael@0 522 *
michael@0 523 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 524 *
michael@0 525 * @return An empty <code>UBiDi</code> object with preallocated memory.
michael@0 526 * @stable ICU 2.0
michael@0 527 */
michael@0 528 U_STABLE UBiDi * U_EXPORT2
michael@0 529 ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
michael@0 530
michael@0 531 /**
michael@0 532 * <code>ubidi_close()</code> must be called to free the memory
michael@0 533 * associated with a UBiDi object.<p>
michael@0 534 *
michael@0 535 * <strong>Important: </strong>
michael@0 536 * A parent <code>UBiDi</code> object must not be destroyed or reused if
michael@0 537 * it still has children.
michael@0 538 * If a <code>UBiDi</code> object has become the <i>child</i>
michael@0 539 * of another one (its <i>parent</i>) by calling
michael@0 540 * <code>ubidi_setLine()</code>, then the child object must
michael@0 541 * be destroyed (closed) or reused (by calling
michael@0 542 * <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)
michael@0 543 * before the parent object.
michael@0 544 *
michael@0 545 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 546 *
michael@0 547 * @see ubidi_setPara
michael@0 548 * @see ubidi_setLine
michael@0 549 * @stable ICU 2.0
michael@0 550 */
michael@0 551 U_STABLE void U_EXPORT2
michael@0 552 ubidi_close(UBiDi *pBiDi);
michael@0 553
michael@0 554 #if U_SHOW_CPLUSPLUS_API
michael@0 555
michael@0 556 U_NAMESPACE_BEGIN
michael@0 557
michael@0 558 /**
michael@0 559 * \class LocalUBiDiPointer
michael@0 560 * "Smart pointer" class, closes a UBiDi via ubidi_close().
michael@0 561 * For most methods see the LocalPointerBase base class.
michael@0 562 *
michael@0 563 * @see LocalPointerBase
michael@0 564 * @see LocalPointer
michael@0 565 * @stable ICU 4.4
michael@0 566 */
michael@0 567 U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiPointer, UBiDi, ubidi_close);
michael@0 568
michael@0 569 U_NAMESPACE_END
michael@0 570
michael@0 571 #endif
michael@0 572
michael@0 573 /**
michael@0 574 * Modify the operation of the Bidi algorithm such that it
michael@0 575 * approximates an "inverse Bidi" algorithm. This function
michael@0 576 * must be called before <code>ubidi_setPara()</code>.
michael@0 577 *
michael@0 578 * <p>The normal operation of the Bidi algorithm as described
michael@0 579 * in the Unicode Technical Report is to take text stored in logical
michael@0 580 * (keyboard, typing) order and to determine the reordering of it for visual
michael@0 581 * rendering.
michael@0 582 * Some legacy systems store text in visual order, and for operations
michael@0 583 * with standard, Unicode-based algorithms, the text needs to be transformed
michael@0 584 * to logical order. This is effectively the inverse algorithm of the
michael@0 585 * described Bidi algorithm. Note that there is no standard algorithm for
michael@0 586 * this "inverse Bidi" and that the current implementation provides only an
michael@0 587 * approximation of "inverse Bidi".</p>
michael@0 588 *
michael@0 589 * <p>With <code>isInverse</code> set to <code>TRUE</code>,
michael@0 590 * this function changes the behavior of some of the subsequent functions
michael@0 591 * in a way that they can be used for the inverse Bidi algorithm.
michael@0 592 * Specifically, runs of text with numeric characters will be treated in a
michael@0 593 * special way and may need to be surrounded with LRM characters when they are
michael@0 594 * written in reordered sequence.</p>
michael@0 595 *
michael@0 596 * <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.
michael@0 597 * Since the actual input for "inverse Bidi" is visually ordered text and
michael@0 598 * <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually
michael@0 599 * the runs of the logically ordered output.</p>
michael@0 600 *
michael@0 601 * <p>Calling this function with argument <code>isInverse</code> set to
michael@0 602 * <code>TRUE</code> is equivalent to calling
michael@0 603 * <code>ubidi_setReorderingMode</code> with argument
michael@0 604 * <code>reorderingMode</code>
michael@0 605 * set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
michael@0 606 * Calling this function with argument <code>isInverse</code> set to
michael@0 607 * <code>FALSE</code> is equivalent to calling
michael@0 608 * <code>ubidi_setReorderingMode</code> with argument
michael@0 609 * <code>reorderingMode</code>
michael@0 610 * set to <code>#UBIDI_REORDER_DEFAULT</code>.
michael@0 611 *
michael@0 612 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 613 *
michael@0 614 * @param isInverse specifies "forward" or "inverse" Bidi operation.
michael@0 615 *
michael@0 616 * @see ubidi_setPara
michael@0 617 * @see ubidi_writeReordered
michael@0 618 * @see ubidi_setReorderingMode
michael@0 619 * @stable ICU 2.0
michael@0 620 */
michael@0 621 U_STABLE void U_EXPORT2
michael@0 622 ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
michael@0 623
michael@0 624 /**
michael@0 625 * Is this Bidi object set to perform the inverse Bidi algorithm?
michael@0 626 * <p>Note: calling this function after setting the reordering mode with
michael@0 627 * <code>ubidi_setReorderingMode</code> will return <code>TRUE</code> if the
michael@0 628 * reordering mode was set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>,
michael@0 629 * <code>FALSE</code> for all other values.</p>
michael@0 630 *
michael@0 631 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 632 * @return TRUE if the Bidi object is set to perform the inverse Bidi algorithm
michael@0 633 * by handling numbers as L.
michael@0 634 *
michael@0 635 * @see ubidi_setInverse
michael@0 636 * @see ubidi_setReorderingMode
michael@0 637 * @stable ICU 2.0
michael@0 638 */
michael@0 639
michael@0 640 U_STABLE UBool U_EXPORT2
michael@0 641 ubidi_isInverse(UBiDi *pBiDi);
michael@0 642
michael@0 643 /**
michael@0 644 * Specify whether block separators must be allocated level zero,
michael@0 645 * so that successive paragraphs will progress from left to right.
michael@0 646 * This function must be called before <code>ubidi_setPara()</code>.
michael@0 647 * Paragraph separators (B) may appear in the text. Setting them to level zero
michael@0 648 * means that all paragraph separators (including one possibly appearing
michael@0 649 * in the last text position) are kept in the reordered text after the text
michael@0 650 * that they follow in the source text.
michael@0 651 * When this feature is not enabled, a paragraph separator at the last
michael@0 652 * position of the text before reordering will go to the first position
michael@0 653 * of the reordered text when the paragraph level is odd.
michael@0 654 *
michael@0 655 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 656 *
michael@0 657 * @param orderParagraphsLTR specifies whether paragraph separators (B) must
michael@0 658 * receive level 0, so that successive paragraphs progress from left to right.
michael@0 659 *
michael@0 660 * @see ubidi_setPara
michael@0 661 * @stable ICU 3.4
michael@0 662 */
michael@0 663 U_STABLE void U_EXPORT2
michael@0 664 ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);
michael@0 665
michael@0 666 /**
michael@0 667 * Is this Bidi object set to allocate level 0 to block separators so that
michael@0 668 * successive paragraphs progress from left to right?
michael@0 669 *
michael@0 670 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 671 * @return TRUE if the Bidi object is set to allocate level 0 to block
michael@0 672 * separators.
michael@0 673 *
michael@0 674 * @see ubidi_orderParagraphsLTR
michael@0 675 * @stable ICU 3.4
michael@0 676 */
michael@0 677 U_STABLE UBool U_EXPORT2
michael@0 678 ubidi_isOrderParagraphsLTR(UBiDi *pBiDi);
michael@0 679
michael@0 680 /**
michael@0 681 * <code>UBiDiReorderingMode</code> values indicate which variant of the Bidi
michael@0 682 * algorithm to use.
michael@0 683 *
michael@0 684 * @see ubidi_setReorderingMode
michael@0 685 * @stable ICU 3.6
michael@0 686 */
michael@0 687 typedef enum UBiDiReorderingMode {
michael@0 688 /** Regular Logical to Visual Bidi algorithm according to Unicode.
michael@0 689 * This is a 0 value.
michael@0 690 * @stable ICU 3.6 */
michael@0 691 UBIDI_REORDER_DEFAULT = 0,
michael@0 692 /** Logical to Visual algorithm which handles numbers in a way which
michael@0 693 * mimicks the behavior of Windows XP.
michael@0 694 * @stable ICU 3.6 */
michael@0 695 UBIDI_REORDER_NUMBERS_SPECIAL,
michael@0 696 /** Logical to Visual algorithm grouping numbers with adjacent R characters
michael@0 697 * (reversible algorithm).
michael@0 698 * @stable ICU 3.6 */
michael@0 699 UBIDI_REORDER_GROUP_NUMBERS_WITH_R,
michael@0 700 /** Reorder runs only to transform a Logical LTR string to the Logical RTL
michael@0 701 * string with the same display, or vice-versa.<br>
michael@0 702 * If this mode is set together with option
michael@0 703 * <code>#UBIDI_OPTION_INSERT_MARKS</code>, some Bidi controls in the source
michael@0 704 * text may be removed and other controls may be added to produce the
michael@0 705 * minimum combination which has the required display.
michael@0 706 * @stable ICU 3.6 */
michael@0 707 UBIDI_REORDER_RUNS_ONLY,
michael@0 708 /** Visual to Logical algorithm which handles numbers like L
michael@0 709 * (same algorithm as selected by <code>ubidi_setInverse(TRUE)</code>.
michael@0 710 * @see ubidi_setInverse
michael@0 711 * @stable ICU 3.6 */
michael@0 712 UBIDI_REORDER_INVERSE_NUMBERS_AS_L,
michael@0 713 /** Visual to Logical algorithm equivalent to the regular Logical to Visual
michael@0 714 * algorithm.
michael@0 715 * @stable ICU 3.6 */
michael@0 716 UBIDI_REORDER_INVERSE_LIKE_DIRECT,
michael@0 717 /** Inverse Bidi (Visual to Logical) algorithm for the
michael@0 718 * <code>UBIDI_REORDER_NUMBERS_SPECIAL</code> Bidi algorithm.
michael@0 719 * @stable ICU 3.6 */
michael@0 720 UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,
michael@0 721 /** Number of values for reordering mode.
michael@0 722 * @stable ICU 3.6 */
michael@0 723 UBIDI_REORDER_COUNT
michael@0 724 } UBiDiReorderingMode;
michael@0 725
michael@0 726 /**
michael@0 727 * Modify the operation of the Bidi algorithm such that it implements some
michael@0 728 * variant to the basic Bidi algorithm or approximates an "inverse Bidi"
michael@0 729 * algorithm, depending on different values of the "reordering mode".
michael@0 730 * This function must be called before <code>ubidi_setPara()</code>, and stays
michael@0 731 * in effect until called again with a different argument.
michael@0 732 *
michael@0 733 * <p>The normal operation of the Bidi algorithm as described
michael@0 734 * in the Unicode Standard Annex #9 is to take text stored in logical
michael@0 735 * (keyboard, typing) order and to determine how to reorder it for visual
michael@0 736 * rendering.</p>
michael@0 737 *
michael@0 738 * <p>With the reordering mode set to a value other than
michael@0 739 * <code>#UBIDI_REORDER_DEFAULT</code>, this function changes the behavior of
michael@0 740 * some of the subsequent functions in a way such that they implement an
michael@0 741 * inverse Bidi algorithm or some other algorithm variants.</p>
michael@0 742 *
michael@0 743 * <p>Some legacy systems store text in visual order, and for operations
michael@0 744 * with standard, Unicode-based algorithms, the text needs to be transformed
michael@0 745 * into logical order. This is effectively the inverse algorithm of the
michael@0 746 * described Bidi algorithm. Note that there is no standard algorithm for
michael@0 747 * this "inverse Bidi", so a number of variants are implemented here.</p>
michael@0 748 *
michael@0 749 * <p>In other cases, it may be desirable to emulate some variant of the
michael@0 750 * Logical to Visual algorithm (e.g. one used in MS Windows), or perform a
michael@0 751 * Logical to Logical transformation.</p>
michael@0 752 *
michael@0 753 * <ul>
michael@0 754 * <li>When the reordering mode is set to <code>#UBIDI_REORDER_DEFAULT</code>,
michael@0 755 * the standard Bidi Logical to Visual algorithm is applied.</li>
michael@0 756 *
michael@0 757 * <li>When the reordering mode is set to
michael@0 758 * <code>#UBIDI_REORDER_NUMBERS_SPECIAL</code>,
michael@0 759 * the algorithm used to perform Bidi transformations when calling
michael@0 760 * <code>ubidi_setPara</code> should approximate the algorithm used in
michael@0 761 * Microsoft Windows XP rather than strictly conform to the Unicode Bidi
michael@0 762 * algorithm.
michael@0 763 * <br>
michael@0 764 * The differences between the basic algorithm and the algorithm addressed
michael@0 765 * by this option are as follows:
michael@0 766 * <ul>
michael@0 767 * <li>Within text at an even embedding level, the sequence "123AB"
michael@0 768 * (where AB represent R or AL letters) is transformed to "123BA" by the
michael@0 769 * Unicode algorithm and to "BA123" by the Windows algorithm.</li>
michael@0 770 * <li>Arabic-Indic numbers (AN) are handled by the Windows algorithm just
michael@0 771 * like regular numbers (EN).</li>
michael@0 772 * </ul></li>
michael@0 773 *
michael@0 774 * <li>When the reordering mode is set to
michael@0 775 * <code>#UBIDI_REORDER_GROUP_NUMBERS_WITH_R</code>,
michael@0 776 * numbers located between LTR text and RTL text are associated with the RTL
michael@0 777 * text. For instance, an LTR paragraph with content "abc 123 DEF" (where
michael@0 778 * upper case letters represent RTL characters) will be transformed to
michael@0 779 * "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed
michael@0 780 * to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".
michael@0 781 * This makes the algorithm reversible and makes it useful when round trip
michael@0 782 * (from visual to logical and back to visual) must be achieved without
michael@0 783 * adding LRM characters. However, this is a variation from the standard
michael@0 784 * Unicode Bidi algorithm.<br>
michael@0 785 * The source text should not contain Bidi control characters other than LRM
michael@0 786 * or RLM.</li>
michael@0 787 *
michael@0 788 * <li>When the reordering mode is set to
michael@0 789 * <code>#UBIDI_REORDER_RUNS_ONLY</code>,
michael@0 790 * a "Logical to Logical" transformation must be performed:
michael@0 791 * <ul>
michael@0 792 * <li>If the default text level of the source text (argument <code>paraLevel</code>
michael@0 793 * in <code>ubidi_setPara</code>) is even, the source text will be handled as
michael@0 794 * LTR logical text and will be transformed to the RTL logical text which has
michael@0 795 * the same LTR visual display.</li>
michael@0 796 * <li>If the default level of the source text is odd, the source text
michael@0 797 * will be handled as RTL logical text and will be transformed to the
michael@0 798 * LTR logical text which has the same LTR visual display.</li>
michael@0 799 * </ul>
michael@0 800 * This mode may be needed when logical text which is basically Arabic or
michael@0 801 * Hebrew, with possible included numbers or phrases in English, has to be
michael@0 802 * displayed as if it had an even embedding level (this can happen if the
michael@0 803 * displaying application treats all text as if it was basically LTR).
michael@0 804 * <br>
michael@0 805 * This mode may also be needed in the reverse case, when logical text which is
michael@0 806 * basically English, with possible included phrases in Arabic or Hebrew, has to
michael@0 807 * be displayed as if it had an odd embedding level.
michael@0 808 * <br>
michael@0 809 * Both cases could be handled by adding LRE or RLE at the head of the text,
michael@0 810 * if the display subsystem supports these formatting controls. If it does not,
michael@0 811 * the problem may be handled by transforming the source text in this mode
michael@0 812 * before displaying it, so that it will be displayed properly.<br>
michael@0 813 * The source text should not contain Bidi control characters other than LRM
michael@0 814 * or RLM.</li>
michael@0 815 *
michael@0 816 * <li>When the reordering mode is set to
michael@0 817 * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>, an "inverse Bidi" algorithm
michael@0 818 * is applied.
michael@0 819 * Runs of text with numeric characters will be treated like LTR letters and
michael@0 820 * may need to be surrounded with LRM characters when they are written in
michael@0 821 * reordered sequence (the option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> can
michael@0 822 * be used with function <code>ubidi_writeReordered</code> to this end. This
michael@0 823 * mode is equivalent to calling <code>ubidi_setInverse()</code> with
michael@0 824 * argument <code>isInverse</code> set to <code>TRUE</code>.</li>
michael@0 825 *
michael@0 826 * <li>When the reordering mode is set to
michael@0 827 * <code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code>, the "direct" Logical to Visual
michael@0 828 * Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.
michael@0 829 * This mode is similar to mode <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>
michael@0 830 * but is closer to the regular Bidi algorithm.
michael@0 831 * <br>
michael@0 832 * For example, an LTR paragraph with the content "FED 123 456 CBA" (where
michael@0 833 * upper case represents RTL characters) will be transformed to
michael@0 834 * "ABC 456 123 DEF", as opposed to "DEF 123 456 ABC"
michael@0 835 * with mode <code>UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
michael@0 836 * When used in conjunction with option
michael@0 837 * <code>#UBIDI_OPTION_INSERT_MARKS</code>, this mode generally
michael@0 838 * adds Bidi marks to the output significantly more sparingly than mode
michael@0 839 * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> with option
michael@0 840 * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to
michael@0 841 * <code>ubidi_writeReordered</code>.</li>
michael@0 842 *
michael@0 843 * <li>When the reordering mode is set to
michael@0 844 * <code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the Logical to Visual
michael@0 845 * Bidi algorithm used in Windows XP is used as an approximation of an "inverse Bidi" algorithm.
michael@0 846 * <br>
michael@0 847 * For example, an LTR paragraph with the content "abc FED123" (where
michael@0 848 * upper case represents RTL characters) will be transformed to "abc 123DEF."</li>
michael@0 849 * </ul>
michael@0 850 *
michael@0 851 * <p>In all the reordering modes specifying an "inverse Bidi" algorithm
michael@0 852 * (i.e. those with a name starting with <code>UBIDI_REORDER_INVERSE</code>),
michael@0 853 * output runs should be retrieved using
michael@0 854 * <code>ubidi_getVisualRun()</code>, and the output text with
michael@0 855 * <code>ubidi_writeReordered()</code>. The caller should keep in mind that in
michael@0 856 * "inverse Bidi" modes the input is actually visually ordered text and
michael@0 857 * reordered output returned by <code>ubidi_getVisualRun()</code> or
michael@0 858 * <code>ubidi_writeReordered()</code> are actually runs or character string
michael@0 859 * of logically ordered output.<br>
michael@0 860 * For all the "inverse Bidi" modes, the source text should not contain
michael@0 861 * Bidi control characters other than LRM or RLM.</p>
michael@0 862 *
michael@0 863 * <p>Note that option <code>#UBIDI_OUTPUT_REVERSE</code> of
michael@0 864 * <code>ubidi_writeReordered</code> has no useful meaning and should not be
michael@0 865 * used in conjunction with any value of the reordering mode specifying
michael@0 866 * "inverse Bidi" or with value <code>UBIDI_REORDER_RUNS_ONLY</code>.
michael@0 867 *
michael@0 868 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 869 * @param reorderingMode specifies the required variant of the Bidi algorithm.
michael@0 870 *
michael@0 871 * @see UBiDiReorderingMode
michael@0 872 * @see ubidi_setInverse
michael@0 873 * @see ubidi_setPara
michael@0 874 * @see ubidi_writeReordered
michael@0 875 * @stable ICU 3.6
michael@0 876 */
michael@0 877 U_STABLE void U_EXPORT2
michael@0 878 ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);
michael@0 879
michael@0 880 /**
michael@0 881 * What is the requested reordering mode for a given Bidi object?
michael@0 882 *
michael@0 883 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 884 * @return the current reordering mode of the Bidi object
michael@0 885 * @see ubidi_setReorderingMode
michael@0 886 * @stable ICU 3.6
michael@0 887 */
michael@0 888 U_STABLE UBiDiReorderingMode U_EXPORT2
michael@0 889 ubidi_getReorderingMode(UBiDi *pBiDi);
michael@0 890
michael@0 891 /**
michael@0 892 * <code>UBiDiReorderingOption</code> values indicate which options are
michael@0 893 * specified to affect the Bidi algorithm.
michael@0 894 *
michael@0 895 * @see ubidi_setReorderingOptions
michael@0 896 * @stable ICU 3.6
michael@0 897 */
michael@0 898 typedef enum UBiDiReorderingOption {
michael@0 899 /**
michael@0 900 * option value for <code>ubidi_setReorderingOptions</code>:
michael@0 901 * disable all the options which can be set with this function
michael@0 902 * @see ubidi_setReorderingOptions
michael@0 903 * @stable ICU 3.6
michael@0 904 */
michael@0 905 UBIDI_OPTION_DEFAULT = 0,
michael@0 906
michael@0 907 /**
michael@0 908 * option bit for <code>ubidi_setReorderingOptions</code>:
michael@0 909 * insert Bidi marks (LRM or RLM) when needed to ensure correct result of
michael@0 910 * a reordering to a Logical order
michael@0 911 *
michael@0 912 * <p>This option must be set or reset before calling
michael@0 913 * <code>ubidi_setPara</code>.</p>
michael@0 914 *
michael@0 915 * <p>This option is significant only with reordering modes which generate
michael@0 916 * a result with Logical order, specifically:</p>
michael@0 917 * <ul>
michael@0 918 * <li><code>#UBIDI_REORDER_RUNS_ONLY</code></li>
michael@0 919 * <li><code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code></li>
michael@0 920 * <li><code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code></li>
michael@0 921 * <li><code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code></li>
michael@0 922 * </ul>
michael@0 923 *
michael@0 924 * <p>If this option is set in conjunction with reordering mode
michael@0 925 * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> or with calling
michael@0 926 * <code>ubidi_setInverse(TRUE)</code>, it implies
michael@0 927 * option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>
michael@0 928 * in calls to function <code>ubidi_writeReordered()</code>.</p>
michael@0 929 *
michael@0 930 * <p>For other reordering modes, a minimum number of LRM or RLM characters
michael@0 931 * will be added to the source text after reordering it so as to ensure
michael@0 932 * round trip, i.e. when applying the inverse reordering mode on the
michael@0 933 * resulting logical text with removal of Bidi marks
michael@0 934 * (option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> set before calling
michael@0 935 * <code>ubidi_setPara()</code> or option <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
michael@0 936 * in <code>ubidi_writeReordered</code>), the result will be identical to the
michael@0 937 * source text in the first transformation.
michael@0 938 *
michael@0 939 * <p>This option will be ignored if specified together with option
michael@0 940 * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>. It inhibits option
michael@0 941 * <code>UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to function
michael@0 942 * <code>ubidi_writeReordered()</code> and it implies option
michael@0 943 * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to function
michael@0 944 * <code>ubidi_writeReordered()</code> if the reordering mode is
michael@0 945 * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.</p>
michael@0 946 *
michael@0 947 * @see ubidi_setReorderingMode
michael@0 948 * @see ubidi_setReorderingOptions
michael@0 949 * @stable ICU 3.6
michael@0 950 */
michael@0 951 UBIDI_OPTION_INSERT_MARKS = 1,
michael@0 952
michael@0 953 /**
michael@0 954 * option bit for <code>ubidi_setReorderingOptions</code>:
michael@0 955 * remove Bidi control characters
michael@0 956 *
michael@0 957 * <p>This option must be set or reset before calling
michael@0 958 * <code>ubidi_setPara</code>.</p>
michael@0 959 *
michael@0 960 * <p>This option nullifies option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
michael@0 961 * It inhibits option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls
michael@0 962 * to function <code>ubidi_writeReordered()</code> and it implies option
michael@0 963 * <code>#UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to that function.</p>
michael@0 964 *
michael@0 965 * @see ubidi_setReorderingMode
michael@0 966 * @see ubidi_setReorderingOptions
michael@0 967 * @stable ICU 3.6
michael@0 968 */
michael@0 969 UBIDI_OPTION_REMOVE_CONTROLS = 2,
michael@0 970
michael@0 971 /**
michael@0 972 * option bit for <code>ubidi_setReorderingOptions</code>:
michael@0 973 * process the output as part of a stream to be continued
michael@0 974 *
michael@0 975 * <p>This option must be set or reset before calling
michael@0 976 * <code>ubidi_setPara</code>.</p>
michael@0 977 *
michael@0 978 * <p>This option specifies that the caller is interested in processing large
michael@0 979 * text object in parts.
michael@0 980 * The results of the successive calls are expected to be concatenated by the
michael@0 981 * caller. Only the call for the last part will have this option bit off.</p>
michael@0 982 *
michael@0 983 * <p>When this option bit is on, <code>ubidi_setPara()</code> may process
michael@0 984 * less than the full source text in order to truncate the text at a meaningful
michael@0 985 * boundary. The caller should call <code>ubidi_getProcessedLength()</code>
michael@0 986 * immediately after calling <code>ubidi_setPara()</code> in order to
michael@0 987 * determine how much of the source text has been processed.
michael@0 988 * Source text beyond that length should be resubmitted in following calls to
michael@0 989 * <code>ubidi_setPara</code>. The processed length may be less than
michael@0 990 * the length of the source text if a character preceding the last character of
michael@0 991 * the source text constitutes a reasonable boundary (like a block separator)
michael@0 992 * for text to be continued.<br>
michael@0 993 * If the last character of the source text constitutes a reasonable
michael@0 994 * boundary, the whole text will be processed at once.<br>
michael@0 995 * If nowhere in the source text there exists
michael@0 996 * such a reasonable boundary, the processed length will be zero.<br>
michael@0 997 * The caller should check for such an occurrence and do one of the following:
michael@0 998 * <ul><li>submit a larger amount of text with a better chance to include
michael@0 999 * a reasonable boundary.</li>
michael@0 1000 * <li>resubmit the same text after turning off option
michael@0 1001 * <code>UBIDI_OPTION_STREAMING</code>.</li></ul>
michael@0 1002 * In all cases, this option should be turned off before processing the last
michael@0 1003 * part of the text.</p>
michael@0 1004 *
michael@0 1005 * <p>When the <code>UBIDI_OPTION_STREAMING</code> option is used,
michael@0 1006 * it is recommended to call <code>ubidi_orderParagraphsLTR()</code> with
michael@0 1007 * argument <code>orderParagraphsLTR</code> set to <code>TRUE</code> before
michael@0 1008 * calling <code>ubidi_setPara</code> so that later paragraphs may be
michael@0 1009 * concatenated to previous paragraphs on the right.</p>
michael@0 1010 *
michael@0 1011 * @see ubidi_setReorderingMode
michael@0 1012 * @see ubidi_setReorderingOptions
michael@0 1013 * @see ubidi_getProcessedLength
michael@0 1014 * @see ubidi_orderParagraphsLTR
michael@0 1015 * @stable ICU 3.6
michael@0 1016 */
michael@0 1017 UBIDI_OPTION_STREAMING = 4
michael@0 1018 } UBiDiReorderingOption;
michael@0 1019
michael@0 1020 /**
michael@0 1021 * Specify which of the reordering options
michael@0 1022 * should be applied during Bidi transformations.
michael@0 1023 *
michael@0 1024 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 1025 * @param reorderingOptions is a combination of zero or more of the following
michael@0 1026 * options:
michael@0 1027 * <code>#UBIDI_OPTION_DEFAULT</code>, <code>#UBIDI_OPTION_INSERT_MARKS</code>,
michael@0 1028 * <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>, <code>#UBIDI_OPTION_STREAMING</code>.
michael@0 1029 *
michael@0 1030 * @see ubidi_getReorderingOptions
michael@0 1031 * @stable ICU 3.6
michael@0 1032 */
michael@0 1033 U_STABLE void U_EXPORT2
michael@0 1034 ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);
michael@0 1035
michael@0 1036 /**
michael@0 1037 * What are the reordering options applied to a given Bidi object?
michael@0 1038 *
michael@0 1039 * @param pBiDi is a <code>UBiDi</code> object.
michael@0 1040 * @return the current reordering options of the Bidi object
michael@0 1041 * @see ubidi_setReorderingOptions
michael@0 1042 * @stable ICU 3.6
michael@0 1043 */
michael@0 1044 U_STABLE uint32_t U_EXPORT2
michael@0 1045 ubidi_getReorderingOptions(UBiDi *pBiDi);
michael@0 1046
michael@0 1047 /**
michael@0 1048 * Set the context before a call to ubidi_setPara().<p>
michael@0 1049 *
michael@0 1050 * ubidi_setPara() computes the left-right directionality for a given piece
michael@0 1051 * of text which is supplied as one of its arguments. Sometimes this piece
michael@0 1052 * of text (the "main text") should be considered in context, because text
michael@0 1053 * appearing before ("prologue") and/or after ("epilogue") the main text
michael@0 1054 * may affect the result of this computation.<p>
michael@0 1055 *
michael@0 1056 * This function specifies the prologue and/or the epilogue for the next
michael@0 1057 * call to ubidi_setPara(). The characters specified as prologue and
michael@0 1058 * epilogue should not be modified by the calling program until the call
michael@0 1059 * to ubidi_setPara() has returned. If successive calls to ubidi_setPara()
michael@0 1060 * all need specification of a context, ubidi_setContext() must be called
michael@0 1061 * before each call to ubidi_setPara(). In other words, a context is not
michael@0 1062 * "remembered" after the following successful call to ubidi_setPara().<p>
michael@0 1063 *
michael@0 1064 * If a call to ubidi_setPara() specifies UBIDI_DEFAULT_LTR or
michael@0 1065 * UBIDI_DEFAULT_RTL as paraLevel and is preceded by a call to
michael@0 1066 * ubidi_setContext() which specifies a prologue, the paragraph level will
michael@0 1067 * be computed taking in consideration the text in the prologue.<p>
michael@0 1068 *
michael@0 1069 * When ubidi_setPara() is called without a previous call to
michael@0 1070 * ubidi_setContext, the main text is handled as if preceded and followed
michael@0 1071 * by strong directional characters at the current paragraph level.
michael@0 1072 * Calling ubidi_setContext() with specification of a prologue will change
michael@0 1073 * this behavior by handling the main text as if preceded by the last
michael@0 1074 * strong character appearing in the prologue, if any.
michael@0 1075 * Calling ubidi_setContext() with specification of an epilogue will change
michael@0 1076 * the behavior of ubidi_setPara() by handling the main text as if followed
michael@0 1077 * by the first strong character or digit appearing in the epilogue, if any.<p>
michael@0 1078 *
michael@0 1079 * Note 1: if <code>ubidi_setContext</code> is called repeatedly without
michael@0 1080 * calling <code>ubidi_setPara</code>, the earlier calls have no effect,
michael@0 1081 * only the last call will be remembered for the next call to
michael@0 1082 * <code>ubidi_setPara</code>.<p>
michael@0 1083 *
michael@0 1084 * Note 2: calling <code>ubidi_setContext(pBiDi, NULL, 0, NULL, 0, &errorCode)</code>
michael@0 1085 * cancels any previous setting of non-empty prologue or epilogue.
michael@0 1086 * The next call to <code>ubidi_setPara()</code> will process no
michael@0 1087 * prologue or epilogue.<p>
michael@0 1088 *
michael@0 1089 * Note 3: users must be aware that even after setting the context
michael@0 1090 * before a call to ubidi_setPara() to perform e.g. a logical to visual
michael@0 1091 * transformation, the resulting string may not be identical to what it
michael@0 1092 * would have been if all the text, including prologue and epilogue, had
michael@0 1093 * been processed together.<br>
michael@0 1094 * Example (upper case letters represent RTL characters):<br>
michael@0 1095 * &nbsp;&nbsp;prologue = "<code>abc DE</code>"<br>
michael@0 1096 * &nbsp;&nbsp;epilogue = none<br>
michael@0 1097 * &nbsp;&nbsp;main text = "<code>FGH xyz</code>"<br>
michael@0 1098 * &nbsp;&nbsp;paraLevel = UBIDI_LTR<br>
michael@0 1099 * &nbsp;&nbsp;display without prologue = "<code>HGF xyz</code>"
michael@0 1100 * ("HGF" is adjacent to "xyz")<br>
michael@0 1101 * &nbsp;&nbsp;display with prologue = "<code>abc HGFED xyz</code>"
michael@0 1102 * ("HGF" is not adjacent to "xyz")<br>
michael@0 1103 *
michael@0 1104 * @param pBiDi is a paragraph <code>UBiDi</code> object.
michael@0 1105 *
michael@0 1106 * @param prologue is a pointer to the text which precedes the text that
michael@0 1107 * will be specified in a coming call to ubidi_setPara().
michael@0 1108 * If there is no prologue to consider, then <code>proLength</code>
michael@0 1109 * must be zero and this pointer can be NULL.
michael@0 1110 *
michael@0 1111 * @param proLength is the length of the prologue; if <code>proLength==-1</code>
michael@0 1112 * then the prologue must be zero-terminated.
michael@0 1113 * Otherwise proLength must be >= 0. If <code>proLength==0</code>, it means
michael@0 1114 * that there is no prologue to consider.
michael@0 1115 *
michael@0 1116 * @param epilogue is a pointer to the text which follows the text that
michael@0 1117 * will be specified in a coming call to ubidi_setPara().
michael@0 1118 * If there is no epilogue to consider, then <code>epiLength</code>
michael@0 1119 * must be zero and this pointer can be NULL.
michael@0 1120 *
michael@0 1121 * @param epiLength is the length of the epilogue; if <code>epiLength==-1</code>
michael@0 1122 * then the epilogue must be zero-terminated.
michael@0 1123 * Otherwise epiLength must be >= 0. If <code>epiLength==0</code>, it means
michael@0 1124 * that there is no epilogue to consider.
michael@0 1125 *
michael@0 1126 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1127 *
michael@0 1128 * @see ubidi_setPara
michael@0 1129 * @stable ICU 4.8
michael@0 1130 */
michael@0 1131 U_STABLE void U_EXPORT2
michael@0 1132 ubidi_setContext(UBiDi *pBiDi,
michael@0 1133 const UChar *prologue, int32_t proLength,
michael@0 1134 const UChar *epilogue, int32_t epiLength,
michael@0 1135 UErrorCode *pErrorCode);
michael@0 1136
michael@0 1137 /**
michael@0 1138 * Perform the Unicode Bidi algorithm. It is defined in the
michael@0 1139 * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Anned #9</a>,
michael@0 1140 * version 13,
michael@0 1141 * also described in The Unicode Standard, Version 4.0 .<p>
michael@0 1142 *
michael@0 1143 * This function takes a piece of plain text containing one or more paragraphs,
michael@0 1144 * with or without externally specified embedding levels from <i>styled</i>
michael@0 1145 * text and computes the left-right-directionality of each character.<p>
michael@0 1146 *
michael@0 1147 * If the entire text is all of the same directionality, then
michael@0 1148 * the function may not perform all the steps described by the algorithm,
michael@0 1149 * i.e., some levels may not be the same as if all steps were performed.
michael@0 1150 * This is not relevant for unidirectional text.<br>
michael@0 1151 * For example, in pure LTR text with numbers the numbers would get
michael@0 1152 * a resolved level of 2 higher than the surrounding text according to
michael@0 1153 * the algorithm. This implementation may set all resolved levels to
michael@0 1154 * the same value in such a case.<p>
michael@0 1155 *
michael@0 1156 * The text can be composed of multiple paragraphs. Occurrence of a block
michael@0 1157 * separator in the text terminates a paragraph, and whatever comes next starts
michael@0 1158 * a new paragraph. The exception to this rule is when a Carriage Return (CR)
michael@0 1159 * is followed by a Line Feed (LF). Both CR and LF are block separators, but
michael@0 1160 * in that case, the pair of characters is considered as terminating the
michael@0 1161 * preceding paragraph, and a new paragraph will be started by a character
michael@0 1162 * coming after the LF.
michael@0 1163 *
michael@0 1164 * @param pBiDi A <code>UBiDi</code> object allocated with <code>ubidi_open()</code>
michael@0 1165 * which will be set to contain the reordering information,
michael@0 1166 * especially the resolved levels for all the characters in <code>text</code>.
michael@0 1167 *
michael@0 1168 * @param text is a pointer to the text that the Bidi algorithm will be performed on.
michael@0 1169 * This pointer is stored in the UBiDi object and can be retrieved
michael@0 1170 * with <code>ubidi_getText()</code>.<br>
michael@0 1171 * <strong>Note:</strong> the text must be (at least) <code>length</code> long.
michael@0 1172 *
michael@0 1173 * @param length is the length of the text; if <code>length==-1</code> then
michael@0 1174 * the text must be zero-terminated.
michael@0 1175 *
michael@0 1176 * @param paraLevel specifies the default level for the text;
michael@0 1177 * it is typically 0 (LTR) or 1 (RTL).
michael@0 1178 * If the function shall determine the paragraph level from the text,
michael@0 1179 * then <code>paraLevel</code> can be set to
michael@0 1180 * either <code>#UBIDI_DEFAULT_LTR</code>
michael@0 1181 * or <code>#UBIDI_DEFAULT_RTL</code>; if the text contains multiple
michael@0 1182 * paragraphs, the paragraph level shall be determined separately for
michael@0 1183 * each paragraph; if a paragraph does not include any strongly typed
michael@0 1184 * character, then the desired default is used (0 for LTR or 1 for RTL).
michael@0 1185 * Any other value between 0 and <code>#UBIDI_MAX_EXPLICIT_LEVEL</code>
michael@0 1186 * is also valid, with odd levels indicating RTL.
michael@0 1187 *
michael@0 1188 * @param embeddingLevels (in) may be used to preset the embedding and override levels,
michael@0 1189 * ignoring characters like LRE and PDF in the text.
michael@0 1190 * A level overrides the directional property of its corresponding
michael@0 1191 * (same index) character if the level has the
michael@0 1192 * <code>#UBIDI_LEVEL_OVERRIDE</code> bit set.<br><br>
michael@0 1193 * Except for that bit, it must be
michael@0 1194 * <code>paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL</code>,
michael@0 1195 * with one exception: a level of zero may be specified for a paragraph
michael@0 1196 * separator even if <code>paraLevel>0</code> when multiple paragraphs
michael@0 1197 * are submitted in the same call to <code>ubidi_setPara()</code>.<br><br>
michael@0 1198 * <strong>Caution: </strong>A copy of this pointer, not of the levels,
michael@0 1199 * will be stored in the <code>UBiDi</code> object;
michael@0 1200 * the <code>embeddingLevels</code> array must not be
michael@0 1201 * deallocated before the <code>UBiDi</code> structure is destroyed or reused,
michael@0 1202 * and the <code>embeddingLevels</code>
michael@0 1203 * should not be modified to avoid unexpected results on subsequent Bidi operations.
michael@0 1204 * However, the <code>ubidi_setPara()</code> and
michael@0 1205 * <code>ubidi_setLine()</code> functions may modify some or all of the levels.<br><br>
michael@0 1206 * After the <code>UBiDi</code> object is reused or destroyed, the caller
michael@0 1207 * must take care of the deallocation of the <code>embeddingLevels</code> array.<br><br>
michael@0 1208 * <strong>Note:</strong> the <code>embeddingLevels</code> array must be
michael@0 1209 * at least <code>length</code> long.
michael@0 1210 * This pointer can be <code>NULL</code> if this
michael@0 1211 * value is not necessary.
michael@0 1212 *
michael@0 1213 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1214 * @stable ICU 2.0
michael@0 1215 */
michael@0 1216 U_STABLE void U_EXPORT2
michael@0 1217 ubidi_setPara(UBiDi *pBiDi, const UChar *text, int32_t length,
michael@0 1218 UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
michael@0 1219 UErrorCode *pErrorCode);
michael@0 1220
michael@0 1221 /**
michael@0 1222 * <code>ubidi_setLine()</code> sets a <code>UBiDi</code> to
michael@0 1223 * contain the reordering information, especially the resolved levels,
michael@0 1224 * for all the characters in a line of text. This line of text is
michael@0 1225 * specified by referring to a <code>UBiDi</code> object representing
michael@0 1226 * this information for a piece of text containing one or more paragraphs,
michael@0 1227 * and by specifying a range of indexes in this text.<p>
michael@0 1228 * In the new line object, the indexes will range from 0 to <code>limit-start-1</code>.<p>
michael@0 1229 *
michael@0 1230 * This is used after calling <code>ubidi_setPara()</code>
michael@0 1231 * for a piece of text, and after line-breaking on that text.
michael@0 1232 * It is not necessary if each paragraph is treated as a single line.<p>
michael@0 1233 *
michael@0 1234 * After line-breaking, rules (L1) and (L2) for the treatment of
michael@0 1235 * trailing WS and for reordering are performed on
michael@0 1236 * a <code>UBiDi</code> object that represents a line.<p>
michael@0 1237 *
michael@0 1238 * <strong>Important: </strong><code>pLineBiDi</code> shares data with
michael@0 1239 * <code>pParaBiDi</code>.
michael@0 1240 * You must destroy or reuse <code>pLineBiDi</code> before <code>pParaBiDi</code>.
michael@0 1241 * In other words, you must destroy or reuse the <code>UBiDi</code> object for a line
michael@0 1242 * before the object for its parent paragraph.<p>
michael@0 1243 *
michael@0 1244 * The text pointer that was stored in <code>pParaBiDi</code> is also copied,
michael@0 1245 * and <code>start</code> is added to it so that it points to the beginning of the
michael@0 1246 * line for this object.
michael@0 1247 *
michael@0 1248 * @param pParaBiDi is the parent paragraph object. It must have been set
michael@0 1249 * by a successful call to ubidi_setPara.
michael@0 1250 *
michael@0 1251 * @param start is the line's first index into the text.
michael@0 1252 *
michael@0 1253 * @param limit is just behind the line's last index into the text
michael@0 1254 * (its last index +1).<br>
michael@0 1255 * It must be <code>0<=start<limit<=</code>containing paragraph limit.
michael@0 1256 * If the specified line crosses a paragraph boundary, the function
michael@0 1257 * will terminate with error code U_ILLEGAL_ARGUMENT_ERROR.
michael@0 1258 *
michael@0 1259 * @param pLineBiDi is the object that will now represent a line of the text.
michael@0 1260 *
michael@0 1261 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1262 *
michael@0 1263 * @see ubidi_setPara
michael@0 1264 * @see ubidi_getProcessedLength
michael@0 1265 * @stable ICU 2.0
michael@0 1266 */
michael@0 1267 U_STABLE void U_EXPORT2
michael@0 1268 ubidi_setLine(const UBiDi *pParaBiDi,
michael@0 1269 int32_t start, int32_t limit,
michael@0 1270 UBiDi *pLineBiDi,
michael@0 1271 UErrorCode *pErrorCode);
michael@0 1272
michael@0 1273 /**
michael@0 1274 * Get the directionality of the text.
michael@0 1275 *
michael@0 1276 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1277 *
michael@0 1278 * @return a value of <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>
michael@0 1279 * or <code>UBIDI_MIXED</code>
michael@0 1280 * that indicates if the entire text
michael@0 1281 * represented by this object is unidirectional,
michael@0 1282 * and which direction, or if it is mixed-directional.
michael@0 1283 * Note - The value <code>UBIDI_NEUTRAL</code> is never returned from this method.
michael@0 1284 *
michael@0 1285 * @see UBiDiDirection
michael@0 1286 * @stable ICU 2.0
michael@0 1287 */
michael@0 1288 U_STABLE UBiDiDirection U_EXPORT2
michael@0 1289 ubidi_getDirection(const UBiDi *pBiDi);
michael@0 1290
michael@0 1291 /**
michael@0 1292 * Gets the base direction of the text provided according
michael@0 1293 * to the Unicode Bidirectional Algorithm. The base direction
michael@0 1294 * is derived from the first character in the string with bidirectional
michael@0 1295 * character type L, R, or AL. If the first such character has type L,
michael@0 1296 * <code>UBIDI_LTR</code> is returned. If the first such character has
michael@0 1297 * type R or AL, <code>UBIDI_RTL</code> is returned. If the string does
michael@0 1298 * not contain any character of these types, then
michael@0 1299 * <code>UBIDI_NEUTRAL</code> is returned.
michael@0 1300 *
michael@0 1301 * This is a lightweight function for use when only the base direction
michael@0 1302 * is needed and no further bidi processing of the text is needed.
michael@0 1303 *
michael@0 1304 * @param text is a pointer to the text whose base
michael@0 1305 * direction is needed.
michael@0 1306 * Note: the text must be (at least) @c length long.
michael@0 1307 *
michael@0 1308 * @param length is the length of the text;
michael@0 1309 * if <code>length==-1</code> then the text
michael@0 1310 * must be zero-terminated.
michael@0 1311 *
michael@0 1312 * @return <code>UBIDI_LTR</code>, <code>UBIDI_RTL</code>,
michael@0 1313 * <code>UBIDI_NEUTRAL</code>
michael@0 1314 *
michael@0 1315 * @see UBiDiDirection
michael@0 1316 * @stable ICU 4.6
michael@0 1317 */
michael@0 1318 U_STABLE UBiDiDirection U_EXPORT2
michael@0 1319 ubidi_getBaseDirection(const UChar *text, int32_t length );
michael@0 1320
michael@0 1321 /**
michael@0 1322 * Get the pointer to the text.
michael@0 1323 *
michael@0 1324 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1325 *
michael@0 1326 * @return The pointer to the text that the UBiDi object was created for.
michael@0 1327 *
michael@0 1328 * @see ubidi_setPara
michael@0 1329 * @see ubidi_setLine
michael@0 1330 * @stable ICU 2.0
michael@0 1331 */
michael@0 1332 U_STABLE const UChar * U_EXPORT2
michael@0 1333 ubidi_getText(const UBiDi *pBiDi);
michael@0 1334
michael@0 1335 /**
michael@0 1336 * Get the length of the text.
michael@0 1337 *
michael@0 1338 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1339 *
michael@0 1340 * @return The length of the text that the UBiDi object was created for.
michael@0 1341 * @stable ICU 2.0
michael@0 1342 */
michael@0 1343 U_STABLE int32_t U_EXPORT2
michael@0 1344 ubidi_getLength(const UBiDi *pBiDi);
michael@0 1345
michael@0 1346 /**
michael@0 1347 * Get the paragraph level of the text.
michael@0 1348 *
michael@0 1349 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1350 *
michael@0 1351 * @return The paragraph level. If there are multiple paragraphs, their
michael@0 1352 * level may vary if the required paraLevel is UBIDI_DEFAULT_LTR or
michael@0 1353 * UBIDI_DEFAULT_RTL. In that case, the level of the first paragraph
michael@0 1354 * is returned.
michael@0 1355 *
michael@0 1356 * @see UBiDiLevel
michael@0 1357 * @see ubidi_getParagraph
michael@0 1358 * @see ubidi_getParagraphByIndex
michael@0 1359 * @stable ICU 2.0
michael@0 1360 */
michael@0 1361 U_STABLE UBiDiLevel U_EXPORT2
michael@0 1362 ubidi_getParaLevel(const UBiDi *pBiDi);
michael@0 1363
michael@0 1364 /**
michael@0 1365 * Get the number of paragraphs.
michael@0 1366 *
michael@0 1367 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1368 *
michael@0 1369 * @return The number of paragraphs.
michael@0 1370 * @stable ICU 3.4
michael@0 1371 */
michael@0 1372 U_STABLE int32_t U_EXPORT2
michael@0 1373 ubidi_countParagraphs(UBiDi *pBiDi);
michael@0 1374
michael@0 1375 /**
michael@0 1376 * Get a paragraph, given a position within the text.
michael@0 1377 * This function returns information about a paragraph.<br>
michael@0 1378 * Note: if the paragraph index is known, it is more efficient to
michael@0 1379 * retrieve the paragraph information using ubidi_getParagraphByIndex().<p>
michael@0 1380 *
michael@0 1381 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1382 *
michael@0 1383 * @param charIndex is the index of a character within the text, in the
michael@0 1384 * range <code>[0..ubidi_getProcessedLength(pBiDi)-1]</code>.
michael@0 1385 *
michael@0 1386 * @param pParaStart will receive the index of the first character of the
michael@0 1387 * paragraph in the text.
michael@0 1388 * This pointer can be <code>NULL</code> if this
michael@0 1389 * value is not necessary.
michael@0 1390 *
michael@0 1391 * @param pParaLimit will receive the limit of the paragraph.
michael@0 1392 * The l-value that you point to here may be the
michael@0 1393 * same expression (variable) as the one for
michael@0 1394 * <code>charIndex</code>.
michael@0 1395 * This pointer can be <code>NULL</code> if this
michael@0 1396 * value is not necessary.
michael@0 1397 *
michael@0 1398 * @param pParaLevel will receive the level of the paragraph.
michael@0 1399 * This pointer can be <code>NULL</code> if this
michael@0 1400 * value is not necessary.
michael@0 1401 *
michael@0 1402 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1403 *
michael@0 1404 * @return The index of the paragraph containing the specified position.
michael@0 1405 *
michael@0 1406 * @see ubidi_getProcessedLength
michael@0 1407 * @stable ICU 3.4
michael@0 1408 */
michael@0 1409 U_STABLE int32_t U_EXPORT2
michael@0 1410 ubidi_getParagraph(const UBiDi *pBiDi, int32_t charIndex, int32_t *pParaStart,
michael@0 1411 int32_t *pParaLimit, UBiDiLevel *pParaLevel,
michael@0 1412 UErrorCode *pErrorCode);
michael@0 1413
michael@0 1414 /**
michael@0 1415 * Get a paragraph, given the index of this paragraph.
michael@0 1416 *
michael@0 1417 * This function returns information about a paragraph.<p>
michael@0 1418 *
michael@0 1419 * @param pBiDi is the paragraph <code>UBiDi</code> object.
michael@0 1420 *
michael@0 1421 * @param paraIndex is the number of the paragraph, in the
michael@0 1422 * range <code>[0..ubidi_countParagraphs(pBiDi)-1]</code>.
michael@0 1423 *
michael@0 1424 * @param pParaStart will receive the index of the first character of the
michael@0 1425 * paragraph in the text.
michael@0 1426 * This pointer can be <code>NULL</code> if this
michael@0 1427 * value is not necessary.
michael@0 1428 *
michael@0 1429 * @param pParaLimit will receive the limit of the paragraph.
michael@0 1430 * This pointer can be <code>NULL</code> if this
michael@0 1431 * value is not necessary.
michael@0 1432 *
michael@0 1433 * @param pParaLevel will receive the level of the paragraph.
michael@0 1434 * This pointer can be <code>NULL</code> if this
michael@0 1435 * value is not necessary.
michael@0 1436 *
michael@0 1437 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1438 *
michael@0 1439 * @stable ICU 3.4
michael@0 1440 */
michael@0 1441 U_STABLE void U_EXPORT2
michael@0 1442 ubidi_getParagraphByIndex(const UBiDi *pBiDi, int32_t paraIndex,
michael@0 1443 int32_t *pParaStart, int32_t *pParaLimit,
michael@0 1444 UBiDiLevel *pParaLevel, UErrorCode *pErrorCode);
michael@0 1445
michael@0 1446 /**
michael@0 1447 * Get the level for one character.
michael@0 1448 *
michael@0 1449 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1450 *
michael@0 1451 * @param charIndex the index of a character. It must be in the range
michael@0 1452 * [0..ubidi_getProcessedLength(pBiDi)].
michael@0 1453 *
michael@0 1454 * @return The level for the character at charIndex (0 if charIndex is not
michael@0 1455 * in the valid range).
michael@0 1456 *
michael@0 1457 * @see UBiDiLevel
michael@0 1458 * @see ubidi_getProcessedLength
michael@0 1459 * @stable ICU 2.0
michael@0 1460 */
michael@0 1461 U_STABLE UBiDiLevel U_EXPORT2
michael@0 1462 ubidi_getLevelAt(const UBiDi *pBiDi, int32_t charIndex);
michael@0 1463
michael@0 1464 /**
michael@0 1465 * Get an array of levels for each character.<p>
michael@0 1466 *
michael@0 1467 * Note that this function may allocate memory under some
michael@0 1468 * circumstances, unlike <code>ubidi_getLevelAt()</code>.
michael@0 1469 *
michael@0 1470 * @param pBiDi is the paragraph or line <code>UBiDi</code> object, whose
michael@0 1471 * text length must be strictly positive.
michael@0 1472 *
michael@0 1473 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1474 *
michael@0 1475 * @return The levels array for the text,
michael@0 1476 * or <code>NULL</code> if an error occurs.
michael@0 1477 *
michael@0 1478 * @see UBiDiLevel
michael@0 1479 * @see ubidi_getProcessedLength
michael@0 1480 * @stable ICU 2.0
michael@0 1481 */
michael@0 1482 U_STABLE const UBiDiLevel * U_EXPORT2
michael@0 1483 ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);
michael@0 1484
michael@0 1485 /**
michael@0 1486 * Get a logical run.
michael@0 1487 * This function returns information about a run and is used
michael@0 1488 * to retrieve runs in logical order.<p>
michael@0 1489 * This is especially useful for line-breaking on a paragraph.
michael@0 1490 *
michael@0 1491 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1492 *
michael@0 1493 * @param logicalPosition is a logical position within the source text.
michael@0 1494 *
michael@0 1495 * @param pLogicalLimit will receive the limit of the corresponding run.
michael@0 1496 * The l-value that you point to here may be the
michael@0 1497 * same expression (variable) as the one for
michael@0 1498 * <code>logicalPosition</code>.
michael@0 1499 * This pointer can be <code>NULL</code> if this
michael@0 1500 * value is not necessary.
michael@0 1501 *
michael@0 1502 * @param pLevel will receive the level of the corresponding run.
michael@0 1503 * This pointer can be <code>NULL</code> if this
michael@0 1504 * value is not necessary.
michael@0 1505 *
michael@0 1506 * @see ubidi_getProcessedLength
michael@0 1507 * @stable ICU 2.0
michael@0 1508 */
michael@0 1509 U_STABLE void U_EXPORT2
michael@0 1510 ubidi_getLogicalRun(const UBiDi *pBiDi, int32_t logicalPosition,
michael@0 1511 int32_t *pLogicalLimit, UBiDiLevel *pLevel);
michael@0 1512
michael@0 1513 /**
michael@0 1514 * Get the number of runs.
michael@0 1515 * This function may invoke the actual reordering on the
michael@0 1516 * <code>UBiDi</code> object, after <code>ubidi_setPara()</code>
michael@0 1517 * may have resolved only the levels of the text. Therefore,
michael@0 1518 * <code>ubidi_countRuns()</code> may have to allocate memory,
michael@0 1519 * and may fail doing so.
michael@0 1520 *
michael@0 1521 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1522 *
michael@0 1523 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1524 *
michael@0 1525 * @return The number of runs.
michael@0 1526 * @stable ICU 2.0
michael@0 1527 */
michael@0 1528 U_STABLE int32_t U_EXPORT2
michael@0 1529 ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
michael@0 1530
michael@0 1531 /**
michael@0 1532 * Get one run's logical start, length, and directionality,
michael@0 1533 * which can be 0 for LTR or 1 for RTL.
michael@0 1534 * In an RTL run, the character at the logical start is
michael@0 1535 * visually on the right of the displayed run.
michael@0 1536 * The length is the number of characters in the run.<p>
michael@0 1537 * <code>ubidi_countRuns()</code> should be called
michael@0 1538 * before the runs are retrieved.
michael@0 1539 *
michael@0 1540 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1541 *
michael@0 1542 * @param runIndex is the number of the run in visual order, in the
michael@0 1543 * range <code>[0..ubidi_countRuns(pBiDi)-1]</code>.
michael@0 1544 *
michael@0 1545 * @param pLogicalStart is the first logical character index in the text.
michael@0 1546 * The pointer may be <code>NULL</code> if this index is not needed.
michael@0 1547 *
michael@0 1548 * @param pLength is the number of characters (at least one) in the run.
michael@0 1549 * The pointer may be <code>NULL</code> if this is not needed.
michael@0 1550 *
michael@0 1551 * @return the directionality of the run,
michael@0 1552 * <code>UBIDI_LTR==0</code> or <code>UBIDI_RTL==1</code>,
michael@0 1553 * never <code>UBIDI_MIXED</code>,
michael@0 1554 * never <code>UBIDI_NEUTRAL</code>.
michael@0 1555 *
michael@0 1556 * @see ubidi_countRuns
michael@0 1557 *
michael@0 1558 * Example:
michael@0 1559 * <pre>
michael@0 1560 * \code
michael@0 1561 * int32_t i, count=ubidi_countRuns(pBiDi),
michael@0 1562 * logicalStart, visualIndex=0, length;
michael@0 1563 * for(i=0; i<count; ++i) {
michael@0 1564 * if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {
michael@0 1565 * do { // LTR
michael@0 1566 * show_char(text[logicalStart++], visualIndex++);
michael@0 1567 * } while(--length>0);
michael@0 1568 * } else {
michael@0 1569 * logicalStart+=length; // logicalLimit
michael@0 1570 * do { // RTL
michael@0 1571 * show_char(text[--logicalStart], visualIndex++);
michael@0 1572 * } while(--length>0);
michael@0 1573 * }
michael@0 1574 * }
michael@0 1575 *\endcode
michael@0 1576 * </pre>
michael@0 1577 *
michael@0 1578 * Note that in right-to-left runs, code like this places
michael@0 1579 * second surrogates before first ones (which is generally a bad idea)
michael@0 1580 * and combining characters before base characters.
michael@0 1581 * <p>
michael@0 1582 * Use of <code>ubidi_writeReordered()</code>, optionally with the
michael@0 1583 * <code>#UBIDI_KEEP_BASE_COMBINING</code> option, can be considered in order
michael@0 1584 * to avoid these issues.
michael@0 1585 * @stable ICU 2.0
michael@0 1586 */
michael@0 1587 U_STABLE UBiDiDirection U_EXPORT2
michael@0 1588 ubidi_getVisualRun(UBiDi *pBiDi, int32_t runIndex,
michael@0 1589 int32_t *pLogicalStart, int32_t *pLength);
michael@0 1590
michael@0 1591 /**
michael@0 1592 * Get the visual position from a logical text position.
michael@0 1593 * If such a mapping is used many times on the same
michael@0 1594 * <code>UBiDi</code> object, then calling
michael@0 1595 * <code>ubidi_getLogicalMap()</code> is more efficient.<p>
michael@0 1596 *
michael@0 1597 * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
michael@0 1598 * visual position because the corresponding text character is a Bidi control
michael@0 1599 * removed from output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
michael@0 1600 * <p>
michael@0 1601 * When the visual output is altered by using options of
michael@0 1602 * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
michael@0 1603 * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
michael@0 1604 * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual position returned may not
michael@0 1605 * be correct. It is advised to use, when possible, reordering options
michael@0 1606 * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
michael@0 1607 * <p>
michael@0 1608 * Note that in right-to-left runs, this mapping places
michael@0 1609 * second surrogates before first ones (which is generally a bad idea)
michael@0 1610 * and combining characters before base characters.
michael@0 1611 * Use of <code>ubidi_writeReordered()</code>, optionally with the
michael@0 1612 * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
michael@0 1613 * of using the mapping, in order to avoid these issues.
michael@0 1614 *
michael@0 1615 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1616 *
michael@0 1617 * @param logicalIndex is the index of a character in the text.
michael@0 1618 *
michael@0 1619 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1620 *
michael@0 1621 * @return The visual position of this character.
michael@0 1622 *
michael@0 1623 * @see ubidi_getLogicalMap
michael@0 1624 * @see ubidi_getLogicalIndex
michael@0 1625 * @see ubidi_getProcessedLength
michael@0 1626 * @stable ICU 2.0
michael@0 1627 */
michael@0 1628 U_STABLE int32_t U_EXPORT2
michael@0 1629 ubidi_getVisualIndex(UBiDi *pBiDi, int32_t logicalIndex, UErrorCode *pErrorCode);
michael@0 1630
michael@0 1631 /**
michael@0 1632 * Get the logical text position from a visual position.
michael@0 1633 * If such a mapping is used many times on the same
michael@0 1634 * <code>UBiDi</code> object, then calling
michael@0 1635 * <code>ubidi_getVisualMap()</code> is more efficient.<p>
michael@0 1636 *
michael@0 1637 * The value returned may be <code>#UBIDI_MAP_NOWHERE</code> if there is no
michael@0 1638 * logical position because the corresponding text character is a Bidi mark
michael@0 1639 * inserted in the output by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
michael@0 1640 * <p>
michael@0 1641 * This is the inverse function to <code>ubidi_getVisualIndex()</code>.
michael@0 1642 * <p>
michael@0 1643 * When the visual output is altered by using options of
michael@0 1644 * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
michael@0 1645 * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
michael@0 1646 * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical position returned may not
michael@0 1647 * be correct. It is advised to use, when possible, reordering options
michael@0 1648 * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
michael@0 1649 *
michael@0 1650 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1651 *
michael@0 1652 * @param visualIndex is the visual position of a character.
michael@0 1653 *
michael@0 1654 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1655 *
michael@0 1656 * @return The index of this character in the text.
michael@0 1657 *
michael@0 1658 * @see ubidi_getVisualMap
michael@0 1659 * @see ubidi_getVisualIndex
michael@0 1660 * @see ubidi_getResultLength
michael@0 1661 * @stable ICU 2.0
michael@0 1662 */
michael@0 1663 U_STABLE int32_t U_EXPORT2
michael@0 1664 ubidi_getLogicalIndex(UBiDi *pBiDi, int32_t visualIndex, UErrorCode *pErrorCode);
michael@0 1665
michael@0 1666 /**
michael@0 1667 * Get a logical-to-visual index map (array) for the characters in the UBiDi
michael@0 1668 * (paragraph or line) object.
michael@0 1669 * <p>
michael@0 1670 * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
michael@0 1671 * corresponding text characters are Bidi controls removed from the visual
michael@0 1672 * output by the option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>.
michael@0 1673 * <p>
michael@0 1674 * When the visual output is altered by using options of
michael@0 1675 * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
michael@0 1676 * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
michael@0 1677 * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the visual positions returned may not
michael@0 1678 * be correct. It is advised to use, when possible, reordering options
michael@0 1679 * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
michael@0 1680 * <p>
michael@0 1681 * Note that in right-to-left runs, this mapping places
michael@0 1682 * second surrogates before first ones (which is generally a bad idea)
michael@0 1683 * and combining characters before base characters.
michael@0 1684 * Use of <code>ubidi_writeReordered()</code>, optionally with the
michael@0 1685 * <code>#UBIDI_KEEP_BASE_COMBINING</code> option can be considered instead
michael@0 1686 * of using the mapping, in order to avoid these issues.
michael@0 1687 *
michael@0 1688 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1689 *
michael@0 1690 * @param indexMap is a pointer to an array of <code>ubidi_getProcessedLength()</code>
michael@0 1691 * indexes which will reflect the reordering of the characters.
michael@0 1692 * If option <code>#UBIDI_OPTION_INSERT_MARKS</code> is set, the number
michael@0 1693 * of elements allocated in <code>indexMap</code> must be no less than
michael@0 1694 * <code>ubidi_getResultLength()</code>.
michael@0 1695 * The array does not need to be initialized.<br><br>
michael@0 1696 * The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
michael@0 1697 *
michael@0 1698 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1699 *
michael@0 1700 * @see ubidi_getVisualMap
michael@0 1701 * @see ubidi_getVisualIndex
michael@0 1702 * @see ubidi_getProcessedLength
michael@0 1703 * @see ubidi_getResultLength
michael@0 1704 * @stable ICU 2.0
michael@0 1705 */
michael@0 1706 U_STABLE void U_EXPORT2
michael@0 1707 ubidi_getLogicalMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
michael@0 1708
michael@0 1709 /**
michael@0 1710 * Get a visual-to-logical index map (array) for the characters in the UBiDi
michael@0 1711 * (paragraph or line) object.
michael@0 1712 * <p>
michael@0 1713 * Some values in the map may be <code>#UBIDI_MAP_NOWHERE</code> if the
michael@0 1714 * corresponding text characters are Bidi marks inserted in the visual output
michael@0 1715 * by the option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
michael@0 1716 * <p>
michael@0 1717 * When the visual output is altered by using options of
michael@0 1718 * <code>ubidi_writeReordered()</code> such as <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
michael@0 1719 * <code>UBIDI_KEEP_BASE_COMBINING</code>, <code>UBIDI_OUTPUT_REVERSE</code>,
michael@0 1720 * <code>UBIDI_REMOVE_BIDI_CONTROLS</code>, the logical positions returned may not
michael@0 1721 * be correct. It is advised to use, when possible, reordering options
michael@0 1722 * such as <code>UBIDI_OPTION_INSERT_MARKS</code> and <code>UBIDI_OPTION_REMOVE_CONTROLS</code>.
michael@0 1723 *
michael@0 1724 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
michael@0 1725 *
michael@0 1726 * @param indexMap is a pointer to an array of <code>ubidi_getResultLength()</code>
michael@0 1727 * indexes which will reflect the reordering of the characters.
michael@0 1728 * If option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is set, the number
michael@0 1729 * of elements allocated in <code>indexMap</code> must be no less than
michael@0 1730 * <code>ubidi_getProcessedLength()</code>.
michael@0 1731 * The array does not need to be initialized.<br><br>
michael@0 1732 * The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
michael@0 1733 *
michael@0 1734 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 1735 *
michael@0 1736 * @see ubidi_getLogicalMap
michael@0 1737 * @see ubidi_getLogicalIndex
michael@0 1738 * @see ubidi_getProcessedLength
michael@0 1739 * @see ubidi_getResultLength
michael@0 1740 * @stable ICU 2.0
michael@0 1741 */
michael@0 1742 U_STABLE void U_EXPORT2
michael@0 1743 ubidi_getVisualMap(UBiDi *pBiDi, int32_t *indexMap, UErrorCode *pErrorCode);
michael@0 1744
michael@0 1745 /**
michael@0 1746 * This is a convenience function that does not use a UBiDi object.
michael@0 1747 * It is intended to be used for when an application has determined the levels
michael@0 1748 * of objects (character sequences) and just needs to have them reordered (L2).
michael@0 1749 * This is equivalent to using <code>ubidi_getLogicalMap()</code> on a
michael@0 1750 * <code>UBiDi</code> object.
michael@0 1751 *
michael@0 1752 * @param levels is an array with <code>length</code> levels that have been determined by
michael@0 1753 * the application.
michael@0 1754 *
michael@0 1755 * @param length is the number of levels in the array, or, semantically,
michael@0 1756 * the number of objects to be reordered.
michael@0 1757 * It must be <code>length>0</code>.
michael@0 1758 *
michael@0 1759 * @param indexMap is a pointer to an array of <code>length</code>
michael@0 1760 * indexes which will reflect the reordering of the characters.
michael@0 1761 * The array does not need to be initialized.<p>
michael@0 1762 * The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
michael@0 1763 * @stable ICU 2.0
michael@0 1764 */
michael@0 1765 U_STABLE void U_EXPORT2
michael@0 1766 ubidi_reorderLogical(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
michael@0 1767
michael@0 1768 /**
michael@0 1769 * This is a convenience function that does not use a UBiDi object.
michael@0 1770 * It is intended to be used for when an application has determined the levels
michael@0 1771 * of objects (character sequences) and just needs to have them reordered (L2).
michael@0 1772 * This is equivalent to using <code>ubidi_getVisualMap()</code> on a
michael@0 1773 * <code>UBiDi</code> object.
michael@0 1774 *
michael@0 1775 * @param levels is an array with <code>length</code> levels that have been determined by
michael@0 1776 * the application.
michael@0 1777 *
michael@0 1778 * @param length is the number of levels in the array, or, semantically,
michael@0 1779 * the number of objects to be reordered.
michael@0 1780 * It must be <code>length>0</code>.
michael@0 1781 *
michael@0 1782 * @param indexMap is a pointer to an array of <code>length</code>
michael@0 1783 * indexes which will reflect the reordering of the characters.
michael@0 1784 * The array does not need to be initialized.<p>
michael@0 1785 * The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
michael@0 1786 * @stable ICU 2.0
michael@0 1787 */
michael@0 1788 U_STABLE void U_EXPORT2
michael@0 1789 ubidi_reorderVisual(const UBiDiLevel *levels, int32_t length, int32_t *indexMap);
michael@0 1790
michael@0 1791 /**
michael@0 1792 * Invert an index map.
michael@0 1793 * The index mapping of the first map is inverted and written to
michael@0 1794 * the second one.
michael@0 1795 *
michael@0 1796 * @param srcMap is an array with <code>length</code> elements
michael@0 1797 * which defines the original mapping from a source array containing
michael@0 1798 * <code>length</code> elements to a destination array.
michael@0 1799 * Some elements of the source array may have no mapping in the
michael@0 1800 * destination array. In that case, their value will be
michael@0 1801 * the special value <code>UBIDI_MAP_NOWHERE</code>.
michael@0 1802 * All elements must be >=0 or equal to <code>UBIDI_MAP_NOWHERE</code>.
michael@0 1803 * Some elements may have a value >= <code>length</code>, if the
michael@0 1804 * destination array has more elements than the source array.
michael@0 1805 * There must be no duplicate indexes (two or more elements with the
michael@0 1806 * same value except <code>UBIDI_MAP_NOWHERE</code>).
michael@0 1807 *
michael@0 1808 * @param destMap is an array with a number of elements equal to 1 + the highest
michael@0 1809 * value in <code>srcMap</code>.
michael@0 1810 * <code>destMap</code> will be filled with the inverse mapping.
michael@0 1811 * If element with index i in <code>srcMap</code> has a value k different
michael@0 1812 * from <code>UBIDI_MAP_NOWHERE</code>, this means that element i of
michael@0 1813 * the source array maps to element k in the destination array.
michael@0 1814 * The inverse map will have value i in its k-th element.
michael@0 1815 * For all elements of the destination array which do not map to
michael@0 1816 * an element in the source array, the corresponding element in the
michael@0 1817 * inverse map will have a value equal to <code>UBIDI_MAP_NOWHERE</code>.
michael@0 1818 *
michael@0 1819 * @param length is the length of each array.
michael@0 1820 * @see UBIDI_MAP_NOWHERE
michael@0 1821 * @stable ICU 2.0
michael@0 1822 */
michael@0 1823 U_STABLE void U_EXPORT2
michael@0 1824 ubidi_invertMap(const int32_t *srcMap, int32_t *destMap, int32_t length);
michael@0 1825
michael@0 1826 /** option flags for ubidi_writeReordered() */
michael@0 1827
michael@0 1828 /**
michael@0 1829 * option bit for ubidi_writeReordered():
michael@0 1830 * keep combining characters after their base characters in RTL runs
michael@0 1831 *
michael@0 1832 * @see ubidi_writeReordered
michael@0 1833 * @stable ICU 2.0
michael@0 1834 */
michael@0 1835 #define UBIDI_KEEP_BASE_COMBINING 1
michael@0 1836
michael@0 1837 /**
michael@0 1838 * option bit for ubidi_writeReordered():
michael@0 1839 * replace characters with the "mirrored" property in RTL runs
michael@0 1840 * by their mirror-image mappings
michael@0 1841 *
michael@0 1842 * @see ubidi_writeReordered
michael@0 1843 * @stable ICU 2.0
michael@0 1844 */
michael@0 1845 #define UBIDI_DO_MIRRORING 2
michael@0 1846
michael@0 1847 /**
michael@0 1848 * option bit for ubidi_writeReordered():
michael@0 1849 * surround the run with LRMs if necessary;
michael@0 1850 * this is part of the approximate "inverse Bidi" algorithm
michael@0 1851 *
michael@0 1852 * <p>This option does not imply corresponding adjustment of the index
michael@0 1853 * mappings.</p>
michael@0 1854 *
michael@0 1855 * @see ubidi_setInverse
michael@0 1856 * @see ubidi_writeReordered
michael@0 1857 * @stable ICU 2.0
michael@0 1858 */
michael@0 1859 #define UBIDI_INSERT_LRM_FOR_NUMERIC 4
michael@0 1860
michael@0 1861 /**
michael@0 1862 * option bit for ubidi_writeReordered():
michael@0 1863 * remove Bidi control characters
michael@0 1864 * (this does not affect #UBIDI_INSERT_LRM_FOR_NUMERIC)
michael@0 1865 *
michael@0 1866 * <p>This option does not imply corresponding adjustment of the index
michael@0 1867 * mappings.</p>
michael@0 1868 *
michael@0 1869 * @see ubidi_writeReordered
michael@0 1870 * @stable ICU 2.0
michael@0 1871 */
michael@0 1872 #define UBIDI_REMOVE_BIDI_CONTROLS 8
michael@0 1873
michael@0 1874 /**
michael@0 1875 * option bit for ubidi_writeReordered():
michael@0 1876 * write the output in reverse order
michael@0 1877 *
michael@0 1878 * <p>This has the same effect as calling <code>ubidi_writeReordered()</code>
michael@0 1879 * first without this option, and then calling
michael@0 1880 * <code>ubidi_writeReverse()</code> without mirroring.
michael@0 1881 * Doing this in the same step is faster and avoids a temporary buffer.
michael@0 1882 * An example for using this option is output to a character terminal that
michael@0 1883 * is designed for RTL scripts and stores text in reverse order.</p>
michael@0 1884 *
michael@0 1885 * @see ubidi_writeReordered
michael@0 1886 * @stable ICU 2.0
michael@0 1887 */
michael@0 1888 #define UBIDI_OUTPUT_REVERSE 16
michael@0 1889
michael@0 1890 /**
michael@0 1891 * Get the length of the source text processed by the last call to
michael@0 1892 * <code>ubidi_setPara()</code>. This length may be different from the length
michael@0 1893 * of the source text if option <code>#UBIDI_OPTION_STREAMING</code>
michael@0 1894 * has been set.
michael@0 1895 * <br>
michael@0 1896 * Note that whenever the length of the text affects the execution or the
michael@0 1897 * result of a function, it is the processed length which must be considered,
michael@0 1898 * except for <code>ubidi_setPara</code> (which receives unprocessed source
michael@0 1899 * text) and <code>ubidi_getLength</code> (which returns the original length
michael@0 1900 * of the source text).<br>
michael@0 1901 * In particular, the processed length is the one to consider in the following
michael@0 1902 * cases:
michael@0 1903 * <ul>
michael@0 1904 * <li>maximum value of the <code>limit</code> argument of
michael@0 1905 * <code>ubidi_setLine</code></li>
michael@0 1906 * <li>maximum value of the <code>charIndex</code> argument of
michael@0 1907 * <code>ubidi_getParagraph</code></li>
michael@0 1908 * <li>maximum value of the <code>charIndex</code> argument of
michael@0 1909 * <code>ubidi_getLevelAt</code></li>
michael@0 1910 * <li>number of elements in the array returned by <code>ubidi_getLevels</code></li>
michael@0 1911 * <li>maximum value of the <code>logicalStart</code> argument of
michael@0 1912 * <code>ubidi_getLogicalRun</code></li>
michael@0 1913 * <li>maximum value of the <code>logicalIndex</code> argument of
michael@0 1914 * <code>ubidi_getVisualIndex</code></li>
michael@0 1915 * <li>number of elements filled in the <code>*indexMap</code> argument of
michael@0 1916 * <code>ubidi_getLogicalMap</code></li>
michael@0 1917 * <li>length of text processed by <code>ubidi_writeReordered</code></li>
michael@0 1918 * </ul>
michael@0 1919 *
michael@0 1920 * @param pBiDi is the paragraph <code>UBiDi</code> object.
michael@0 1921 *
michael@0 1922 * @return The length of the part of the source text processed by
michael@0 1923 * the last call to <code>ubidi_setPara</code>.
michael@0 1924 * @see ubidi_setPara
michael@0 1925 * @see UBIDI_OPTION_STREAMING
michael@0 1926 * @stable ICU 3.6
michael@0 1927 */
michael@0 1928 U_STABLE int32_t U_EXPORT2
michael@0 1929 ubidi_getProcessedLength(const UBiDi *pBiDi);
michael@0 1930
michael@0 1931 /**
michael@0 1932 * Get the length of the reordered text resulting from the last call to
michael@0 1933 * <code>ubidi_setPara()</code>. This length may be different from the length
michael@0 1934 * of the source text if option <code>#UBIDI_OPTION_INSERT_MARKS</code>
michael@0 1935 * or option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> has been set.
michael@0 1936 * <br>
michael@0 1937 * This resulting length is the one to consider in the following cases:
michael@0 1938 * <ul>
michael@0 1939 * <li>maximum value of the <code>visualIndex</code> argument of
michael@0 1940 * <code>ubidi_getLogicalIndex</code></li>
michael@0 1941 * <li>number of elements of the <code>*indexMap</code> argument of
michael@0 1942 * <code>ubidi_getVisualMap</code></li>
michael@0 1943 * </ul>
michael@0 1944 * Note that this length stays identical to the source text length if
michael@0 1945 * Bidi marks are inserted or removed using option bits of
michael@0 1946 * <code>ubidi_writeReordered</code>, or if option
michael@0 1947 * <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> has been set.
michael@0 1948 *
michael@0 1949 * @param pBiDi is the paragraph <code>UBiDi</code> object.
michael@0 1950 *
michael@0 1951 * @return The length of the reordered text resulting from
michael@0 1952 * the last call to <code>ubidi_setPara</code>.
michael@0 1953 * @see ubidi_setPara
michael@0 1954 * @see UBIDI_OPTION_INSERT_MARKS
michael@0 1955 * @see UBIDI_OPTION_REMOVE_CONTROLS
michael@0 1956 * @stable ICU 3.6
michael@0 1957 */
michael@0 1958 U_STABLE int32_t U_EXPORT2
michael@0 1959 ubidi_getResultLength(const UBiDi *pBiDi);
michael@0 1960
michael@0 1961 U_CDECL_BEGIN
michael@0 1962 /**
michael@0 1963 * value returned by <code>UBiDiClassCallback</code> callbacks when
michael@0 1964 * there is no need to override the standard Bidi class for a given code point.
michael@0 1965 * @see UBiDiClassCallback
michael@0 1966 * @stable ICU 3.6
michael@0 1967 */
michael@0 1968 #define U_BIDI_CLASS_DEFAULT U_CHAR_DIRECTION_COUNT
michael@0 1969
michael@0 1970 /**
michael@0 1971 * Callback type declaration for overriding default Bidi class values with
michael@0 1972 * custom ones.
michael@0 1973 * <p>Usually, the function pointer will be propagated to a <code>UBiDi</code>
michael@0 1974 * object by calling the <code>ubidi_setClassCallback()</code> function;
michael@0 1975 * then the callback will be invoked by the UBA implementation any time the
michael@0 1976 * class of a character is to be determined.</p>
michael@0 1977 *
michael@0 1978 * @param context is a pointer to the callback private data.
michael@0 1979 *
michael@0 1980 * @param c is the code point to get a Bidi class for.
michael@0 1981 *
michael@0 1982 * @return The directional property / Bidi class for the given code point
michael@0 1983 * <code>c</code> if the default class has been overridden, or
michael@0 1984 * <code>#U_BIDI_CLASS_DEFAULT</code> if the standard Bidi class value
michael@0 1985 * for <code>c</code> is to be used.
michael@0 1986 * @see ubidi_setClassCallback
michael@0 1987 * @see ubidi_getClassCallback
michael@0 1988 * @stable ICU 3.6
michael@0 1989 */
michael@0 1990 typedef UCharDirection U_CALLCONV
michael@0 1991 UBiDiClassCallback(const void *context, UChar32 c);
michael@0 1992
michael@0 1993 U_CDECL_END
michael@0 1994
michael@0 1995 /**
michael@0 1996 * Retrieve the Bidi class for a given code point.
michael@0 1997 * <p>If a <code>#UBiDiClassCallback</code> callback is defined and returns a
michael@0 1998 * value other than <code>#U_BIDI_CLASS_DEFAULT</code>, that value is used;
michael@0 1999 * otherwise the default class determination mechanism is invoked.</p>
michael@0 2000 *
michael@0 2001 * @param pBiDi is the paragraph <code>UBiDi</code> object.
michael@0 2002 *
michael@0 2003 * @param c is the code point whose Bidi class must be retrieved.
michael@0 2004 *
michael@0 2005 * @return The Bidi class for character <code>c</code> based
michael@0 2006 * on the given <code>pBiDi</code> instance.
michael@0 2007 * @see UBiDiClassCallback
michael@0 2008 * @stable ICU 3.6
michael@0 2009 */
michael@0 2010 U_STABLE UCharDirection U_EXPORT2
michael@0 2011 ubidi_getCustomizedClass(UBiDi *pBiDi, UChar32 c);
michael@0 2012
michael@0 2013 /**
michael@0 2014 * Set the callback function and callback data used by the UBA
michael@0 2015 * implementation for Bidi class determination.
michael@0 2016 * <p>This may be useful for assigning Bidi classes to PUA characters, or
michael@0 2017 * for special application needs. For instance, an application may want to
michael@0 2018 * handle all spaces like L or R characters (according to the base direction)
michael@0 2019 * when creating the visual ordering of logical lines which are part of a report
michael@0 2020 * organized in columns: there should not be interaction between adjacent
michael@0 2021 * cells.<p>
michael@0 2022 *
michael@0 2023 * @param pBiDi is the paragraph <code>UBiDi</code> object.
michael@0 2024 *
michael@0 2025 * @param newFn is the new callback function pointer.
michael@0 2026 *
michael@0 2027 * @param newContext is the new callback context pointer. This can be NULL.
michael@0 2028 *
michael@0 2029 * @param oldFn fillin: Returns the old callback function pointer. This can be
michael@0 2030 * NULL.
michael@0 2031 *
michael@0 2032 * @param oldContext fillin: Returns the old callback's context. This can be
michael@0 2033 * NULL.
michael@0 2034 *
michael@0 2035 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 2036 *
michael@0 2037 * @see ubidi_getClassCallback
michael@0 2038 * @stable ICU 3.6
michael@0 2039 */
michael@0 2040 U_STABLE void U_EXPORT2
michael@0 2041 ubidi_setClassCallback(UBiDi *pBiDi, UBiDiClassCallback *newFn,
michael@0 2042 const void *newContext, UBiDiClassCallback **oldFn,
michael@0 2043 const void **oldContext, UErrorCode *pErrorCode);
michael@0 2044
michael@0 2045 /**
michael@0 2046 * Get the current callback function used for Bidi class determination.
michael@0 2047 *
michael@0 2048 * @param pBiDi is the paragraph <code>UBiDi</code> object.
michael@0 2049 *
michael@0 2050 * @param fn fillin: Returns the callback function pointer.
michael@0 2051 *
michael@0 2052 * @param context fillin: Returns the callback's private context.
michael@0 2053 *
michael@0 2054 * @see ubidi_setClassCallback
michael@0 2055 * @stable ICU 3.6
michael@0 2056 */
michael@0 2057 U_STABLE void U_EXPORT2
michael@0 2058 ubidi_getClassCallback(UBiDi *pBiDi, UBiDiClassCallback **fn, const void **context);
michael@0 2059
michael@0 2060 /**
michael@0 2061 * Take a <code>UBiDi</code> object containing the reordering
michael@0 2062 * information for a piece of text (one or more paragraphs) set by
michael@0 2063 * <code>ubidi_setPara()</code> or for a line of text set by
michael@0 2064 * <code>ubidi_setLine()</code> and write a reordered string to the
michael@0 2065 * destination buffer.
michael@0 2066 *
michael@0 2067 * This function preserves the integrity of characters with multiple
michael@0 2068 * code units and (optionally) combining characters.
michael@0 2069 * Characters in RTL runs can be replaced by mirror-image characters
michael@0 2070 * in the destination buffer. Note that "real" mirroring has
michael@0 2071 * to be done in a rendering engine by glyph selection
michael@0 2072 * and that for many "mirrored" characters there are no
michael@0 2073 * Unicode characters as mirror-image equivalents.
michael@0 2074 * There are also options to insert or remove Bidi control
michael@0 2075 * characters; see the description of the <code>destSize</code>
michael@0 2076 * and <code>options</code> parameters and of the option bit flags.
michael@0 2077 *
michael@0 2078 * @param pBiDi A pointer to a <code>UBiDi</code> object that
michael@0 2079 * is set by <code>ubidi_setPara()</code> or
michael@0 2080 * <code>ubidi_setLine()</code> and contains the reordering
michael@0 2081 * information for the text that it was defined for,
michael@0 2082 * as well as a pointer to that text.<br><br>
michael@0 2083 * The text was aliased (only the pointer was stored
michael@0 2084 * without copying the contents) and must not have been modified
michael@0 2085 * since the <code>ubidi_setPara()</code> call.
michael@0 2086 *
michael@0 2087 * @param dest A pointer to where the reordered text is to be copied.
michael@0 2088 * The source text and <code>dest[destSize]</code>
michael@0 2089 * must not overlap.
michael@0 2090 *
michael@0 2091 * @param destSize The size of the <code>dest</code> buffer,
michael@0 2092 * in number of UChars.
michael@0 2093 * If the <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>
michael@0 2094 * option is set, then the destination length could be
michael@0 2095 * as large as
michael@0 2096 * <code>ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)</code>.
michael@0 2097 * If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
michael@0 2098 * is set, then the destination length may be less than
michael@0 2099 * <code>ubidi_getLength(pBiDi)</code>.
michael@0 2100 * If none of these options is set, then the destination length
michael@0 2101 * will be exactly <code>ubidi_getProcessedLength(pBiDi)</code>.
michael@0 2102 *
michael@0 2103 * @param options A bit set of options for the reordering that control
michael@0 2104 * how the reordered text is written.
michael@0 2105 * The options include mirroring the characters on a code
michael@0 2106 * point basis and inserting LRM characters, which is used
michael@0 2107 * especially for transforming visually stored text
michael@0 2108 * to logically stored text (although this is still an
michael@0 2109 * imperfect implementation of an "inverse Bidi" algorithm
michael@0 2110 * because it uses the "forward Bidi" algorithm at its core).
michael@0 2111 * The available options are:
michael@0 2112 * <code>#UBIDI_DO_MIRRORING</code>,
michael@0 2113 * <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>,
michael@0 2114 * <code>#UBIDI_KEEP_BASE_COMBINING</code>,
michael@0 2115 * <code>#UBIDI_OUTPUT_REVERSE</code>,
michael@0 2116 * <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
michael@0 2117 *
michael@0 2118 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 2119 *
michael@0 2120 * @return The length of the output string.
michael@0 2121 *
michael@0 2122 * @see ubidi_getProcessedLength
michael@0 2123 * @stable ICU 2.0
michael@0 2124 */
michael@0 2125 U_STABLE int32_t U_EXPORT2
michael@0 2126 ubidi_writeReordered(UBiDi *pBiDi,
michael@0 2127 UChar *dest, int32_t destSize,
michael@0 2128 uint16_t options,
michael@0 2129 UErrorCode *pErrorCode);
michael@0 2130
michael@0 2131 /**
michael@0 2132 * Reverse a Right-To-Left run of Unicode text.
michael@0 2133 *
michael@0 2134 * This function preserves the integrity of characters with multiple
michael@0 2135 * code units and (optionally) combining characters.
michael@0 2136 * Characters can be replaced by mirror-image characters
michael@0 2137 * in the destination buffer. Note that "real" mirroring has
michael@0 2138 * to be done in a rendering engine by glyph selection
michael@0 2139 * and that for many "mirrored" characters there are no
michael@0 2140 * Unicode characters as mirror-image equivalents.
michael@0 2141 * There are also options to insert or remove Bidi control
michael@0 2142 * characters.
michael@0 2143 *
michael@0 2144 * This function is the implementation for reversing RTL runs as part
michael@0 2145 * of <code>ubidi_writeReordered()</code>. For detailed descriptions
michael@0 2146 * of the parameters, see there.
michael@0 2147 * Since no Bidi controls are inserted here, the output string length
michael@0 2148 * will never exceed <code>srcLength</code>.
michael@0 2149 *
michael@0 2150 * @see ubidi_writeReordered
michael@0 2151 *
michael@0 2152 * @param src A pointer to the RTL run text.
michael@0 2153 *
michael@0 2154 * @param srcLength The length of the RTL run.
michael@0 2155 *
michael@0 2156 * @param dest A pointer to where the reordered text is to be copied.
michael@0 2157 * <code>src[srcLength]</code> and <code>dest[destSize]</code>
michael@0 2158 * must not overlap.
michael@0 2159 *
michael@0 2160 * @param destSize The size of the <code>dest</code> buffer,
michael@0 2161 * in number of UChars.
michael@0 2162 * If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
michael@0 2163 * is set, then the destination length may be less than
michael@0 2164 * <code>srcLength</code>.
michael@0 2165 * If this option is not set, then the destination length
michael@0 2166 * will be exactly <code>srcLength</code>.
michael@0 2167 *
michael@0 2168 * @param options A bit set of options for the reordering that control
michael@0 2169 * how the reordered text is written.
michael@0 2170 * See the <code>options</code> parameter in <code>ubidi_writeReordered()</code>.
michael@0 2171 *
michael@0 2172 * @param pErrorCode must be a valid pointer to an error code value.
michael@0 2173 *
michael@0 2174 * @return The length of the output string.
michael@0 2175 * @stable ICU 2.0
michael@0 2176 */
michael@0 2177 U_STABLE int32_t U_EXPORT2
michael@0 2178 ubidi_writeReverse(const UChar *src, int32_t srcLength,
michael@0 2179 UChar *dest, int32_t destSize,
michael@0 2180 uint16_t options,
michael@0 2181 UErrorCode *pErrorCode);
michael@0 2182
michael@0 2183 /*#define BIDI_SAMPLE_CODE*/
michael@0 2184 /*@}*/
michael@0 2185
michael@0 2186 #endif

mercurial