os/textandloc/fontservices/textbase/sgdi/GlyphSel.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2003-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#ifndef __GLYPHSEL_H__
sl@0
    17
#define __GLYPHSEL_H__
sl@0
    18
sl@0
    19
sl@0
    20
#include <e32std.h>
sl@0
    21
//#include <textbase.h>
sl@0
    22
#include <gdi.h>
sl@0
    23
#include "ShapeInfo.h"
sl@0
    24
sl@0
    25
/**
sl@0
    26
Forward declarations.
sl@0
    27
@internalComponent
sl@0
    28
*/
sl@0
    29
#ifndef __TEXTBASE_H__
sl@0
    30
#ifndef __GLYPHSEL_TEXTBASE_H__
sl@0
    31
#define __GLYPHSEL_TEXTBASE_H__
sl@0
    32
/**
sl@0
    33
This enumeration holds the possible panic codes that may be raised 
sl@0
    34
by the TextBase API on detecting an unrecoverable error. */
sl@0
    35
enum TTextBasePanic
sl@0
    36
    {
sl@0
    37
    /** Not used */
sl@0
    38
    ETextBasePanic_Unknown              = 0,
sl@0
    39
    /** One or more of the input parameters to the interface were invalid */
sl@0
    40
    ETextBasePanic_InvalidInputParam        = 1,
sl@0
    41
    /** Insufficient text for successful completion of the method */
sl@0
    42
    ETextBasePanic_OutOfText                = 2,
sl@0
    43
    /** Internal failure. */
sl@0
    44
    ETextBasePanic_Invariant                = 3,
sl@0
    45
    /** Reserved panic codes. Not to be used. */
sl@0
    46
    ETextBasePanic_Reserved1                = 4,
sl@0
    47
    ETextBasePanic_Reserved2                = 5,
sl@0
    48
    /** Setting a typeface name that is too long */
sl@0
    49
    ETextBasePanic_TypefaceNameOverflow = 6,
sl@0
    50
    };
sl@0
    51
#endif
sl@0
    52
#endif
sl@0
    53
sl@0
    54
void TextBasePanic(TTextBasePanic aError);
sl@0
    55
sl@0
    56
class TGlyphSelectionState;
sl@0
    57
sl@0
    58
sl@0
    59
/** 
sl@0
    60
 The Unicode char to use for glyph cluster without a base char 
sl@0
    61
@internalComponent
sl@0
    62
*/
sl@0
    63
#define KUnicodeDottedCircle 0x25CC
sl@0
    64
sl@0
    65
// 
sl@0
    66
//
sl@0
    67
// TUtf32Iterator Class declaration
sl@0
    68
//
sl@0
    69
//
sl@0
    70
sl@0
    71
class TUtf32Iterator
sl@0
    72
/*
sl@0
    73
 Converts UTF16 encoded array of bytes into UTF32 characters, 
sl@0
    74
 ignoring non-characters and unpaired surrogates and 
sl@0
    75
 combining paired surrogates.
sl@0
    76
@internalComponent
sl@0
    77
*/
sl@0
    78
	{
sl@0
    79
public:
sl@0
    80
	TUtf32Iterator(const TText16* aStart, const TText16* aEnd, TInt aOffset=0);
sl@0
    81
sl@0
    82
	inline TBool AtEnd() const;
sl@0
    83
	inline TBool BeforeStart() const;
sl@0
    84
	TChar Next();
sl@0
    85
	TChar Prev();
sl@0
    86
	void SetPos(TInt aOffset);
sl@0
    87
	inline TChar Get() const;
sl@0
    88
	TUint Get(TInt offset);
sl@0
    89
	TChar GetThenNext();
sl@0
    90
	TChar GetThenPrev();
sl@0
    91
	const TText16* CurrentPosition() const;
sl@0
    92
	void SetCurrentPosition(const TText16*);
sl@0
    93
sl@0
    94
	TInt LengthToStart() const;
sl@0
    95
	TInt LengthToEnd() const;
sl@0
    96
sl@0
    97
private:
sl@0
    98
	TUint UTF16ToTChar(const TText16* a);
sl@0
    99
sl@0
   100
private:
sl@0
   101
	/** Start address of the UTF16 array */
sl@0
   102
	const TText16* iStart;
sl@0
   103
	/** Address of current position in array */
sl@0
   104
	const TText16* iCurrent;
sl@0
   105
	/** Address of the first entry past the end of the array */
sl@0
   106
	const TText16* iEnd;
sl@0
   107
sl@0
   108
	/** UTF32 value of the character at the current iterator position */
sl@0
   109
	TChar iChar;
sl@0
   110
	};
sl@0
   111
sl@0
   112
sl@0
   113
// 
sl@0
   114
//
sl@0
   115
// GlyphSelUtils Namespace declaration
sl@0
   116
//
sl@0
   117
//
sl@0
   118
sl@0
   119
sl@0
   120
namespace GlyphSelUtils
sl@0
   121
/**
sl@0
   122
 This namespace holds a collection of useful common utility 
sl@0
   123
 functions used in glyph selection. These functions are intended to be
sl@0
   124
 used by the glyph selector classes.
sl@0
   125
@internalComponent
sl@0
   126
*/
sl@0
   127
	{
sl@0
   128
    inline TBool IsSurrogate(TText a) 
sl@0
   129
    	{ 
sl@0
   130
    	return 0xD800 == (a & 0xF800); 
sl@0
   131
    	}
sl@0
   132
sl@0
   133
    inline TBool IsHighSurrogate(TText a) 
sl@0
   134
    	{ 
sl@0
   135
    	return 0xD800 == (a & 0xFC00); 
sl@0
   136
    	}
sl@0
   137
sl@0
   138
    inline TBool IsLowSurrogate(TText a) 
sl@0
   139
    	{ 
sl@0
   140
    	return 0xDC00 == (a & 0xFC00); 
sl@0
   141
    	}
sl@0
   142
sl@0
   143
    inline TChar PairSurrogates(TText aHigh, TText aLow)
sl@0
   144
    	{
sl@0
   145
    	return ((aHigh - 0xd7f7) << 10) + aLow;
sl@0
   146
    	}
sl@0
   147
sl@0
   148
    inline TBool IsThaiCharacter(TUint code)
sl@0
   149
    	{
sl@0
   150
    	return ((code > 0x0E00 && code < 0x0E3B) ||
sl@0
   151
    			(code > 0x0E3E && code < 0x0E5C));
sl@0
   152
    	}
sl@0
   153
sl@0
   154
	}
sl@0
   155
sl@0
   156
sl@0
   157
// 
sl@0
   158
//
sl@0
   159
// TGlyphSelectionState Class declaration
sl@0
   160
//
sl@0
   161
//
sl@0
   162
sl@0
   163
sl@0
   164
class TGlyphSelectionState
sl@0
   165
/**
sl@0
   166
 This container class holds the data for glyph selection algorithm and is
sl@0
   167
 used to pass this data around the algorithm methods.
sl@0
   168
@internalComponent
sl@0
   169
*/
sl@0
   170
	{
sl@0
   171
public:
sl@0
   172
    enum TPenAdvance
sl@0
   173
    /** 
sl@0
   174
     Enum used in glyph selection code indicating if a pen advance is needed following
sl@0
   175
     the processing of the current glyph. 
sl@0
   176
    */
sl@0
   177
    	{
sl@0
   178
    	EPenAdvance_No,
sl@0
   179
    	EPenAdvance_Yes,
sl@0
   180
    	};
sl@0
   181
sl@0
   182
    enum TGlyphClusterStateOverride
sl@0
   183
    /**
sl@0
   184
     These enumeration values are used by the glyph selector classes to indicated
sl@0
   185
     back to the glyph selection algorithm when they find a cluster complete.
sl@0
   186
    */
sl@0
   187
    	{
sl@0
   188
    	EGClusterComplete,
sl@0
   189
    	EGClusterNotComplete
sl@0
   190
    	};
sl@0
   191
    	
sl@0
   192
    enum TGlyphPostCombine
sl@0
   193
    /**
sl@0
   194
    These enumeration values are used by the glyph selector classes to decide whether
sl@0
   195
    post combining is needed to combine the diacritic to the base character.
sl@0
   196
    */
sl@0
   197
    	{
sl@0
   198
    	EGPostCombine_No,
sl@0
   199
    	EGPostCombine_Yes
sl@0
   200
    	};
sl@0
   201
    	
sl@0
   202
    	
sl@0
   203
	TGlyphSelectionState(TUtf32Iterator& aIter, const CFont* aFont, CFont::TPositionParam& aParam)
sl@0
   204
		: iCodePt(0xFFFF), iCodeChar(0xFFFF), iCombCls(-1), iCats(0),
sl@0
   205
		  iText(aIter), iFont(aFont), iParam(aParam),
sl@0
   206
		  iClusterState(EGClusterNotComplete), iPen(EPenAdvance_No),
sl@0
   207
		  iAdvance(), iLigaturePortionsRemaining(0), iGlyphPostCombine(EGPostCombine_No) { };
sl@0
   208
sl@0
   209
	TBool IsCombiningClass() { return (iCats & 0xF0) ==  TChar::EMarkGroup; }
sl@0
   210
	void CombineLastGlyphToBase(const TRect& aBase, TInt aFirstDiacritic);
sl@0
   211
sl@0
   212
	TBool AppendGlyphToCluster(TUint code);
sl@0
   213
sl@0
   214
public:
sl@0
   215
	/** The properties of the current character being processed */
sl@0
   216
	TUint   iCodePt;
sl@0
   217
	TChar	iCodeChar;
sl@0
   218
	TInt	iCombCls;
sl@0
   219
	TUint	iCats;
sl@0
   220
sl@0
   221
	/** The Unicode iterator to the text processed */ 
sl@0
   222
	TUtf32Iterator& iText;
sl@0
   223
sl@0
   224
	/** The font to select glyphs from */
sl@0
   225
	const CFont* iFont;
sl@0
   226
sl@0
   227
	/** The in/out parameter data to the glyph selection code from outside */
sl@0
   228
	CFont::TPositionParam& iParam;	
sl@0
   229
sl@0
   230
	/** Result from the glyph selector class as to whether it thinks the 
sl@0
   231
	    cluster is complete or incomplete. 
sl@0
   232
	*/
sl@0
   233
	TGlyphClusterStateOverride	iClusterState;
sl@0
   234
	
sl@0
   235
	/** These hold the possible pen advance and if it should be applied */
sl@0
   236
	TPenAdvance iPen;
sl@0
   237
	TSize       iAdvance;
sl@0
   238
sl@0
   239
	/** Can be used in any way or not at all by the processing function. It is
sl@0
   240
	set to 0 on intitialisation. Suggested use is to pass information about
sl@0
   241
	which part of a ligature is currently having diacritics attatched to it. */
sl@0
   242
	TInt iLigaturePortionsRemaining;
sl@0
   243
	/** Can be used in any way or not at all by the processing function. It is
sl@0
   244
	not initialised. Suggested use is to record the position in the output
sl@0
   245
	glyph array of the first diacritic on this portion of the ligature. */
sl@0
   246
	TInt iLigaturePortionFirstMark;
sl@0
   247
	
sl@0
   248
	/** 
sl@0
   249
	Result from the glyph selector class as to whether it needs to
sl@0
   250
	combine the diacritic with the base character.
sl@0
   251
	*/
sl@0
   252
	TGlyphPostCombine iGlyphPostCombine;
sl@0
   253
	};
sl@0
   254
sl@0
   255
sl@0
   256
// 
sl@0
   257
//
sl@0
   258
// GlyphSelector_SoftHyphen Class declaration
sl@0
   259
//
sl@0
   260
//
sl@0
   261
sl@0
   262
class GlyphSelector_SoftHyphen
sl@0
   263
/**
sl@0
   264
 This glyph selector class processes the Unicode soft hyphen U+00AD
sl@0
   265
 character.
sl@0
   266
 This is a discretionary hyphen, i.e. it is only rendered when required
sl@0
   267
 and in Symbian OS that is when it is found at the end of a line.
sl@0
   268
@internalComponent
sl@0
   269
*/
sl@0
   270
	{
sl@0
   271
public:
sl@0
   272
sl@0
   273
	static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&);
sl@0
   274
	};
sl@0
   275
sl@0
   276
sl@0
   277
// 
sl@0
   278
//
sl@0
   279
// GlyphSelector_Default Class declaration
sl@0
   280
//
sl@0
   281
//
sl@0
   282
sl@0
   283
class GlyphSelector_Default
sl@0
   284
/**
sl@0
   285
 This is the default glyph selector class which has the behaviour of outputting
sl@0
   286
 all glyphs it is invoked to process.
sl@0
   287
@internalComponent
sl@0
   288
*/
sl@0
   289
	{
sl@0
   290
public:
sl@0
   291
sl@0
   292
	static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&);
sl@0
   293
	};
sl@0
   294
sl@0
   295
sl@0
   296
// 
sl@0
   297
// TUtf32Iterator inline Function definitions.
sl@0
   298
//
sl@0
   299
sl@0
   300
sl@0
   301
inline TBool TUtf32Iterator::AtEnd() const
sl@0
   302
	{
sl@0
   303
	return iEnd == iCurrent;
sl@0
   304
	}
sl@0
   305
sl@0
   306
inline TBool TUtf32Iterator::BeforeStart() const
sl@0
   307
	{
sl@0
   308
	return iStart > iCurrent;
sl@0
   309
	}
sl@0
   310
sl@0
   311
inline TChar TUtf32Iterator::Get() const
sl@0
   312
	{
sl@0
   313
	__ASSERT_DEBUG(iCurrent >= iStart && iCurrent < iEnd, TextBasePanic(ETextBasePanic_OutOfText));
sl@0
   314
sl@0
   315
	return iChar;
sl@0
   316
	}
sl@0
   317
sl@0
   318
#endif // __GLYPHSEL_H__