/
ubidi.h
2013 lines (1943 loc) · 81.1 KB
/
ubidi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
******************************************************************************
*
* Copyright (C) 1999-2008, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
* file name: ubidi.h
* encoding: US-ASCII
* tab size: 8 (not used)
* indentation:4
*
* created on: 1999jul27
* created by: Markus W. Scherer, updated by Matitiahu Allouche
*/
#ifndef UBIDI_H
#define UBIDI_H
#include "unicode/utypes.h"
#include "unicode/uchar.h"
/**
*\file
* \brief C API: Bidi algorithm
*
* <h2>Bidi algorithm for ICU</h2>
*
* This is an implementation of the Unicode Bidirectional algorithm.
* The algorithm is defined in the
* <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Annex #9</a>,
* version 13, also described in The Unicode Standard, Version 4.0 .<p>
*
* Note: Libraries that perform a bidirectional algorithm and
* reorder strings accordingly are sometimes called "Storage Layout Engines".
* ICU's Bidi and shaping (u_shapeArabic()) APIs can be used at the core of such
* "Storage Layout Engines".
*
* <h3>General remarks about the API:</h3>
*
* In functions with an error code parameter,
* the <code>pErrorCode</code> pointer must be valid
* and the value that it points to must not indicate a failure before
* the function call. Otherwise, the function returns immediately.
* After the function call, the value indicates success or failure.<p>
*
* The "limit" of a sequence of characters is the position just after their
* last character, i.e., one more than that position.<p>
*
* Some of the API functions provide access to "runs".
* Such a "run" is defined as a sequence of characters
* that are at the same embedding level
* after performing the Bidi algorithm.<p>
*
* @author Markus W. Scherer
* @version 1.0
*
*
* <h4> Sample code for the ICU Bidi API </h4>
*
* <h5>Rendering a paragraph with the ICU Bidi API</h5>
*
* This is (hypothetical) sample code that illustrates
* how the ICU Bidi API could be used to render a paragraph of text.
* Rendering code depends highly on the graphics system,
* therefore this sample code must make a lot of assumptions,
* which may or may not match any existing graphics system's properties.
*
* <p>The basic assumptions are:</p>
* <ul>
* <li>Rendering is done from left to right on a horizontal line.</li>
* <li>A run of single-style, unidirectional text can be rendered at once.</li>
* <li>Such a run of text is passed to the graphics system with
* characters (code units) in logical order.</li>
* <li>The line-breaking algorithm is very complicated
* and Locale-dependent -
* and therefore its implementation omitted from this sample code.</li>
* </ul>
*
* <pre>
* \code
*#include "unicode/ubidi.h"
*
*typedef enum {
* styleNormal=0, styleSelected=1,
* styleBold=2, styleItalics=4,
* styleSuper=8, styleSub=16
*} Style;
*
*typedef struct { int32_t limit; Style style; } StyleRun;
*
*int getTextWidth(const UChar *text, int32_t start, int32_t limit,
* const StyleRun *styleRuns, int styleRunCount);
*
* // set *pLimit and *pStyleRunLimit for a line
* // from text[start] and from styleRuns[styleRunStart]
* // using ubidi_getLogicalRun(para, ...)
*void getLineBreak(const UChar *text, int32_t start, int32_t *pLimit,
* UBiDi *para,
* const StyleRun *styleRuns, int styleRunStart, int *pStyleRunLimit,
* int *pLineWidth);
*
* // render runs on a line sequentially, always from left to right
*
* // prepare rendering a new line
* void startLine(UBiDiDirection textDirection, int lineWidth);
*
* // render a run of text and advance to the right by the run width
* // the text[start..limit-1] is always in logical order
* void renderRun(const UChar *text, int32_t start, int32_t limit,
* UBiDiDirection textDirection, Style style);
*
* // We could compute a cross-product
* // from the style runs with the directional runs
* // and then reorder it.
* // Instead, here we iterate over each run type
* // and render the intersections -
* // with shortcuts in simple (and common) cases.
* // renderParagraph() is the main function.
*
* // render a directional run with
* // (possibly) multiple style runs intersecting with it
* void renderDirectionalRun(const UChar *text,
* int32_t start, int32_t limit,
* UBiDiDirection direction,
* const StyleRun *styleRuns, int styleRunCount) {
* int i;
*
* // iterate over style runs
* if(direction==UBIDI_LTR) {
* int styleLimit;
*
* for(i=0; i<styleRunCount; ++i) {
* styleLimit=styleRun[i].limit;
* if(start<styleLimit) {
* if(styleLimit>limit) { styleLimit=limit; }
* renderRun(text, start, styleLimit,
* direction, styleRun[i].style);
* if(styleLimit==limit) { break; }
* start=styleLimit;
* }
* }
* } else {
* int styleStart;
*
* for(i=styleRunCount-1; i>=0; --i) {
* if(i>0) {
* styleStart=styleRun[i-1].limit;
* } else {
* styleStart=0;
* }
* if(limit>=styleStart) {
* if(styleStart<start) { styleStart=start; }
* renderRun(text, styleStart, limit,
* direction, styleRun[i].style);
* if(styleStart==start) { break; }
* limit=styleStart;
* }
* }
* }
* }
*
* // the line object represents text[start..limit-1]
* void renderLine(UBiDi *line, const UChar *text,
* int32_t start, int32_t limit,
* const StyleRun *styleRuns, int styleRunCount) {
* UBiDiDirection direction=ubidi_getDirection(line);
* if(direction!=UBIDI_MIXED) {
* // unidirectional
* if(styleRunCount<=1) {
* renderRun(text, start, limit, direction, styleRuns[0].style);
* } else {
* renderDirectionalRun(text, start, limit,
* direction, styleRuns, styleRunCount);
* }
* } else {
* // mixed-directional
* int32_t count, i, length;
* UBiDiLevel level;
*
* count=ubidi_countRuns(para, pErrorCode);
* if(U_SUCCESS(*pErrorCode)) {
* if(styleRunCount<=1) {
* Style style=styleRuns[0].style;
*
* // iterate over directional runs
* for(i=0; i<count; ++i) {
* direction=ubidi_getVisualRun(para, i, &start, &length);
* renderRun(text, start, start+length, direction, style);
* }
* } else {
* int32_t j;
*
* // iterate over both directional and style runs
* for(i=0; i<count; ++i) {
* direction=ubidi_getVisualRun(line, i, &start, &length);
* renderDirectionalRun(text, start, start+length,
* direction, styleRuns, styleRunCount);
* }
* }
* }
* }
* }
*
*void renderParagraph(const UChar *text, int32_t length,
* UBiDiDirection textDirection,
* const StyleRun *styleRuns, int styleRunCount,
* int lineWidth,
* UErrorCode *pErrorCode) {
* UBiDi *para;
*
* if(pErrorCode==NULL || U_FAILURE(*pErrorCode) || length<=0) {
* return;
* }
*
* para=ubidi_openSized(length, 0, pErrorCode);
* if(para==NULL) { return; }
*
* ubidi_setPara(para, text, length,
* textDirection ? UBIDI_DEFAULT_RTL : UBIDI_DEFAULT_LTR,
* NULL, pErrorCode);
* if(U_SUCCESS(*pErrorCode)) {
* UBiDiLevel paraLevel=1&ubidi_getParaLevel(para);
* StyleRun styleRun={ length, styleNormal };
* int width;
*
* if(styleRuns==NULL || styleRunCount<=0) {
* styleRunCount=1;
* styleRuns=&styleRun;
* }
*
* // assume styleRuns[styleRunCount-1].limit>=length
*
* width=getTextWidth(text, 0, length, styleRuns, styleRunCount);
* if(width<=lineWidth) {
* // everything fits onto one line
*
* // prepare rendering a new line from either left or right
* startLine(paraLevel, width);
*
* renderLine(para, text, 0, length,
* styleRuns, styleRunCount);
* } else {
* UBiDi *line;
*
* // we need to render several lines
* line=ubidi_openSized(length, 0, pErrorCode);
* if(line!=NULL) {
* int32_t start=0, limit;
* int styleRunStart=0, styleRunLimit;
*
* for(;;) {
* limit=length;
* styleRunLimit=styleRunCount;
* getLineBreak(text, start, &limit, para,
* styleRuns, styleRunStart, &styleRunLimit,
* &width);
* ubidi_setLine(para, start, limit, line, pErrorCode);
* if(U_SUCCESS(*pErrorCode)) {
* // prepare rendering a new line
* // from either left or right
* startLine(paraLevel, width);
*
* renderLine(line, text, start, limit,
* styleRuns+styleRunStart,
* styleRunLimit-styleRunStart);
* }
* if(limit==length) { break; }
* start=limit;
* styleRunStart=styleRunLimit-1;
* if(start>=styleRuns[styleRunStart].limit) {
* ++styleRunStart;
* }
* }
*
* ubidi_close(line);
* }
* }
* }
*
* ubidi_close(para);
*}
*\endcode
* </pre>
*/
/*DOCXX_TAG*/
/*@{*/
/**
* UBiDiLevel is the type of the level values in this
* Bidi implementation.
* It holds an embedding level and indicates the visual direction
* by its bit 0 (even/odd value).<p>
*
* It can also hold non-level values for the
* <code>paraLevel</code> and <code>embeddingLevels</code>
* arguments of <code>ubidi_setPara()</code>; there:
* <ul>
* <li>bit 7 of an <code>embeddingLevels[]</code>
* value indicates whether the using application is
* specifying the level of a character to <i>override</i> whatever the
* Bidi implementation would resolve it to.</li>
* <li><code>paraLevel</code> can be set to the
* pseudo-level values <code>UBIDI_DEFAULT_LTR</code>
* and <code>UBIDI_DEFAULT_RTL</code>.</li>
* </ul>
*
* @see ubidi_setPara
*
* <p>The related constants are not real, valid level values.
* <code>UBIDI_DEFAULT_XXX</code> can be used to specify
* a default for the paragraph level for
* when the <code>ubidi_setPara()</code> function
* shall determine it but there is no
* strongly typed character in the input.<p>
*
* Note that the value for <code>UBIDI_DEFAULT_LTR</code> is even
* and the one for <code>UBIDI_DEFAULT_RTL</code> is odd,
* just like with normal LTR and RTL level values -
* these special values are designed that way. Also, the implementation
* assumes that UBIDI_MAX_EXPLICIT_LEVEL is odd.
*
* @see UBIDI_DEFAULT_LTR
* @see UBIDI_DEFAULT_RTL
* @see UBIDI_LEVEL_OVERRIDE
* @see UBIDI_MAX_EXPLICIT_LEVEL
* @stable ICU 2.0
*/
typedef uint8_t UBiDiLevel;
/** Paragraph level setting.<p>
*
* Constant indicating that the base direction depends on the first strong
* directional character in the text according to the Unicode Bidirectional
* Algorithm. If no strong directional character is present,
* then set the paragraph level to 0 (left-to-right).<p>
*
* If this value is used in conjunction with reordering modes
* <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
* <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
* is assumed to be visual LTR, and the text after reordering is required
* to be the corresponding logical string with appropriate contextual
* direction. The direction of the result string will be RTL if either
* the righmost or leftmost strong character of the source text is RTL
* or Arabic Letter, the direction will be LTR otherwise.<p>
*
* If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
* be added at the beginning of the result string to ensure round trip
* (that the result string, when reordered back to visual, will produce
* the original source text).
* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
* @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
* @stable ICU 2.0
*/
#define UBIDI_DEFAULT_LTR 0xfe
/** Paragraph level setting.<p>
*
* Constant indicating that the base direction depends on the first strong
* directional character in the text according to the Unicode Bidirectional
* Algorithm. If no strong directional character is present,
* then set the paragraph level to 1 (right-to-left).<p>
*
* If this value is used in conjunction with reordering modes
* <code>UBIDI_REORDER_INVERSE_LIKE_DIRECT</code> or
* <code>UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the text to reorder
* is assumed to be visual LTR, and the text after reordering is required
* to be the corresponding logical string with appropriate contextual
* direction. The direction of the result string will be RTL if either
* the righmost or leftmost strong character of the source text is RTL
* or Arabic Letter, or if the text contains no strong character;
* the direction will be LTR otherwise.<p>
*
* If reordering option <code>UBIDI_OPTION_INSERT_MARKS</code> is set, an RLM may
* be added at the beginning of the result string to ensure round trip
* (that the result string, when reordered back to visual, will produce
* the original source text).
* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
* @see UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL
* @stable ICU 2.0
*/
#define UBIDI_DEFAULT_RTL 0xff
/**
* Maximum explicit embedding level.
* (The maximum resolved level can be up to <code>UBIDI_MAX_EXPLICIT_LEVEL+1</code>).
* @stable ICU 2.0
*/
#define UBIDI_MAX_EXPLICIT_LEVEL 61
/** Bit flag for level input.
* Overrides directional properties.
* @stable ICU 2.0
*/
#define UBIDI_LEVEL_OVERRIDE 0x80
/**
* Special value which can be returned by the mapping functions when a logical
* index has no corresponding visual index or vice-versa. This may happen
* for the logical-to-visual mapping of a Bidi control when option
* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> is specified. This can also happen
* for the visual-to-logical mapping of a Bidi mark (LRM or RLM) inserted
* by option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
* @see ubidi_getVisualIndex
* @see ubidi_getVisualMap
* @see ubidi_getLogicalIndex
* @see ubidi_getLogicalMap
* @stable ICU 3.6
*/
#define UBIDI_MAP_NOWHERE (-1)
/**
* <code>UBiDiDirection</code> values indicate the text direction.
* @stable ICU 2.0
*/
enum UBiDiDirection {
/** All left-to-right text. This is a 0 value. @stable ICU 2.0 */
UBIDI_LTR,
/** All right-to-left text. This is a 1 value. @stable ICU 2.0 */
UBIDI_RTL,
/** Mixed-directional text. @stable ICU 2.0 */
UBIDI_MIXED
};
/** @stable ICU 2.0 */
typedef enum UBiDiDirection UBiDiDirection;
/**
* Forward declaration of the <code>UBiDi</code> structure for the declaration of
* the API functions. Its fields are implementation-specific.<p>
* This structure holds information about a paragraph (or multiple paragraphs)
* of text with Bidi-algorithm-related details, or about one line of
* such a paragraph.<p>
* Reordering can be done on a line, or on one or more paragraphs which are
* then interpreted each as one single line.
* @stable ICU 2.0
*/
struct UBiDi;
/** @stable ICU 2.0 */
typedef struct UBiDi UBiDi;
/**
* Allocate a <code>UBiDi</code> structure.
* Such an object is initially empty. It is assigned
* the Bidi properties of a piece of text containing one or more paragraphs
* by <code>ubidi_setPara()</code>
* or the Bidi properties of a line within a paragraph by
* <code>ubidi_setLine()</code>.<p>
* This object can be reused for as long as it is not deallocated
* by calling <code>ubidi_close()</code>.<p>
* <code>ubidi_setPara()</code> and <code>ubidi_setLine()</code> will allocate
* additional memory for internal structures as necessary.
*
* @return An empty <code>UBiDi</code> object.
* @stable ICU 2.0
*/
U_STABLE UBiDi * U_EXPORT2
ubidi_open(void);
/**
* Allocate a <code>UBiDi</code> structure with preallocated memory
* for internal structures.
* This function provides a <code>UBiDi</code> object like <code>ubidi_open()</code>
* with no arguments, but it also preallocates memory for internal structures
* according to the sizings supplied by the caller.<p>
* Subsequent functions will not allocate any more memory, and are thus
* guaranteed not to fail because of lack of memory.<p>
* The preallocation can be limited to some of the internal memory
* by setting some values to 0 here. That means that if, e.g.,
* <code>maxRunCount</code> cannot be reasonably predetermined and should not
* be set to <code>maxLength</code> (the only failproof value) to avoid
* wasting memory, then <code>maxRunCount</code> could be set to 0 here
* and the internal structures that are associated with it will be allocated
* on demand, just like with <code>ubidi_open()</code>.
*
* @param maxLength is the maximum text or line length that internal memory
* will be preallocated for. An attempt to associate this object with a
* longer text will fail, unless this value is 0, which leaves the allocation
* up to the implementation.
*
* @param maxRunCount is the maximum anticipated number of same-level runs
* that internal memory will be preallocated for. An attempt to access
* visual runs on an object that was not preallocated for as many runs
* as the text was actually resolved to will fail,
* unless this value is 0, which leaves the allocation up to the implementation.<br><br>
* The number of runs depends on the actual text and maybe anywhere between
* 1 and <code>maxLength</code>. It is typically small.
*
* @param pErrorCode must be a valid pointer to an error code value.
*
* @return An empty <code>UBiDi</code> object with preallocated memory.
* @stable ICU 2.0
*/
U_STABLE UBiDi * U_EXPORT2
ubidi_openSized(int32_t maxLength, int32_t maxRunCount, UErrorCode *pErrorCode);
/**
* <code>ubidi_close()</code> must be called to free the memory
* associated with a UBiDi object.<p>
*
* <strong>Important: </strong>
* A parent <code>UBiDi</code> object must not be destroyed or reused if
* it still has children.
* If a <code>UBiDi</code> object has become the <i>child</i>
* of another one (its <i>parent</i>) by calling
* <code>ubidi_setLine()</code>, then the child object must
* be destroyed (closed) or reused (by calling
* <code>ubidi_setPara()</code> or <code>ubidi_setLine()</code>)
* before the parent object.
*
* @param pBiDi is a <code>UBiDi</code> object.
*
* @see ubidi_setPara
* @see ubidi_setLine
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_close(UBiDi *pBiDi);
/**
* Modify the operation of the Bidi algorithm such that it
* approximates an "inverse Bidi" algorithm. This function
* must be called before <code>ubidi_setPara()</code>.
*
* <p>The normal operation of the Bidi algorithm as described
* in the Unicode Technical Report is to take text stored in logical
* (keyboard, typing) order and to determine the reordering of it for visual
* rendering.
* Some legacy systems store text in visual order, and for operations
* with standard, Unicode-based algorithms, the text needs to be transformed
* to logical order. This is effectively the inverse algorithm of the
* described Bidi algorithm. Note that there is no standard algorithm for
* this "inverse Bidi" and that the current implementation provides only an
* approximation of "inverse Bidi".</p>
*
* <p>With <code>isInverse</code> set to <code>TRUE</code>,
* this function changes the behavior of some of the subsequent functions
* in a way that they can be used for the inverse Bidi algorithm.
* Specifically, runs of text with numeric characters will be treated in a
* special way and may need to be surrounded with LRM characters when they are
* written in reordered sequence.</p>
*
* <p>Output runs should be retrieved using <code>ubidi_getVisualRun()</code>.
* Since the actual input for "inverse Bidi" is visually ordered text and
* <code>ubidi_getVisualRun()</code> gets the reordered runs, these are actually
* the runs of the logically ordered output.</p>
*
* <p>Calling this function with argument <code>isInverse</code> set to
* <code>TRUE</code> is equivalent to calling
* <code>ubidi_setReorderingMode</code> with argument
* <code>reorderingMode</code>
* set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
* Calling this function with argument <code>isInverse</code> set to
* <code>FALSE</code> is equivalent to calling
* <code>ubidi_setReorderingMode</code> with argument
* <code>reorderingMode</code>
* set to <code>#UBIDI_REORDER_DEFAULT</code>.
*
* @param pBiDi is a <code>UBiDi</code> object.
*
* @param isInverse specifies "forward" or "inverse" Bidi operation.
*
* @see ubidi_setPara
* @see ubidi_writeReordered
* @see ubidi_setReorderingMode
* @stable ICU 2.0
*/
U_STABLE void U_EXPORT2
ubidi_setInverse(UBiDi *pBiDi, UBool isInverse);
/**
* Is this Bidi object set to perform the inverse Bidi algorithm?
* <p>Note: calling this function after setting the reordering mode with
* <code>ubidi_setReorderingMode</code> will return <code>TRUE</code> if the
* reordering mode was set to <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>,
* <code>FALSE</code> for all other values.</p>
*
* @param pBiDi is a <code>UBiDi</code> object.
* @return TRUE if the Bidi object is set to perform the inverse Bidi algorithm
* by handling numbers as L.
*
* @see ubidi_setInverse
* @see ubidi_setReorderingMode
* @stable ICU 2.0
*/
U_STABLE UBool U_EXPORT2
ubidi_isInverse(UBiDi *pBiDi);
/**
* Specify whether block separators must be allocated level zero,
* so that successive paragraphs will progress from left to right.
* This function must be called before <code>ubidi_setPara()</code>.
* Paragraph separators (B) may appear in the text. Setting them to level zero
* means that all paragraph separators (including one possibly appearing
* in the last text position) are kept in the reordered text after the text
* that they follow in the source text.
* When this feature is not enabled, a paragraph separator at the last
* position of the text before reordering will go to the first position
* of the reordered text when the paragraph level is odd.
*
* @param pBiDi is a <code>UBiDi</code> object.
*
* @param orderParagraphsLTR specifies whether paragraph separators (B) must
* receive level 0, so that successive paragraphs progress from left to right.
*
* @see ubidi_setPara
* @stable ICU 3.4
*/
U_STABLE void U_EXPORT2
ubidi_orderParagraphsLTR(UBiDi *pBiDi, UBool orderParagraphsLTR);
/**
* Is this Bidi object set to allocate level 0 to block separators so that
* successive paragraphs progress from left to right?
*
* @param pBiDi is a <code>UBiDi</code> object.
* @return TRUE if the Bidi object is set to allocate level 0 to block
* separators.
*
* @see ubidi_orderParagraphsLTR
* @stable ICU 3.4
*/
U_STABLE UBool U_EXPORT2
ubidi_isOrderParagraphsLTR(UBiDi *pBiDi);
/**
* <code>UBiDiReorderingMode</code> values indicate which variant of the Bidi
* algorithm to use.
*
* @see ubidi_setReorderingMode
* @stable ICU 3.6
*/
typedef enum UBiDiReorderingMode {
/** Regular Logical to Visual Bidi algorithm according to Unicode.
* This is a 0 value.
* @stable ICU 3.6 */
UBIDI_REORDER_DEFAULT = 0,
/** Logical to Visual algorithm which handles numbers in a way which
* mimicks the behavior of Windows XP.
* @stable ICU 3.6 */
UBIDI_REORDER_NUMBERS_SPECIAL,
/** Logical to Visual algorithm grouping numbers with adjacent R characters
* (reversible algorithm).
* @stable ICU 3.6 */
UBIDI_REORDER_GROUP_NUMBERS_WITH_R,
/** Reorder runs only to transform a Logical LTR string to the Logical RTL
* string with the same display, or vice-versa.<br>
* If this mode is set together with option
* <code>#UBIDI_OPTION_INSERT_MARKS</code>, some Bidi controls in the source
* text may be removed and other controls may be added to produce the
* minimum combination which has the required display.
* @stable ICU 3.6 */
UBIDI_REORDER_RUNS_ONLY,
/** Visual to Logical algorithm which handles numbers like L
* (same algorithm as selected by <code>ubidi_setInverse(TRUE)</code>.
* @see ubidi_setInverse
* @stable ICU 3.6 */
UBIDI_REORDER_INVERSE_NUMBERS_AS_L,
/** Visual to Logical algorithm equivalent to the regular Logical to Visual
* algorithm.
* @stable ICU 3.6 */
UBIDI_REORDER_INVERSE_LIKE_DIRECT,
/** Inverse Bidi (Visual to Logical) algorithm for the
* <code>UBIDI_REORDER_NUMBERS_SPECIAL</code> Bidi algorithm.
* @stable ICU 3.6 */
UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL,
/** Number of values for reordering mode.
* @stable ICU 3.6 */
UBIDI_REORDER_COUNT
} UBiDiReorderingMode;
/**
* Modify the operation of the Bidi algorithm such that it implements some
* variant to the basic Bidi algorithm or approximates an "inverse Bidi"
* algorithm, depending on different values of the "reordering mode".
* This function must be called before <code>ubidi_setPara()</code>, and stays
* in effect until called again with a different argument.
*
* <p>The normal operation of the Bidi algorithm as described
* in the Unicode Standard Annex #9 is to take text stored in logical
* (keyboard, typing) order and to determine how to reorder it for visual
* rendering.</p>
*
* <p>With the reordering mode set to a value other than
* <code>#UBIDI_REORDER_DEFAULT</code>, this function changes the behavior of
* some of the subsequent functions in a way such that they implement an
* inverse Bidi algorithm or some other algorithm variants.</p>
*
* <p>Some legacy systems store text in visual order, and for operations
* with standard, Unicode-based algorithms, the text needs to be transformed
* into logical order. This is effectively the inverse algorithm of the
* described Bidi algorithm. Note that there is no standard algorithm for
* this "inverse Bidi", so a number of variants are implemented here.</p>
*
* <p>In other cases, it may be desirable to emulate some variant of the
* Logical to Visual algorithm (e.g. one used in MS Windows), or perform a
* Logical to Logical transformation.</p>
*
* <ul>
* <li>When the reordering mode is set to <code>#UBIDI_REORDER_DEFAULT</code>,
* the standard Bidi Logical to Visual algorithm is applied.</li>
*
* <li>When the reordering mode is set to
* <code>#UBIDI_REORDER_NUMBERS_SPECIAL</code>,
* the algorithm used to perform Bidi transformations when calling
* <code>ubidi_setPara</code> should approximate the algorithm used in
* Microsoft Windows XP rather than strictly conform to the Unicode Bidi
* algorithm.
* <br>
* The differences between the basic algorithm and the algorithm addressed
* by this option are as follows:
* <ul>
* <li>Within text at an even embedding level, the sequence "123AB"
* (where AB represent R or AL letters) is transformed to "123BA" by the
* Unicode algorithm and to "BA123" by the Windows algorithm.</li>
* <li>Arabic-Indic numbers (AN) are handled by the Windows algorithm just
* like regular numbers (EN).</li>
* </ul></li>
*
* <li>When the reordering mode is set to
* <code>#UBIDI_REORDER_GROUP_NUMBERS_WITH_R</code>,
* numbers located between LTR text and RTL text are associated with the RTL
* text. For instance, an LTR paragraph with content "abc 123 DEF" (where
* upper case letters represent RTL characters) will be transformed to
* "abc FED 123" (and not "abc 123 FED"), "DEF 123 abc" will be transformed
* to "123 FED abc" and "123 FED abc" will be transformed to "DEF 123 abc".
* This makes the algorithm reversible and makes it useful when round trip
* (from visual to logical and back to visual) must be achieved without
* adding LRM characters. However, this is a variation from the standard
* Unicode Bidi algorithm.<br>
* The source text should not contain Bidi control characters other than LRM
* or RLM.</li>
*
* <li>When the reordering mode is set to
* <code>#UBIDI_REORDER_RUNS_ONLY</code>,
* a "Logical to Logical" transformation must be performed:
* <ul>
* <li>If the default text level of the source text (argument <code>paraLevel</code>
* in <code>ubidi_setPara</code>) is even, the source text will be handled as
* LTR logical text and will be transformed to the RTL logical text which has
* the same LTR visual display.</li>
* <li>If the default level of the source text is odd, the source text
* will be handled as RTL logical text and will be transformed to the
* LTR logical text which has the same LTR visual display.</li>
* </ul>
* This mode may be needed when logical text which is basically Arabic or
* Hebrew, with possible included numbers or phrases in English, has to be
* displayed as if it had an even embedding level (this can happen if the
* displaying application treats all text as if it was basically LTR).
* <br>
* This mode may also be needed in the reverse case, when logical text which is
* basically English, with possible included phrases in Arabic or Hebrew, has to
* be displayed as if it had an odd embedding level.
* <br>
* Both cases could be handled by adding LRE or RLE at the head of the text,
* if the display subsystem supports these formatting controls. If it does not,
* the problem may be handled by transforming the source text in this mode
* before displaying it, so that it will be displayed properly.<br>
* The source text should not contain Bidi control characters other than LRM
* or RLM.</li>
*
* <li>When the reordering mode is set to
* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>, an "inverse Bidi" algorithm
* is applied.
* Runs of text with numeric characters will be treated like LTR letters and
* may need to be surrounded with LRM characters when they are written in
* reordered sequence (the option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> can
* be used with function <code>ubidi_writeReordered</code> to this end. This
* mode is equivalent to calling <code>ubidi_setInverse()</code> with
* argument <code>isInverse</code> set to <code>TRUE</code>.</li>
*
* <li>When the reordering mode is set to
* <code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code>, the "direct" Logical to Visual
* Bidi algorithm is used as an approximation of an "inverse Bidi" algorithm.
* This mode is similar to mode <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>
* but is closer to the regular Bidi algorithm.
* <br>
* For example, an LTR paragraph with the content "FED 123 456 CBA" (where
* upper case represents RTL characters) will be transformed to
* "ABC 456 123 DEF", as opposed to "DEF 123 456 ABC"
* with mode <code>UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.<br>
* When used in conjunction with option
* <code>#UBIDI_OPTION_INSERT_MARKS</code>, this mode generally
* adds Bidi marks to the output significantly more sparingly than mode
* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> with option
* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to
* <code>ubidi_writeReordered</code>.</li>
*
* <li>When the reordering mode is set to
* <code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code>, the Logical to Visual
* Bidi algorithm used in Windows XP is used as an approximation of an
* "inverse Bidi" algorithm.
* <br>
* For example, an LTR paragraph with the content "abc FED123" (where
* upper case represents RTL characters) will be transformed to
* "abc 123DEF.</li>
* </ul>
*
* <p>In all the reordering modes specifying an "inverse Bidi" algorithm
* (i.e. those with a name starting with <code>UBIDI_REORDER_INVERSE</code>),
* output runs should be retrieved using
* <code>ubidi_getVisualRun()</code>, and the output text with
* <code>ubidi_writeReordered()</code>. The caller should keep in mind that in
* "inverse Bidi" modes the input is actually visually ordered text and
* reordered output returned by <code>ubidi_getVisualRun()</code> or
* <code>ubidi_writeReordered()</code> are actually runs or character string
* of logically ordered output.<br>
* For all the "inverse Bidi" modes, the source text should not contain
* Bidi control characters other than LRM or RLM.</p>
*
* <p>Note that option <code>#UBIDI_OUTPUT_REVERSE</code> of
* <code>ubidi_writeReordered</code> has no useful meaning and should not be
* used in conjunction with any value of the reordering mode specifying
* "inverse Bidi" or with value <code>UBIDI_REORDER_RUNS_ONLY</code>.
*
* @param pBiDi is a <code>UBiDi</code> object.
* @param reorderingMode specifies the required variant of the Bidi algorithm.
*
* @see UBiDiReorderingMode
* @see ubidi_setInverse
* @see ubidi_setPara
* @see ubidi_writeReordered
* @stable ICU 3.6
*/
U_STABLE void U_EXPORT2
ubidi_setReorderingMode(UBiDi *pBiDi, UBiDiReorderingMode reorderingMode);
/**
* What is the requested reordering mode for a given Bidi object?
*
* @param pBiDi is a <code>UBiDi</code> object.
* @return the current reordering mode of the Bidi object
* @see ubidi_setReorderingMode
* @stable ICU 3.6
*/
U_STABLE UBiDiReorderingMode U_EXPORT2
ubidi_getReorderingMode(UBiDi *pBiDi);
/**
* <code>UBiDiReorderingOption</code> values indicate which options are
* specified to affect the Bidi algorithm.
*
* @see ubidi_setReorderingOptions
* @stable ICU 3.6
*/
typedef enum UBiDiReorderingOption {
/**
* option value for <code>ubidi_setReorderingOptions</code>:
* disable all the options which can be set with this function
* @see ubidi_setReorderingOptions
* @stable ICU 3.6
*/
UBIDI_OPTION_DEFAULT = 0,
/**
* option bit for <code>ubidi_setReorderingOptions</code>:
* insert Bidi marks (LRM or RLM) when needed to ensure correct result of
* a reordering to a Logical order
*
* <p>This option must be set or reset before calling
* <code>ubidi_setPara</code>.</p>
*
* <p>This option is significant only with reordering modes which generate
* a result with Logical order, specifically:</p>
* <ul>
* <li><code>#UBIDI_REORDER_RUNS_ONLY</code></li>
* <li><code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code></li>
* <li><code>#UBIDI_REORDER_INVERSE_LIKE_DIRECT</code></li>
* <li><code>#UBIDI_REORDER_INVERSE_FOR_NUMBERS_SPECIAL</code></li>
* </ul>
*
* <p>If this option is set in conjunction with reordering mode
* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code> or with calling
* <code>ubidi_setInverse(TRUE)</code>, it implies
* option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code>
* in calls to function <code>ubidi_writeReordered()</code>.</p>
*
* <p>For other reordering modes, a minimum number of LRM or RLM characters
* will be added to the source text after reordering it so as to ensure
* round trip, i.e. when applying the inverse reordering mode on the
* resulting logical text with removal of Bidi marks
* (option <code>#UBIDI_OPTION_REMOVE_CONTROLS</code> set before calling
* <code>ubidi_setPara()</code> or option <code>#UBIDI_REMOVE_BIDI_CONTROLS</code>
* in <code>ubidi_writeReordered</code>), the result will be identical to the
* source text in the first transformation.
*
* <p>This option will be ignored if specified together with option
* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>. It inhibits option
* <code>UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to function
* <code>ubidi_writeReordered()</code> and it implies option
* <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls to function
* <code>ubidi_writeReordered()</code> if the reordering mode is
* <code>#UBIDI_REORDER_INVERSE_NUMBERS_AS_L</code>.</p>
*
* @see ubidi_setReorderingMode
* @see ubidi_setReorderingOptions
* @stable ICU 3.6
*/
UBIDI_OPTION_INSERT_MARKS = 1,
/**
* option bit for <code>ubidi_setReorderingOptions</code>:
* remove Bidi control characters
*
* <p>This option must be set or reset before calling
* <code>ubidi_setPara</code>.</p>
*
* <p>This option nullifies option <code>#UBIDI_OPTION_INSERT_MARKS</code>.
* It inhibits option <code>#UBIDI_INSERT_LRM_FOR_NUMERIC</code> in calls
* to function <code>ubidi_writeReordered()</code> and it implies option
* <code>#UBIDI_REMOVE_BIDI_CONTROLS</code> in calls to that function.</p>
*
* @see ubidi_setReorderingMode
* @see ubidi_setReorderingOptions
* @stable ICU 3.6
*/
UBIDI_OPTION_REMOVE_CONTROLS = 2,
/**
* option bit for <code>ubidi_setReorderingOptions</code>:
* process the output as part of a stream to be continued
*
* <p>This option must be set or reset before calling
* <code>ubidi_setPara</code>.</p>
*
* <p>This option specifies that the caller is interested in processing large
* text object in parts.
* The results of the successive calls are expected to be concatenated by the
* caller. Only the call for the last part will have this option bit off.</p>
*
* <p>When this option bit is on, <code>ubidi_setPara()</code> may process
* less than the full source text in order to truncate the text at a meaningful
* boundary. The caller should call <code>ubidi_getProcessedLength()</code>
* immediately after calling <code>ubidi_setPara()</code> in order to
* determine how much of the source text has been processed.
* Source text beyond that length should be resubmitted in following calls to
* <code>ubidi_setPara</code>. The processed length may be less than
* the length of the source text if a character preceding the last character of
* the source text constitutes a reasonable boundary (like a block separator)
* for text to be continued.<br>
* If the last character of the source text constitutes a reasonable
* boundary, the whole text will be processed at once.<br>
* If nowhere in the source text there exists
* such a reasonable boundary, the processed length will be zero.<br>
* The caller should check for such an occurrence and do one of the following:
* <ul><li>submit a larger amount of text with a better chance to include
* a reasonable boundary.</li>
* <li>resubmit the same text after turning off option
* <code>UBIDI_OPTION_STREAMING</code>.</li></ul>
* In all cases, this option should be turned off before processing the last
* part of the text.</p>
*
* <p>When the <code>UBIDI_OPTION_STREAMING</code> option is used,
* it is recommended to call <code>ubidi_orderParagraphsLTR()</code> with
* argument <code>orderParagraphsLTR</code> set to <code>TRUE</code> before
* calling <code>ubidi_setPara</code> so that later paragraphs may be
* concatenated to previous paragraphs on the right.</p>
*
* @see ubidi_setReorderingMode
* @see ubidi_setReorderingOptions
* @see ubidi_getProcessedLength
* @see ubidi_orderParagraphsLTR
* @stable ICU 3.6
*/
UBIDI_OPTION_STREAMING = 4
} UBiDiReorderingOption;
/**
* Specify which of the reordering options
* should be applied during Bidi transformations.
*
* @param pBiDi is a <code>UBiDi</code> object.
* @param reorderingOptions is a combination of zero or more of the following
* options:
* <code>#UBIDI_OPTION_DEFAULT</code>, <code>#UBIDI_OPTION_INSERT_MARKS</code>,
* <code>#UBIDI_OPTION_REMOVE_CONTROLS</code>, <code>#UBIDI_OPTION_STREAMING</code>.
*
* @see ubidi_getReorderingOptions
* @stable ICU 3.6
*/
U_STABLE void U_EXPORT2
ubidi_setReorderingOptions(UBiDi *pBiDi, uint32_t reorderingOptions);
/**
* What are the reordering options applied to a given Bidi object?
*
* @param pBiDi is a <code>UBiDi</code> object.
* @return the current reordering options of the Bidi object
* @see ubidi_setReorderingOptions
* @stable ICU 3.6
*/
U_STABLE uint32_t U_EXPORT2
ubidi_getReorderingOptions(UBiDi *pBiDi);
/**
* Perform the Unicode Bidi algorithm. It is defined in the
* <a href="http://www.unicode.org/unicode/reports/tr9/">Unicode Standard Anned #9</a>,