Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/native/common/unicode/ubiditransform.h
38827 views
/*1******************************************************************************2*3* © 2016 and later: Unicode, Inc. and others.4* License & terms of use: http://www.unicode.org/copyright.html5*6******************************************************************************7* file name: ubiditransform.h8* encoding: UTF-89* tab size: 8 (not used)10* indentation:411*12* created on: 2016jul2413* created by: Lina Kemmel14*15*/1617#ifndef UBIDITRANSFORM_H18#define UBIDITRANSFORM_H1920#include "unicode/utypes.h"21#include "unicode/ubidi.h"22#include "unicode/uchar.h"2324#if U_SHOW_CPLUSPLUS_API25#include "unicode/localpointer.h"26#endif // U_SHOW_CPLUSPLUS_API2728/**29* \file30* \brief Bidi Transformations31*/3233/**34* `UBiDiOrder` indicates the order of text.35*36* This bidi transformation engine supports all possible combinations (4 in37* total) of input and output text order:38*39* - <logical input, visual output>: unless the output direction is RTL, this40* corresponds to a normal operation of the Bidi algorithm as described in the41* Unicode Technical Report and implemented by `UBiDi` when the42* reordering mode is set to `UBIDI_REORDER_DEFAULT`. Visual RTL43* mode is not supported by `UBiDi` and is accomplished through44* reversing a visual LTR string,45*46* - <visual input, logical output>: unless the input direction is RTL, this47* corresponds to an "inverse bidi algorithm" in `UBiDi` with the48* reordering mode set to `UBIDI_REORDER_INVERSE_LIKE_DIRECT`.49* Visual RTL mode is not not supported by `UBiDi` and is50* accomplished through reversing a visual LTR string,51*52* - <logical input, logical output>: if the input and output base directions53* mismatch, this corresponds to the `UBiDi` implementation with the54* reordering mode set to `UBIDI_REORDER_RUNS_ONLY`; and if the55* input and output base directions are identical, the transformation engine56* will only handle character mirroring and Arabic shaping operations without57* reordering,58*59* - <visual input, visual output>: this reordering mode is not supported by60* the `UBiDi` engine; it implies character mirroring, Arabic61* shaping, and - if the input/output base directions mismatch - string62* reverse operations.63* @see ubidi_setInverse64* @see ubidi_setReorderingMode65* @see UBIDI_REORDER_DEFAULT66* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT67* @see UBIDI_REORDER_RUNS_ONLY68* @stable ICU 5869*/70typedef enum {71/** 0: Constant indicating a logical order.72* This is the default for input text.73* @stable ICU 5874*/75UBIDI_LOGICAL = 0,76/** 1: Constant indicating a visual order.77* This is a default for output text.78* @stable ICU 5879*/80UBIDI_VISUAL81} UBiDiOrder;8283/**84* <code>UBiDiMirroring</code> indicates whether or not characters with the85* "mirrored" property in RTL runs should be replaced with their mirror-image86* counterparts.87* @see UBIDI_DO_MIRRORING88* @see ubidi_setReorderingOptions89* @see ubidi_writeReordered90* @see ubidi_writeReverse91* @stable ICU 5892*/93typedef enum {94/** 0: Constant indicating that character mirroring should not be95* performed.96* This is the default.97* @stable ICU 5898*/99UBIDI_MIRRORING_OFF = 0,100/** 1: Constant indicating that character mirroring should be performed.101* This corresponds to calling <code>ubidi_writeReordered</code> or102* <code>ubidi_writeReverse</code> with the103* <code>UBIDI_DO_MIRRORING</code> option bit set.104* @stable ICU 58105*/106UBIDI_MIRRORING_ON107} UBiDiMirroring;108109/**110* Forward declaration of the <code>UBiDiTransform</code> structure that stores111* information used by the layout transformation engine.112* @stable ICU 58113*/114typedef struct UBiDiTransform UBiDiTransform;115116/**117* Performs transformation of text from the bidi layout defined by the input118* ordering scheme to the bidi layout defined by the output ordering scheme,119* and applies character mirroring and Arabic shaping operations.<p>120* In terms of <code>UBiDi</code>, such a transformation implies:121* <ul>122* <li>calling <code>ubidi_setReorderingMode</code> as needed (when the123* reordering mode is other than normal),</li>124* <li>calling <code>ubidi_setInverse</code> as needed (when text should be125* transformed from a visual to a logical form),</li>126* <li>resolving embedding levels of each character in the input text by127* calling <code>ubidi_setPara</code>,</li>128* <li>reordering the characters based on the computed embedding levels, also129* performing character mirroring as needed, and streaming the result to the130* output, by calling <code>ubidi_writeReordered</code>,</li>131* <li>performing Arabic digit and letter shaping on the output text by calling132* <code>u_shapeArabic</code>.</li>133* </ul>134* An "ordering scheme" encompasses the base direction and the order of text,135* and these characteristics must be defined by the caller for both input and136* output explicitly .<p>137* There are 36 possible combinations of <input, output> ordering schemes,138* which are partially supported by <code>UBiDi</code> already. Examples of the139* currently supported combinations:140* <ul>141* <li><Logical LTR, Visual LTR>: this is equivalent to calling142* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_LTR</code>,</li>143* <li><Logical RTL, Visual LTR>: this is equivalent to calling144* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_RTL</code>,</li>145* <li><Logical Default ("Auto") LTR, Visual LTR>: this is equivalent to146* calling <code>ubidi_setPara</code> with147* <code>paraLevel == UBIDI_DEFAULT_LTR</code>,</li>148* <li><Logical Default ("Auto") RTL, Visual LTR>: this is equivalent to149* calling <code>ubidi_setPara</code> with150* <code>paraLevel == UBIDI_DEFAULT_RTL</code>,</li>151* <li><Visual LTR, Logical LTR>: this is equivalent to152* calling <code>ubidi_setInverse(UBiDi*, TRUE)</code> and then153* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_LTR</code>,</li>154* <li><Visual LTR, Logical RTL>: this is equivalent to155* calling <code>ubidi_setInverse(UBiDi*, TRUE)</code> and then156* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_RTL</code>.</li>157* </ul>158* All combinations that involve the Visual RTL scheme are unsupported by159* <code>UBiDi</code>, for instance:160* <ul>161* <li><Logical LTR, Visual RTL>,</li>162* <li><Visual RTL, Logical RTL>.</li>163* </ul>164* <p>Example of usage of the transformation engine:<br>165* <pre>166* \code167* UChar text1[] = {'a', 'b', 'c', 0x0625, '1', 0};168* UChar text2[] = {'a', 'b', 'c', 0x0625, '1', 0};169* UErrorCode errorCode = U_ZERO_ERROR;170* // Run a transformation.171* ubiditransform_transform(pBidiTransform,172* text1, -1, text2, -1,173* UBIDI_LTR, UBIDI_VISUAL,174* UBIDI_RTL, UBIDI_LOGICAL,175* UBIDI_MIRRORING_OFF,176* U_SHAPE_DIGITS_AN2EN | U_SHAPE_DIGIT_TYPE_AN_EXTENDED,177* &errorCode);178* // Do something with text2.179* text2[4] = '2';180* // Run a reverse transformation.181* ubiditransform_transform(pBidiTransform,182* text2, -1, text1, -1,183* UBIDI_RTL, UBIDI_LOGICAL,184* UBIDI_LTR, UBIDI_VISUAL,185* UBIDI_MIRRORING_OFF,186* U_SHAPE_DIGITS_EN2AN | U_SHAPE_DIGIT_TYPE_AN_EXTENDED,187* &errorCode);188*\endcode189* </pre>190* </p>191*192* @param pBiDiTransform A pointer to a <code>UBiDiTransform</code> object193* allocated with <code>ubiditransform_open()</code> or194* <code>NULL</code>.<p>195* This object serves for one-time setup to amortize initialization196* overheads. Use of this object is not thread-safe. All other threads197* should allocate a new <code>UBiDiTransform</code> object by calling198* <code>ubiditransform_open()</code> before using it. Alternatively,199* a caller can set this parameter to <code>NULL</code>, in which case200* the object will be allocated by the engine on the fly.</p>201* @param src A pointer to the text that the Bidi layout transformations will202* be performed on.203* <p><strong>Note:</strong> the text must be (at least)204* <code>srcLength</code> long.</p>205* @param srcLength The length of the text, in number of UChars. If206* <code>length == -1</code> then the text must be zero-terminated.207* @param dest A pointer to where the processed text is to be copied.208* @param destSize The size of the <code>dest</code> buffer, in number of209* UChars. If the <code>U_SHAPE_LETTERS_UNSHAPE</code> option is set,210* then the destination length could be as large as211* <code>srcLength * 2</code>. Otherwise, the destination length will212* not exceed <code>srcLength</code>. If the caller reserves the last213* position for zero-termination, it should be excluded from214* <code>destSize</code>.215* <p><code>destSize == -1</code> is allowed and makes sense when216* <code>dest</code> was holds some meaningful value, e.g. that of217* <code>src</code>. In this case <code>dest</code> must be218* zero-terminated.</p>219* @param inParaLevel A base embedding level of the input as defined in220* <code>ubidi_setPara</code> documentation for the221* <code>paraLevel</code> parameter.222* @param inOrder An order of the input, which can be one of the223* <code>UBiDiOrder</code> values.224* @param outParaLevel A base embedding level of the output as defined in225* <code>ubidi_setPara</code> documentation for the226* <code>paraLevel</code> parameter.227* @param outOrder An order of the output, which can be one of the228* <code>UBiDiOrder</code> values.229* @param doMirroring Indicates whether or not to perform character mirroring,230* and can accept one of the <code>UBiDiMirroring</code> values.231* @param shapingOptions Arabic digit and letter shaping options defined in the232* ushape.h documentation.233* <p><strong>Note:</strong> Direction indicator options are computed by234* the transformation engine based on the effective ordering schemes, so235* user-defined direction indicators will be ignored.</p>236* @param pErrorCode A pointer to an error code value.237*238* @return The destination length, i.e. the number of UChars written to239* <code>dest</code>. If the transformation fails, the return value240* will be 0 (and the error code will be written to241* <code>pErrorCode</code>).242*243* @see UBiDiLevel244* @see UBiDiOrder245* @see UBiDiMirroring246* @see ubidi_setPara247* @see u_shapeArabic248* @stable ICU 58249*/250U_STABLE uint32_t U_EXPORT2251ubiditransform_transform(UBiDiTransform *pBiDiTransform,252const UChar *src, int32_t srcLength,253UChar *dest, int32_t destSize,254UBiDiLevel inParaLevel, UBiDiOrder inOrder,255UBiDiLevel outParaLevel, UBiDiOrder outOrder,256UBiDiMirroring doMirroring, uint32_t shapingOptions,257UErrorCode *pErrorCode);258259/**260* Allocates a <code>UBiDiTransform</code> object. This object can be reused,261* e.g. with different ordering schemes, mirroring or shaping options.<p>262* <strong>Note:</strong>The object can only be reused in the same thread.263* All other threads should allocate a new <code>UBiDiTransform</code> object264* before using it.<p>265* Example of usage:<p>266* <pre>267* \code268* UErrorCode errorCode = U_ZERO_ERROR;269* // Open a new UBiDiTransform.270* UBiDiTransform* transform = ubiditransform_open(&errorCode);271* // Run a transformation.272* ubiditransform_transform(transform,273* text1, -1, text2, -1,274* UBIDI_RTL, UBIDI_LOGICAL,275* UBIDI_LTR, UBIDI_VISUAL,276* UBIDI_MIRRORING_ON,277* U_SHAPE_DIGITS_EN2AN,278* &errorCode);279* // Do something with the output text and invoke another transformation using280* // that text as input.281* ubiditransform_transform(transform,282* text2, -1, text3, -1,283* UBIDI_LTR, UBIDI_VISUAL,284* UBIDI_RTL, UBIDI_VISUAL,285* UBIDI_MIRRORING_ON,286* 0, &errorCode);287*\endcode288* </pre>289* <p>290* The <code>UBiDiTransform</code> object must be deallocated by calling291* <code>ubiditransform_close()</code>.292*293* @return An empty <code>UBiDiTransform</code> object.294* @stable ICU 58295*/296U_STABLE UBiDiTransform* U_EXPORT2297ubiditransform_open(UErrorCode *pErrorCode);298299/**300* Deallocates the given <code>UBiDiTransform</code> object.301* @stable ICU 58302*/303U_STABLE void U_EXPORT2304ubiditransform_close(UBiDiTransform *pBidiTransform);305306#if U_SHOW_CPLUSPLUS_API307308U_NAMESPACE_BEGIN309310/**311* \class LocalUBiDiTransformPointer312* "Smart pointer" class, closes a UBiDiTransform via ubiditransform_close().313* For most methods see the LocalPointerBase base class.314*315* @see LocalPointerBase316* @see LocalPointer317* @stable ICU 58318*/319U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiTransformPointer, UBiDiTransform, ubiditransform_close);320321U_NAMESPACE_END322323#endif324325#endif326327328