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