1/*
2*******************************************************************************
3*
4*   Copyright (C) 2004-2013, International Business Machines
5*   Corporation and others.  All Rights Reserved.
6*
7*******************************************************************************
8*   file name:  ubidi_props.h
9*   encoding:   US-ASCII
10*   tab size:   8 (not used)
11*   indentation:4
12*
13*   created on: 2004dec30
14*   created by: Markus W. Scherer
15*
16*   Low-level Unicode bidi/shaping properties access.
17*/
18
19#ifndef __UBIDI_PROPS_H__
20#define __UBIDI_PROPS_H__
21
22#include "unicode/utypes.h"
23#include "unicode/uset.h"
24#include "putilimp.h"
25#include "uset_imp.h"
26#include "udataswp.h"
27
28U_CDECL_BEGIN
29
30/* library API -------------------------------------------------------------- */
31
32struct UBiDiProps;
33typedef struct UBiDiProps UBiDiProps;
34
35U_CFUNC const UBiDiProps *
36ubidi_getSingleton(void);
37
38U_CFUNC void
39ubidi_addPropertyStarts(const UBiDiProps *bdp, const USetAdder *sa, UErrorCode *pErrorCode);
40
41/* property access functions */
42
43U_CFUNC int32_t
44ubidi_getMaxValue(const UBiDiProps *bdp, UProperty which);
45
46U_CAPI UCharDirection
47ubidi_getClass(const UBiDiProps *bdp, UChar32 c);
48
49U_CFUNC UBool
50ubidi_isMirrored(const UBiDiProps *bdp, UChar32 c);
51
52U_CFUNC UChar32
53ubidi_getMirror(const UBiDiProps *bdp, UChar32 c);
54
55U_CFUNC UBool
56ubidi_isBidiControl(const UBiDiProps *bdp, UChar32 c);
57
58U_CFUNC UBool
59ubidi_isJoinControl(const UBiDiProps *bdp, UChar32 c);
60
61U_CFUNC UJoiningType
62ubidi_getJoiningType(const UBiDiProps *bdp, UChar32 c);
63
64U_CFUNC UJoiningGroup
65ubidi_getJoiningGroup(const UBiDiProps *bdp, UChar32 c);
66
67U_CFUNC UBidiPairedBracketType
68ubidi_getPairedBracketType(const UBiDiProps *bdp, UChar32 c);
69
70U_CFUNC UChar32
71ubidi_getPairedBracket(const UBiDiProps *bdp, UChar32 c);
72
73/* file definitions --------------------------------------------------------- */
74
75#define UBIDI_DATA_NAME "ubidi"
76#define UBIDI_DATA_TYPE "icu"
77
78/* format "BiDi" */
79#define UBIDI_FMT_0 0x42
80#define UBIDI_FMT_1 0x69
81#define UBIDI_FMT_2 0x44
82#define UBIDI_FMT_3 0x69
83
84/* indexes into indexes[] */
85enum {
86    UBIDI_IX_INDEX_TOP,
87    UBIDI_IX_LENGTH,
88    UBIDI_IX_TRIE_SIZE,
89    UBIDI_IX_MIRROR_LENGTH,
90
91    UBIDI_IX_JG_START,
92    UBIDI_IX_JG_LIMIT,
93
94    UBIDI_MAX_VALUES_INDEX=15,
95    UBIDI_IX_TOP=16
96};
97
98/* definitions for 16-bit bidi/shaping properties word ---------------------- */
99
100enum {
101 /* UBIDI_CLASS_SHIFT=0, */     /* bidi class: 5 bits (4..0) */
102    UBIDI_JT_SHIFT=5,           /* joining type: 3 bits (7..5) */
103
104    UBIDI_BPT_SHIFT=8,          /* Bidi_Paired_Bracket_Type(bpt): 2 bits (9..8) */
105
106    UBIDI_JOIN_CONTROL_SHIFT=10,
107    UBIDI_BIDI_CONTROL_SHIFT=11,
108
109    UBIDI_IS_MIRRORED_SHIFT=12,         /* 'is mirrored' */
110    UBIDI_MIRROR_DELTA_SHIFT=13,        /* bidi mirroring delta: 3 bits (15..13) */
111
112    UBIDI_MAX_JG_SHIFT=16               /* max JG value in indexes[UBIDI_MAX_VALUES_INDEX] bits 23..16 */
113};
114
115#define UBIDI_CLASS_MASK        0x0000001f
116#define UBIDI_JT_MASK           0x000000e0
117#define UBIDI_BPT_MASK          0x00000300
118
119#define UBIDI_MAX_JG_MASK       0x00ff0000
120
121#define UBIDI_GET_CLASS(props) ((props)&UBIDI_CLASS_MASK)
122#define UBIDI_GET_FLAG(props, shift) (((props)>>(shift))&1)
123
124#if U_SIGNED_RIGHT_SHIFT_IS_ARITHMETIC
125#   define UBIDI_GET_MIRROR_DELTA(props) ((int16_t)(props)>>UBIDI_MIRROR_DELTA_SHIFT)
126#else
127#   define UBIDI_GET_MIRROR_DELTA(props) (int16_t)(((props)&0x8000) ? (((props)>>UBIDI_MIRROR_DELTA_SHIFT)|0xe000) : ((props)>>UBIDI_MIRROR_DELTA_SHIFT))
128#endif
129
130enum {
131    UBIDI_ESC_MIRROR_DELTA=-4,
132    UBIDI_MIN_MIRROR_DELTA=-3,
133    UBIDI_MAX_MIRROR_DELTA=3
134};
135
136/* definitions for 32-bit mirror table entry -------------------------------- */
137
138enum {
139    /* the source Unicode code point takes 21 bits (20..0) */
140    UBIDI_MIRROR_INDEX_SHIFT=21,
141    UBIDI_MAX_MIRROR_INDEX=0x7ff
142};
143
144#define UBIDI_GET_MIRROR_CODE_POINT(m) (UChar32)((m)&0x1fffff)
145
146#define UBIDI_GET_MIRROR_INDEX(m) ((m)>>UBIDI_MIRROR_INDEX_SHIFT)
147
148U_CDECL_END
149
150#endif
151