ubidi.h 89 KB

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