ubidi.h 90 KB

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