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