1.1 --- a/epoc32/include/bidi.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/bidi.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,210 @@
1.4 -bidi.h
1.5 +/*
1.6 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.7 +* All rights reserved.
1.8 +* This component and the accompanying materials are made available
1.9 +* under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.10 +* which accompanies this distribution, and is available
1.11 +* at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.12 +*
1.13 +* Initial Contributors:
1.14 +* Nokia Corporation - initial contribution.
1.15 +*
1.16 +* Contributors:
1.17 +*
1.18 +* Description:
1.19 +* Definitions for bidirectional text reordering.
1.20 +*
1.21 +*
1.22 +*/
1.23 +
1.24 +
1.25 +
1.26 +
1.27 +
1.28 +
1.29 +#ifndef BIDI_H_
1.30 +#define BIDI_H_
1.31 +
1.32 +#include <e32std.h>
1.33 +
1.34 +class RWriteStream;
1.35 +class RReadStream;
1.36 +
1.37 +
1.38 +class TBidirectionalState
1.39 +/**
1.40 +The bidirectional state class.
1.41 +This class contains functions that implement the Unicode Bidirectional Algorithm,
1.42 +which changes text from logical order to display order for the correct display
1.43 +of right-to-left scripts, like Arabic and Hebrew. A TBidirectionalState object
1.44 +carries the embedding level and stack from one line to the next. On construction
1.45 +it is in its 'start of paragraph' state.
1.46 +@publishedAll
1.47 +@released
1.48 +*/
1.49 + {
1.50 +public:
1.51 +
1.52 + class TRunInfo
1.53 + /**
1.54 + Information about a run of characters with the same bidirectional
1.55 + category.
1.56 +
1.57 + An array of these representing a line is passed into, and reordered by,
1.58 + ReorderLine().
1.59 + @publishedAll
1.60 + @released
1.61 + */
1.62 + {
1.63 + public:
1.64 + /** Category of a run of text: passed to ReorderLine(); these are
1.65 + passed in as TChar::TBdCategory values but are modified for internal
1.66 + use. */
1.67 + TUint iCategory;
1.68 + /** Embedding level of this run: used internally by ReorderLine(). */
1.69 + TUint8 iEmbeddingLevel;
1.70 + /** Resolved direction of this run: 0 for left to right, 1 for right
1.71 + to left. */
1.72 + TUint8 iDirection;
1.73 + /** Index of this run after reordering. */
1.74 + TInt iIndex;
1.75 + /** Start of text; returned by ReorderText(). */
1.76 + TInt iStart;
1.77 + /** Length of text; returned by ReorderText(). */
1.78 + TInt iLength;
1.79 + };
1.80 +
1.81 + IMPORT_C TBidirectionalState();
1.82 + IMPORT_C void ReorderLine(TRunInfo* aRunInfo,TInt aRuns,TBool aParStart,TBool aParEnd,TBool aParRightToLeft,
1.83 + TChar::TBdCategory aNextCategory,TChar::TBdCategory aNextStrongCategory,
1.84 + TBool& aVisualEndIsAmbiguous);
1.85 + IMPORT_C void ReorderLine(TRunInfo* aRunInfo,TInt aRuns,TBool aParStart,TBool aParEnd,TBool aParRightToLeft,
1.86 + TChar::TBdCategory aNextCategory,TChar::TBdCategory aNextStrongCategory);
1.87 + IMPORT_C static TInt ReorderText(const TText* aText,TInt aLength,TBool aParRightToLeft,TText*& aNewText);
1.88 + IMPORT_C static void ReverseGroups(TText* aStart,TInt aLength);
1.89 + IMPORT_C void Reset();
1.90 + IMPORT_C TBool IsDefault() const;
1.91 + IMPORT_C TBool operator==(const TBidirectionalState& aState) const;
1.92 + IMPORT_C void ExternalizeL(RWriteStream& aDest);
1.93 + IMPORT_C void InternalizeL(RReadStream& aSource);
1.94 + TBool ParRightToLeft() const { return iStack[0].iEmbeddingLevel & 1; }
1.95 +
1.96 +private:
1.97 + // Bidirectional categories coded as bit flags
1.98 + enum TCategory
1.99 + {
1.100 + ELeftToRight = 1 << TChar::ELeftToRight,
1.101 + ELeftToRightEmbedding = 1 << TChar::ELeftToRightEmbedding,
1.102 + ELeftToRightOverride = 1 << TChar::ELeftToRightOverride,
1.103 + ERightToLeft = 1 << TChar::ERightToLeft,
1.104 + ERightToLeftArabic = 1 << TChar::ERightToLeftArabic,
1.105 + ERightToLeftEmbedding = 1 << TChar::ERightToLeftEmbedding,
1.106 + ERightToLeftOverride = 1 << TChar::ERightToLeftOverride,
1.107 + EPopDirectionalFormat = 1 << TChar::EPopDirectionalFormat,
1.108 + EEuropeanNumber = 1 << TChar::EEuropeanNumber,
1.109 + EEuropeanNumberSeparator = 1 << TChar::EEuropeanNumberSeparator,
1.110 + EEuropeanNumberTerminator = 1 << TChar::EEuropeanNumberTerminator,
1.111 + EArabicNumber = 1 << TChar::EArabicNumber,
1.112 + ECommonNumberSeparator = 1 << TChar::ECommonNumberSeparator,
1.113 + ENonSpacingMark = 1 << TChar::ENonSpacingMark,
1.114 + EBoundaryNeutral = 1 << TChar::EBoundaryNeutral,
1.115 + EParagraphSeparator = 1 << TChar::EParagraphSeparator,
1.116 + ESegmentSeparator = 1 << TChar::ESegmentSeparator,
1.117 + EWhitespace = 1 << TChar::EWhitespace,
1.118 + EOtherNeutral = 1 << TChar::EOtherNeutral,
1.119 +
1.120 + // useful groups
1.121 + EBdControlsGroup = ELeftToRightEmbedding | ERightToLeftEmbedding |
1.122 + ELeftToRightOverride | ERightToLeftOverride | EPopDirectionalFormat,
1.123 + ELeftToRightGroup = ELeftToRight | EEuropeanNumber | ELeftToRightOverride | ELeftToRightEmbedding,
1.124 + ERightToLeftGroup = ERightToLeft | EArabicNumber | ERightToLeftArabic | ERightToLeftOverride |
1.125 + ERightToLeftEmbedding,
1.126 + EStrongGroup = ELeftToRightEmbedding | ERightToLeftEmbedding
1.127 + | ELeftToRightOverride | ERightToLeftOverride
1.128 + | ELeftToRight | ERightToLeft | ERightToLeftArabic,
1.129 +
1.130 + ENoCategory = 0
1.131 + };
1.132 +
1.133 + enum
1.134 + {
1.135 + EMaxExplicitLevel = 61,
1.136 + EMaxLevel = 63,
1.137 + EMaxStackLevels = 62
1.138 + };
1.139 +
1.140 + enum TOverrideState
1.141 + {
1.142 + ENoOverrideState = 0,
1.143 + ELeftToRightOverrideState = ELeftToRightOverride,
1.144 + ERightToLeftOverrideState = ERightToLeftOverride
1.145 + };
1.146 +
1.147 + class TStackItem
1.148 + {
1.149 + public:
1.150 + TUint8 iEmbeddingLevel; // embedding level
1.151 + TOverrideState iOverrideState; // directional override state
1.152 + TCategory iStartCategory; // category that started this level; EOtherNeutral if none
1.153 + };
1.154 +
1.155 +public:
1.156 + /** The information needed during line reordering.
1.157 + @internalComponent */
1.158 + class TReorderContext
1.159 + {
1.160 + public:
1.161 + void SetNextCategory(TChar::TBdCategory aCat);
1.162 + void SetNextStrongCategory(TChar::TBdCategory aCat);
1.163 + public:
1.164 + /** Category at start of next line, or ON if at the end of the
1.165 + paragraph. */
1.166 + TCategory iNextCategory;
1.167 + /** Which of L, R or AL appears first in the remainder of the
1.168 + paragraph, or ON if none. */
1.169 + TCategory iNextStrongCategory;
1.170 + /** The run array for this line. */
1.171 + TRunInfo* iRunInfo;
1.172 + /** The length of iRunInfo. */
1.173 + TInt iRuns;
1.174 + /** Bitmap of categories currently present in iRunInfo. */
1.175 + TUint32 iCategories;
1.176 + /** Found by the algorithm to set iPreviousStrongCategory. */
1.177 + TCategory iLastStrongCategory;
1.178 + };
1.179 +
1.180 +public:
1.181 + static TInt GenerateBdRunArray(const TText* aText, TInt aLength,
1.182 + TBidirectionalState::TRunInfo* aRun, TInt aMaxRuns);
1.183 +
1.184 +private:
1.185 + const TStackItem& State() const { return iStack[iStackLevel]; }
1.186 + TCategory Push(TCategory aStartCategory);
1.187 + TCategory Pop();
1.188 +
1.189 +public:
1.190 + TBidirectionalState(TChar::TBdCategory aPrevCat,
1.191 + TChar::TBdCategory aPrevStrongCat, TBool aParRightToLeft);
1.192 + void HandleBdControls(TReorderContext& aContext);
1.193 + void ResolveWeakTypesW1W2W3(TReorderContext& aContext);
1.194 + void ResolveWeakTypesW4W5W6(TReorderContext& aContext);
1.195 + void ResolveWeakTypesW7(TReorderContext& aContext);
1.196 + void ResolveNeutralTypes(TReorderContext& aContext);
1.197 + void ResolveImplicitLevels(TReorderContext& aContext);
1.198 + void PrepareForNextLine(const TReorderContext& aContext);
1.199 + void ReorderRuns(TReorderContext& aContext);
1.200 + static TInt CatToNumber(TInt aCat);
1.201 + static TCategory CharToBdCat(TChar::TBdCategory aCat);
1.202 + static TCategory UintToBdCat(TUint aCat);
1.203 + static void DeneutralizeRuns(TRunInfo* aStart, TRunInfo* aEnd,
1.204 + TCategory aStartCategory, TCategory aEndCategory);
1.205 +private:
1.206 + TCategory iPreviousCategory; // category at end of last line, or EStartOfParagraph if at start of par
1.207 + TCategory iPreviousStrongCategory; // L or R; derived from embedding level if at start of par
1.208 + TInt16 iStackLevel; // current stack level
1.209 + TInt8 iPushesBeyond60; // number of times Push called with iStackLevel == 60 and Left-To-Right category
1.210 + TInt8 iPushesBeyond61; // number of times Push called with iStackLevel == 61
1.211 + TStackItem iStack[EMaxStackLevels]; // the stack of embedding levels
1.212 + };
1.213 +
1.214 +#endif // BIDI_H_