Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:09

0001 /*
0002 ******************************************************************************
0003 *
0004 * © 2016 and later: Unicode, Inc. and others.
0005 * License & terms of use: http://www.unicode.org/copyright.html
0006 *
0007 ******************************************************************************
0008 *   file name:  ubiditransform.h
0009 *   encoding:   UTF-8
0010 *   tab size:   8 (not used)
0011 *   indentation:4
0012 *
0013 *   created on: 2016jul24
0014 *   created by: Lina Kemmel
0015 *
0016 */
0017 
0018 #ifndef UBIDITRANSFORM_H
0019 #define UBIDITRANSFORM_H
0020 
0021 #include "unicode/utypes.h"
0022 #include "unicode/ubidi.h"
0023 #include "unicode/uchar.h"
0024 
0025 #if U_SHOW_CPLUSPLUS_API
0026 #include "unicode/localpointer.h"
0027 #endif   // U_SHOW_CPLUSPLUS_API
0028 
0029 /**
0030  * \file
0031  * \brief C API: Bidi Transformations
0032  */
0033 
0034 /**
0035  * `UBiDiOrder` indicates the order of text.
0036  *
0037  * This bidi transformation engine supports all possible combinations (4 in
0038  * total) of input and output text order:
0039  *
0040  *   - <logical input, visual output>: unless the output direction is RTL, this
0041  *     corresponds to a normal operation of the Bidi algorithm as described in the
0042  *     Unicode Technical Report and implemented by `UBiDi` when the
0043  *     reordering mode is set to `UBIDI_REORDER_DEFAULT`. Visual RTL
0044  *     mode is not supported by `UBiDi` and is accomplished through
0045  *     reversing a visual LTR string,
0046  *
0047  *   - <visual input, logical output>: unless the input direction is RTL, this
0048  *     corresponds to an "inverse bidi algorithm" in `UBiDi` with the
0049  *     reordering mode set to `UBIDI_REORDER_INVERSE_LIKE_DIRECT`.
0050  *     Visual RTL mode is not not supported by `UBiDi` and is
0051  *     accomplished through reversing a visual LTR string,
0052  *
0053  *   - <logical input, logical output>: if the input and output base directions
0054  *     mismatch, this corresponds to the `UBiDi` implementation with the
0055  *     reordering mode set to `UBIDI_REORDER_RUNS_ONLY`; and if the
0056  *     input and output base directions are identical, the transformation engine
0057  *     will only handle character mirroring and Arabic shaping operations without
0058  *     reordering,
0059  *
0060  *   - <visual input, visual output>: this reordering mode is not supported by
0061  *     the `UBiDi` engine; it implies character mirroring, Arabic
0062  *     shaping, and - if the input/output base directions mismatch -  string
0063  *     reverse operations.
0064  * @see ubidi_setInverse
0065  * @see ubidi_setReorderingMode
0066  * @see UBIDI_REORDER_DEFAULT
0067  * @see UBIDI_REORDER_INVERSE_LIKE_DIRECT
0068  * @see UBIDI_REORDER_RUNS_ONLY
0069  * @stable ICU 58
0070  */
0071 typedef enum {
0072     /** 0: Constant indicating a logical order.
0073       * This is the default for input text.
0074       * @stable ICU 58
0075       */
0076     UBIDI_LOGICAL = 0,
0077     /** 1: Constant indicating a visual order.
0078       * This is a default for output text.
0079       * @stable ICU 58
0080       */
0081     UBIDI_VISUAL
0082 } UBiDiOrder;
0083 
0084 /**
0085  * <code>UBiDiMirroring</code> indicates whether or not characters with the
0086  * "mirrored" property in RTL runs should be replaced with their mirror-image
0087  * counterparts.
0088  * @see UBIDI_DO_MIRRORING
0089  * @see ubidi_setReorderingOptions
0090  * @see ubidi_writeReordered
0091  * @see ubidi_writeReverse
0092  * @stable ICU 58
0093  */
0094 typedef enum {
0095     /** 0: Constant indicating that character mirroring should not be
0096       * performed.
0097       * This is the default.
0098       * @stable ICU 58
0099       */
0100     UBIDI_MIRRORING_OFF = 0,
0101     /** 1: Constant indicating that character mirroring should be performed.
0102       * This corresponds to calling <code>ubidi_writeReordered</code> or
0103       * <code>ubidi_writeReverse</code> with the
0104       * <code>UBIDI_DO_MIRRORING</code> option bit set.
0105       * @stable ICU 58
0106       */
0107     UBIDI_MIRRORING_ON
0108 } UBiDiMirroring;
0109 
0110 /**
0111  * Forward declaration of the <code>UBiDiTransform</code> structure that stores
0112  * information used by the layout transformation engine.
0113  * @stable ICU 58
0114  */
0115 typedef struct UBiDiTransform UBiDiTransform;
0116 
0117 /**
0118  * Performs transformation of text from the bidi layout defined by the input
0119  * ordering scheme to the bidi layout defined by the output ordering scheme,
0120  * and applies character mirroring and Arabic shaping operations.<p>
0121  * In terms of <code>UBiDi</code>, such a transformation implies:
0122  * <ul>
0123  * <li>calling <code>ubidi_setReorderingMode</code> as needed (when the
0124  * reordering mode is other than normal),</li>
0125  * <li>calling <code>ubidi_setInverse</code> as needed (when text should be
0126  * transformed from a visual to a logical form),</li>
0127  * <li>resolving embedding levels of each character in the input text by
0128  * calling <code>ubidi_setPara</code>,</li>
0129  * <li>reordering the characters based on the computed embedding levels, also
0130  * performing character mirroring as needed, and streaming the result to the
0131  * output, by calling <code>ubidi_writeReordered</code>,</li>
0132  * <li>performing Arabic digit and letter shaping on the output text by calling
0133  * <code>u_shapeArabic</code>.</li>
0134  * </ul>
0135  * An "ordering scheme" encompasses the base direction and the order of text,
0136  * and these characteristics must be defined by the caller for both input and
0137  * output explicitly .<p>
0138  * There are 36 possible combinations of <input, output> ordering schemes,
0139  * which are partially supported by <code>UBiDi</code> already. Examples of the
0140  * currently supported combinations:
0141  * <ul>
0142  * <li><Logical LTR, Visual LTR>: this is equivalent to calling
0143  * <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_LTR</code>,</li>
0144  * <li><Logical RTL, Visual LTR>: this is equivalent to calling
0145  * <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_RTL</code>,</li>
0146  * <li><Logical Default ("Auto") LTR, Visual LTR>: this is equivalent to
0147  * calling <code>ubidi_setPara</code> with
0148  * <code>paraLevel == UBIDI_DEFAULT_LTR</code>,</li>
0149  * <li><Logical Default ("Auto") RTL, Visual LTR>: this is equivalent to
0150  * calling <code>ubidi_setPara</code> with
0151  * <code>paraLevel == UBIDI_DEFAULT_RTL</code>,</li>
0152  * <li><Visual LTR, Logical LTR>: this is equivalent to
0153  * calling <code>ubidi_setInverse(UBiDi*, true)</code> and then
0154  * <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_LTR</code>,</li>
0155  * <li><Visual LTR, Logical RTL>: this is equivalent to
0156  * calling <code>ubidi_setInverse(UBiDi*, true)</code> and then
0157  * <code>ubidi_setPara</code> with <code>paraLevel == UBIDI_RTL</code>.</li>
0158  * </ul>
0159  * All combinations that involve the Visual RTL scheme are unsupported by
0160  * <code>UBiDi</code>, for instance:
0161  * <ul>
0162  * <li><Logical LTR, Visual RTL>,</li>
0163  * <li><Visual RTL, Logical RTL>.</li>
0164  * </ul>
0165  * <p>Example of usage of the transformation engine:<br>
0166  * <pre>
0167  * \code
0168  * UChar text1[] = {'a', 'b', 'c', 0x0625, '1', 0};
0169  * UChar text2[] = {'a', 'b', 'c', 0x0625, '1', 0};
0170  * UErrorCode errorCode = U_ZERO_ERROR;
0171  * // Run a transformation.
0172  * ubiditransform_transform(pBidiTransform,
0173  *          text1, -1, text2, -1,
0174  *          UBIDI_LTR, UBIDI_VISUAL,
0175  *          UBIDI_RTL, UBIDI_LOGICAL,
0176  *          UBIDI_MIRRORING_OFF,
0177  *          U_SHAPE_DIGITS_AN2EN | U_SHAPE_DIGIT_TYPE_AN_EXTENDED,
0178  *          &errorCode);
0179  * // Do something with text2.
0180  *  text2[4] = '2';
0181  * // Run a reverse transformation.
0182  * ubiditransform_transform(pBidiTransform,
0183  *          text2, -1, text1, -1,
0184  *          UBIDI_RTL, UBIDI_LOGICAL,
0185  *          UBIDI_LTR, UBIDI_VISUAL,
0186  *          UBIDI_MIRRORING_OFF,
0187  *          U_SHAPE_DIGITS_EN2AN | U_SHAPE_DIGIT_TYPE_AN_EXTENDED,
0188  *          &errorCode);
0189  *\endcode
0190  * </pre>
0191  * </p>
0192  *
0193  * @param pBiDiTransform A pointer to a <code>UBiDiTransform</code> object
0194  *        allocated with <code>ubiditransform_open()</code> or
0195  *        <code>NULL</code>.<p>
0196  *        This object serves for one-time setup to amortize initialization
0197  *        overheads. Use of this object is not thread-safe. All other threads
0198  *        should allocate a new <code>UBiDiTransform</code> object by calling
0199  *        <code>ubiditransform_open()</code> before using it. Alternatively,
0200  *        a caller can set this parameter to <code>NULL</code>, in which case
0201  *        the object will be allocated by the engine on the fly.</p>
0202  * @param src A pointer to the text that the Bidi layout transformations will
0203  *        be performed on.
0204  *        <p><strong>Note:</strong> the text must be (at least)
0205  *        <code>srcLength</code> long.</p>
0206  * @param srcLength The length of the text, in number of UChars. If
0207  *        <code>length == -1</code> then the text must be zero-terminated.
0208  * @param dest A pointer to where the processed text is to be copied.
0209  * @param destSize The size of the <code>dest</code> buffer, in number of
0210  *        UChars. If the <code>U_SHAPE_LETTERS_UNSHAPE</code> option is set,
0211  *        then the destination length could be as large as
0212  *        <code>srcLength * 2</code>. Otherwise, the destination length will
0213  *        not exceed <code>srcLength</code>. If the caller reserves the last
0214  *        position for zero-termination, it should be excluded from
0215  *        <code>destSize</code>.
0216  *        <p><code>destSize == -1</code> is allowed and makes sense when
0217  *        <code>dest</code> was holds some meaningful value, e.g. that of
0218  *        <code>src</code>. In this case <code>dest</code> must be
0219  *        zero-terminated.</p>
0220  * @param inParaLevel A base embedding level of the input as defined in
0221  *        <code>ubidi_setPara</code> documentation for the
0222  *        <code>paraLevel</code> parameter.
0223  * @param inOrder An order of the input, which can be one of the
0224  *        <code>UBiDiOrder</code> values.
0225  * @param outParaLevel A base embedding level of the output as defined in
0226  *        <code>ubidi_setPara</code> documentation for the
0227  *        <code>paraLevel</code> parameter.
0228  * @param outOrder An order of the output, which can be one of the
0229  *        <code>UBiDiOrder</code> values.
0230  * @param doMirroring Indicates whether or not to perform character mirroring,
0231  *        and can accept one of the <code>UBiDiMirroring</code> values.
0232  * @param shapingOptions Arabic digit and letter shaping options defined in the
0233  *        ushape.h documentation.
0234  *        <p><strong>Note:</strong> Direction indicator options are computed by
0235  *        the transformation engine based on the effective ordering schemes, so
0236  *        user-defined direction indicators will be ignored.</p>
0237  * @param pErrorCode A pointer to an error code value.
0238  *
0239  * @return The destination length, i.e. the number of UChars written to
0240  *         <code>dest</code>. If the transformation fails, the return value
0241  *         will be 0 (and the error code will be written to
0242  *         <code>pErrorCode</code>).
0243  *
0244  * @see UBiDiLevel
0245  * @see UBiDiOrder
0246  * @see UBiDiMirroring
0247  * @see ubidi_setPara
0248  * @see u_shapeArabic
0249  * @stable ICU 58
0250  */
0251 U_CAPI uint32_t U_EXPORT2
0252 ubiditransform_transform(UBiDiTransform *pBiDiTransform,
0253             const UChar *src, int32_t srcLength,
0254             UChar *dest, int32_t destSize,
0255             UBiDiLevel inParaLevel, UBiDiOrder inOrder,
0256             UBiDiLevel outParaLevel, UBiDiOrder outOrder,
0257             UBiDiMirroring doMirroring, uint32_t shapingOptions,
0258             UErrorCode *pErrorCode);
0259 
0260 /**
0261  * Allocates a <code>UBiDiTransform</code> object. This object can be reused,
0262  * e.g. with different ordering schemes, mirroring or shaping options.<p>
0263  * <strong>Note:</strong>The object can only be reused in the same thread.
0264  * All other threads should allocate a new <code>UBiDiTransform</code> object
0265  * before using it.<p>
0266  * Example of usage:<p>
0267  * <pre>
0268  * \code
0269  * UErrorCode errorCode = U_ZERO_ERROR;
0270  * // Open a new UBiDiTransform.
0271  * UBiDiTransform* transform = ubiditransform_open(&errorCode);
0272  * // Run a transformation.
0273  * ubiditransform_transform(transform,
0274  *          text1, -1, text2, -1,
0275  *          UBIDI_RTL, UBIDI_LOGICAL,
0276  *          UBIDI_LTR, UBIDI_VISUAL,
0277  *          UBIDI_MIRRORING_ON,
0278  *          U_SHAPE_DIGITS_EN2AN,
0279  *          &errorCode);
0280  * // Do something with the output text and invoke another transformation using
0281  * //   that text as input.
0282  * ubiditransform_transform(transform,
0283  *          text2, -1, text3, -1,
0284  *          UBIDI_LTR, UBIDI_VISUAL,
0285  *          UBIDI_RTL, UBIDI_VISUAL,
0286  *          UBIDI_MIRRORING_ON,
0287  *          0, &errorCode);
0288  *\endcode
0289  * </pre>
0290  * <p>
0291  * The <code>UBiDiTransform</code> object must be deallocated by calling
0292  * <code>ubiditransform_close()</code>.
0293  *
0294  * @return An empty <code>UBiDiTransform</code> object.
0295  * @stable ICU 58
0296  */
0297 U_CAPI UBiDiTransform* U_EXPORT2
0298 ubiditransform_open(UErrorCode *pErrorCode);
0299 
0300 /**
0301  * Deallocates the given <code>UBiDiTransform</code> object.
0302  * @stable ICU 58
0303  */
0304 U_CAPI void U_EXPORT2
0305 ubiditransform_close(UBiDiTransform *pBidiTransform);
0306 
0307 #if U_SHOW_CPLUSPLUS_API
0308 
0309 U_NAMESPACE_BEGIN
0310 
0311 /**
0312  * \class LocalUBiDiTransformPointer
0313  * "Smart pointer" class, closes a UBiDiTransform via ubiditransform_close().
0314  * For most methods see the LocalPointerBase base class.
0315  *
0316  * @see LocalPointerBase
0317  * @see LocalPointer
0318  * @stable ICU 58
0319  */
0320 U_DEFINE_LOCAL_OPEN_POINTER(LocalUBiDiTransformPointer, UBiDiTransform, ubiditransform_close);
0321 
0322 U_NAMESPACE_END
0323 
0324 #endif
0325 
0326 #endif