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