michael@0: /* michael@0: ****************************************************************************** michael@0: * michael@0: * Copyright (C) 2000-2012, International Business Machines michael@0: * Corporation and others. All Rights Reserved. michael@0: * michael@0: ****************************************************************************** michael@0: * file name: ushape.h michael@0: * encoding: US-ASCII michael@0: * tab size: 8 (not used) michael@0: * indentation:4 michael@0: * michael@0: * created on: 2000jun29 michael@0: * created by: Markus W. Scherer michael@0: */ michael@0: michael@0: #ifndef __USHAPE_H__ michael@0: #define __USHAPE_H__ michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: /** michael@0: * \file michael@0: * \brief C API: Arabic shaping michael@0: * michael@0: */ michael@0: michael@0: /** michael@0: * Shape Arabic text on a character basis. michael@0: * michael@0: *
This function performs basic operations for "shaping" Arabic text. It is most michael@0: * useful for use with legacy data formats and legacy display technology michael@0: * (simple terminals). All operations are performed on Unicode characters.
michael@0: * michael@0: *Text-based shaping means that some character code points in the text are michael@0: * replaced by others depending on the context. It transforms one kind of text michael@0: * into another. In comparison, modern displays for Arabic text select michael@0: * appropriate, context-dependent font glyphs for each text element, which means michael@0: * that they transform text into a glyph vector.
michael@0: * michael@0: *Text transformations are necessary when modern display technology is not michael@0: * available or when text needs to be transformed to or from legacy formats that michael@0: * use "shaped" characters. Since the Arabic script is cursive, connecting michael@0: * adjacent letters to each other, computers select images for each letter based michael@0: * on the surrounding letters. This usually results in four images per Arabic michael@0: * letter: initial, middle, final, and isolated forms. In Unicode, on the other michael@0: * hand, letters are normally stored abstract, and a display system is expected michael@0: * to select the necessary glyphs. (This makes searching and other text michael@0: * processing easier because the same letter has only one code.) It is possible michael@0: * to mimic this with text transformations because there are characters in michael@0: * Unicode that are rendered as letters with a specific shape michael@0: * (or cursive connectivity). They were included for interoperability with michael@0: * legacy systems and codepages, and for unsophisticated display systems.
michael@0: * michael@0: *A second kind of text transformations is supported for Arabic digits: michael@0: * For compatibility with legacy codepages that only include European digits, michael@0: * it is possible to replace one set of digits by another, changing the michael@0: * character code points. These operations can be performed for either michael@0: * Arabic-Indic Digits (U+0660...U+0669) or Eastern (Extended) Arabic-Indic michael@0: * digits (U+06f0...U+06f9).
michael@0: * michael@0: *Some replacements may result in more or fewer characters (code points). michael@0: * By default, this means that the destination buffer may receive text with a michael@0: * length different from the source length. Some legacy systems rely on the michael@0: * length of the text to be constant. They expect extra spaces to be added michael@0: * or consumed either next to the affected character or at the end of the michael@0: * text.
michael@0: * michael@0: *For details about the available operations, see the description of the
michael@0: * U_SHAPE_...
options.
source
.
michael@0: *
michael@0: * @param dest The destination buffer that will receive the results of the
michael@0: * requested operations. It may be NULL
only if
michael@0: * destSize
is 0. The source and destination must not
michael@0: * overlap.
michael@0: *
michael@0: * @param destSize The size (capacity) of the destination buffer in UChars.
michael@0: * If destSize
is 0, then no output is produced,
michael@0: * but the necessary buffer size is returned ("preflighting").
michael@0: *
michael@0: * @param options This is a 32-bit set of flags that specify the operations
michael@0: * that are performed on the input text. If no error occurs,
michael@0: * then the result will always be written to the destination
michael@0: * buffer.
michael@0: *
michael@0: * @param pErrorCode must be a valid pointer to an error code value,
michael@0: * which must not indicate a failure before the function call.
michael@0: *
michael@0: * @return The number of UChars written to the destination buffer.
michael@0: * If an error occured, then no output was written, or it may be
michael@0: * incomplete. If U_BUFFER_OVERFLOW_ERROR
is set, then
michael@0: * the return value indicates the necessary destination buffer size.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: U_STABLE int32_t U_EXPORT2
michael@0: u_shapeArabic(const UChar *source, int32_t sourceLength,
michael@0: UChar *dest, int32_t destSize,
michael@0: uint32_t options,
michael@0: UErrorCode *pErrorCode);
michael@0:
michael@0: /**
michael@0: * Memory option: allow the result to have a different length than the source.
michael@0: * Affects: LamAlef options
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_LENGTH_GROW_SHRINK 0
michael@0:
michael@0: /**
michael@0: * Memory option: allow the result to have a different length than the source.
michael@0: * Affects: LamAlef options
michael@0: * This option is an alias to U_SHAPE_LENGTH_GROW_SHRINK
michael@0: * @stable ICU 4.2
michael@0: */
michael@0: #define U_SHAPE_LAMALEF_RESIZE 0
michael@0:
michael@0: /**
michael@0: * Memory option: the result must have the same length as the source.
michael@0: * If more room is necessary, then try to consume spaces next to modified characters.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_LENGTH_FIXED_SPACES_NEAR 1
michael@0:
michael@0: /**
michael@0: * Memory option: the result must have the same length as the source.
michael@0: * If more room is necessary, then try to consume spaces next to modified characters.
michael@0: * Affects: LamAlef options
michael@0: * This option is an alias to U_SHAPE_LENGTH_FIXED_SPACES_NEAR
michael@0: * @stable ICU 4.2
michael@0: */
michael@0: #define U_SHAPE_LAMALEF_NEAR 1
michael@0:
michael@0: /**
michael@0: * Memory option: the result must have the same length as the source.
michael@0: * If more room is necessary, then try to consume spaces at the end of the text.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_LENGTH_FIXED_SPACES_AT_END 2
michael@0:
michael@0: /**
michael@0: * Memory option: the result must have the same length as the source.
michael@0: * If more room is necessary, then try to consume spaces at the end of the text.
michael@0: * Affects: LamAlef options
michael@0: * This option is an alias to U_SHAPE_LENGTH_FIXED_SPACES_AT_END
michael@0: * @stable ICU 4.2
michael@0: */
michael@0: #define U_SHAPE_LAMALEF_END 2
michael@0:
michael@0: /**
michael@0: * Memory option: the result must have the same length as the source.
michael@0: * If more room is necessary, then try to consume spaces at the beginning of the text.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_LENGTH_FIXED_SPACES_AT_BEGINNING 3
michael@0:
michael@0: /**
michael@0: * Memory option: the result must have the same length as the source.
michael@0: * If more room is necessary, then try to consume spaces at the beginning of the text.
michael@0: * Affects: LamAlef options
michael@0: * This option is an alias to U_SHAPE_LENGTH_FIXED_SPACES_AT_BEGINNING
michael@0: * @stable ICU 4.2
michael@0: */
michael@0: #define U_SHAPE_LAMALEF_BEGIN 3
michael@0:
michael@0:
michael@0: /**
michael@0: * Memory option: the result must have the same length as the source.
michael@0: * Shaping Mode: For each LAMALEF character found, expand LAMALEF using space at end.
michael@0: * If there is no space at end, use spaces at beginning of the buffer. If there
michael@0: * is no space at beginning of the buffer, use spaces at the near (i.e. the space
michael@0: * after the LAMALEF character).
michael@0: * If there are no spaces found, an error U_NO_SPACE_AVAILABLE (as defined in utypes.h)
michael@0: * will be set in pErrorCode
michael@0: *
michael@0: * Deshaping Mode: Perform the same function as the flag equals U_SHAPE_LAMALEF_END.
michael@0: * Affects: LamAlef options
michael@0: * @stable ICU 4.2
michael@0: */
michael@0: #define U_SHAPE_LAMALEF_AUTO 0x10000
michael@0:
michael@0: /** Bit mask for memory options. @stable ICU 2.0 */
michael@0: #define U_SHAPE_LENGTH_MASK 0x10003 /* Changed old value 3 */
michael@0:
michael@0:
michael@0: /**
michael@0: * Bit mask for LamAlef memory options.
michael@0: * @stable ICU 4.2
michael@0: */
michael@0: #define U_SHAPE_LAMALEF_MASK 0x10003 /* updated */
michael@0:
michael@0: /** Direction indicator: the source is in logical (keyboard) order. @stable ICU 2.0 */
michael@0: #define U_SHAPE_TEXT_DIRECTION_LOGICAL 0
michael@0:
michael@0: /**
michael@0: * Direction indicator:
michael@0: * the source is in visual RTL order,
michael@0: * the rightmost displayed character stored first.
michael@0: * This option is an alias to U_SHAPE_TEXT_DIRECTION_LOGICAL
michael@0: * @stable ICU 4.2
michael@0: */
michael@0: #define U_SHAPE_TEXT_DIRECTION_VISUAL_RTL 0
michael@0:
michael@0: /**
michael@0: * Direction indicator:
michael@0: * the source is in visual LTR order,
michael@0: * the leftmost displayed character stored first.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_TEXT_DIRECTION_VISUAL_LTR 4
michael@0:
michael@0: /** Bit mask for direction indicators. @stable ICU 2.0 */
michael@0: #define U_SHAPE_TEXT_DIRECTION_MASK 4
michael@0:
michael@0:
michael@0: /** Letter shaping option: do not perform letter shaping. @stable ICU 2.0 */
michael@0: #define U_SHAPE_LETTERS_NOOP 0
michael@0:
michael@0: /** Letter shaping option: replace abstract letter characters by "shaped" ones. @stable ICU 2.0 */
michael@0: #define U_SHAPE_LETTERS_SHAPE 8
michael@0:
michael@0: /** Letter shaping option: replace "shaped" letter characters by abstract ones. @stable ICU 2.0 */
michael@0: #define U_SHAPE_LETTERS_UNSHAPE 0x10
michael@0:
michael@0: /**
michael@0: * Letter shaping option: replace abstract letter characters by "shaped" ones.
michael@0: * The only difference with U_SHAPE_LETTERS_SHAPE is that Tashkeel letters
michael@0: * are always "shaped" into the isolated form instead of the medial form
michael@0: * (selecting code points from the Arabic Presentation Forms-B block).
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_LETTERS_SHAPE_TASHKEEL_ISOLATED 0x18
michael@0:
michael@0:
michael@0: /** Bit mask for letter shaping options. @stable ICU 2.0 */
michael@0: #define U_SHAPE_LETTERS_MASK 0x18
michael@0:
michael@0:
michael@0: /** Digit shaping option: do not perform digit shaping. @stable ICU 2.0 */
michael@0: #define U_SHAPE_DIGITS_NOOP 0
michael@0:
michael@0: /**
michael@0: * Digit shaping option:
michael@0: * Replace European digits (U+0030...) by Arabic-Indic digits.
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_DIGITS_EN2AN 0x20
michael@0:
michael@0: /**
michael@0: * Digit shaping option:
michael@0: * Replace Arabic-Indic digits by European digits (U+0030...).
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_DIGITS_AN2EN 0x40
michael@0:
michael@0: /**
michael@0: * Digit shaping option:
michael@0: * Replace European digits (U+0030...) by Arabic-Indic digits if the most recent
michael@0: * strongly directional character is an Arabic letter
michael@0: * (u_charDirection()
result U_RIGHT_TO_LEFT_ARABIC
[AL]).U_LEFT_TO_RIGHT
[L] or U_RIGHT_TO_LEFT
[R]).
michael@0: * @stable ICU 2.0
michael@0: */
michael@0: #define U_SHAPE_DIGITS_ALEN2AN_INIT_LR 0x60
michael@0:
michael@0: /**
michael@0: * Digit shaping option:
michael@0: * Replace European digits (U+0030...) by Arabic-Indic digits if the most recent
michael@0: * strongly directional character is an Arabic letter
michael@0: * (u_charDirection()
result U_RIGHT_TO_LEFT_ARABIC
[AL]).