Classes | Defines | Typedefs | Enumerations

nsBidi.h File Reference

#include "nsCOMPtr.h"
#include "nsString.h"
#include "nsBidiUtils.h"
Include dependency graph for nsBidi.h:

Classes

struct  Run
class  nsBidi
 This class holds information about a paragraph of text with Bidi-algorithm-related details, or about one line of such a paragraph. More...

Defines

#define NSBIDI_DEFAULT_LTR   0xfe
 Paragraph level setting.
#define NSBIDI_DEFAULT_RTL   0xff
 Paragraph level setting.
#define NSBIDI_MAX_EXPLICIT_LEVEL   61
 Maximum explicit embedding level.
#define NSBIDI_LEVEL_OVERRIDE   0x80
 Bit flag for level input.
#define NSBIDI_KEEP_BASE_COMBINING   1
 option flags for WriteReverse()
#define NSBIDI_DO_MIRRORING   2
 option bit for WriteReverse(): replace characters with the "mirrored" property in RTL runs by their mirror-image mappings
#define NSBIDI_REMOVE_BIDI_CONTROLS   8
 option bit for WriteReverse(): remove Bidi control characters
#define GETDIRPROPSMEMORY(length)
#define GETLEVELSMEMORY(length)
#define GETRUNSMEMORY(length)
#define GETINITIALDIRPROPSMEMORY(length)
#define GETINITIALLEVELSMEMORY(length)
#define GETINITIALRUNSMEMORY(length)
#define DIRPROP_FLAG(dir)   (1UL<<(dir))
#define DIRPROP_FLAG_MULTI_RUNS   (1UL<<31)
#define MASK_LTR   (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
#define MASK_RTL   (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
#define MASK_LRX   (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
#define MASK_RLX   (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
#define MASK_OVERRIDE   (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO))
#define MASK_EXPLICIT   (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF))
#define MASK_BN_EXPLICIT   (DIRPROP_FLAG(BN)|MASK_EXPLICIT)
#define MASK_B_S   (DIRPROP_FLAG(B)|DIRPROP_FLAG(S))
#define MASK_WS   (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT)
#define MASK_N   (DIRPROP_FLAG(O_N)|MASK_WS)
#define MASK_ET_NSM_BN   (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT)
#define MASK_POSSIBLE_N   (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N)
#define MASK_EMBEDDING   (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N)
#define GET_LR_FROM_LEVEL(level)   ((DirProp)((level)&1))
#define IS_DEFAULT_LEVEL(level)   (((level)&0xfe)==0xfe)
#define IS_FIRST_SURROGATE(uchar)   (((uchar)&0xfc00)==0xd800)
#define IS_SECOND_SURROGATE(uchar)   (((uchar)&0xfc00)==0xdc00)
#define SURROGATE_OFFSET   ((0xd800<<10UL)+0xdc00-0x10000)
#define GET_UTF_32(first, second)   (((first)<<10UL)+(second)-SURROGATE_OFFSET)
#define UTF_ERROR_VALUE   0xffff
#define UTF16_APPEND_CHAR_UNSAFE(s, i, c)
#define UTF16_APPEND_CHAR_SAFE(s, i, length, c)
#define UTF16_PREV_CHAR_UNSAFE(s, i, c)
#define UTF16_BACK_1_UNSAFE(s, i)
#define UTF16_BACK_N_UNSAFE(s, i, n)
#define UTF16_PREV_CHAR_SAFE(s, start, i, c, strict)
#define UTF16_BACK_1_SAFE(s, start, i)
#define UTF16_BACK_N_SAFE(s, start, i, n)
#define UTF_PREV_CHAR_UNSAFE(s, i, c)   UTF16_PREV_CHAR_UNSAFE(s, i, c)
#define UTF_PREV_CHAR_SAFE(s, start, i, c, strict)   UTF16_PREV_CHAR_SAFE(s, start, i, c, strict)
#define UTF_BACK_1_UNSAFE(s, i)   UTF16_BACK_1_UNSAFE(s, i)
#define UTF_BACK_1_SAFE(s, start, i)   UTF16_BACK_1_SAFE(s, start, i)
#define UTF_BACK_N_UNSAFE(s, i, n)   UTF16_BACK_N_UNSAFE(s, i, n)
#define UTF_BACK_N_SAFE(s, start, i, n)   UTF16_BACK_N_SAFE(s, start, i, n)
#define UTF_APPEND_CHAR_UNSAFE(s, i, c)   UTF16_APPEND_CHAR_UNSAFE(s, i, c)
#define UTF_APPEND_CHAR_SAFE(s, i, length, c)   UTF16_APPEND_CHAR_SAFE(s, i, length, c)
#define UTF_PREV_CHAR(s, start, i, c)   UTF_PREV_CHAR_SAFE(s, start, i, c, PR_FALSE)
#define UTF_BACK_1(s, start, i)   UTF_BACK_1_SAFE(s, start, i)
#define UTF_BACK_N(s, start, i, n)   UTF_BACK_N_SAFE(s, start, i, n)
#define UTF_APPEND_CHAR(s, i, length, c)   UTF_APPEND_CHAR_SAFE(s, i, length, c)
#define INDEX_ODD_BIT   (1UL<<31)
#define MAKE_INDEX_ODD_PAIR(index, level)   (index|((PRUint32)level<<31))
#define ADD_ODD_BIT_FROM_LEVEL(x, level)   ((x)|=((PRUint32)level<<31))
#define REMOVE_ODD_BIT(x)   ((x)&=~INDEX_ODD_BIT)
#define GET_INDEX(x)   (x&~INDEX_ODD_BIT)
#define GET_ODD_BIT(x)   ((PRUint32)x>>31)
#define IS_ODD_RUN(x)   ((x&INDEX_ODD_BIT)!=0)
#define IS_EVEN_RUN(x)   ((x&INDEX_ODD_BIT)==0)

Typedefs

typedef PRUint8 nsBidiLevel
 nsBidiLevel is the type of the level values in this Bidi implementation.
typedef enum nsBidiDirection nsBidiDirection
typedef PRUint8 DirProp
typedef struct Run Run
typedef PRUint32 Flags

Enumerations

enum  nsBidiDirection { NSBIDI_LTR, NSBIDI_RTL, NSBIDI_MIXED }
 

nsBidiDirection values indicate the text direction.

More...

Define Documentation

#define ADD_ODD_BIT_FROM_LEVEL (   x,
  level 
)    ((x)|=((PRUint32)level<<31))
#define DIRPROP_FLAG (   dir  )     (1UL<<(dir))
#define DIRPROP_FLAG_MULTI_RUNS   (1UL<<31)
#define GET_INDEX (   x  )     (x&~INDEX_ODD_BIT)
#define GET_LR_FROM_LEVEL (   level  )     ((DirProp)((level)&1))
#define GET_ODD_BIT (   x  )     ((PRUint32)x>>31)
#define GET_UTF_32 (   first,
  second 
)    (((first)<<10UL)+(second)-SURROGATE_OFFSET)
#define GETDIRPROPSMEMORY (   length  ) 
Value:
GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \
                                  mMayAllocateText, (length))
#define GETINITIALDIRPROPSMEMORY (   length  ) 
Value:
GetMemory((void **)&mDirPropsMemory, &mDirPropsSize, \
                                         PR_TRUE, (length))
#define GETINITIALLEVELSMEMORY (   length  ) 
Value:
GetMemory((void **)&mLevelsMemory, &mLevelsSize, \
                                       PR_TRUE, (length))
#define GETINITIALRUNSMEMORY (   length  ) 
Value:
GetMemory((void **)&mRunsMemory, &mRunsSize, \
                                     PR_TRUE, (length)*sizeof(Run))
#define GETLEVELSMEMORY (   length  ) 
Value:
GetMemory((void **)&mLevelsMemory, &mLevelsSize, \
                                mMayAllocateText, (length))
#define GETRUNSMEMORY (   length  ) 
Value:
GetMemory((void **)&mRunsMemory, &mRunsSize, \
                              mMayAllocateRuns, (length)*sizeof(Run))
#define INDEX_ODD_BIT   (1UL<<31)
#define IS_DEFAULT_LEVEL (   level  )     (((level)&0xfe)==0xfe)
#define IS_EVEN_RUN (   x  )     ((x&INDEX_ODD_BIT)==0)
#define IS_FIRST_SURROGATE (   uchar  )     (((uchar)&0xfc00)==0xd800)
#define IS_ODD_RUN (   x  )     ((x&INDEX_ODD_BIT)!=0)
#define IS_SECOND_SURROGATE (   uchar  )     (((uchar)&0xfc00)==0xdc00)
#define MAKE_INDEX_ODD_PAIR (   index,
  level 
)    (index|((PRUint32)level<<31))
#define MASK_B_S   (DIRPROP_FLAG(B)|DIRPROP_FLAG(S))
#define MASK_BN_EXPLICIT   (DIRPROP_FLAG(BN)|MASK_EXPLICIT)
#define MASK_EMBEDDING   (DIRPROP_FLAG(NSM)|MASK_POSSIBLE_N)
#define MASK_ET_NSM_BN   (DIRPROP_FLAG(ET)|DIRPROP_FLAG(NSM)|MASK_BN_EXPLICIT)
#define MASK_EXPLICIT   (MASK_LRX|MASK_RLX|DIRPROP_FLAG(PDF))
#define MASK_LRX   (DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
#define MASK_LTR   (DIRPROP_FLAG(L)|DIRPROP_FLAG(EN)|DIRPROP_FLAG(AN)|DIRPROP_FLAG(LRE)|DIRPROP_FLAG(LRO))
#define MASK_N   (DIRPROP_FLAG(O_N)|MASK_WS)
#define MASK_OVERRIDE   (DIRPROP_FLAG(LRO)|DIRPROP_FLAG(RLO))
#define MASK_POSSIBLE_N   (DIRPROP_FLAG(CS)|DIRPROP_FLAG(ES)|DIRPROP_FLAG(ET)|MASK_N)
#define MASK_RLX   (DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
#define MASK_RTL   (DIRPROP_FLAG(R)|DIRPROP_FLAG(AL)|DIRPROP_FLAG(RLE)|DIRPROP_FLAG(RLO))
#define MASK_WS   (MASK_B_S|DIRPROP_FLAG(WS)|MASK_BN_EXPLICIT)
#define NSBIDI_DEFAULT_LTR   0xfe

Paragraph level setting.

If there is no strong character, then set the paragraph level to 0 (left-to-right).

#define NSBIDI_DEFAULT_RTL   0xff

Paragraph level setting.

If there is no strong character, then set the paragraph level to 1 (right-to-left).

#define NSBIDI_DO_MIRRORING   2

option bit for WriteReverse(): replace characters with the "mirrored" property in RTL runs by their mirror-image mappings

See also:
WriteReverse
#define NSBIDI_KEEP_BASE_COMBINING   1

option flags for WriteReverse()

option bit for WriteReverse(): keep combining characters after their base characters in RTL runs

See also:
WriteReverse
#define NSBIDI_LEVEL_OVERRIDE   0x80

Bit flag for level input.

Overrides directional properties.

#define NSBIDI_MAX_EXPLICIT_LEVEL   61

Maximum explicit embedding level.

(The maximum resolved level can be up to NSBIDI_MAX_EXPLICIT_LEVEL+1).

#define NSBIDI_REMOVE_BIDI_CONTROLS   8

option bit for WriteReverse(): remove Bidi control characters

See also:
WriteReverse
#define REMOVE_ODD_BIT (   x  )     ((x)&=~INDEX_ODD_BIT)
#define SURROGATE_OFFSET   ((0xd800<<10UL)+0xdc00-0x10000)
#define UTF16_APPEND_CHAR_SAFE (   s,
  i,
  length,
  c 
)
Value:
{ \
                                                if((PRUInt32)(c)<=0xffff) { \
                                                (s)[(i)++]=(PRUnichar)(c); \
                                                } else if((PRUInt32)(c)<=0x10ffff) { \
                                                if((i)+1<(length)) { \
                                                (s)[(i)++]=(PRUnichar)((c)>>10)+0xd7c0; \
                                                (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \
                                                } else /* not enough space */ { \
                                                (s)[(i)++]=UTF_ERROR_VALUE; \
                                                } \
                                                } else /* c>0x10ffff, write error value */ { \
                                                (s)[(i)++]=UTF_ERROR_VALUE; \
                                                } \
}
#define UTF16_APPEND_CHAR_UNSAFE (   s,
  i,
  c 
)
Value:
{ \
                                         if((PRUint32)(c)<=0xffff) { \
                                         (s)[(i)++]=(PRUnichar)(c); \
                                         } else { \
                                         (s)[(i)++]=(PRUnichar)((c)>>10)+0xd7c0; \
                                         (s)[(i)++]=(PRUnichar)(c)&0x3ff|0xdc00; \
                                         } \
}
#define UTF16_BACK_1_SAFE (   s,
  start,
  i 
)
Value:
{ \
                                       if(IS_SECOND_SURROGATE((s)[--(i)]) && (i)>(start) && IS_FIRST_SURROGATE((s)[(i)-1])) { \
                                       --(i); \
                                       } \
}
#define UTF16_BACK_1_UNSAFE (   s,
  i 
)
Value:
{ \
                                  if(IS_SECOND_SURROGATE((s)[--(i)])) { \
                                  --(i); \
                                  } \
}
#define UTF16_BACK_N_SAFE (   s,
  start,
  i,
  n 
)
Value:
{ \
                                          PRInt32 __N=(n); \
                                          while(__N>0 && (i)>(start)) { \
                                          UTF16_BACK_1_SAFE(s, start, i); \
                                          --__N; \
                                          } \
}
#define UTF16_BACK_N_UNSAFE (   s,
  i,
  n 
)
Value:
{ \
                                     PRInt32 __N=(n); \
                                     while(__N>0) { \
                                     UTF16_BACK_1_UNSAFE(s, i); \
                                     --__N; \
                                     } \
}
#define UTF16_PREV_CHAR_SAFE (   s,
  start,
  i,
  c,
  strict 
)
Value:
{ \
                                                     (c)=(s)[--(i)]; \
                                                     if(IS_SECOND_SURROGATE(c)) { \
                                                     PRUnichar __c2; \
                                                     if((i)>(start) && IS_FIRST_SURROGATE(__c2=(s)[(i)-1])) { \
                                                     --(i); \
                                                     (c)=GET_UTF_32(__c2, (c)); \
      /* strict: ((c)&0xfffe)==0xfffe is caught by UTF_IS_ERROR() */ \
                                                     } else if(strict) {\
      /* unmatched second surrogate */ \
                                                     (c)=UTF_ERROR_VALUE; \
                                                     } \
                                                     } else if(strict && IS_FIRST_SURROGATE(c)) { \
      /* unmatched first surrogate */ \
                                                     (c)=UTF_ERROR_VALUE; \
  /* else strict: (c)==0xfffe is caught by UTF_IS_ERROR() */ \
                                                     } \
}
#define UTF16_PREV_CHAR_UNSAFE (   s,
  i,
  c 
)
Value:
{ \
                                        (c)=(s)[--(i)]; \
                                        if(IS_SECOND_SURROGATE(c)) { \
                                        (c)=GET_UTF_32((s)[--(i)], (c)); \
                                        } \
}
#define UTF_APPEND_CHAR (   s,
  i,
  length,
  c 
)    UTF_APPEND_CHAR_SAFE(s, i, length, c)
#define UTF_APPEND_CHAR_SAFE (   s,
  i,
  length,
  c 
)    UTF16_APPEND_CHAR_SAFE(s, i, length, c)
#define UTF_APPEND_CHAR_UNSAFE (   s,
  i,
  c 
)    UTF16_APPEND_CHAR_UNSAFE(s, i, c)
#define UTF_BACK_1 (   s,
  start,
  i 
)    UTF_BACK_1_SAFE(s, start, i)
#define UTF_BACK_1_SAFE (   s,
  start,
  i 
)    UTF16_BACK_1_SAFE(s, start, i)
#define UTF_BACK_1_UNSAFE (   s,
  i 
)    UTF16_BACK_1_UNSAFE(s, i)
#define UTF_BACK_N (   s,
  start,
  i,
  n 
)    UTF_BACK_N_SAFE(s, start, i, n)
#define UTF_BACK_N_SAFE (   s,
  start,
  i,
  n 
)    UTF16_BACK_N_SAFE(s, start, i, n)
#define UTF_BACK_N_UNSAFE (   s,
  i,
  n 
)    UTF16_BACK_N_UNSAFE(s, i, n)
#define UTF_ERROR_VALUE   0xffff
#define UTF_PREV_CHAR (   s,
  start,
  i,
  c 
)    UTF_PREV_CHAR_SAFE(s, start, i, c, PR_FALSE)
#define UTF_PREV_CHAR_SAFE (   s,
  start,
  i,
  c,
  strict 
)    UTF16_PREV_CHAR_SAFE(s, start, i, c, strict)
#define UTF_PREV_CHAR_UNSAFE (   s,
  i,
  c 
)    UTF16_PREV_CHAR_UNSAFE(s, i, c)

Typedef Documentation

typedef PRUint8 DirProp
typedef PRUint32 Flags
typedef PRUint8 nsBidiLevel

nsBidiLevel is the type of the level values in this Bidi implementation.

It holds an embedding level and indicates the visual direction by its bit 0 (even/odd value).

It can also hold non-level values for the aParaLevel and aEmbeddingLevels arguments of SetPara; there:

  • bit 7 of an aEmbeddingLevels[] value indicates whether the using application is specifying the level of a character to override whatever the Bidi implementation would resolve it to.
  • aParaLevel can be set to the pseudo-level values NSBIDI_DEFAULT_LTR and NSBIDI_DEFAULT_RTL.
See also:
nsIBidi::SetPara

The related constants are not real, valid level values. NSBIDI_DEFAULT_XXX can be used to specify a default for the paragraph level for when the SetPara function shall determine it but there is no strongly typed character in the input.

Note that the value for NSBIDI_DEFAULT_LTR is even and the one for NSBIDI_DEFAULT_RTL is odd, just like with normal LTR and RTL level values - these special values are designed that way. Also, the implementation assumes that NSBIDI_MAX_EXPLICIT_LEVEL is odd.

See also:
NSBIDI_DEFAULT_LTR
NSBIDI_DEFAULT_RTL
NSBIDI_LEVEL_OVERRIDE
NSBIDI_MAX_EXPLICIT_LEVEL
typedef struct Run Run

Enumeration Type Documentation

nsBidiDirection values indicate the text direction.

Enumerator:
NSBIDI_LTR 

All left-to-right text This is a 0 value.

NSBIDI_RTL 

All right-to-left text This is a 1 value.

NSBIDI_MIXED 

Mixed-directional text.