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