1/*
2*******************************************************************************
3*
4*   Copyright (C) 2004-2008, 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 "uset_imp.h"
25#include "udataswp.h"
26
27#define UBIDI_HARDCODE_DATA 1
28
29U_CDECL_BEGIN
30
31/* library API -------------------------------------------------------------- */
32
33struct UBiDiProps;
34typedef struct UBiDiProps UBiDiProps;
35
36U_CFUNC UBiDiProps *
37ubidi_openProps(UErrorCode *pErrorCode);
38
39U_CFUNC UBiDiProps *
40ubidi_openBinary(const uint8_t *bin, int32_t length, UErrorCode *pErrorCode);
41
42U_CFUNC void
43ubidi_closeProps(UBiDiProps *bdp);
44
45
46U_CFUNC const UBiDiProps *
47ubidi_getSingleton(UErrorCode *pErrorCode);
48
49#if !UBIDI_HARDCODE_DATA
50/**
51 * Get a singleton dummy object, one that works with no real data.
52 * This can be used when the real data is not available.
53 * Using the dummy can reduce checks for available data after an initial failure.
54 */
55U_CAPI const UBiDiProps *
56ubidi_getDummy(UErrorCode *pErrorCode);
57#endif
58
59U_CAPI int32_t
60ubidi_swap(const UDataSwapper *ds,
61           const void *inData, int32_t length, void *outData,
62           UErrorCode *pErrorCode);
63
64U_CFUNC void
65ubidi_addPropertyStarts(const UBiDiProps *bdp, const USetAdder *sa, UErrorCode *pErrorCode);
66
67/* property access functions */
68
69U_CFUNC int32_t
70ubidi_getMaxValue(const UBiDiProps *bdp, UProperty which);
71
72U_CAPI UCharDirection
73ubidi_getClass(const UBiDiProps *bdp, UChar32 c);
74
75U_CFUNC UBool
76ubidi_isMirrored(const UBiDiProps *bdp, UChar32 c);
77
78U_CFUNC UChar32
79ubidi_getMirror(const UBiDiProps *bdp, UChar32 c);
80
81U_CFUNC UBool
82ubidi_isBidiControl(const UBiDiProps *bdp, UChar32 c);
83
84U_CFUNC UBool
85ubidi_isJoinControl(const UBiDiProps *bdp, UChar32 c);
86
87U_CFUNC UJoiningType
88ubidi_getJoiningType(const UBiDiProps *bdp, UChar32 c);
89
90U_CFUNC UJoiningGroup
91ubidi_getJoiningGroup(const UBiDiProps *bdp, UChar32 c);
92
93/* file definitions --------------------------------------------------------- */
94
95#define UBIDI_DATA_NAME "ubidi"
96#define UBIDI_DATA_TYPE "icu"
97
98/* format "BiDi" */
99#define UBIDI_FMT_0 0x42
100#define UBIDI_FMT_1 0x69
101#define UBIDI_FMT_2 0x44
102#define UBIDI_FMT_3 0x69
103
104/* indexes into indexes[] */
105enum {
106    UBIDI_IX_INDEX_TOP,
107    UBIDI_IX_LENGTH,
108    UBIDI_IX_TRIE_SIZE,
109    UBIDI_IX_MIRROR_LENGTH,
110
111    UBIDI_IX_JG_START,
112    UBIDI_IX_JG_LIMIT,
113
114    UBIDI_MAX_VALUES_INDEX=15,
115    UBIDI_IX_TOP=16
116};
117
118/* definitions for 16-bit bidi/shaping properties word ---------------------- */
119
120enum {
121 /* UBIDI_CLASS_SHIFT=0, */     /* bidi class: 5 bits (4..0) */
122    UBIDI_JT_SHIFT=5,           /* joining type: 3 bits (7..5) */
123
124    /* UBIDI__SHIFT=8, reserved: 2 bits (9..8) */
125
126    UBIDI_JOIN_CONTROL_SHIFT=10,
127    UBIDI_BIDI_CONTROL_SHIFT=11,
128
129    UBIDI_IS_MIRRORED_SHIFT=12,         /* 'is mirrored' */
130    UBIDI_MIRROR_DELTA_SHIFT=13,        /* bidi mirroring delta: 3 bits (15..13) */
131
132    UBIDI_MAX_JG_SHIFT=16               /* max JG value in indexes[UBIDI_MAX_VALUES_INDEX] bits 23..16 */
133};
134
135#define UBIDI_CLASS_MASK        0x0000001f
136#define UBIDI_JT_MASK           0x000000e0
137
138#define UBIDI_MAX_JG_MASK       0x00ff0000
139
140#define UBIDI_GET_CLASS(props) ((props)&UBIDI_CLASS_MASK)
141#define UBIDI_GET_FLAG(props, shift) (((props)>>(shift))&1)
142
143enum {
144    UBIDI_ESC_MIRROR_DELTA=-4,
145    UBIDI_MIN_MIRROR_DELTA=-3,
146    UBIDI_MAX_MIRROR_DELTA=3
147};
148
149/* definitions for 32-bit mirror table entry -------------------------------- */
150
151enum {
152    /* the source Unicode code point takes 21 bits (20..0) */
153    UBIDI_MIRROR_INDEX_SHIFT=21,
154    UBIDI_MAX_MIRROR_INDEX=0x7ff
155};
156
157#define UBIDI_GET_MIRROR_CODE_POINT(m) (UChar32)((m)&0x1fffff)
158
159#define UBIDI_GET_MIRROR_INDEX(m) ((m)>>UBIDI_MIRROR_INDEX_SHIFT)
160
161U_CDECL_END
162
163#endif
164