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