ubidi.h 89 KB

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