os/graphics/graphicsdeviceinterface/gdi/sgdi/GlyphSel.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-2009 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 <gdi.h>
sl@0
    22
#include "ShapeInfo.h"
sl@0
    23
sl@0
    24
/**
sl@0
    25
Forward declarations.
sl@0
    26
@internalComponent
sl@0
    27
*/
sl@0
    28
void Panic(TGdiPanic aError);
sl@0
    29
sl@0
    30
class TGlyphSelectionState;
sl@0
    31
sl@0
    32
sl@0
    33
/** 
sl@0
    34
 The Unicode char to use for glyph cluster without a base char 
sl@0
    35
@internalComponent
sl@0
    36
*/
sl@0
    37
#define KUnicodeDottedCircle 0x25CC
sl@0
    38
sl@0
    39
// 
sl@0
    40
//
sl@0
    41
// TUtf32Iterator Class declaration
sl@0
    42
//
sl@0
    43
//
sl@0
    44
sl@0
    45
class TUtf32Iterator
sl@0
    46
/*
sl@0
    47
 Converts UTF16 encoded array of bytes into UTF32 characters, 
sl@0
    48
 ignoring non-characters and unpaired surrogates and 
sl@0
    49
 combining paired surrogates.
sl@0
    50
@internalComponent
sl@0
    51
*/
sl@0
    52
	{
sl@0
    53
public:
sl@0
    54
	TUtf32Iterator(const TText16* aStart, const TText16* aEnd, TInt aOffset=0);
sl@0
    55
sl@0
    56
	inline TBool AtEnd() const;
sl@0
    57
	inline TBool BeforeStart() const;
sl@0
    58
	TChar Next();
sl@0
    59
	TChar Prev();
sl@0
    60
	void SetPos(TInt aOffset);
sl@0
    61
	inline TChar Get() const;
sl@0
    62
	TUint Get(TInt offset);
sl@0
    63
	TChar GetThenNext();
sl@0
    64
	TChar GetThenPrev();
sl@0
    65
	const TText16* CurrentPosition() const;
sl@0
    66
	void SetCurrentPosition(const TText16*);
sl@0
    67
sl@0
    68
	TInt LengthToStart() const;
sl@0
    69
	TInt LengthToEnd() const;
sl@0
    70
sl@0
    71
private:
sl@0
    72
	TUint UTF16ToTChar(const TText16* a);
sl@0
    73
sl@0
    74
private:
sl@0
    75
	/** Start address of the UTF16 array */
sl@0
    76
	const TText16* iStart;
sl@0
    77
	/** Address of current position in array */
sl@0
    78
	const TText16* iCurrent;
sl@0
    79
	/** Address of the first entry past the end of the array */
sl@0
    80
	const TText16* iEnd;
sl@0
    81
sl@0
    82
	/** UTF32 value of the character at the current iterator position */
sl@0
    83
	TChar iChar;
sl@0
    84
	};
sl@0
    85
sl@0
    86
sl@0
    87
// 
sl@0
    88
//
sl@0
    89
// GlyphSelUtils Namespace declaration
sl@0
    90
//
sl@0
    91
//
sl@0
    92
sl@0
    93
sl@0
    94
namespace GlyphSelUtils
sl@0
    95
/**
sl@0
    96
 This namespace holds a collection of useful common utility 
sl@0
    97
 functions used in glyph selection. These functions are intended to be
sl@0
    98
 used by the glyph selector classes.
sl@0
    99
@internalComponent
sl@0
   100
*/
sl@0
   101
	{
sl@0
   102
    inline TBool IsSurrogate(TText a) 
sl@0
   103
    	{ 
sl@0
   104
    	return 0xD800 == (a & 0xF800); 
sl@0
   105
    	}
sl@0
   106
sl@0
   107
    inline TBool IsHighSurrogate(TText a) 
sl@0
   108
    	{ 
sl@0
   109
    	return 0xD800 == (a & 0xFC00); 
sl@0
   110
    	}
sl@0
   111
sl@0
   112
    inline TBool IsLowSurrogate(TText a) 
sl@0
   113
    	{ 
sl@0
   114
    	return 0xDC00 == (a & 0xFC00); 
sl@0
   115
    	}
sl@0
   116
sl@0
   117
    inline TChar PairSurrogates(TText aHigh, TText aLow)
sl@0
   118
    	{
sl@0
   119
    	return ((aHigh - 0xd7f7) << 10) + aLow;
sl@0
   120
    	}
sl@0
   121
sl@0
   122
    inline TBool IsThaiCharacter(TUint code)
sl@0
   123
    	{
sl@0
   124
    	return ((code > 0x0E00 && code < 0x0E3B) ||
sl@0
   125
    			(code > 0x0E3E && code < 0x0E5C));
sl@0
   126
    	}
sl@0
   127
sl@0
   128
	}
sl@0
   129
sl@0
   130
sl@0
   131
// 
sl@0
   132
//
sl@0
   133
// TGlyphSelectionState Class declaration
sl@0
   134
//
sl@0
   135
//
sl@0
   136
sl@0
   137
sl@0
   138
class TGlyphSelectionState
sl@0
   139
/**
sl@0
   140
 This container class holds the data for glyph selection algorithm and is
sl@0
   141
 used to pass this data around the algorithm methods.
sl@0
   142
@internalComponent
sl@0
   143
*/
sl@0
   144
	{
sl@0
   145
public:
sl@0
   146
    enum TPenAdvance
sl@0
   147
    /** 
sl@0
   148
     Enum used in glyph selection code indicating if a pen advance is needed following
sl@0
   149
     the processing of the current glyph. 
sl@0
   150
    */
sl@0
   151
    	{
sl@0
   152
    	EPenAdvance_No,
sl@0
   153
    	EPenAdvance_Yes,
sl@0
   154
    	};
sl@0
   155
sl@0
   156
    enum TGlyphClusterStateOverride
sl@0
   157
    /**
sl@0
   158
     These enumeration values are used by the glyph selector classes to indicated
sl@0
   159
     back to the glyph selection algorithm when they find a cluster complete.
sl@0
   160
    */
sl@0
   161
    	{
sl@0
   162
    	EGClusterComplete,
sl@0
   163
    	EGClusterNotComplete
sl@0
   164
    	};
sl@0
   165
    	
sl@0
   166
    enum TGlyphPostCombine
sl@0
   167
    /**
sl@0
   168
    These enumeration values are used by the glyph selector classes to decide whether
sl@0
   169
    post combining is needed to combine the diacritic to the base character.
sl@0
   170
    */
sl@0
   171
    	{
sl@0
   172
    	EGPostCombine_No,
sl@0
   173
    	EGPostCombine_Yes
sl@0
   174
    	};
sl@0
   175
    	
sl@0
   176
    	
sl@0
   177
	TGlyphSelectionState(TUtf32Iterator& aIter, const CFont* aFont, CFont::TPositionParam& aParam)
sl@0
   178
		: iCodePt(0xFFFF), iCodeChar(0xFFFF), iCombCls(-1), iCats(0),
sl@0
   179
		  iText(aIter), iFont(aFont), iParam(aParam),
sl@0
   180
		  iClusterState(EGClusterNotComplete), iPen(EPenAdvance_No),
sl@0
   181
		  iAdvance(), iLigaturePortionsRemaining(0), iGlyphPostCombine(EGPostCombine_No) { };
sl@0
   182
sl@0
   183
	TBool IsCombiningClass() { return (iCats & 0xF0) ==  TChar::EMarkGroup; }
sl@0
   184
	void CombineLastGlyphToBase(const TRect& aBase, TInt aFirstDiacritic);
sl@0
   185
sl@0
   186
	TBool AppendGlyphToCluster(TUint code);
sl@0
   187
sl@0
   188
public:
sl@0
   189
	/** The properties of the current character being processed */
sl@0
   190
	TUint   iCodePt;
sl@0
   191
	TChar	iCodeChar;
sl@0
   192
	TInt	iCombCls;
sl@0
   193
	TUint	iCats;
sl@0
   194
sl@0
   195
	/** The Unicode iterator to the text processed */ 
sl@0
   196
	TUtf32Iterator& iText;
sl@0
   197
sl@0
   198
	/** The font to select glyphs from */
sl@0
   199
	const CFont* iFont;
sl@0
   200
sl@0
   201
	/** The in/out parameter data to the glyph selection code from outside */
sl@0
   202
	CFont::TPositionParam& iParam;	
sl@0
   203
sl@0
   204
	/** Result from the glyph selector class as to whether it thinks the 
sl@0
   205
	    cluster is complete or incomplete. 
sl@0
   206
	*/
sl@0
   207
	TGlyphClusterStateOverride	iClusterState;
sl@0
   208
	
sl@0
   209
	/** These hold the possible pen advance and if it should be applied */
sl@0
   210
	TPenAdvance iPen;
sl@0
   211
	TSize       iAdvance;
sl@0
   212
sl@0
   213
	/** Can be used in any way or not at all by the processing function. It is
sl@0
   214
	set to 0 on intitialisation. Suggested use is to pass information about
sl@0
   215
	which part of a ligature is currently having diacritics attatched to it. */
sl@0
   216
	TInt iLigaturePortionsRemaining;
sl@0
   217
	/** Can be used in any way or not at all by the processing function. It is
sl@0
   218
	not initialised. Suggested use is to record the position in the output
sl@0
   219
	glyph array of the first diacritic on this portion of the ligature. */
sl@0
   220
	TInt iLigaturePortionFirstMark;
sl@0
   221
	
sl@0
   222
	/** 
sl@0
   223
	Result from the glyph selector class as to whether it needs to
sl@0
   224
	combine the diacritic with the base character.
sl@0
   225
	*/
sl@0
   226
	TGlyphPostCombine iGlyphPostCombine;
sl@0
   227
	};
sl@0
   228
sl@0
   229
sl@0
   230
// 
sl@0
   231
//
sl@0
   232
// GlyphSelector_SoftHyphen Class declaration
sl@0
   233
//
sl@0
   234
//
sl@0
   235
sl@0
   236
class GlyphSelector_SoftHyphen
sl@0
   237
/**
sl@0
   238
 This glyph selector class processes the Unicode soft hyphen U+00AD
sl@0
   239
 character.
sl@0
   240
 This is a discretionary hyphen, i.e. it is only rendered when required
sl@0
   241
 and in Symbian OS that is when it is found at the end of a line.
sl@0
   242
@internalComponent
sl@0
   243
*/
sl@0
   244
	{
sl@0
   245
public:
sl@0
   246
sl@0
   247
	static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&);
sl@0
   248
	};
sl@0
   249
sl@0
   250
sl@0
   251
// 
sl@0
   252
//
sl@0
   253
// GlyphSelector_Default Class declaration
sl@0
   254
//
sl@0
   255
//
sl@0
   256
sl@0
   257
class GlyphSelector_Default
sl@0
   258
/**
sl@0
   259
 This is the default glyph selector class which has the behaviour of outputting
sl@0
   260
 all glyphs it is invoked to process.
sl@0
   261
@internalComponent
sl@0
   262
*/
sl@0
   263
	{
sl@0
   264
public:
sl@0
   265
sl@0
   266
	static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&);
sl@0
   267
	};
sl@0
   268
sl@0
   269
sl@0
   270
// 
sl@0
   271
// TUtf32Iterator inline Function definitions.
sl@0
   272
//
sl@0
   273
sl@0
   274
sl@0
   275
inline TBool TUtf32Iterator::AtEnd() const
sl@0
   276
	{
sl@0
   277
	return iEnd == iCurrent;
sl@0
   278
	}
sl@0
   279
sl@0
   280
inline TBool TUtf32Iterator::BeforeStart() const
sl@0
   281
	{
sl@0
   282
	return iStart > iCurrent;
sl@0
   283
	}
sl@0
   284
sl@0
   285
inline TChar TUtf32Iterator::Get() const
sl@0
   286
	{
sl@0
   287
	__ASSERT_DEBUG(iCurrent >= iStart && iCurrent < iEnd, Panic(EGdiPanic_OutOfText));
sl@0
   288
sl@0
   289
	return iChar;
sl@0
   290
	}
sl@0
   291
sl@0
   292
#endif // __GLYPHSEL_H__