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