Path: blob/jdk8u272-b10-aarch32-20201026/jdk/src/share/native/common/unicode/ubiditransform.h
48737 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"23#include "unicode/localpointer.h"2425/**26* \file27* \brief Bidi Transformations28*/2930/**31* `UBiDiOrder` indicates the order of text.32*33* This bidi transformation engine supports all possible combinations (4 in34* total) of input and output text order:35*36* - <logical input, visual output>: unless the output direction is RTL, this37* corresponds to a normal operation of the Bidi algorithm as described in the38* Unicode Technical Report and implemented by `UBiDi` when the39* reordering mode is set to `UBIDI_REORDER_DEFAULT`. Visual RTL40* mode is not supported by `UBiDi` and is accomplished through41* reversing a visual LTR string,42*43* - <visual input, logical output>: unless the input direction is RTL, this44* corresponds to an "inverse bidi algorithm" in `UBiDi` with the45* reordering mode set to `UBIDI_REORDER_INVERSE_LIKE_DIRECT`.46* Visual RTL mode is not not supported by `UBiDi` and is47* accomplished through reversing a visual LTR string,48*49* - <logical input, logical output>: if the input and output base directions50* mismatch, this corresponds to the `UBiDi` implementation with the51* reordering mode set to `UBIDI_REORDER_RUNS_ONLY`; and if the52* input and output base directions are identical, the transformation engine53* will only handle character mirroring and Arabic shaping operations without54* reordering,55*56* - <visual input, visual output>: this reordering mode is not supported by57* the `UBiDi` engine; it implies character mirroring, Arabic58* shaping, and - if the input/output base directions mismatch - string59* reverse operations.60* @see ubidi_setInverse61* @see ubidi_setReorderingMode62* @see UBIDI_REORDER_DEFAULT63* @see UBIDI_REORDER_INVERSE_LIKE_DIRECT64* @see UBIDI_REORDER_RUNS_ONLY65* @stable ICU 5866*/67typedef enum {68/** 0: Constant indicating a logical order.69* This is the default for input text.70* @stable ICU 5871*/72UBIDI_LOGICAL = 0,73/** 1: Constant indicating a visual order.74* This is a default for output text.75* @stable ICU 5876*/77UBIDI_VISUAL78} UBiDiOrder;7980/**81* <code>UBiDiMirroring</code> indicates whether or not characters with the82* "mirrored" property in RTL runs should be replaced with their mirror-image83* counterparts.84* @see UBIDI_DO_MIRRORING85* @see ubidi_setReorderingOptions86* @see ubidi_writeReordered87* @see ubidi_writeReverse88* @stable ICU 5889*/90typedef enum {91/** 0: Constant indicating that character mirroring should not be92* performed.93* This is the default.94* @stable ICU 5895*/96UBIDI_MIRRORING_OFF = 0,97/** 1: Constant indicating that character mirroring should be performed.98* This corresponds to calling <code>ubidi_writeReordered</code> or99* <code>ubidi_writeReverse</code> with the100* <code>UBIDI_DO_MIRRORING</code> option bit set.101* @stable ICU 58102*/103UBIDI_MIRRORING_ON104} UBiDiMirroring;105106/**107* Forward declaration of the <code>UBiDiTransform</code> structure that stores108* information used by the layout transformation engine.109* @stable ICU 58110*/111typedef struct UBiDiTransform UBiDiTransform;112113/**114* Performs transformation of text from the bidi layout defined by the input115* ordering scheme to the bidi layout defined by the output ordering scheme,116* and applies character mirroring and Arabic shaping operations.<p>117* In terms of <code>UBiDi</code>, such a transformation implies:118* <ul>119* <li>calling <code>ubidi_setReorderingMode</code> as needed (when the120* reordering mode is other than normal),</li>121* <li>calling <code>ubidi_setInverse</code> as needed (when text should be122* transformed from a visual to a logical form),</li>123* <li>resolving embedding levels of each character in the input text by124* calling <code>ubidi_setPara</code>,</li>125* <li>reordering the characters based on the computed embedding levels, also126* performing character mirroring as needed, and streaming the result to the127* output, by calling <code>ubidi_writeReordered</code>,</li>128* <li>performing Arabic digit and letter shaping on the output text by calling129* <code>u_shapeArabic</code>.</li>130* </ul>131* An "ordering scheme" encompasses the base direction and the order of text,132* and these characteristics must be defined by the caller for both input and133* output explicitly .<p>134* There are 36 possible combinations of <input, output> ordering schemes,135* which are partially supported by <code>UBiDi</code> already. Examples of the136* currently supported combinations:137* <ul>138* <li><Logical LTR, Visual LTR>: this is equivalent to calling139* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_LTR</code>,</li>140* <li><Logical RTL, Visual LTR>: this is equivalent to calling141* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_RTL</code>,</li>142* <li><Logical Default ("Auto") LTR, Visual LTR>: this is equivalent to143* calling <code>ubidi_setPara</code> with144* <code>paraLevel == UBIDI_DEFAULT_LTR</code>,</li>145* <li><Logical Default ("Auto") RTL, Visual LTR>: this is equivalent to146* calling <code>ubidi_setPara</code> with147* <code>paraLevel == UBIDI_DEFAULT_RTL</code>,</li>148* <li><Visual LTR, Logical LTR>: this is equivalent to149* calling <code>ubidi_setInverse(UBiDi*, TRUE)</code> and then150* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_LTR</code>,</li>151* <li><Visual LTR, Logical RTL>: this is equivalent to152* calling <code>ubidi_setInverse(UBiDi*, TRUE)</code> and then153* <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_RTL</code>.</li>154* </ul>155* All combinations that involve the Visual RTL scheme are unsupported by156* <code>UBiDi</code>, for instance:157* <ul>158* <li><Logical LTR, Visual RTL>,</li>159* <li><Visual RTL, Logical RTL>.</li>160* </ul>161* <p>Example of usage of the transformation engine:<br>162* <pre>163* \code164* UChar text1[] = {'a', 'b', 'c', 0x0625, '1', 0};165* UChar text2[] = {'a', 'b', 'c', 0x0625, '1', 0};166* UErrorCode errorCode = U_ZERO_ERROR;167* // Run a transformation.168* ubiditransform_transform(pBidiTransform,169* text1, -1, text2, -1,170* UBIDI_LTR, UBIDI_VISUAL,171* UBIDI_RTL, UBIDI_LOGICAL,172* UBIDI_MIRRORING_OFF,173* U_SHAPE_DIGITS_AN2EN | U_SHAPE_DIGIT_TYPE_AN_EXTENDED,174* &errorCode);175* // Do something with text2.176* text2[4] = '2';177* // Run a reverse transformation.178* ubiditransform_transform(pBidiTransform,179* text2, -1, text1, -1,180* UBIDI_RTL, UBIDI_LOGICAL,181* UBIDI_LTR, UBIDI_VISUAL,182* UBIDI_MIRRORING_OFF,183* U_SHAPE_DIGITS_EN2AN | U_SHAPE_DIGIT_TYPE_AN_EXTENDED,184* &errorCode);185*\endcode186* </pre>187* </p>188*189* @param pBiDiTransform A pointer to a <code>UBiDiTransform</code> object190* allocated with <code>ubiditransform_open()</code> or191* <code>NULL</code>.<p>192* This object serves for one-time setup to amortize initialization193* overheads. Use of this object is not thread-safe. All other threads194* should allocate a new <code>UBiDiTransform</code> object by calling195* <code>ubiditransform_open()</code> before using it. Alternatively,196* a caller can set this parameter to <code>NULL</code>, in which case197* the object will be allocated by the engine on the fly.</p>198* @param src A pointer to the text that the Bidi layout transformations will199* be performed on.200* <p><strong>Note:</strong> the text must be (at least)201* <code>srcLength</code> long.</p>202* @param srcLength The length of the text, in number of UChars. If203* <code>length == -1</code> then the text must be zero-terminated.204* @param dest A pointer to where the processed text is to be copied.205* @param destSize The size of the <code>dest</code> buffer, in number of206* UChars. If the <code>U_SHAPE_LETTERS_UNSHAPE</code> option is set,207* then the destination length could be as large as208* <code>srcLength * 2</code>. Otherwise, the destination length will209* not exceed <code>srcLength</code>. If the caller reserves the last210* position for zero-termination, it should be excluded from211* <code>destSize</code>.212* <p><code>destSize == -1</code> is allowed and makes sense when213* <code>dest</code> was holds some meaningful value, e.g. that of214* <code>src</code>. In this case <code>dest</code> must be215* zero-terminated.</p>216* @param inParaLevel A base embedding level of the input as defined in217* <code>ubidi_setPara</code> documentation for the218* <code>paraLevel</code> parameter.219* @param inOrder An order of the input, which can be one of the220* <code>UBiDiOrder</code> values.221* @param outParaLevel A base embedding level of the output as defined in222* <code>ubidi_setPara</code> documentation for the223* <code>paraLevel</code> parameter.224* @param outOrder An order of the output, which can be one of the225* <code>UBiDiOrder</code> values.226* @param doMirroring Indicates whether or not to perform character mirroring,227* and can accept one of the <code>UBiDiMirroring</code> values.228* @param shapingOptions Arabic digit and letter shaping options defined in the229* ushape.h documentation.230* <p><strong>Note:</strong> Direction indicator options are computed by231* the transformation engine based on the effective ordering schemes, so232* user-defined direction indicators will be ignored.</p>233* @param pErrorCode A pointer to an error code value.234*235* @return The destination length, i.e. the number of UChars written to236* <code>dest</code>. If the transformation fails, the return value237* will be 0 (and the error code will be written to238* <code>pErrorCode</code>).239*240* @see UBiDiLevel241* @see UBiDiOrder242* @see UBiDiMirroring243* @see ubidi_setPara244* @see u_shapeArabic245* @stable ICU 58246*/247U_STABLE uint32_t U_EXPORT2248ubiditransform_transform(UBiDiTransform *pBiDiTransform,249const UChar *src, int32_t srcLength,250UChar *dest, int32_t destSize,251UBiDiLevel inParaLevel, UBiDiOrder inOrder,252UBiDiLevel outParaLevel, UBiDiOrder outOrder,253UBiDiMirroring doMirroring, uint32_t shapingOptions,254UErrorCode *pErrorCode);255256/**257* Allocates a <code>UBiDiTransform</code> object. This object can be reused,258* e.g. with different ordering schemes, mirroring or shaping options.<p>259* <strong>Note:</strong>The object can only be reused in the same thread.260* All other threads should allocate a new <code>UBiDiTransform</code> object261* before using it.<p>262* Example of usage:<p>263* <pre>264* \code265* UErrorCode errorCode = U_ZERO_ERROR;266* // Open a new UBiDiTransform.267* UBiDiTransform* transform = ubiditransform_open(&errorCode);268* // Run a transformation.269* ubiditransform_transform(transform,270* text1, -1, text2, -1,271* UBIDI_RTL, UBIDI_LOGICAL,272* UBIDI_LTR, UBIDI_VISUAL,273* UBIDI_MIRRORING_ON,274* U_SHAPE_DIGITS_EN2AN,275* &errorCode);276* // Do something with the output text and invoke another transformation using277* // that text as input.278* ubiditransform_transform(transform,279* text2, -1, text3, -1,280* UBIDI_LTR, UBIDI_VISUAL,281* UBIDI_RTL, UBIDI_VISUAL,282* UBIDI_MIRRORING_ON,283* 0, &errorCode);284*\endcode285* </pre>286* <p>287* The <code>UBiDiTransform</code> object must be deallocated by calling288* <code>ubiditransform_close()</code>.289*290* @return An empty <code>UBiDiTransform</code> object.291* @stable ICU 58292*/293U_STABLE UBiDiTransform* U_EXPORT2294ubiditransform_open(UErrorCode *pErrorCode);295296/**297* Deallocates the given <code>UBiDiTransform</code> object.298* @stable ICU 58299*/300U_STABLE void U_EXPORT2301ubiditransform_close(UBiDiTransform *pBidiTransform);302303#if U_SHOW_CPLUSPLUS_API304305U_NAMESPACE_BEGIN306307/**308* \class LocalUBiDiTransformPointer309* "Smart pointer" class, closes a UBiDiTransform via ubiditransform_close().310* For most methods see the LocalPointerBase base class.311*312* @see LocalPointerBase313* @see LocalPointer314* @stable ICU 58315*/316U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiTransformPointer, UBiDiTransform, ubiditransform_close);317318U_NAMESPACE_END319320#endif321322#endif323324325