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