Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ubidiimp.h

Go to the documentation of this file.
00001 /*  
00002 *******************************************************************************
00003 *
00004 *   Copyright (C) 1999-2000, International Business Machines
00005 *   Corporation and others.  All Rights Reserved.
00006 *
00007 *******************************************************************************
00008 *   file name:  ubidiimp.h
00009 *   encoding:   US-ASCII
00010 *   tab size:   8 (not used)
00011 *   indentation:4
00012 *
00013 *   created on: 1999aug06
00014 *   created by: Markus W. Scherer
00015 */
00016 
00017 #ifndef UBIDIIMP_H
00018 #define UBIDIIMP_H
00019 
00020 /* set import/export definitions */
00021 #ifdef U_COMMON_IMPLEMENTATION
00022 
00023 #include "unicode/utypes.h"
00024 #include "unicode/uchar.h"
00025 
00026 /* miscellaneous definitions ------------------------------------------------ */
00027 
00028 typedef uint8_t DirProp;
00029 typedef uint32_t Flags;
00030 
00031 /*  Comparing the description of the BiDi algorithm with this implementation
00032     is easier with the same names for the BiDi types in the code as there.
00033     See UCharDirection in uchar.h .
00034 */
00035 enum { 
00036     L=  U_LEFT_TO_RIGHT,
00037     R=  U_RIGHT_TO_LEFT,
00038     EN= U_EUROPEAN_NUMBER,
00039     ES= U_EUROPEAN_NUMBER_SEPARATOR,
00040     ET= U_EUROPEAN_NUMBER_TERMINATOR,
00041     AN= U_ARABIC_NUMBER,
00042     CS= U_COMMON_NUMBER_SEPARATOR,
00043     B=  U_BLOCK_SEPARATOR,
00044     S=  U_SEGMENT_SEPARATOR,
00045     WS= U_WHITE_SPACE_NEUTRAL,
00046     ON= U_OTHER_NEUTRAL,
00047     LRE=U_LEFT_TO_RIGHT_EMBEDDING,
00048     LRO=U_LEFT_TO_RIGHT_OVERRIDE,
00049     AL= U_RIGHT_TO_LEFT_ARABIC,
00050     RLE=U_RIGHT_TO_LEFT_EMBEDDING,
00051     RLO=U_RIGHT_TO_LEFT_OVERRIDE,
00052     PDF=U_POP_DIRECTIONAL_FORMAT,
00053     NSM=U_DIR_NON_SPACING_MARK,
00054     BN= U_BOUNDARY_NEUTRAL,
00055     dirPropCount
00056 };
00057 
00058 /*
00059  * Sometimes, bit values are more appropriate
00060  * to deal with directionality properties.
00061  * Abbreviations in these macro names refer to names
00062  * used in the BiDi algorithm.
00063  */
00064 #define DIRPROP_FLAG(dir) (1UL<<(dir))
00065 
00066 /* special flag for multiple runs from explicit embedding codes */
00067 #define DIRPROP_FLAG_MULTI_RUNS (1UL<<31)
00068 
00069 /* are there any characters that are LTR or RTL? */
00070 #define MASK_LTR (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
00071 #define MASK_RTL (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
00072 
00073 /* explicit embedding codes */
00074 #define MASK_LRX (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
00075 #define MASK_RLX (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
00076 #define MASK_OVERRIDE (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO))
00077 
00078 #define MASK_EXPLICIT (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF))
00079 #define MASK_BN_EXPLICIT (DIRPROP_FLAG(BN)|MASK_EXPLICIT)
00080 
00081 /* paragraph and segment separators */
00082 #define MASK_B_S (DIRPROP_FLAG(B)|DIRPROP_FLAG(S))
00083 
00084 /* all types that are counted as White Space or Neutral in some steps */
00085 #define MASK_WS (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT)
00086 #define MASK_N (DIRPROP_FLAG(ON)|MASK_WS)
00087 
00088 /* all types that are included in a sequence of European Terminators for (W5) */
00089 #define MASK_ET_NSM_BN (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT)
00090 
00091 /* types that are neutrals or could becomes neutrals in (Wn) */
00092 #define MASK_POSSIBLE_N (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N)
00093 
00094 /*
00095  * These types may be changed to "e",
00096  * the embedding type (L or R) of the run,
00097  * in the BiDi algorithm (N2)
00098  */
00099 #define MASK_EMBEDDING (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N)
00100 
00101 /* the dirProp's L and R are defined to 0 and 1 values in UCharDirection */
00102 #define GET_LR_FROM_LEVEL(level) ((DirProp)((level)&1))
00103 
00104 #define IS_DEFAULT_LEVEL(level) (((level)&0xfe)==0xfe)
00105 
00106 /* Run structure for reordering --------------------------------------------- */
00107 
00108 typedef struct Run {
00109     UTextOffset logicalStart,   /* first character of the run; b31 indicates even/odd level */
00110                 visualLimit;    /* last visual position of the run +1 */
00111 } Run;
00112 
00113 /* in a Run, logicalStart will get this bit set if the run level is odd */
00114 #define INDEX_ODD_BIT (1UL<<31)
00115 
00116 #define MAKE_INDEX_ODD_PAIR(index, level) (index|((int32_t)level<<31))
00117 #define ADD_ODD_BIT_FROM_LEVEL(x, level)  ((x)|=((int32_t)level<<31))
00118 #define REMOVE_ODD_BIT(x)                 ((x)&=~INDEX_ODD_BIT)
00119 
00120 #define GET_INDEX(x)   (x&~INDEX_ODD_BIT)
00121 #define GET_ODD_BIT(x) ((uint32_t)x>>31)
00122 #define IS_ODD_RUN(x)  ((x&INDEX_ODD_BIT)!=0)
00123 #define IS_EVEN_RUN(x) ((x&INDEX_ODD_BIT)==0)
00124 
00125 U_CFUNC UBool
00126 ubidi_getRuns(UBiDi *pBiDi);
00127 
00128 /* UBiDi structure ----------------------------------------------------------- */
00129 
00130 struct UBiDi {
00131     /* alias pointer to the current text */
00132     const UChar *text;
00133 
00134     /* length of the current text */
00135     UTextOffset length;
00136 
00137     /* memory sizes in bytes */
00138     UTextOffset dirPropsSize, levelsSize, runsSize;
00139 
00140     /* allocated memory */
00141     DirProp *dirPropsMemory;
00142     UBiDiLevel *levelsMemory;
00143     Run *runsMemory;
00144 
00145     /* indicators for whether memory may be allocated after ubidi_open() */
00146     UBool mayAllocateText, mayAllocateRuns;
00147 
00148     /* arrays with one value per text-character */
00149     const DirProp *dirProps;
00150     UBiDiLevel *levels;
00151 
00152     /* are we performing an approximation of the "inverse BiDi" algorithm? */
00153     UBool isInverse;
00154 
00155     /* the paragraph level */
00156     UBiDiLevel paraLevel;
00157 
00158     /* the overall paragraph or line directionality - see UBiDiDirection */
00159     UBiDiDirection direction;
00160 
00161     /* flags is a bit set for which directional properties are in the text */
00162     Flags flags;
00163 
00164     /* characters after trailingWSStart are WS and are */
00165     /* implicitly at the paraLevel (rule (L1)) - levels may not reflect that */
00166     UTextOffset trailingWSStart;
00167 
00168     /* fields for line reordering */
00169     UTextOffset runCount;     /* ==-1: runs not set up yet */
00170     Run *runs;
00171 
00172     /* for non-mixed text, we only need a tiny array of runs (no malloc()) */
00173     Run simpleRuns[1];
00174 };
00175 
00176 /* helper function to (re)allocate memory if allowed */
00177 extern UBool
00178 getMemory(void **pMemory, UTextOffset *pSize, UBool mayAllocate, UTextOffset sizeNeeded);
00179 
00180 /* helper macros for each allocated array in UBiDi */
00181 #define getDirPropsMemory(pBiDi, length) \
00182         getMemory((void **)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \
00183                         (pBiDi)->mayAllocateText, (length))
00184 
00185 #define getLevelsMemory(pBiDi, length) \
00186         getMemory((void **)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \
00187                         (pBiDi)->mayAllocateText, (length))
00188 
00189 #define getRunsMemory(pBiDi, length) \
00190         getMemory((void **)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \
00191                         (pBiDi)->mayAllocateRuns, (length)*sizeof(Run))
00192 
00193 /* additional macros used by ubidi_open() - always allow allocation */
00194 #define getInitialDirPropsMemory(pBiDi, length) \
00195         getMemory((void **)&(pBiDi)->dirPropsMemory, &(pBiDi)->dirPropsSize, \
00196                         TRUE, (length))
00197 
00198 #define getInitialLevelsMemory(pBiDi, length) \
00199         getMemory((void **)&(pBiDi)->levelsMemory, &(pBiDi)->levelsSize, \
00200                         TRUE, (length))
00201 
00202 #define getInitialRunsMemory(pBiDi, length) \
00203         getMemory((void **)&(pBiDi)->runsMemory, &(pBiDi)->runsSize, \
00204                         TRUE, (length)*sizeof(Run))
00205 
00206 #endif
00207 
00208 #endif

Generated at Tue Dec 5 17:55:33 2000 for ICU by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000