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