~ubuntu-branches/ubuntu/quantal/icu/quantal

« back to all changes in this revision

Viewing changes to source/common/unicode/ubidi.h

  • Committer: Package Import Robot
  • Author(s): Yves Arrouye
  • Date: 2002-03-03 15:31:13 UTC
  • Revision ID: package-import@ubuntu.com-20020303153113-3ssceqlq45xbmbnc
Tags: upstream-2.0-2.1pre20020303
ImportĀ upstreamĀ versionĀ 2.0-2.1pre20020303

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
******************************************************************************
 
3
*
 
4
*   Copyright (C) 1999-2001, International Business Machines
 
5
*   Corporation and others.  All Rights Reserved.
 
6
*
 
7
******************************************************************************
 
8
*   file name:  ubidi.h
 
9
*   encoding:   US-ASCII
 
10
*   tab size:   8 (not used)
 
11
*   indentation:4
 
12
*
 
13
*   created on: 1999jul27
 
14
*   created by: Markus W. Scherer
 
15
*/
 
16
 
 
17
#ifndef UBIDI_H
 
18
#define UBIDI_H
 
19
 
 
20
#include "unicode/utypes.h"
 
21
#include "unicode/uchar.h"
 
22
 
 
23
/*
 
24
 * javadoc-style comments are intended to be transformed into HTML
 
25
 * using DOC++ - see
 
26
 * http://www.zib.de/Visual/software/doc++/index.html .
 
27
 *
 
28
 * The HTML documentation is created with
 
29
 *  doc++ -H ubidi.h
 
30
 *
 
31
 * The following #define trick allows us to do it all in one file
 
32
 * and still be able to compile it.
 
33
 */
 
34
/*#define DOCXX_TAG*/
 
35
/*#define BIDI_SAMPLE_CODE*/
 
36
 
 
37
/**
 
38
 *\file
 
39
 * \brief C API: BIDI algorithm 
 
40
 *
 
41
 * <h2>BIDI algorithm for ICU</h2>
 
42
 *
 
43
 * This is an implementation of the Unicode Bidirectional algorithm.
 
44
 * The algorithm is defined in the
 
45
 * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Technical Report 9</a>,
 
46
 * version 5, also described in The Unicode Standard, Version 3.0 .<p>
 
47
 *
 
48
 * <h3>General remarks about the API:</h3>
 
49
 *
 
50
 * In functions with an error code parameter,
 
51
 * the <code>pErrorCode</code> pointer must be valid
 
52
 * and the value that it points to must not indicate a failure before
 
53
 * the function call. Otherwise, the function returns immediately.
 
54
 * After the function call, the value indicates success or failure.<p>
 
55
 *
 
56
 * The &quot;limit&quot; of a sequence of characters is the position just after their
 
57
 * last character, i.e., one more than that position.<p>
 
58
 *
 
59
 * Some of the API functions provide access to &quot;runs&quot;.
 
60
 * Such a &quot;run&quot; is defined as a sequence of characters
 
61
 * that are at the same embedding level
 
62
 * after performing the BIDI algorithm.<p>
 
63
 *
 
64
 * @author Markus W. Scherer
 
65
 * @version 1.0
 
66
 *
 
67
 *
 
68
 * <h4> Sample code for the ICU BIDI API </h4>
 
69
 *
 
70
 * <h5>Rendering a paragraph with the ICU BiDi API</h5>
 
71
 *
 
72
 * This is (hypothetical) sample code that illustrates
 
73
 * how the ICU BiDi API could be used to render a paragraph of text.
 
74
 * Rendering code depends highly on the graphics system,
 
75
 * therefore this sample code must make a lot of assumptions,
 
76
 * which may or may not match any existing graphics system's properties.
 
77
 *
 
78
 * <p>The basic assumptions are:</p>
 
79
 * <ul>
 
80
 * <li>Rendering is done from left to right on a horizontal line.</li>
 
81
 * <li>A run of single-style, unidirectional text can be rendered at once.</li>
 
82
 * <li>Such a run of text is passed to the graphics system with
 
83
 *     characters (code units) in logical order.</li>
 
84
 * <li>The line-breaking algorithm is very complicated
 
85
 *     and Locale-dependent -
 
86
 *     and therefore its implementation omitted from this sample code.</li>
 
87
 * </ul>
 
88
 *
 
89
 * <pre>
 
90
 * \code
 
91
 *#include "unicode/ubidi.h"
 
92
 *
 
93
 *typedef enum {
 
94
 *     styleNormal=0, styleSelected=1,
 
95
 *     styleBold=2, styleItalics=4,
 
96
 *     styleSuper=8, styleSub=16
 
97
 *} Style;
 
98
 *
 
99
 *typedef struct { UTextOffset limit; Style style; } StyleRun;
 
100
 *
 
101
 *int getTextWidth(const UChar *text, UTextOffset start, UTextOffset limit,
 
102
 *                  const StyleRun *styleRuns, int styleRunCount);
 
103
 *
 
104
 * // set *pLimit and *pStyleRunLimit for a line
 
105
 * // from text[start] and from styleRuns[styleRunStart]
 
106
 * // using ubidi_getLogicalRun(para, ...)
 
107
 *void getLineBreak(const UChar *text, UTextOffset start, UTextOffset *pLimit,
 
108
 *                  UBiDi *para,
 
109
 *                  const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,
 
110
 *                  int *pLineWidth);
 
111
 *
 
112
 * // render runs on a line sequentially, always from left to right
 
113
 *
 
114
 * // prepare rendering a new line
 
115
 *void startLine(UBiDiDirection textDirection, int lineWidth);
 
116
 *
 
117
 * // render a run of text and advance to the right by the run width
 
118
 * // the text[start..limit-1] is always in logical order
 
119
 *void renderRun(const UChar *text, UTextOffset start, UTextOffset limit,
 
120
 *               UBiDiDirection textDirection, Style style);
 
121
 *
 
122
 * // We could compute a cross-product
 
123
 * // from the style runs with the directional runs
 
124
 * // and then reorder it.
 
125
 * // Instead, here we iterate over each run type
 
126
 * // and render the intersections -
 
127
 * // with shortcuts in simple (and common) cases.
 
128
 * // renderParagraph() is the main function.
 
129
 *
 
130
 * // render a directional run with
 
131
 * // (possibly) multiple style runs intersecting with it
 
132
 *void renderDirectionalRun(const UChar *text,
 
133
 *                           UTextOffset start, UTextOffset limit,
 
134
 *                           UBiDiDirection direction,
 
135
 *                           const StyleRun *styleRuns, int styleRunCount) {
 
136
 *     int i;
 
137
 *
 
138
 *     // iterate over style runs
 
139
 *     if(direction==UBIDI_LTR) {
 
140
 *         int styleLimit;
 
141
 *
 
142
 *         for(i=0; i<styleRunCount; ++i) {
 
143
 *             styleLimit=styleRun[i].limit;
 
144
 *             if(start<styleLimit) {
 
145
 *                 if(styleLimit>limit) { styleLimit=limit; }
 
146
 *                 renderRun(text, start, styleLimit,
 
147
 *                           direction, styleRun[i].style);
 
148
 *                 if(styleLimit==limit) { break; }
 
149
 *                 start=styleLimit;
 
150
 *             }
 
151
 *         }
 
152
 *     } else {
 
153
 *         int styleStart;
 
154
 *
 
155
 *         for(i=styleRunCount-1; i>=0; --i) {
 
156
 *             if(i>0) {
 
157
 *                 styleStart=styleRun[i-1].limit;
 
158
 *             } else {
 
159
 *                 styleStart=0;
 
160
 *             }
 
161
 *             if(limit>=styleStart) {
 
162
 *                 if(styleStart<start) { styleStart=start; }
 
163
 *                 renderRun(text, styleStart, limit,
 
164
 *                           direction, styleRun[i].style);
 
165
 *                 if(styleStart==start) { break; }
 
166
 *                 limit=styleStart;
 
167
 *             }
 
168
 *         }
 
169
 *     }
 
170
 * }
 
171
 *
 
172
 * // the line object represents text[start..limit-1]
 
173
 * void renderLine(UBiDi *line, const UChar *text,
 
174
 *                 UTextOffset start, UTextOffset limit,
 
175
 *                 const StyleRun *styleRuns, int styleRunCount) {
 
176
 *     UBiDiDirection direction=ubidi_getDirection(line);
 
177
 *     if(direction!=UBIDI_MIXED) {
 
178
 *         // unidirectional
 
179
 *         if(styleRunCount<=1) {
 
180
 *             renderRun(text, start, limit, direction, styleRuns[0].style);
 
181
 *         } else {
 
182
 *             renderDirectionalRun(text, start, limit,
 
183
 *                                  direction, styleRuns, styleRunCount);
 
184
 *         }
 
185
 *     } else {
 
186
 *         // mixed-directional
 
187
 *         UTextOffset count, i, length;
 
188
 *         UBiDiLevel level;
 
189
 *
 
190
 *         count=ubidi_countRuns(para, pErrorCode);
 
191
 *         if(U_SUCCESS(*pErrorCode)) {
 
192
 *             if(styleRunCount<=1) {
 
193
 *                 Style style=styleRuns[0].style;
 
194
 *
 
195
 *                 // iterate over directional runs
 
196
 *                for(i=0; i<count; ++i) {
 
197
 *                    direction=ubidi_getVisualRun(para, i, &start, &length);
 
198
 *                     renderRun(text, start, start+length, direction, style);
 
199
 *                }
 
200
 *             } else {
 
201
 *                 UTextOffset j;
 
202
 *
 
203
 *                 // iterate over both directional and style runs
 
204
 *                 for(i=0; i<count; ++i) {
 
205
 *                     direction=ubidi_getVisualRun(line, i, &start, &length);
 
206
 *                     renderDirectionalRun(text, start, start+length,
 
207
 *                                          direction, styleRuns, styleRunCount);
 
208
 *                 }
 
209
 *             }
 
210
 *         }
 
211
 *     }
 
212
 * }
 
213
 *
 
214
 *void renderParagraph(const UChar *text, UTextOffset length,
 
215
 *                     UBiDiDirection textDirection,
 
216
 *                      const StyleRun *styleRuns, int styleRunCount,
 
217
 *                      int lineWidth,
 
218
 *                      UErrorCode *pErrorCode) {
 
219
 *     UBiDi *para;
 
220
 *
 
221
 *     if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {
 
222
 *         return;
 
223
 *     }
 
224
 *
 
225
 *     para=ubidi_openSized(length, 0, pErrorCode);
 
226
 *     if(para==NULL) { return; }
 
227
 *
 
228
 *     ubidi_setPara(para, text, length,
 
229
 *                   textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
 
230
 *                   NULL, pErrorCode);
 
231
 *     if(U_SUCCESS(*pErrorCode)) {
 
232
 *         UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);
 
233
 *         StyleRun styleRun={ length, styleNormal };
 
234
 *         int width;
 
235
 *
 
236
 *         if(styleRuns==NULL || styleRunCount<=0) {
 
237
 *            styleRunCount=1;
 
238
 *             styleRuns=&styleRun;
 
239
 *         }
 
240
 *
 
241
 *        // assume styleRuns[styleRunCount-1].limit>=length
 
242
 *
 
243
 *         width=getTextWidth(text, 0, length, styleRuns, styleRunCount);
 
244
 *         if(width<=lineWidth) {
 
245
 *             // everything fits onto one line
 
246
 *
 
247
 *            // prepare rendering a new line from either left or right
 
248
 *             startLine(paraLevel, width);
 
249
 *
 
250
 *             renderLine(para, text, 0, length,
 
251
 *                        styleRuns, styleRunCount);
 
252
 *         } else {
 
253
 *             UBiDi *line;
 
254
 *
 
255
 *             // we need to render several lines
 
256
 *             line=ubidi_openSized(length, 0, pErrorCode);
 
257
 *             if(line!=NULL) {
 
258
 *                 UTextOffset start=0, limit;
 
259
 *                 int styleRunStart=0, styleRunLimit;
 
260
 *
 
261
 *                 for(;;) {
 
262
 *                     limit=length;
 
263
 *                     styleRunLimit=styleRunCount;
 
264
 *                     getLineBreak(text, start, &limit, para,
 
265
 *                                  styleRuns, styleRunStart, &styleRunLimit,
 
266
 *                                 &width);
 
267
 *                     ubidi_setLine(para, start, limit, line, pErrorCode);
 
268
 *                     if(U_SUCCESS(*pErrorCode)) {
 
269
 *                         // prepare rendering a new line
 
270
 *                         // from either left or right
 
271
 *                         startLine(paraLevel, width);
 
272
 *
 
273
 *                         renderLine(line, text, start, limit,
 
274
 *                                    styleRuns+styleRunStart,
 
275
 *                                    styleRunLimit-styleRunStart);
 
276
 *                     }
 
277
 *                     if(limit==length) { break; }
 
278
 *                     start=limit;
 
279
 *                     styleRunStart=styleRunLimit-1;
 
280
 *                     if(start>=styleRuns[styleRunStart].limit) {
 
281
 *                         ++styleRunStart;
 
282
 *                     }
 
283
 *                 }
 
284
 *
 
285
 *                 ubidi_close(line);
 
286
 *             }
 
287
 *        }
 
288
 *    }
 
289
 *
 
290
 *     ubidi_close(para);
 
291
 *}
 
292
 *\endcode
 
293
 * </pre>
 
294
 */
 
295
 
 
296
/*DOCXX_TAG*/
 
297
/*@{*/
 
298
 
 
299
/**
 
300
 * UBiDiLevel is the type of the level values in this
 
301
 * BiDi implementation.
 
302
 * It holds an embedding level and indicates the visual direction
 
303
 * by its bit&nbsp;0 (even/odd value).<p>
 
304
 *
 
305
 * It can also hold non-level values for the
 
306
 * <code>paraLevel</code> and <code>embeddingLevels</code>
 
307
 * arguments of <code>ubidi_setPara()</code>; there:
 
308
 * <ul>
 
309
 * <li>bit&nbsp;7 of an <code>embeddingLevels[]</code>
 
310
 * value indicates whether the using application is
 
311
 * specifying the level of a character to <i>override</i> whatever the
 
312
 * BiDi implementation would resolve it to.</li>
 
313
 * <li><code>paraLevel</code> can be set to the
 
314
 * pesudo-level values <code>UBIDI_DEFAULT_LTR</code>
 
315
 * and <code>UBIDI_DEFAULT_RTL</code>.</li>
 
316
 *
 
317
 * @see ubidi_setPara
 
318
 *
 
319
 * <p>The related constants are not real, valid level values.
 
320
 * <code>UBIDI_DEFAULT_XXX</code> can be used to specify
 
321
 * a default for the paragraph level for
 
322
 * when the <code>ubidi_setPara()</code> function
 
323
 * shall determine it but there is no
 
324
 * strongly typed character in the input.<p>
 
325
 *
 
326
 * Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even
 
327
 * and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,
 
328
 * just like with normal LTR and RTL level values -
 
329
 * these special values are designed that way. Also, the implementation
 
330
 * assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
 
331
 *
 
332
 * @see UBIDI_DEFAULT_LTR
 
333
 * @see UBIDI_DEFAULT_RTL
 
334
 * @see UBIDI_LEVEL_OVERRIDE
 
335
 * @see UBIDI_MAX_EXPLICIT_LEVEL
 
336
 * @stable
 
337
 */
 
338
typedef uint8_t UBiDiLevel;
 
339
 
 
340
/** Paragraph level setting.
 
341
 *  If there is no strong character, then set the paragraph level to 0 (left-to-right).
 
342
 * @stable
 
343
 */
 
344
#define UBIDI_DEFAULT_LTR 0xfe
 
345
 
 
346
/** Paragraph level setting.
 
347
 *  If there is no strong character, then set the paragraph level to 1 (right-to-left).
 
348
 * @stable
 
349
 */
 
350
#define UBIDI_DEFAULT_RTL 0xff
 
351
 
 
352
/**
 
353
 * Maximum explicit embedding level.
 
354
 * (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).
 
355
 * @stable
 
356
 */
 
357
#define UBIDI_MAX_EXPLICIT_LEVEL 61
 
358
 
 
359
/** Bit flag for level input. 
 
360
 *  Overrides directional properties. 
 
361
 * @stable
 
362
 */
 
363
#define UBIDI_LEVEL_OVERRIDE 0x80
 
364
 
 
365
/**
 
366
 * @memo <code>UBiDiDirection</code> values indicate the text direction.
 
367
 * @stable
 
368
 */
 
369
enum UBiDiDirection {
 
370
    /** @memo All left-to-right text. This is a 0 value. @stable */
 
371
    UBIDI_LTR,
 
372
    /** @memo All right-to-left text. This is a 1 value. @stable */
 
373
    UBIDI_RTL,
 
374
    /** @memo Mixed-directional text. @stable */
 
375
    UBIDI_MIXED
 
376
};
 
377
 
 
378
/** @stable */
 
379
typedef enum UBiDiDirection UBiDiDirection;
 
380
 
 
381
/**
 
382
 * Forward declaration of the <code>UBiDi</code> structure for the declaration of
 
383
 * the API functions. Its fields are implementation-specific.<p>
 
384
 * This structure holds information about a paragraph of text
 
385
 * with BiDi-algorithm-related details, or about one line of
 
386
 * such a paragraph.<p>
 
387
 * Reordering can be done on a line, or on a paragraph which is
 
388
 * then interpreted as one single line.
 
389
 * @stable
 
390
 */
 
391
struct UBiDi;
 
392
 
 
393
/** @stable */
 
394
typedef struct UBiDi UBiDi;
 
395
 
 
396
/**
 
397
 * Allocate a <code>UBiDi</code> structure.
 
398
 * Such an object is initially empty. It is assigned
 
399
 * the BiDi properties of a paragraph by <code>ubidi_setPara()</code>
 
400
 * or the BiDi properties of a line of a paragraph by
 
401
 * <code>ubidi_setLine()</code>.<p>
 
402
 * This object can be reused for as long as it is not deallocated
 
403
 * by calling <code>ubidi_close()</code>.<p>
 
404
 * <code>ubidi_set()</code> will allocate additional memory for
 
405
 * internal structures as necessary.
 
406
 *
 
407
 * @return An empty <code>UBiDi</code> object.
 
408
 * @stable
 
409
 */
 
410
U_CAPI UBiDi * U_EXPORT2
 
411
ubidi_open(void);
 
412
 
 
413
/**
 
414
 * Allocate a <code>UBiDi</code> structure with preallocated memory
 
415
 * for internal structures.
 
416
 * This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>
 
417
 * with no arguments, but it also preallocates memory for internal structures
 
418
 * according to the sizings supplied by the caller.<p>
 
419
 * Subsequent functions will not allocate any more memory, and are thus
 
420
 * guaranteed not to fail because of lack of memory.<p>
 
421
 * The preallocation can be limited to some of the internal memory
 
422
 * by setting some values to 0 here. That means that if, e.g.,
 
423
 * <code>maxRunCount</code> cannot be reasonably predetermined and should not
 
424
 * be set to <code>maxLength</code> (the only failproof value) to avoid
 
425
 * wasting memory, then <code>maxRunCount</code> could be set to 0 here
 
426
 * and the internal structures that are associated with it will be allocated
 
427
 * on demand, just like with <code>ubidi_open()</code>.
 
428
 *
 
429
 * @param maxLength is the maximum paragraph or line length that internal memory
 
430
 *        will be preallocated for. An attempt to associate this object with a
 
431
 *        longer text will fail, unless this value is 0, which leaves the allocation
 
432
 *        up to the implementation.
 
433
 *
 
434
 * @param maxRunCount is the maximum anticipated number of same-level runs
 
435
 *        that internal memory will be preallocated for. An attempt to access
 
436
 *        visual runs on an object that was not preallocated for as many runs
 
437
 *        as the text was actually resolved to will fail,
 
438
 *        unless this value is 0, which leaves the allocation up to the implementation.<p>
 
439
 *        The number of runs depends on the actual text and maybe anywhere between
 
440
 *        1 and <code>maxLength</code>. It is typically small.<p>
 
441
 *
 
442
 * @param pErrorCode must be a valid pointer to an error code value,
 
443
 *        which must not indicate a failure before the function call.
 
444
 *
 
445
 * @return An empty <code>UBiDi</code> object with preallocated memory.
 
446
 * @stable
 
447
 */
 
448
U_CAPI UBiDi * U_EXPORT2
 
449
ubidi_openSized(UTextOffset maxLength, UTextOffset maxRunCount, UErrorCode *pErrorCode);
 
450
 
 
451
/**
 
452
 * <code>ubidi_close()</code> must be called to free the memory
 
453
 * associated with a UBiDi object.<p>
 
454
 *
 
455
 * <strong>Important: </strong>
 
456
 * If a <code>UBiDi</code> object is the <quote>child</quote>
 
457
 * of another one (its <quote>parent</quote>), after calling
 
458
 * <code>ubidi_setLine()</code>, then the child object must
 
459
 * be destroyed (closed) or reused (by calling
 
460
 * <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)
 
461
 * before the parent object.
 
462
 *
 
463
 * @param pBiDi is a <code>UBiDi</code> object.
 
464
 *
 
465
 * @see ubidi_setPara
 
466
 * @see ubidi_setLine
 
467
 * @stable
 
468
 */
 
469
U_CAPI void U_EXPORT2
 
470
ubidi_close(UBiDi *pBiDi);
 
471
 
 
472
/**
 
473
 * Modify the operation of the BiDi algorithm such that it
 
474
 * approximates an "inverse BiDi" algorithm. This function
 
475
 * must be called before <code>ubidi_setPara()</code>.
 
476
 *
 
477
 * <p>The normal operation of the BiDi algorithm as described
 
478
 * in the Unicode Technical Report is to take text stored in logical
 
479
 * (keyboard, typing) order and to determine the reordering of it for visual
 
480
 * rendering.
 
481
 * Some legacy codepages store text in visual order, and for operations
 
482
 * with standard, Unicode-based algorithms, the text needs to be transformed
 
483
 * to logical order. This is effectively the inverse algorithm of the
 
484
 * described BiDi algorithm. Note that there is no standard algorithm for
 
485
 * this "inverse BiDi" and that the current implementation provides only an
 
486
 * approximation of "inverse BiDi".</p>
 
487
 * 
 
488
 * <p>With <code>isInverse</code> set to <code>TRUE</code>,
 
489
 * this function changes the behavior of some of the subsequent functions
 
490
 * in a way that they can be used for the inverse BiDi algorithm.
 
491
 * Specifically, runs of text with numeric characters will be treated in a
 
492
 * special way and may need to be surrounded with LRM characters when they are
 
493
 * written in reordered sequence.</p>
 
494
 *
 
495
 * <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.
 
496
 * Since the actual input for "inverse BiDi" is visually ordered text and
 
497
 * <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually
 
498
 * the runs of the logically ordered output.</p>
 
499
 *
 
500
 * @param pBiDi is a <code>UBiDi</code> object.
 
501
 *
 
502
 * @param isInverse specifies "forward" or "inverse" BiDi operation
 
503
 *
 
504
 * @see ubidi_setPara
 
505
 * @see ubidi_writeReordered
 
506
 * @stable
 
507
 */
 
508
U_CAPI void U_EXPORT2
 
509
ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
 
510
 
 
511
/**
 
512
 * Is this BiDi object set to perform the inverse BiDi algorithm?
 
513
 *
 
514
 * @param pBiDi is a <code>UBiDi</code> object.
 
515
 *
 
516
 * @see ubidi_setInverse
 
517
 * @stable
 
518
 */
 
519
U_CAPI UBool U_EXPORT2
 
520
ubidi_isInverse(UBiDi *pBiDi);
 
521
 
 
522
/**
 
523
 * Perform the Unicode BiDi algorithm. It is defined in the
 
524
 * <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Technical Report 9</a>,
 
525
 * version 5,
 
526
 * also described in The Unicode Standard, Version 3.0 .<p>
 
527
 *
 
528
 * This function takes a single plain text paragraph with or without
 
529
 * externally specified embedding levels from <quote>styled</quote> text
 
530
 * and computes the left-right-directionality of each character.<p>
 
531
 *
 
532
 * If the entire paragraph consists of text of only one direction, then
 
533
 * the function may not perform all the steps described by the algorithm,
 
534
 * i.e., some levels may not be the same as if all steps were performed.
 
535
 * This is not relevant for unidirectional text.<br>
 
536
 * For example, in pure LTR text with numbers the numbers would get
 
537
 * a resolved level of 2 higher than the surrounding text according to
 
538
 * the algorithm. This implementation may set all resolved levels to
 
539
 * the same value in such a case.<p>
 
540
 *
 
541
 * The text must be externally split into separate paragraphs (rule P1).
 
542
 * Paragraph separators (B) should appear at most at the very end.
 
543
 *
 
544
 * @param pBiDi A <code>UBiDi</code> object allocated with <code>ubidi_open()</code>
 
545
 *        which will be set to contain the reordering information,
 
546
 *        especially the resolved levels for all the characters in <code>text</code>.
 
547
 *
 
548
 * @param text is a pointer to the single-paragraph text that the
 
549
 *        BiDi algorithm will be performed on
 
550
 *        (step (P1) of the algorithm is performed externally).
 
551
 *        <strong>The text must be (at least) <code>length</code> long.</strong>
 
552
 *        This pointer is stored in the UBiDi object and can be retrieved
 
553
 *        with <code>ubidi_getText()</code>.
 
554
 *
 
555
 * @param length is the length of the text; if <code>length==-1</code> then
 
556
 *        the text must be zero-terminated.
 
557
 *
 
558
 * @param paraLevel specifies the default level for the paragraph;
 
559
 *        it is typically 0 (LTR) or 1 (RTL).
 
560
 *        If the function shall determine the paragraph level from the text,
 
561
 *        then <code>paraLevel</code> can be set to
 
562
 *        either <code>UBIDI_DEFAULT_LTR</code>
 
563
 *        or <code>UBIDI_DEFAULT_RTL</code>;
 
564
 *        if there is no strongly typed character, then
 
565
 *        the desired default is used (0 for LTR or 1 for RTL).
 
566
 *        Any other value between 0 and <code>UBIDI_MAX_EXPLICIT_LEVEL</code> is also valid,
 
567
 *        with odd levels indicating RTL.
 
568
 *
 
569
 * @param embeddingLevels (in) may be used to preset the embedding and override levels,
 
570
 *        ignoring characters like LRE and PDF in the text.
 
571
 *        A level overrides the directional property of its corresponding
 
572
 *        (same index) character if the level has the
 
573
 *        <code>UBIDI_LEVEL_OVERRIDE</code> bit set.<p>
 
574
 *        Except for that bit, it must be
 
575
 *        <code>paraLevel<=embeddingLevels[]<=UBIDI_MAX_EXPLICIT_LEVEL</code>.<p>
 
576
 *        <strong>Caution: </strong>A copy of this pointer, not of the levels,
 
577
 *        will be stored in the <code>UBiDi</code> object;
 
578
 *        the <code>embeddingLevels</code> array must not be
 
579
 *        deallocated before the <code>UBiDi</code> structure is destroyed or reused,
 
580
 *        and the <code>embeddingLevels</code>
 
581
 *        should not be modified to avoid unexpected results on subsequent BiDi operations.
 
582
 *        However, the <code>ubidi_setPara()</code> and
 
583
 *        <code>ubidi_setLine()</code> functions may modify some or all of the levels.<p>
 
584
 *        After the <code>UBiDi</code> object is reused or destroyed, the caller
 
585
 *        must take care of the deallocation of the <code>embeddingLevels</code> array.<p>
 
586
 *        <strong>The <code>embeddingLevels</code> array must be
 
587
 *        at least <code>length</code> long.</strong>
 
588
 *
 
589
 * @param pErrorCode must be a valid pointer to an error code value,
 
590
 *        which must not indicate a failure before the function call.
 
591
 * @stable
 
592
 */
 
593
U_CAPI void U_EXPORT2
 
594
ubidi_setPara(UBiDi *pBiDi, const UChar *text, UTextOffset length,
 
595
              UBiDiLevel paraLevel, UBiDiLevel *embeddingLevels,
 
596
              UErrorCode *pErrorCode);
 
597
 
 
598
/**
 
599
 * <code>ubidi_setLine()</code> sets a <code>UBiDi</code> to
 
600
 * contain the reordering information, especially the resolved levels,
 
601
 * for all the characters in a line of text. This line of text is
 
602
 * specified by referring to a <code>UBiDi</code> object representing
 
603
 * this information for a paragraph of text, and by specifying
 
604
 * a range of indexes in this paragraph.<p>
 
605
 * In the new line object, the indexes will range from 0 to <code>limit-start</code>.<p>
 
606
 *
 
607
 * This is used after calling <code>ubidi_setPara()</code>
 
608
 * for a paragraph, and after line-breaking on that paragraph.
 
609
 * It is not necessary if the paragraph is treated as a single line.<p>
 
610
 *
 
611
 * After line-breaking, rules (L1) and (L2) for the treatment of
 
612
 * trailing WS and for reordering are performed on
 
613
 * a <code>UBiDi</code> object that represents a line.<p>
 
614
 *
 
615
 * <strong>Important: </strong><code>pLineBiDi</code> shares data with
 
616
 * <code>pParaBiDi</code>.
 
617
 * You must destroy or reuse <code>pLineBiDi</code> before <code>pParaBiDi</code>.
 
618
 * In other words, you must destroy or reuse the <code>UBiDi</code> object for a line
 
619
 * before the object for its parent paragraph.<p>
 
620
 *
 
621
 * The text pointer that was stored in <code>pParaBiDi</code> is also copied,
 
622
 * and <code>start</code> is added to it so that it points to the beginning of the
 
623
 * line for this object.
 
624
 *
 
625
 * @param pParaBiDi is the parent paragraph object.
 
626
 *
 
627
 * @param start is the line's first index into the paragraph text.
 
628
 *
 
629
 * @param limit is just behind the line's last index into the paragraph text
 
630
 *        (its last index +1).<br>
 
631
 *        It must be <code>0<=start<=limit<=</code>paragraph length.
 
632
 *
 
633
 * @param pLineBiDi is the object that will now represent a line of the paragraph.
 
634
 *
 
635
 * @param pErrorCode must be a valid pointer to an error code value,
 
636
 *        which must not indicate a failure before the function call.
 
637
 *
 
638
 * @see ubidi_setPara
 
639
 * @stable
 
640
 */
 
641
U_CAPI void U_EXPORT2
 
642
ubidi_setLine(const UBiDi *pParaBiDi,
 
643
              UTextOffset start, UTextOffset limit,
 
644
              UBiDi *pLineBiDi,
 
645
              UErrorCode *pErrorCode);
 
646
 
 
647
/**
 
648
 * Get the directionality of the text.
 
649
 *
 
650
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
651
 *
 
652
 * @return A <code>UBIDI_XXX</code> value that indicates if the entire text
 
653
 *         represented by this object is unidirectional,
 
654
 *         and which direction, or if it is mixed-directional.
 
655
 *
 
656
 * @see UBiDiDirection
 
657
 * @stable
 
658
 */
 
659
U_CAPI UBiDiDirection U_EXPORT2
 
660
ubidi_getDirection(const UBiDi *pBiDi);
 
661
 
 
662
/**
 
663
 * Get the pointer to the text.
 
664
 *
 
665
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
666
 *
 
667
 * @return The pointer to the text that the UBiDi object was created for.
 
668
 *
 
669
 * @see ubidi_setPara
 
670
 * @see ubidi_setLine
 
671
 * @stable
 
672
 */
 
673
U_CAPI const UChar * U_EXPORT2
 
674
ubidi_getText(const UBiDi *pBiDi);
 
675
 
 
676
/**
 
677
 * Get the length of the text.
 
678
 *
 
679
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
680
 *
 
681
 * @return The length of the text that the UBiDi object was created for.
 
682
 * @stable
 
683
 */
 
684
U_CAPI UTextOffset U_EXPORT2
 
685
ubidi_getLength(const UBiDi *pBiDi);
 
686
 
 
687
/**
 
688
 * Get the paragraph level of the text.
 
689
 *
 
690
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
691
 *
 
692
 * @return The paragraph level.
 
693
 *
 
694
 * @see UBiDiLevel
 
695
 * @stable
 
696
 */
 
697
U_CAPI UBiDiLevel U_EXPORT2
 
698
ubidi_getParaLevel(const UBiDi *pBiDi);
 
699
 
 
700
/**
 
701
 * Get the level for one character.
 
702
 *
 
703
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
704
 *
 
705
 * @param charIndex the index of a character.
 
706
 *
 
707
 * @return The level for the character at charIndex.
 
708
 *
 
709
 * @see UBiDiLevel
 
710
 * @stable
 
711
 */
 
712
U_CAPI UBiDiLevel U_EXPORT2
 
713
ubidi_getLevelAt(const UBiDi *pBiDi, UTextOffset charIndex);
 
714
 
 
715
/**
 
716
 * Get an array of levels for each character.<p>
 
717
 *
 
718
 * Note that this function may allocate memory under some
 
719
 * circumstances, unlike <code>ubidi_getLevelAt()</code>.
 
720
 *
 
721
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
722
 *
 
723
 * @param pErrorCode must be a valid pointer to an error code value,
 
724
 *        which must not indicate a failure before the function call.
 
725
 *
 
726
 * @return The levels array for the text,
 
727
 *         or <code>NULL</code> if an error occurs.
 
728
 *
 
729
 * @see UBiDiLevel
 
730
 * @stable
 
731
 */
 
732
U_CAPI const UBiDiLevel * U_EXPORT2
 
733
ubidi_getLevels(UBiDi *pBiDi, UErrorCode *pErrorCode);
 
734
 
 
735
/**
 
736
 * Get a logical run.
 
737
 * This function returns information about a run and is used
 
738
 * to retrieve runs in logical order.<p>
 
739
 * This is especially useful for line-breaking on a paragraph.
 
740
 *
 
741
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
742
 *
 
743
 * @param logicalStart is the first character of the run.
 
744
 *
 
745
 * @param pLogicalLimit will receive the limit of the run.
 
746
 *        The l-value that you point to here may be the
 
747
 *        same expression (variable) as the one for
 
748
 *        <code>logicalStart</code>.
 
749
 *        This pointer can be <code>NULL</code> if this
 
750
 *        value is not necessary.
 
751
 *
 
752
 * @param pLevel will receive the level of the run.
 
753
 *        This pointer can be <code>NULL</code> if this
 
754
 *        value is not necessary.
 
755
 * @stable
 
756
 */
 
757
U_CAPI void U_EXPORT2
 
758
ubidi_getLogicalRun(const UBiDi *pBiDi, UTextOffset logicalStart,
 
759
                    UTextOffset *pLogicalLimit, UBiDiLevel *pLevel);
 
760
 
 
761
/**
 
762
 * Get the number of runs.
 
763
 * This function may invoke the actual reordering on the
 
764
 * <code>UBiDi</code> object, after <code>ubidi_setPara()</code>
 
765
 * may have resolved only the levels of the text. Therefore,
 
766
 * <code>ubidi_countRuns()</code> may have to allocate memory,
 
767
 * and may fail doing so.
 
768
 *
 
769
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
770
 *
 
771
 * @param pErrorCode must be a valid pointer to an error code value,
 
772
 *        which must not indicate a failure before the function call.
 
773
 *
 
774
 * @return The number of runs.
 
775
 * @stable
 
776
 */
 
777
U_CAPI UTextOffset U_EXPORT2
 
778
ubidi_countRuns(UBiDi *pBiDi, UErrorCode *pErrorCode);
 
779
 
 
780
/**
 
781
 * Get one run's logical start, length, and directionality,
 
782
 * which can be 0 for LTR or 1 for RTL.
 
783
 * In an RTL run, the character at the logical start is
 
784
 * visually on the right of the displayed run.
 
785
 * The length is the number of characters in the run.<p>
 
786
 * <code>ubidi_countRuns()</code> should be called
 
787
 * before the runs are retrieved.
 
788
 *
 
789
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
790
 *
 
791
 * @param runIndex is the number of the run in visual order, in the
 
792
 *        range <code>[0..ubidi_countRuns(pBiDi)-1]</code>.
 
793
 *
 
794
 * @param pLogicalStart is the first logical character index in the text.
 
795
 *        The pointer may be <code>NULL</code> if this index is not needed.
 
796
 *
 
797
 * @param pLength is the number of characters (at least one) in the run.
 
798
 *        The pointer may be <code>NULL</code> if this is not needed.
 
799
 *
 
800
 * @return the directionality of the run,
 
801
 *         <code>UBIDI_LTR==0</code> or <code>UBIDI_RTL==1</code>,
 
802
 *         never <code>UBIDI_MIXED</code>.
 
803
 *
 
804
 * @see ubidi_countRuns
 
805
 *
 
806
 * Example:
 
807
 * <pre>
 
808
 * \code
 
809
 * UTextOffset i, count=ubidi_countRuns(pBiDi),
 
810
 *         logicalStart, visualIndex=0, length;
 
811
 * for(i=0; i<count; ++i) {
 
812
 *    if(UBIDI_LTR==ubidi_getVisualRun(pBiDi, i, &logicalStart, &length)) {
 
813
 *         do { // LTR
 
814
 *             show_char(text[logicalStart++], visualIndex++);
 
815
 *         } while(--length>0);
 
816
 *     } else {
 
817
 *         logicalStart+=length;  // logicalLimit
 
818
 *         do { // RTL
 
819
 *             show_char(text[--logicalStart], visualIndex++);
 
820
 *         } while(--length>0);
 
821
 *     }
 
822
 * }
 
823
 *\endcode
 
824
 * </pre>
 
825
 *
 
826
 * Note that in right-to-left runs, code like this places
 
827
 * modifier letters before base characters and second surrogates
 
828
 * before first ones.
 
829
 * @stable
 
830
 */
 
831
U_CAPI UBiDiDirection U_EXPORT2
 
832
ubidi_getVisualRun(UBiDi *pBiDi, UTextOffset runIndex,
 
833
                   UTextOffset *pLogicalStart, UTextOffset *pLength);
 
834
 
 
835
/**
 
836
 * Get the visual position from a logical text position.
 
837
 * If such a mapping is used many times on the same
 
838
 * <code>UBiDi</code> object, then calling
 
839
 * <code>ubidi_getLogicalMap()</code> is more efficient.<p>
 
840
 *
 
841
 * Note that in right-to-left runs, this mapping places
 
842
 * modifier letters before base characters and second surrogates
 
843
 * before first ones.
 
844
 *
 
845
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
846
 *
 
847
 * @param logicalIndex is the index of a character in the text.
 
848
 *
 
849
 * @param pErrorCode must be a valid pointer to an error code value,
 
850
 *        which must not indicate a failure before the function call.
 
851
 *
 
852
 * @return The visual position of this character.
 
853
 *
 
854
 * @see ubidi_getLogicalMap
 
855
 * @see ubidi_getLogicalIndex
 
856
 * @stable
 
857
 */
 
858
U_CAPI UTextOffset U_EXPORT2
 
859
ubidi_getVisualIndex(UBiDi *pBiDi, UTextOffset logicalIndex, UErrorCode *pErrorCode);
 
860
 
 
861
/**
 
862
 * Get the logical text position from a visual position.
 
863
 * If such a mapping is used many times on the same
 
864
 * <code>UBiDi</code> object, then calling
 
865
 * <code>ubidi_getVisualMap()</code> is more efficient.<p>
 
866
 *
 
867
 * This is the inverse function to <code>ubidi_getVisualIndex()</code>.
 
868
 *
 
869
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
870
 *
 
871
 * @param visualIndex is the visual position of a character.
 
872
 *
 
873
 * @param pErrorCode must be a valid pointer to an error code value,
 
874
 *        which must not indicate a failure before the function call.
 
875
 *
 
876
 * @return The index of this character in the text.
 
877
 *
 
878
 * @see ubidi_getVisualMap
 
879
 * @see ubidi_getVisualIndex
 
880
 * @stable
 
881
 */
 
882
U_CAPI UTextOffset U_EXPORT2
 
883
ubidi_getLogicalIndex(UBiDi *pBiDi, UTextOffset visualIndex, UErrorCode *pErrorCode);
 
884
 
 
885
/**
 
886
 * Get a logical-to-visual index map (array) for the characters in the UBiDi
 
887
 * (paragraph or line) object.
 
888
 *
 
889
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
890
 *
 
891
 * @param indexMap is a pointer to an array of <code>ubidi_getLength()</code>
 
892
 *        indexes which will reflect the reordering of the characters.
 
893
 *        The array does not need to be initialized.<p>
 
894
 *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.<p>
 
895
 *
 
896
 * @param pErrorCode must be a valid pointer to an error code value,
 
897
 *        which must not indicate a failure before the function call.
 
898
 *
 
899
 * @see ubidi_getVisualMap
 
900
 * @see ubidi_getVisualIndex
 
901
 * @stable
 
902
 */
 
903
U_CAPI void U_EXPORT2
 
904
ubidi_getLogicalMap(UBiDi *pBiDi, UTextOffset *indexMap, UErrorCode *pErrorCode);
 
905
 
 
906
/**
 
907
 * Get a visual-to-logical index map (array) for the characters in the UBiDi
 
908
 * (paragraph or line) object.
 
909
 *
 
910
 * @param pBiDi is the paragraph or line <code>UBiDi</code> object.
 
911
 *
 
912
 * @param indexMap is a pointer to an array of <code>ubidi_getLength()</code>
 
913
 *        indexes which will reflect the reordering of the characters.
 
914
 *        The array does not need to be initialized.<p>
 
915
 *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.<p>
 
916
 *
 
917
 * @param pErrorCode must be a valid pointer to an error code value,
 
918
 *        which must not indicate a failure before the function call.
 
919
 *
 
920
 * @see ubidi_getLogicalMap
 
921
 * @see ubidi_getLogicalIndex
 
922
 * @stable
 
923
 */
 
924
U_CAPI void U_EXPORT2
 
925
ubidi_getVisualMap(UBiDi *pBiDi, UTextOffset *indexMap, UErrorCode *pErrorCode);
 
926
 
 
927
/**
 
928
 * This is a convenience function that does not use a UBiDi object.
 
929
 * It is intended to be used for when an application has determined the levels
 
930
 * of objects (character sequences) and just needs to have them reordered (L2).
 
931
 * This is equivalent to using <code>ubidi_getLogicalMap</code> on a
 
932
 * <code>UBiDi</code> object.
 
933
 *
 
934
 * @param levels is an array with <code>length</code> levels that have been determined by
 
935
 *        the application.
 
936
 *
 
937
 * @param length is the number of levels in the array, or, semantically,
 
938
 *        the number of objects to be reordered.
 
939
 *        It must be <code>length>0</code>.
 
940
 *
 
941
 * @param indexMap is a pointer to an array of <code>length</code>
 
942
 *        indexes which will reflect the reordering of the characters.
 
943
 *        The array does not need to be initialized.<p>
 
944
 *        The index map will result in <code>indexMap[logicalIndex]==visualIndex</code>.
 
945
 * @stable
 
946
 */
 
947
U_CAPI void U_EXPORT2
 
948
ubidi_reorderLogical(const UBiDiLevel *levels, UTextOffset length, UTextOffset *indexMap);
 
949
 
 
950
/**
 
951
 * This is a convenience function that does not use a UBiDi object.
 
952
 * It is intended to be used for when an application has determined the levels
 
953
 * of objects (character sequences) and just needs to have them reordered (L2).
 
954
 * This is equivalent to using <code>ubidi_getVisualMap</code> on a
 
955
 * <code>UBiDi</code> object.
 
956
 *
 
957
 * @param levels is an array with <code>length</code> levels that have been determined by
 
958
 *        the application.
 
959
 *
 
960
 * @param length is the number of levels in the array, or, semantically,
 
961
 *        the number of objects to be reordered.
 
962
 *        It must be <code>length>0</code>.
 
963
 *
 
964
 * @param indexMap is a pointer to an array of <code>length</code>
 
965
 *        indexes which will reflect the reordering of the characters.
 
966
 *        The array does not need to be initialized.<p>
 
967
 *        The index map will result in <code>indexMap[visualIndex]==logicalIndex</code>.
 
968
 * @stable
 
969
 */
 
970
U_CAPI void U_EXPORT2
 
971
ubidi_reorderVisual(const UBiDiLevel *levels, UTextOffset length, UTextOffset *indexMap);
 
972
 
 
973
/**
 
974
 * Invert an index map.
 
975
 * The one-to-one index mapping of the first map is inverted and written to
 
976
 * the second one.
 
977
 *
 
978
 * @param srcMap is an array with <code>length</code> indexes
 
979
 *        which define the original mapping.
 
980
 *
 
981
 * @param destMap is an array with <code>length</code> indexes
 
982
 *        which will be filled with the inverse mapping.
 
983
 *
 
984
 * @param length is the length of each array.
 
985
 * @stable
 
986
 */
 
987
U_CAPI void U_EXPORT2
 
988
ubidi_invertMap(const UTextOffset *srcMap, UTextOffset *destMap, UTextOffset length);
 
989
 
 
990
/** option flags for ubidi_writeReordered() */
 
991
 
 
992
/**
 
993
 * option bit for ubidi_writeReordered():
 
994
 * keep combining characters after their base characters in RTL runs
 
995
 *
 
996
 * @see ubidi_writeReordered
 
997
 * @stable
 
998
 */
 
999
#define UBIDI_KEEP_BASE_COMBINING       1
 
1000
 
 
1001
/**
 
1002
 * option bit for ubidi_writeReordered():
 
1003
 * replace characters with the "mirrored" property in RTL runs
 
1004
 * by their mirror-image mappings
 
1005
 *
 
1006
 * @see ubidi_writeReordered
 
1007
 * @stable
 
1008
 */
 
1009
#define UBIDI_DO_MIRRORING              2
 
1010
 
 
1011
/**
 
1012
 * option bit for ubidi_writeReordered():
 
1013
 * surround the run with LRMs if necessary;
 
1014
 * this is part of the approximate "inverse BiDi" algorithm
 
1015
 *
 
1016
 * @see ubidi_setInverse
 
1017
 * @see ubidi_writeReordered
 
1018
 * @stable
 
1019
 */
 
1020
#define UBIDI_INSERT_LRM_FOR_NUMERIC    4
 
1021
 
 
1022
/**
 
1023
 * option bit for ubidi_writeReordered():
 
1024
 * remove BiDi control characters
 
1025
 * (this does not affect UBIDI_INSERT_LRM_FOR_NUMERIC)
 
1026
 *
 
1027
 * @see ubidi_writeReordered
 
1028
 * @stable
 
1029
 */
 
1030
#define UBIDI_REMOVE_BIDI_CONTROLS      8
 
1031
 
 
1032
/**
 
1033
 * option bit for ubidi_writeReordered():
 
1034
 * write the output in reverse order
 
1035
 *
 
1036
 * <p>This has the same effect as calling <code>ubidi_writeReordered()</code>
 
1037
 * first without this option, and then calling
 
1038
 * <code>ubidi_writeReverse()</code> without mirroring.
 
1039
 * Doing this in the same step is faster and avoids a temporary buffer.
 
1040
 * An example for using this option is output to a character terminal that
 
1041
 * is designed for RTL scripts and stores text in reverse order.</p>
 
1042
 *
 
1043
 * @see ubidi_writeReordered
 
1044
 * @stable
 
1045
 */
 
1046
#define UBIDI_OUTPUT_REVERSE            16
 
1047
 
 
1048
/**
 
1049
 * Take a <code>UBiDi</code> object containing the reordering
 
1050
 * information for one paragraph or line of text as set by
 
1051
 * <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code> and
 
1052
 * write a reordered string to the destination buffer.
 
1053
 *
 
1054
 * This function preserves the integrity of characters with multiple
 
1055
 * code units and (optionally) modifier letters.
 
1056
 * Characters in RTL runs can be replaced by mirror-image characters
 
1057
 * in the destination buffer. Note that "real" mirroring has
 
1058
 * to be done in a rendering engine by glyph selection
 
1059
 * and that for many "mirrored" characters there are no
 
1060
 * Unicode characters as mirror-image equivalents.
 
1061
 * There are also options to insert or remove BiDi control
 
1062
 * characters; see the description of the <code>destSize</code>
 
1063
 * and <code>options</code> parameters and of the option bit flags.
 
1064
 *
 
1065
 * @param pBiDi A pointer to a <code>UBiDi</code> object that
 
1066
 *              is set by <code>ubidi_setPara()</code> or
 
1067
 *              <code>ubidi_setLine()</code> and contains the reordering
 
1068
 *              information for the text that it was defined for,
 
1069
 *              as well as a pointer to that text.
 
1070
 *              <p>The text was aliased (only the pointer was stored
 
1071
 *              without copying the contents) and must not have been modified
 
1072
 *              since the <code>ubidi_setPara()</code> call.</p>
 
1073
 *
 
1074
 * @param dest A pointer to where the reordered text is to be copied.
 
1075
 *             The source text and <code>dest[destSize]</code>
 
1076
 *             must not overlap.
 
1077
 *
 
1078
 * @param destSize The size of the <code>dest</code> buffer,
 
1079
 *                 in number of UChars.
 
1080
 *                 If the <code>UBIDI_INSERT_LRM_FOR_NUMERIC</code>
 
1081
 *                 option is set, then the destination length could be
 
1082
 *                 as large as
 
1083
 *                 <code>ubidi_getLength(pBiDi)+2*ubidi_countRuns(pBiDi)</code>.
 
1084
 *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
 
1085
 *                 is set, then the destination length may be less than
 
1086
 *                 <code>ubidi_getLength(pBiDi)</code>.
 
1087
 *                 If none of these options is set, then the destination length
 
1088
 *                 will be exactly <code>ubidi_getLength(pBiDi)</code>.
 
1089
 *
 
1090
 * @param options A bit set of options for the reordering that control
 
1091
 *                how the reordered text is written.
 
1092
 *                The options include mirroring the characters on a code
 
1093
 *                point basis and inserting LRM characters, which is used
 
1094
 *                especially for transforming visually stored text
 
1095
 *                to logically stored text (although this is still an
 
1096
 *                imperfect implementation of an "inverse BiDi" algorithm
 
1097
 *                because it uses the "forward BiDi" algorithm at its core).
 
1098
 *
 
1099
 * @param pErrorCode must be a valid pointer to an error code value,
 
1100
 *        which must not indicate a failure before the function call.
 
1101
 *
 
1102
 * @return The length of the output string.
 
1103
 * @stable
 
1104
 */
 
1105
U_CAPI UTextOffset U_EXPORT2
 
1106
ubidi_writeReordered(UBiDi *pBiDi,
 
1107
                     UChar *dest, int32_t destSize,
 
1108
                     uint16_t options,
 
1109
                     UErrorCode *pErrorCode);
 
1110
 
 
1111
/**
 
1112
 * Reverse a Right-To-Left run of Unicode text.
 
1113
 *
 
1114
 * This function preserves the integrity of characters with multiple
 
1115
 * code units and (optionally) modifier letters.
 
1116
 * Characters can be replaced by mirror-image characters
 
1117
 * in the destination buffer. Note that "real" mirroring has
 
1118
 * to be done in a rendering engine by glyph selection
 
1119
 * and that for many "mirrored" characters there are no
 
1120
 * Unicode characters as mirror-image equivalents.
 
1121
 * There are also options to insert or remove BiDi control
 
1122
 * characters.
 
1123
 *
 
1124
 * This function is the implementation for reversing RTL runs as part
 
1125
 * of <code>ubidi_writeReordered()</code>. For detailed descriptions
 
1126
 * of the parameters, see there.
 
1127
 * Since no BiDi controls are inserted here, the output string length
 
1128
 * will never exceed <code>srcLength</code>.
 
1129
 *
 
1130
 * @see ubidi_writeReordered
 
1131
 *
 
1132
 * @param src A pointer to the RTL run text.
 
1133
 *
 
1134
 * @param srcLength The length of the RTL run.
 
1135
 *
 
1136
 * @param dest A pointer to where the reordered text is to be copied.
 
1137
 *             <code>src[srcLength]</code> and <code>dest[destSize]</code>
 
1138
 *             must not overlap.
 
1139
 *
 
1140
 * @param destSize The size of the <code>dest</code> buffer,
 
1141
 *                 in number of UChars.
 
1142
 *                 If the <code>UBIDI_REMOVE_BIDI_CONTROLS</code> option
 
1143
 *                 is set, then the destination length may be less than
 
1144
 *                 <code>srcLength</code>.
 
1145
 *                 If this option is not set, then the destination length
 
1146
 *                 will be exactly <code>srcLength</code>.
 
1147
 *
 
1148
 * @param options A bit set of options for the reordering that control
 
1149
 *                how the reordered text is written.
 
1150
 *                See <code>ubidi_writeReordered()</code>.
 
1151
 *
 
1152
 * @param pErrorCode must be a valid pointer to an error code value,
 
1153
 *        which must not indicate a failure before the function call.
 
1154
 *
 
1155
 * @return The length of the output string.
 
1156
 * @stable
 
1157
 */
 
1158
U_CAPI UTextOffset U_EXPORT2
 
1159
ubidi_writeReverse(const UChar *src, int32_t srcLength,
 
1160
                   UChar *dest, int32_t destSize,
 
1161
                   uint16_t options,
 
1162
                   UErrorCode *pErrorCode);
 
1163
/*#define BIDI_SAMPLE_CODE*/
 
1164
/*@}*/
 
1165
 
 
1166
/*@}*/
 
1167
 
 
1168
/*@}*/
 
1169
 
 
1170
#endif