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
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@2
     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
williamr@2
     6
* which accompanies this distribution, and is available
williamr@2
     7
* at the URL "http://www.symbianfoundation.org/legal/licencesv10.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
williamr@2
    23
williamr@2
    24
williamr@2
    25
#ifndef BIDI_H_
williamr@2
    26
#define BIDI_H_
williamr@2
    27
williamr@2
    28
#include <e32std.h>
williamr@2
    29
williamr@2
    30
class RWriteStream;
williamr@2
    31
class RReadStream;
williamr@2
    32
williamr@2
    33
williamr@2
    34
class TBidirectionalState
williamr@2
    35
/** 
williamr@2
    36
The bidirectional state class. 
williamr@2
    37
This class contains functions that implement the Unicode Bidirectional Algorithm, 
williamr@2
    38
which changes text from logical order to display order for the correct display 
williamr@2
    39
of right-to-left scripts, like Arabic and Hebrew. A TBidirectionalState object 
williamr@2
    40
carries the embedding level and stack from one line to the next. On construction 
williamr@2
    41
it is in its 'start of paragraph' state. 
williamr@2
    42
@publishedAll
williamr@2
    43
@released
williamr@2
    44
*/
williamr@2
    45
	{
williamr@2
    46
public:
williamr@2
    47
	
williamr@2
    48
	class TRunInfo
williamr@2
    49
	/** 
williamr@2
    50
	Information about a run of characters with the same bidirectional 
williamr@2
    51
	category. 
williamr@2
    52
williamr@2
    53
	An array of these representing a line is passed into, and reordered by, 
williamr@2
    54
	ReorderLine(). 
williamr@2
    55
	@publishedAll
williamr@2
    56
	@released
williamr@2
    57
	*/
williamr@2
    58
		{
williamr@2
    59
		public:
williamr@2
    60
		/** Category of a run of text: passed to ReorderLine(); these are 
williamr@2
    61
		passed in as TChar::TBdCategory values but are modified for internal 
williamr@2
    62
		use. */
williamr@2
    63
		TUint iCategory;		
williamr@2
    64
		/** Embedding level of this run: used internally by ReorderLine(). */
williamr@2
    65
		TUint8 iEmbeddingLevel;	
williamr@2
    66
		/** Resolved direction of this run: 0 for left to right, 1 for right 
williamr@2
    67
		to left. */
williamr@2
    68
		TUint8 iDirection;		
williamr@2
    69
		/** Index of this run after reordering. */
williamr@2
    70
		TInt iIndex;			
williamr@2
    71
		/** Start of text; returned by ReorderText(). */
williamr@2
    72
		TInt iStart;			
williamr@2
    73
		/** Length of text; returned by ReorderText(). */
williamr@2
    74
		TInt iLength;			
williamr@2
    75
		};
williamr@2
    76
williamr@2
    77
	IMPORT_C TBidirectionalState();
williamr@2
    78
	IMPORT_C void ReorderLine(TRunInfo* aRunInfo,TInt aRuns,TBool aParStart,TBool aParEnd,TBool aParRightToLeft,
williamr@2
    79
					 TChar::TBdCategory aNextCategory,TChar::TBdCategory aNextStrongCategory,
williamr@2
    80
					 TBool& aVisualEndIsAmbiguous);
williamr@2
    81
	IMPORT_C void ReorderLine(TRunInfo* aRunInfo,TInt aRuns,TBool aParStart,TBool aParEnd,TBool aParRightToLeft,
williamr@2
    82
					 TChar::TBdCategory aNextCategory,TChar::TBdCategory aNextStrongCategory);
williamr@2
    83
	IMPORT_C static TInt ReorderText(const TText* aText,TInt aLength,TBool aParRightToLeft,TText*& aNewText);
williamr@2
    84
	IMPORT_C static void ReverseGroups(TText* aStart,TInt aLength);
williamr@2
    85
	IMPORT_C void Reset();
williamr@2
    86
	IMPORT_C TBool IsDefault() const;
williamr@2
    87
	IMPORT_C TBool operator==(const TBidirectionalState& aState) const;
williamr@2
    88
	IMPORT_C void ExternalizeL(RWriteStream& aDest);
williamr@2
    89
	IMPORT_C void InternalizeL(RReadStream& aSource);
williamr@2
    90
	TBool ParRightToLeft() const { return iStack[0].iEmbeddingLevel & 1; }
williamr@2
    91
williamr@2
    92
private:
williamr@2
    93
	// Bidirectional categories coded as bit flags
williamr@2
    94
	enum TCategory
williamr@2
    95
		{
williamr@2
    96
		ELeftToRight = 1 << TChar::ELeftToRight, 
williamr@2
    97
		ELeftToRightEmbedding = 1 << TChar::ELeftToRightEmbedding,
williamr@2
    98
		ELeftToRightOverride = 1 << TChar::ELeftToRightOverride,
williamr@2
    99
		ERightToLeft = 1 << TChar::ERightToLeft,
williamr@2
   100
		ERightToLeftArabic = 1 << TChar::ERightToLeftArabic,
williamr@2
   101
		ERightToLeftEmbedding = 1 << TChar::ERightToLeftEmbedding, 
williamr@2
   102
		ERightToLeftOverride = 1 << TChar::ERightToLeftOverride,
williamr@2
   103
		EPopDirectionalFormat = 1 << TChar::EPopDirectionalFormat, 
williamr@2
   104
		EEuropeanNumber = 1 << TChar::EEuropeanNumber, 
williamr@2
   105
		EEuropeanNumberSeparator = 1 << TChar::EEuropeanNumberSeparator, 
williamr@2
   106
		EEuropeanNumberTerminator = 1 << TChar::EEuropeanNumberTerminator, 
williamr@2
   107
		EArabicNumber = 1 << TChar::EArabicNumber,
williamr@2
   108
		ECommonNumberSeparator = 1 << TChar::ECommonNumberSeparator, 
williamr@2
   109
		ENonSpacingMark = 1 << TChar::ENonSpacingMark, 
williamr@2
   110
		EBoundaryNeutral = 1 << TChar::EBoundaryNeutral, 
williamr@2
   111
		EParagraphSeparator = 1 << TChar::EParagraphSeparator, 
williamr@2
   112
		ESegmentSeparator = 1 << TChar::ESegmentSeparator, 
williamr@2
   113
		EWhitespace = 1 << TChar::EWhitespace, 
williamr@2
   114
		EOtherNeutral = 1 << TChar::EOtherNeutral,
williamr@2
   115
williamr@2
   116
		// useful groups
williamr@2
   117
		EBdControlsGroup = ELeftToRightEmbedding | ERightToLeftEmbedding |
williamr@2
   118
						   ELeftToRightOverride | ERightToLeftOverride | EPopDirectionalFormat,
williamr@2
   119
		ELeftToRightGroup = ELeftToRight | EEuropeanNumber | ELeftToRightOverride | ELeftToRightEmbedding,
williamr@2
   120
		ERightToLeftGroup = ERightToLeft | EArabicNumber | ERightToLeftArabic | ERightToLeftOverride |
williamr@2
   121
							ERightToLeftEmbedding,
williamr@2
   122
		EStrongGroup = ELeftToRightEmbedding | ERightToLeftEmbedding
williamr@2
   123
			| ELeftToRightOverride | ERightToLeftOverride
williamr@2
   124
			| ELeftToRight | ERightToLeft | ERightToLeftArabic,
williamr@2
   125
williamr@2
   126
		ENoCategory = 0
williamr@2
   127
		};
williamr@2
   128
williamr@2
   129
	enum
williamr@2
   130
		{
williamr@2
   131
		EMaxExplicitLevel = 61,
williamr@2
   132
		EMaxLevel = 63,
williamr@2
   133
		EMaxStackLevels = 62
williamr@2
   134
		};
williamr@2
   135
williamr@2
   136
	enum TOverrideState
williamr@2
   137
		{
williamr@2
   138
		ENoOverrideState = 0,
williamr@2
   139
		ELeftToRightOverrideState = ELeftToRightOverride,
williamr@2
   140
		ERightToLeftOverrideState = ERightToLeftOverride
williamr@2
   141
		};
williamr@2
   142
williamr@2
   143
	class TStackItem
williamr@2
   144
		{
williamr@2
   145
	public:
williamr@2
   146
		TUint8 iEmbeddingLevel;			// embedding level
williamr@2
   147
		TOverrideState iOverrideState;	// directional override state
williamr@2
   148
		TCategory iStartCategory;		// category that started this level; EOtherNeutral if none
williamr@2
   149
		};
williamr@2
   150
williamr@2
   151
public:
williamr@2
   152
	/**	The information needed during line reordering.
williamr@2
   153
	@internalComponent	*/
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_