ushape.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. /*
  2. ******************************************************************************
  3. *
  4. * Copyright (C) 2000-2012, International Business Machines
  5. * Corporation and others. All Rights Reserved.
  6. *
  7. ******************************************************************************
  8. * file name: ushape.h
  9. * encoding: US-ASCII
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 2000jun29
  14. * created by: Markus W. Scherer
  15. */
  16. #ifndef __USHAPE_H__
  17. #define __USHAPE_H__
  18. #include "unicode/utypes.h"
  19. /**
  20. * \file
  21. * \brief C API: Arabic shaping
  22. *
  23. */
  24. /**
  25. * Shape Arabic text on a character basis.
  26. *
  27. * <p>This function performs basic operations for "shaping" Arabic text. It is most
  28. * useful for use with legacy data formats and legacy display technology
  29. * (simple terminals). All operations are performed on Unicode characters.</p>
  30. *
  31. * <p>Text-based shaping means that some character code points in the text are
  32. * replaced by others depending on the context. It transforms one kind of text
  33. * into another. In comparison, modern displays for Arabic text select
  34. * appropriate, context-dependent font glyphs for each text element, which means
  35. * that they transform text into a glyph vector.</p>
  36. *
  37. * <p>Text transformations are necessary when modern display technology is not
  38. * available or when text needs to be transformed to or from legacy formats that
  39. * use "shaped" characters. Since the Arabic script is cursive, connecting
  40. * adjacent letters to each other, computers select images for each letter based
  41. * on the surrounding letters. This usually results in four images per Arabic
  42. * letter: initial, middle, final, and isolated forms. In Unicode, on the other
  43. * hand, letters are normally stored abstract, and a display system is expected
  44. * to select the necessary glyphs. (This makes searching and other text
  45. * processing easier because the same letter has only one code.) It is possible
  46. * to mimic this with text transformations because there are characters in
  47. * Unicode that are rendered as letters with a specific shape
  48. * (or cursive connectivity). They were included for interoperability with
  49. * legacy systems and codepages, and for unsophisticated display systems.</p>
  50. *
  51. * <p>A second kind of text transformations is supported for Arabic digits:
  52. * For compatibility with legacy codepages that only include European digits,
  53. * it is possible to replace one set of digits by another, changing the
  54. * character code points. These operations can be performed for either
  55. * Arabic-Indic Digits (U+0660...U+0669) or Eastern (Extended) Arabic-Indic
  56. * digits (U+06f0...U+06f9).</p>
  57. *
  58. * <p>Some replacements may result in more or fewer characters (code points).
  59. * By default, this means that the destination buffer may receive text with a
  60. * length different from the source length. Some legacy systems rely on the
  61. * length of the text to be constant. They expect extra spaces to be added
  62. * or consumed either next to the affected character or at the end of the
  63. * text.</p>
  64. *
  65. * <p>For details about the available operations, see the description of the
  66. * <code>U_SHAPE_...</code> options.</p>
  67. *
  68. * @param source The input text.
  69. *
  70. * @param sourceLength The number of UChars in <code>source</code>.
  71. *
  72. * @param dest The destination buffer that will receive the results of the
  73. * requested operations. It may be <code>NULL</code> only if
  74. * <code>destSize</code> is 0. The source and destination must not
  75. * overlap.
  76. *
  77. * @param destSize The size (capacity) of the destination buffer in UChars.
  78. * If <code>destSize</code> is 0, then no output is produced,
  79. * but the necessary buffer size is returned ("preflighting").
  80. *
  81. * @param options This is a 32-bit set of flags that specify the operations
  82. * that are performed on the input text. If no error occurs,
  83. * then the result will always be written to the destination
  84. * buffer.
  85. *
  86. * @param pErrorCode must be a valid pointer to an error code value,
  87. * which must not indicate a failure before the function call.
  88. *
  89. * @return The number of UChars written to the destination buffer.
  90. * If an error occured, then no output was written, or it may be
  91. * incomplete. If <code>U_BUFFER_OVERFLOW_ERROR</code> is set, then
  92. * the return value indicates the necessary destination buffer size.
  93. * @stable ICU 2.0
  94. */
  95. U_STABLE int32_t U_EXPORT2
  96. u_shapeArabic(const UChar *source, int32_t sourceLength,
  97. UChar *dest, int32_t destSize,
  98. uint32_t options,
  99. UErrorCode *pErrorCode);
  100. /**
  101. * Memory option: allow the result to have a different length than the source.
  102. * Affects: LamAlef options
  103. * @stable ICU 2.0
  104. */
  105. #define U_SHAPE_LENGTH_GROW_SHRINK 0
  106. /**
  107. * Memory option: allow the result to have a different length than the source.
  108. * Affects: LamAlef options
  109. * This option is an alias to U_SHAPE_LENGTH_GROW_SHRINK
  110. * @stable ICU 4.2
  111. */
  112. #define U_SHAPE_LAMALEF_RESIZE 0
  113. /**
  114. * Memory option: the result must have the same length as the source.
  115. * If more room is necessary, then try to consume spaces next to modified characters.
  116. * @stable ICU 2.0
  117. */
  118. #define U_SHAPE_LENGTH_FIXED_SPACES_NEAR 1
  119. /**
  120. * Memory option: the result must have the same length as the source.
  121. * If more room is necessary, then try to consume spaces next to modified characters.
  122. * Affects: LamAlef options
  123. * This option is an alias to U_SHAPE_LENGTH_FIXED_SPACES_NEAR
  124. * @stable ICU 4.2
  125. */
  126. #define U_SHAPE_LAMALEF_NEAR 1
  127. /**
  128. * Memory option: the result must have the same length as the source.
  129. * If more room is necessary, then try to consume spaces at the end of the text.
  130. * @stable ICU 2.0
  131. */
  132. #define U_SHAPE_LENGTH_FIXED_SPACES_AT_END 2
  133. /**
  134. * Memory option: the result must have the same length as the source.
  135. * If more room is necessary, then try to consume spaces at the end of the text.
  136. * Affects: LamAlef options
  137. * This option is an alias to U_SHAPE_LENGTH_FIXED_SPACES_AT_END
  138. * @stable ICU 4.2
  139. */
  140. #define U_SHAPE_LAMALEF_END 2
  141. /**
  142. * Memory option: the result must have the same length as the source.
  143. * If more room is necessary, then try to consume spaces at the beginning of the text.
  144. * @stable ICU 2.0
  145. */
  146. #define U_SHAPE_LENGTH_FIXED_SPACES_AT_BEGINNING 3
  147. /**
  148. * Memory option: the result must have the same length as the source.
  149. * If more room is necessary, then try to consume spaces at the beginning of the text.
  150. * Affects: LamAlef options
  151. * This option is an alias to U_SHAPE_LENGTH_FIXED_SPACES_AT_BEGINNING
  152. * @stable ICU 4.2
  153. */
  154. #define U_SHAPE_LAMALEF_BEGIN 3
  155. /**
  156. * Memory option: the result must have the same length as the source.
  157. * Shaping Mode: For each LAMALEF character found, expand LAMALEF using space at end.
  158. * If there is no space at end, use spaces at beginning of the buffer. If there
  159. * is no space at beginning of the buffer, use spaces at the near (i.e. the space
  160. * after the LAMALEF character).
  161. * If there are no spaces found, an error U_NO_SPACE_AVAILABLE (as defined in utypes.h)
  162. * will be set in pErrorCode
  163. *
  164. * Deshaping Mode: Perform the same function as the flag equals U_SHAPE_LAMALEF_END.
  165. * Affects: LamAlef options
  166. * @stable ICU 4.2
  167. */
  168. #define U_SHAPE_LAMALEF_AUTO 0x10000
  169. /** Bit mask for memory options. @stable ICU 2.0 */
  170. #define U_SHAPE_LENGTH_MASK 0x10003 /* Changed old value 3 */
  171. /**
  172. * Bit mask for LamAlef memory options.
  173. * @stable ICU 4.2
  174. */
  175. #define U_SHAPE_LAMALEF_MASK 0x10003 /* updated */
  176. /** Direction indicator: the source is in logical (keyboard) order. @stable ICU 2.0 */
  177. #define U_SHAPE_TEXT_DIRECTION_LOGICAL 0
  178. /**
  179. * Direction indicator:
  180. * the source is in visual RTL order,
  181. * the rightmost displayed character stored first.
  182. * This option is an alias to U_SHAPE_TEXT_DIRECTION_LOGICAL
  183. * @stable ICU 4.2
  184. */
  185. #define U_SHAPE_TEXT_DIRECTION_VISUAL_RTL 0
  186. /**
  187. * Direction indicator:
  188. * the source is in visual LTR order,
  189. * the leftmost displayed character stored first.
  190. * @stable ICU 2.0
  191. */
  192. #define U_SHAPE_TEXT_DIRECTION_VISUAL_LTR 4
  193. /** Bit mask for direction indicators. @stable ICU 2.0 */
  194. #define U_SHAPE_TEXT_DIRECTION_MASK 4
  195. /** Letter shaping option: do not perform letter shaping. @stable ICU 2.0 */
  196. #define U_SHAPE_LETTERS_NOOP 0
  197. /** Letter shaping option: replace abstract letter characters by "shaped" ones. @stable ICU 2.0 */
  198. #define U_SHAPE_LETTERS_SHAPE 8
  199. /** Letter shaping option: replace "shaped" letter characters by abstract ones. @stable ICU 2.0 */
  200. #define U_SHAPE_LETTERS_UNSHAPE 0x10
  201. /**
  202. * Letter shaping option: replace abstract letter characters by "shaped" ones.
  203. * The only difference with U_SHAPE_LETTERS_SHAPE is that Tashkeel letters
  204. * are always "shaped" into the isolated form instead of the medial form
  205. * (selecting code points from the Arabic Presentation Forms-B block).
  206. * @stable ICU 2.0
  207. */
  208. #define U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED 0x18
  209. /** Bit mask for letter shaping options. @stable ICU 2.0 */
  210. #define U_SHAPE_LETTERS_MASK 0x18
  211. /** Digit shaping option: do not perform digit shaping. @stable ICU 2.0 */
  212. #define U_SHAPE_DIGITS_NOOP 0
  213. /**
  214. * Digit shaping option:
  215. * Replace European digits (U+0030...) by Arabic-Indic digits.
  216. * @stable ICU 2.0
  217. */
  218. #define U_SHAPE_DIGITS_EN2AN 0x20
  219. /**
  220. * Digit shaping option:
  221. * Replace Arabic-Indic digits by European digits (U+0030...).
  222. * @stable ICU 2.0
  223. */
  224. #define U_SHAPE_DIGITS_AN2EN 0x40
  225. /**
  226. * Digit shaping option:
  227. * Replace European digits (U+0030...) by Arabic-Indic digits if the most recent
  228. * strongly directional character is an Arabic letter
  229. * (<code>u_charDirection()</code> result <code>U_RIGHT_TO_LEFT_ARABIC</code> [AL]).<br>
  230. * The direction of "preceding" depends on the direction indicator option.
  231. * For the first characters, the preceding strongly directional character
  232. * (initial state) is assumed to be not an Arabic letter
  233. * (it is <code>U_LEFT_TO_RIGHT</code> [L] or <code>U_RIGHT_TO_LEFT</code> [R]).
  234. * @stable ICU 2.0
  235. */
  236. #define U_SHAPE_DIGITS_ALEN2AN_INIT_LR 0x60
  237. /**
  238. * Digit shaping option:
  239. * Replace European digits (U+0030...) by Arabic-Indic digits if the most recent
  240. * strongly directional character is an Arabic letter
  241. * (<code>u_charDirection()</code> result <code>U_RIGHT_TO_LEFT_ARABIC</code> [AL]).<br>
  242. * The direction of "preceding" depends on the direction indicator option.
  243. * For the first characters, the preceding strongly directional character
  244. * (initial state) is assumed to be an Arabic letter.
  245. * @stable ICU 2.0
  246. */
  247. #define U_SHAPE_DIGITS_ALEN2AN_INIT_AL 0x80
  248. /** Not a valid option value. May be replaced by a new option. @stable ICU 2.0 */
  249. #define U_SHAPE_DIGITS_RESERVED 0xa0
  250. /** Bit mask for digit shaping options. @stable ICU 2.0 */
  251. #define U_SHAPE_DIGITS_MASK 0xe0
  252. /** Digit type option: Use Arabic-Indic digits (U+0660...U+0669). @stable ICU 2.0 */
  253. #define U_SHAPE_DIGIT_TYPE_AN 0
  254. /** Digit type option: Use Eastern (Extended) Arabic-Indic digits (U+06f0...U+06f9). @stable ICU 2.0 */
  255. #define U_SHAPE_DIGIT_TYPE_AN_EXTENDED 0x100
  256. /** Not a valid option value. May be replaced by a new option. @stable ICU 2.0 */
  257. #define U_SHAPE_DIGIT_TYPE_RESERVED 0x200
  258. /** Bit mask for digit type options. @stable ICU 2.0 */
  259. #define U_SHAPE_DIGIT_TYPE_MASK 0x300 /* I need to change this from 0x3f00 to 0x300 */
  260. /**
  261. * Tashkeel aggregation option:
  262. * Replaces any combination of U+0651 with one of
  263. * U+064C, U+064D, U+064E, U+064F, U+0650 with
  264. * U+FC5E, U+FC5F, U+FC60, U+FC61, U+FC62 consecutively.
  265. * @stable ICU 3.6
  266. */
  267. #define U_SHAPE_AGGREGATE_TASHKEEL 0x4000
  268. /** Tashkeel aggregation option: do not aggregate tashkeels. @stable ICU 3.6 */
  269. #define U_SHAPE_AGGREGATE_TASHKEEL_NOOP 0
  270. /** Bit mask for tashkeel aggregation. @stable ICU 3.6 */
  271. #define U_SHAPE_AGGREGATE_TASHKEEL_MASK 0x4000
  272. /**
  273. * Presentation form option:
  274. * Don't replace Arabic Presentation Forms-A and Arabic Presentation Forms-B
  275. * characters with 0+06xx characters, before shaping.
  276. * @stable ICU 3.6
  277. */
  278. #define U_SHAPE_PRESERVE_PRESENTATION 0x8000
  279. /** Presentation form option:
  280. * Replace Arabic Presentation Forms-A and Arabic Presentationo Forms-B with
  281. * their unshaped correspondants in range 0+06xx, before shaping.
  282. * @stable ICU 3.6
  283. */
  284. #define U_SHAPE_PRESERVE_PRESENTATION_NOOP 0
  285. /** Bit mask for preserve presentation form. @stable ICU 3.6 */
  286. #define U_SHAPE_PRESERVE_PRESENTATION_MASK 0x8000
  287. /* Seen Tail option */
  288. /**
  289. * Memory option: the result must have the same length as the source.
  290. * Shaping mode: The SEEN family character will expand into two characters using space near
  291. * the SEEN family character(i.e. the space after the character).
  292. * If there are no spaces found, an error U_NO_SPACE_AVAILABLE (as defined in utypes.h)
  293. * will be set in pErrorCode
  294. *
  295. * De-shaping mode: Any Seen character followed by Tail character will be
  296. * replaced by one cell Seen and a space will replace the Tail.
  297. * Affects: Seen options
  298. * @stable ICU 4.2
  299. */
  300. #define U_SHAPE_SEEN_TWOCELL_NEAR 0x200000
  301. /**
  302. * Bit mask for Seen memory options.
  303. * @stable ICU 4.2
  304. */
  305. #define U_SHAPE_SEEN_MASK 0x700000
  306. /* YehHamza option */
  307. /**
  308. * Memory option: the result must have the same length as the source.
  309. * Shaping mode: The YEHHAMZA character will expand into two characters using space near it
  310. * (i.e. the space after the character
  311. * If there are no spaces found, an error U_NO_SPACE_AVAILABLE (as defined in utypes.h)
  312. * will be set in pErrorCode
  313. *
  314. * De-shaping mode: Any Yeh (final or isolated) character followed by Hamza character will be
  315. * replaced by one cell YehHamza and space will replace the Hamza.
  316. * Affects: YehHamza options
  317. * @stable ICU 4.2
  318. */
  319. #define U_SHAPE_YEHHAMZA_TWOCELL_NEAR 0x1000000
  320. /**
  321. * Bit mask for YehHamza memory options.
  322. * @stable ICU 4.2
  323. */
  324. #define U_SHAPE_YEHHAMZA_MASK 0x3800000
  325. /* New Tashkeel options */
  326. /**
  327. * Memory option: the result must have the same length as the source.
  328. * Shaping mode: Tashkeel characters will be replaced by spaces.
  329. * Spaces will be placed at beginning of the buffer
  330. *
  331. * De-shaping mode: N/A
  332. * Affects: Tashkeel options
  333. * @stable ICU 4.2
  334. */
  335. #define U_SHAPE_TASHKEEL_BEGIN 0x40000
  336. /**
  337. * Memory option: the result must have the same length as the source.
  338. * Shaping mode: Tashkeel characters will be replaced by spaces.
  339. * Spaces will be placed at end of the buffer
  340. *
  341. * De-shaping mode: N/A
  342. * Affects: Tashkeel options
  343. * @stable ICU 4.2
  344. */
  345. #define U_SHAPE_TASHKEEL_END 0x60000
  346. /**
  347. * Memory option: allow the result to have a different length than the source.
  348. * Shaping mode: Tashkeel characters will be removed, buffer length will shrink.
  349. * De-shaping mode: N/A
  350. *
  351. * Affect: Tashkeel options
  352. * @stable ICU 4.2
  353. */
  354. #define U_SHAPE_TASHKEEL_RESIZE 0x80000
  355. /**
  356. * Memory option: the result must have the same length as the source.
  357. * Shaping mode: Tashkeel characters will be replaced by Tatweel if it is connected to adjacent
  358. * characters (i.e. shaped on Tatweel) or replaced by space if it is not connected.
  359. *
  360. * De-shaping mode: N/A
  361. * Affects: YehHamza options
  362. * @stable ICU 4.2
  363. */
  364. #define U_SHAPE_TASHKEEL_REPLACE_BY_TATWEEL 0xC0000
  365. /**
  366. * Bit mask for Tashkeel replacement with Space or Tatweel memory options.
  367. * @stable ICU 4.2
  368. */
  369. #define U_SHAPE_TASHKEEL_MASK 0xE0000
  370. /* Space location Control options */
  371. /**
  372. * This option affect the meaning of BEGIN and END options. if this option is not used the default
  373. * for BEGIN and END will be as following:
  374. * The Default (for both Visual LTR, Visual RTL and Logical Text)
  375. * 1. BEGIN always refers to the start address of physical memory.
  376. * 2. END always refers to the end address of physical memory.
  377. *
  378. * If this option is used it will swap the meaning of BEGIN and END only for Visual LTR text.
  379. *
  380. * The effect on BEGIN and END Memory Options will be as following:
  381. * A. BEGIN For Visual LTR text: This will be the beginning (right side) of the visual text(
  382. * corresponding to the physical memory address end for Visual LTR text, Same as END in
  383. * default behavior)
  384. * B. BEGIN For Logical text: Same as BEGIN in default behavior.
  385. * C. END For Visual LTR text: This will be the end (left side) of the visual text (corresponding
  386. * to the physical memory address beginning for Visual LTR text, Same as BEGIN in default behavior.
  387. * D. END For Logical text: Same as END in default behavior).
  388. * Affects: All LamAlef BEGIN, END and AUTO options.
  389. * @stable ICU 4.2
  390. */
  391. #define U_SHAPE_SPACES_RELATIVE_TO_TEXT_BEGIN_END 0x4000000
  392. /**
  393. * Bit mask for swapping BEGIN and END for Visual LTR text
  394. * @stable ICU 4.2
  395. */
  396. #define U_SHAPE_SPACES_RELATIVE_TO_TEXT_MASK 0x4000000
  397. /**
  398. * If this option is used, shaping will use the new Unicode code point for TAIL (i.e. 0xFE73).
  399. * If this option is not specified (Default), old unofficial Unicode TAIL code point is used (i.e. 0x200B)
  400. * De-shaping will not use this option as it will always search for both the new Unicode code point for the
  401. * TAIL (i.e. 0xFE73) or the old unofficial Unicode TAIL code point (i.e. 0x200B) and de-shape the
  402. * Seen-Family letter accordingly.
  403. *
  404. * Shaping Mode: Only shaping.
  405. * De-shaping Mode: N/A.
  406. * Affects: All Seen options
  407. * @stable ICU 4.8
  408. */
  409. #define U_SHAPE_TAIL_NEW_UNICODE 0x8000000
  410. /**
  411. * Bit mask for new Unicode Tail option
  412. * @stable ICU 4.8
  413. */
  414. #define U_SHAPE_TAIL_TYPE_MASK 0x8000000
  415. #endif