ICU 59.1  59.1
Namespaces | Typedefs | Enumerations | Functions
ubiditransform.h File Reference

Bidi Transformations. More...

#include "unicode/utypes.h"
#include "unicode/ubidi.h"
#include "unicode/uchar.h"
#include "unicode/localpointer.h"

Go to the source code of this file.

Namespaces

 icu
 File coll.h.
 

Typedefs

typedef struct UBiDiTransform UBiDiTransform
 Forward declaration of the UBiDiTransform structure that stores information used by the layout transformation engine. More...
 

Enumerations

enum  UBiDiOrder { UBIDI_LOGICAL = 0, UBIDI_VISUAL }
 
enum  UBiDiMirroring { UBIDI_MIRRORING_OFF = 0, UBIDI_MIRRORING_ON }
 UBiDiMirroring indicates whether or not characters with the "mirrored" property in RTL runs should be replaced with their mirror-image counterparts. More...
 

Functions

uint32_t ubiditransform_transform (UBiDiTransform *pBiDiTransform, const UChar *src, int32_t srcLength, UChar *dest, int32_t destSize, UBiDiLevel inParaLevel, UBiDiOrder inOrder, UBiDiLevel outParaLevel, UBiDiOrder outOrder, UBiDiMirroring doMirroring, uint32_t shapingOptions, UErrorCode *pErrorCode)
 Performs transformation of text from the bidi layout defined by the input ordering scheme to the bidi layout defined by the output ordering scheme, and applies character mirroring and Arabic shaping operations. More...
 
UBiDiTransformubiditransform_open (UErrorCode *pErrorCode)
 Allocates a UBiDiTransform object. More...
 
void ubiditransform_close (UBiDiTransform *pBidiTransform)
 Deallocates the given UBiDiTransform object. More...
 

Detailed Description

Bidi Transformations.

UBiDiOrder indicates the order of text.

This bidi transformation engine supports all possible combinations (4 in total) of input and output text order:

See also
ubidi_setInverse
ubidi_setReorderingMode
UBIDI_REORDER_DEFAULT
UBIDI_REORDER_INVERSE_LIKE_DIRECT
UBIDI_REORDER_RUNS_ONLY
Draft:
This API may be changed in the future versions and was introduced in ICU 58

Definition in file ubiditransform.h.

Typedef Documentation

§ UBiDiTransform

Forward declaration of the UBiDiTransform structure that stores information used by the layout transformation engine.

Draft:
This API may be changed in the future versions and was introduced in ICU 58

Definition at line 109 of file ubiditransform.h.

Enumeration Type Documentation

§ UBiDiMirroring

UBiDiMirroring indicates whether or not characters with the "mirrored" property in RTL runs should be replaced with their mirror-image counterparts.

See also
UBIDI_DO_MIRRORING
ubidi_setReorderingOptions
ubidi_writeReordered
ubidi_writeReverse
Draft:
This API may be changed in the future versions and was introduced in ICU 58
Enumerator
UBIDI_MIRRORING_OFF 

0: Constant indicating that character mirroring should not be performed.

This is the default.

Draft:
This API may be changed in the future versions and was introduced in ICU 58
UBIDI_MIRRORING_ON 

1: Constant indicating that character mirroring should be performed.

This corresponds to calling ubidi_writeReordered or ubidi_writeReverse with the UBIDI_DO_MIRRORING option bit set.

Draft:
This API may be changed in the future versions and was introduced in ICU 58

Definition at line 88 of file ubiditransform.h.

§ UBiDiOrder

enum UBiDiOrder
Enumerator
UBIDI_LOGICAL 

0: Constant indicating a logical order.

This is the default for input text.

Draft:
This API may be changed in the future versions and was introduced in ICU 58
UBIDI_VISUAL 

1: Constant indicating a visual order.

This is a default for output text.

Draft:
This API may be changed in the future versions and was introduced in ICU 58

Definition at line 65 of file ubiditransform.h.

Function Documentation

§ ubiditransform_close()

void ubiditransform_close ( UBiDiTransform pBidiTransform)

Deallocates the given UBiDiTransform object.

Draft:
This API may be changed in the future versions and was introduced in ICU 58

§ ubiditransform_open()

UBiDiTransform* ubiditransform_open ( UErrorCode pErrorCode)

Allocates a UBiDiTransform object.

This object can be reused, e.g. with different ordering schemes, mirroring or shaping options.

Note:The object can only be reused in the same thread. All other threads should allocate a new UBiDiTransform object before using it.

Example of usage:

UErrorCode errorCode = U_ZERO_ERROR;
// Open a new UBiDiTransform.
UBiDiTransform* transform = ubiditransform_open(&errorCode);
// Run a transformation.
text1, -1, text2, -1,
&errorCode);
// Do something with the output text and invoke another transformation using
// that text as input.
text2, -1, text3, -1,
0, &errorCode);
*

The UBiDiTransform object must be deallocated by calling ubiditransform_close().

Returns
An empty UBiDiTransform object.
Draft:
This API may be changed in the future versions and was introduced in ICU 58

§ ubiditransform_transform()

uint32_t ubiditransform_transform ( UBiDiTransform pBiDiTransform,
const UChar src,
int32_t  srcLength,
UChar dest,
int32_t  destSize,
UBiDiLevel  inParaLevel,
UBiDiOrder  inOrder,
UBiDiLevel  outParaLevel,
UBiDiOrder  outOrder,
UBiDiMirroring  doMirroring,
uint32_t  shapingOptions,
UErrorCode pErrorCode 
)

Performs transformation of text from the bidi layout defined by the input ordering scheme to the bidi layout defined by the output ordering scheme, and applies character mirroring and Arabic shaping operations.

In terms of UBiDi, such a transformation implies:

  • calling ubidi_setReorderingMode as needed (when the reordering mode is other than normal),
  • calling ubidi_setInverse as needed (when text should be transformed from a visual to a logical form),
  • resolving embedding levels of each character in the input text by calling ubidi_setPara,
  • reordering the characters based on the computed embedding levels, also performing character mirroring as needed, and streaming the result to the output, by calling ubidi_writeReordered,
  • performing Arabic digit and letter shaping on the output text by calling u_shapeArabic.

An "ordering scheme" encompasses the base direction and the order of text, and these characteristics must be defined by the caller for both input and output explicitly .

There are 36 possible combinations of <input, output> ordering schemes, which are partially supported by UBiDi already. Examples of the currently supported combinations:

  • <Logical LTR, Visual LTR>: this is equivalent to calling ubidi_setPara with paraLevel == UBIDI_LTR,
  • <Logical RTL, Visual LTR>: this is equivalent to calling ubidi_setPara with paraLevel == UBIDI_RTL,
  • <Logical Default ("Auto") LTR, Visual LTR>: this is equivalent to calling ubidi_setPara with paraLevel == UBIDI_DEFAULT_LTR,
  • <Logical Default ("Auto") RTL, Visual LTR>: this is equivalent to calling ubidi_setPara with paraLevel == UBIDI_DEFAULT_RTL,
  • <Visual LTR, Logical LTR>: this is equivalent to calling ubidi_setInverse(UBiDi*, TRUE) and then ubidi_setPara with paraLevel == UBIDI_LTR,
  • <Visual LTR, Logical RTL>: this is equivalent to calling ubidi_setInverse(UBiDi*, TRUE) and then ubidi_setPara with paraLevel == UBIDI_RTL.

All combinations that involve the Visual RTL scheme are unsupported by UBiDi, for instance:

  • <Logical LTR, Visual RTL>,
  • <Visual RTL, Logical RTL>.

Example of usage of the transformation engine:

UChar text1[] = {'a', 'b', 'c', 0x0625, '1', 0};
UChar text2[] = {'a', 'b', 'c', 0x0625, '1', 0};
UErrorCode errorCode = U_ZERO_ERROR;
// Run a transformation.
ubiditransform_transform(pBidiTransform,
text1, -1, text2, -1,
&errorCode);
// Do something with text2.
text2[4] = '2';
// Run a reverse transformation.
ubiditransform_transform(pBidiTransform,
text2, -1, text1, -1,
&errorCode);
*
Parameters
pBiDiTransformA pointer to a UBiDiTransform object allocated with ubiditransform_open() or NULL.

This object serves for one-time setup to amortize initialization overheads. Use of this object is not thread-safe. All other threads should allocate a new UBiDiTransform object by calling ubiditransform_open() before using it. Alternatively, a caller can set this parameter to NULL, in which case the object will be allocated by the engine on the fly.

Parameters
srcA pointer to the text that the Bidi layout transformations will be performed on.

Note: the text must be (at least) srcLength long.

Parameters
srcLengthThe length of the text, in number of UChars. If length == -1 then the text must be zero-terminated.
destA pointer to where the processed text is to be copied.
destSizeThe size of the dest buffer, in number of UChars. If the U_SHAPE_LETTERS_UNSHAPE option is set, then the destination length could be as large as srcLength * 2. Otherwise, the destination length will not exceed srcLength. If the caller reserves the last position for zero-termination, it should be excluded from destSize.

destSize == -1 is allowed and makes sense when dest was holds some meaningful value, e.g. that of src. In this case dest must be zero-terminated.

Parameters
inParaLevelA base embedding level of the input as defined in ubidi_setPara documentation for the paraLevel parameter.
inOrderAn order of the input, which can be one of the UBiDiOrder values.
outParaLevelA base embedding level of the output as defined in ubidi_setPara documentation for the paraLevel parameter.
outOrderAn order of the output, which can be one of the UBiDiOrder values.
doMirroringIndicates whether or not to perform character mirroring, and can accept one of the UBiDiMirroring values.
shapingOptionsArabic digit and letter shaping options defined in the ushape.h documentation.

Note: Direction indicator options are computed by the transformation engine based on the effective ordering schemes, so user-defined direction indicators will be ignored.

Parameters
pErrorCodeA pointer to an error code value.
Returns
The destination length, i.e. the number of UChars written to dest. If the transformation fails, the return value will be 0 (and the error code will be written to pErrorCode).
See also
UBiDiLevel
UBiDiOrder
UBiDiMirroring
ubidi_setPara
u_shapeArabic
Draft:
This API may be changed in the future versions and was introduced in ICU 58