ushape.h 18 KB

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