sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* Definitions for bidirectional text reordering.
|
sl@0
|
16 |
*
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
#ifndef BIDI_H_
|
sl@0
|
23 |
#define BIDI_H_
|
sl@0
|
24 |
|
sl@0
|
25 |
#include <e32std.h>
|
sl@0
|
26 |
|
sl@0
|
27 |
class RWriteStream;
|
sl@0
|
28 |
class RReadStream;
|
sl@0
|
29 |
|
sl@0
|
30 |
|
sl@0
|
31 |
class TBidirectionalState
|
sl@0
|
32 |
/**
|
sl@0
|
33 |
The bidirectional state class.
|
sl@0
|
34 |
This class contains functions that implement the Unicode Bidirectional Algorithm,
|
sl@0
|
35 |
which changes text from logical order to display order for the correct display
|
sl@0
|
36 |
of right-to-left scripts, like Arabic and Hebrew. A TBidirectionalState object
|
sl@0
|
37 |
carries the embedding level and stack from one line to the next. On construction
|
sl@0
|
38 |
it is in its 'start of paragraph' state.
|
sl@0
|
39 |
@publishedAll
|
sl@0
|
40 |
@released
|
sl@0
|
41 |
*/
|
sl@0
|
42 |
{
|
sl@0
|
43 |
friend class CTBiDi;
|
sl@0
|
44 |
|
sl@0
|
45 |
public:
|
sl@0
|
46 |
|
sl@0
|
47 |
class TRunInfo
|
sl@0
|
48 |
/**
|
sl@0
|
49 |
Information about a run of characters with the same bidirectional
|
sl@0
|
50 |
category.
|
sl@0
|
51 |
|
sl@0
|
52 |
An array of these representing a line is passed into, and reordered by,
|
sl@0
|
53 |
ReorderLine().
|
sl@0
|
54 |
@publishedAll
|
sl@0
|
55 |
@released
|
sl@0
|
56 |
*/
|
sl@0
|
57 |
{
|
sl@0
|
58 |
public:
|
sl@0
|
59 |
/** Category of a run of text: passed to ReorderLine(); these are
|
sl@0
|
60 |
passed in as TChar::TBdCategory values but are modified for internal
|
sl@0
|
61 |
use. */
|
sl@0
|
62 |
TUint iCategory;
|
sl@0
|
63 |
/** Embedding level of this run: used internally by ReorderLine(). */
|
sl@0
|
64 |
TUint8 iEmbeddingLevel;
|
sl@0
|
65 |
/** Resolved direction of this run: 0 for left to right, 1 for right
|
sl@0
|
66 |
to left. */
|
sl@0
|
67 |
TUint8 iDirection;
|
sl@0
|
68 |
/** Index of this run after reordering. */
|
sl@0
|
69 |
TInt iIndex;
|
sl@0
|
70 |
/** Start of text; returned by ReorderText(). */
|
sl@0
|
71 |
TInt iStart;
|
sl@0
|
72 |
/** Length of text; returned by ReorderText(). */
|
sl@0
|
73 |
TInt iLength;
|
sl@0
|
74 |
};
|
sl@0
|
75 |
|
sl@0
|
76 |
IMPORT_C TBidirectionalState();
|
sl@0
|
77 |
IMPORT_C void ReorderLine(TRunInfo* aRunInfo,TInt aRuns,TBool aParStart,TBool aParEnd,TBool aParRightToLeft,
|
sl@0
|
78 |
TChar::TBdCategory aNextCategory,TChar::TBdCategory aNextStrongCategory,
|
sl@0
|
79 |
TBool& aVisualEndIsAmbiguous);
|
sl@0
|
80 |
IMPORT_C void ReorderLine(TRunInfo* aRunInfo,TInt aRuns,TBool aParStart,TBool aParEnd,TBool aParRightToLeft,
|
sl@0
|
81 |
TChar::TBdCategory aNextCategory,TChar::TBdCategory aNextStrongCategory);
|
sl@0
|
82 |
IMPORT_C static TInt ReorderText(const TText* aText,TInt aLength,TBool aParRightToLeft,TText*& aNewText);
|
sl@0
|
83 |
IMPORT_C static void ReverseGroups(TText* aStart,TInt aLength);
|
sl@0
|
84 |
IMPORT_C void Reset();
|
sl@0
|
85 |
IMPORT_C TBool IsDefault() const;
|
sl@0
|
86 |
IMPORT_C TBool operator==(const TBidirectionalState& aState) const;
|
sl@0
|
87 |
IMPORT_C void ExternalizeL(RWriteStream& aDest);
|
sl@0
|
88 |
IMPORT_C void InternalizeL(RReadStream& aSource);
|
sl@0
|
89 |
TBool ParRightToLeft() const { return iStack[0].iEmbeddingLevel & 1; }
|
sl@0
|
90 |
|
sl@0
|
91 |
private:
|
sl@0
|
92 |
// Bidirectional categories coded as bit flags
|
sl@0
|
93 |
enum TCategory
|
sl@0
|
94 |
{
|
sl@0
|
95 |
ELeftToRight = 1 << TChar::ELeftToRight,
|
sl@0
|
96 |
ELeftToRightEmbedding = 1 << TChar::ELeftToRightEmbedding,
|
sl@0
|
97 |
ELeftToRightOverride = 1 << TChar::ELeftToRightOverride,
|
sl@0
|
98 |
ERightToLeft = 1 << TChar::ERightToLeft,
|
sl@0
|
99 |
ERightToLeftArabic = 1 << TChar::ERightToLeftArabic,
|
sl@0
|
100 |
ERightToLeftEmbedding = 1 << TChar::ERightToLeftEmbedding,
|
sl@0
|
101 |
ERightToLeftOverride = 1 << TChar::ERightToLeftOverride,
|
sl@0
|
102 |
EPopDirectionalFormat = 1 << TChar::EPopDirectionalFormat,
|
sl@0
|
103 |
EEuropeanNumber = 1 << TChar::EEuropeanNumber,
|
sl@0
|
104 |
EEuropeanNumberSeparator = 1 << TChar::EEuropeanNumberSeparator,
|
sl@0
|
105 |
EEuropeanNumberTerminator = 1 << TChar::EEuropeanNumberTerminator,
|
sl@0
|
106 |
EArabicNumber = 1 << TChar::EArabicNumber,
|
sl@0
|
107 |
ECommonNumberSeparator = 1 << TChar::ECommonNumberSeparator,
|
sl@0
|
108 |
ENonSpacingMark = 1 << TChar::ENonSpacingMark,
|
sl@0
|
109 |
EBoundaryNeutral = 1 << TChar::EBoundaryNeutral,
|
sl@0
|
110 |
EParagraphSeparator = 1 << TChar::EParagraphSeparator,
|
sl@0
|
111 |
ESegmentSeparator = 1 << TChar::ESegmentSeparator,
|
sl@0
|
112 |
EWhitespace = 1 << TChar::EWhitespace,
|
sl@0
|
113 |
EOtherNeutral = 1 << TChar::EOtherNeutral,
|
sl@0
|
114 |
|
sl@0
|
115 |
// useful groups
|
sl@0
|
116 |
EBdControlsGroup = ELeftToRightEmbedding | ERightToLeftEmbedding |
|
sl@0
|
117 |
ELeftToRightOverride | ERightToLeftOverride | EPopDirectionalFormat,
|
sl@0
|
118 |
ELeftToRightGroup = ELeftToRight | EEuropeanNumber | ELeftToRightOverride | ELeftToRightEmbedding,
|
sl@0
|
119 |
ERightToLeftGroup = ERightToLeft | EArabicNumber | ERightToLeftArabic | ERightToLeftOverride |
|
sl@0
|
120 |
ERightToLeftEmbedding,
|
sl@0
|
121 |
EStrongGroup = ELeftToRightEmbedding | ERightToLeftEmbedding
|
sl@0
|
122 |
| ELeftToRightOverride | ERightToLeftOverride
|
sl@0
|
123 |
| ELeftToRight | ERightToLeft | ERightToLeftArabic,
|
sl@0
|
124 |
|
sl@0
|
125 |
ENoCategory = 0
|
sl@0
|
126 |
};
|
sl@0
|
127 |
|
sl@0
|
128 |
enum
|
sl@0
|
129 |
{
|
sl@0
|
130 |
EMaxExplicitLevel = 61,
|
sl@0
|
131 |
EMaxLevel = 63,
|
sl@0
|
132 |
EMaxStackLevels = 62
|
sl@0
|
133 |
};
|
sl@0
|
134 |
|
sl@0
|
135 |
enum TOverrideState
|
sl@0
|
136 |
{
|
sl@0
|
137 |
ENoOverrideState = 0,
|
sl@0
|
138 |
ELeftToRightOverrideState = ELeftToRightOverride,
|
sl@0
|
139 |
ERightToLeftOverrideState = ERightToLeftOverride
|
sl@0
|
140 |
};
|
sl@0
|
141 |
|
sl@0
|
142 |
class TStackItem
|
sl@0
|
143 |
{
|
sl@0
|
144 |
public:
|
sl@0
|
145 |
TUint8 iEmbeddingLevel; // embedding level
|
sl@0
|
146 |
TOverrideState iOverrideState; // directional override state
|
sl@0
|
147 |
TCategory iStartCategory; // category that started this level; EOtherNeutral if none
|
sl@0
|
148 |
};
|
sl@0
|
149 |
|
sl@0
|
150 |
private:
|
sl@0
|
151 |
/** The information needed during line reordering.
|
sl@0
|
152 |
WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases.
|
sl@0
|
153 |
*/
|
sl@0
|
154 |
class TReorderContext
|
sl@0
|
155 |
{
|
sl@0
|
156 |
public:
|
sl@0
|
157 |
void SetNextCategory(TChar::TBdCategory aCat);
|
sl@0
|
158 |
void SetNextStrongCategory(TChar::TBdCategory aCat);
|
sl@0
|
159 |
public:
|
sl@0
|
160 |
/** Category at start of next line, or ON if at the end of the
|
sl@0
|
161 |
paragraph. */
|
sl@0
|
162 |
TCategory iNextCategory;
|
sl@0
|
163 |
/** Which of L, R or AL appears first in the remainder of the
|
sl@0
|
164 |
paragraph, or ON if none. */
|
sl@0
|
165 |
TCategory iNextStrongCategory;
|
sl@0
|
166 |
/** The run array for this line. */
|
sl@0
|
167 |
TRunInfo* iRunInfo;
|
sl@0
|
168 |
/** The length of iRunInfo. */
|
sl@0
|
169 |
TInt iRuns;
|
sl@0
|
170 |
/** Bitmap of categories currently present in iRunInfo. */
|
sl@0
|
171 |
TUint32 iCategories;
|
sl@0
|
172 |
/** Found by the algorithm to set iPreviousStrongCategory. */
|
sl@0
|
173 |
TCategory iLastStrongCategory;
|
sl@0
|
174 |
};
|
sl@0
|
175 |
|
sl@0
|
176 |
public:
|
sl@0
|
177 |
static TInt GenerateBdRunArray(const TText* aText, TInt aLength,
|
sl@0
|
178 |
TBidirectionalState::TRunInfo* aRun, TInt aMaxRuns);
|
sl@0
|
179 |
|
sl@0
|
180 |
private:
|
sl@0
|
181 |
const TStackItem& State() const { return iStack[iStackLevel]; }
|
sl@0
|
182 |
TCategory Push(TCategory aStartCategory);
|
sl@0
|
183 |
TCategory Pop();
|
sl@0
|
184 |
|
sl@0
|
185 |
public:
|
sl@0
|
186 |
TBidirectionalState(TChar::TBdCategory aPrevCat,
|
sl@0
|
187 |
TChar::TBdCategory aPrevStrongCat, TBool aParRightToLeft);
|
sl@0
|
188 |
void HandleBdControls(TReorderContext& aContext);
|
sl@0
|
189 |
void ResolveWeakTypesW1W2W3(TReorderContext& aContext);
|
sl@0
|
190 |
void ResolveWeakTypesW4W5W6(TReorderContext& aContext);
|
sl@0
|
191 |
void ResolveWeakTypesW7(TReorderContext& aContext);
|
sl@0
|
192 |
void ResolveNeutralTypes(TReorderContext& aContext);
|
sl@0
|
193 |
void ResolveImplicitLevels(TReorderContext& aContext);
|
sl@0
|
194 |
void PrepareForNextLine(const TReorderContext& aContext);
|
sl@0
|
195 |
void ReorderRuns(TReorderContext& aContext);
|
sl@0
|
196 |
static TInt CatToNumber(TInt aCat);
|
sl@0
|
197 |
static TCategory CharToBdCat(TChar::TBdCategory aCat);
|
sl@0
|
198 |
static TCategory UintToBdCat(TUint aCat);
|
sl@0
|
199 |
static void DeneutralizeRuns(TRunInfo* aStart, TRunInfo* aEnd,
|
sl@0
|
200 |
TCategory aStartCategory, TCategory aEndCategory);
|
sl@0
|
201 |
private:
|
sl@0
|
202 |
TCategory iPreviousCategory; // category at end of last line, or EStartOfParagraph if at start of par
|
sl@0
|
203 |
TCategory iPreviousStrongCategory; // L or R; derived from embedding level if at start of par
|
sl@0
|
204 |
TInt16 iStackLevel; // current stack level
|
sl@0
|
205 |
TInt8 iPushesBeyond60; // number of times Push called with iStackLevel == 60 and Left-To-Right category
|
sl@0
|
206 |
TInt8 iPushesBeyond61; // number of times Push called with iStackLevel == 61
|
sl@0
|
207 |
TStackItem iStack[EMaxStackLevels]; // the stack of embedding levels
|
sl@0
|
208 |
};
|
sl@0
|
209 |
|
sl@0
|
210 |
#endif // BIDI_H_
|