ubidi.h 90 KB

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