os/graphics/graphicsdeviceinterface/gdi/sgdi/GlyphSel.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicsdeviceinterface/gdi/sgdi/GlyphSel.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,292 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#ifndef __GLYPHSEL_H__
    1.20 +#define __GLYPHSEL_H__
    1.21 +
    1.22 +
    1.23 +#include <e32std.h>
    1.24 +#include <gdi.h>
    1.25 +#include "ShapeInfo.h"
    1.26 +
    1.27 +/**
    1.28 +Forward declarations.
    1.29 +@internalComponent
    1.30 +*/
    1.31 +void Panic(TGdiPanic aError);
    1.32 +
    1.33 +class TGlyphSelectionState;
    1.34 +
    1.35 +
    1.36 +/** 
    1.37 + The Unicode char to use for glyph cluster without a base char 
    1.38 +@internalComponent
    1.39 +*/
    1.40 +#define KUnicodeDottedCircle 0x25CC
    1.41 +
    1.42 +// 
    1.43 +//
    1.44 +// TUtf32Iterator Class declaration
    1.45 +//
    1.46 +//
    1.47 +
    1.48 +class TUtf32Iterator
    1.49 +/*
    1.50 + Converts UTF16 encoded array of bytes into UTF32 characters, 
    1.51 + ignoring non-characters and unpaired surrogates and 
    1.52 + combining paired surrogates.
    1.53 +@internalComponent
    1.54 +*/
    1.55 +	{
    1.56 +public:
    1.57 +	TUtf32Iterator(const TText16* aStart, const TText16* aEnd, TInt aOffset=0);
    1.58 +
    1.59 +	inline TBool AtEnd() const;
    1.60 +	inline TBool BeforeStart() const;
    1.61 +	TChar Next();
    1.62 +	TChar Prev();
    1.63 +	void SetPos(TInt aOffset);
    1.64 +	inline TChar Get() const;
    1.65 +	TUint Get(TInt offset);
    1.66 +	TChar GetThenNext();
    1.67 +	TChar GetThenPrev();
    1.68 +	const TText16* CurrentPosition() const;
    1.69 +	void SetCurrentPosition(const TText16*);
    1.70 +
    1.71 +	TInt LengthToStart() const;
    1.72 +	TInt LengthToEnd() const;
    1.73 +
    1.74 +private:
    1.75 +	TUint UTF16ToTChar(const TText16* a);
    1.76 +
    1.77 +private:
    1.78 +	/** Start address of the UTF16 array */
    1.79 +	const TText16* iStart;
    1.80 +	/** Address of current position in array */
    1.81 +	const TText16* iCurrent;
    1.82 +	/** Address of the first entry past the end of the array */
    1.83 +	const TText16* iEnd;
    1.84 +
    1.85 +	/** UTF32 value of the character at the current iterator position */
    1.86 +	TChar iChar;
    1.87 +	};
    1.88 +
    1.89 +
    1.90 +// 
    1.91 +//
    1.92 +// GlyphSelUtils Namespace declaration
    1.93 +//
    1.94 +//
    1.95 +
    1.96 +
    1.97 +namespace GlyphSelUtils
    1.98 +/**
    1.99 + This namespace holds a collection of useful common utility 
   1.100 + functions used in glyph selection. These functions are intended to be
   1.101 + used by the glyph selector classes.
   1.102 +@internalComponent
   1.103 +*/
   1.104 +	{
   1.105 +    inline TBool IsSurrogate(TText a) 
   1.106 +    	{ 
   1.107 +    	return 0xD800 == (a & 0xF800); 
   1.108 +    	}
   1.109 +
   1.110 +    inline TBool IsHighSurrogate(TText a) 
   1.111 +    	{ 
   1.112 +    	return 0xD800 == (a & 0xFC00); 
   1.113 +    	}
   1.114 +
   1.115 +    inline TBool IsLowSurrogate(TText a) 
   1.116 +    	{ 
   1.117 +    	return 0xDC00 == (a & 0xFC00); 
   1.118 +    	}
   1.119 +
   1.120 +    inline TChar PairSurrogates(TText aHigh, TText aLow)
   1.121 +    	{
   1.122 +    	return ((aHigh - 0xd7f7) << 10) + aLow;
   1.123 +    	}
   1.124 +
   1.125 +    inline TBool IsThaiCharacter(TUint code)
   1.126 +    	{
   1.127 +    	return ((code > 0x0E00 && code < 0x0E3B) ||
   1.128 +    			(code > 0x0E3E && code < 0x0E5C));
   1.129 +    	}
   1.130 +
   1.131 +	}
   1.132 +
   1.133 +
   1.134 +// 
   1.135 +//
   1.136 +// TGlyphSelectionState Class declaration
   1.137 +//
   1.138 +//
   1.139 +
   1.140 +
   1.141 +class TGlyphSelectionState
   1.142 +/**
   1.143 + This container class holds the data for glyph selection algorithm and is
   1.144 + used to pass this data around the algorithm methods.
   1.145 +@internalComponent
   1.146 +*/
   1.147 +	{
   1.148 +public:
   1.149 +    enum TPenAdvance
   1.150 +    /** 
   1.151 +     Enum used in glyph selection code indicating if a pen advance is needed following
   1.152 +     the processing of the current glyph. 
   1.153 +    */
   1.154 +    	{
   1.155 +    	EPenAdvance_No,
   1.156 +    	EPenAdvance_Yes,
   1.157 +    	};
   1.158 +
   1.159 +    enum TGlyphClusterStateOverride
   1.160 +    /**
   1.161 +     These enumeration values are used by the glyph selector classes to indicated
   1.162 +     back to the glyph selection algorithm when they find a cluster complete.
   1.163 +    */
   1.164 +    	{
   1.165 +    	EGClusterComplete,
   1.166 +    	EGClusterNotComplete
   1.167 +    	};
   1.168 +    	
   1.169 +    enum TGlyphPostCombine
   1.170 +    /**
   1.171 +    These enumeration values are used by the glyph selector classes to decide whether
   1.172 +    post combining is needed to combine the diacritic to the base character.
   1.173 +    */
   1.174 +    	{
   1.175 +    	EGPostCombine_No,
   1.176 +    	EGPostCombine_Yes
   1.177 +    	};
   1.178 +    	
   1.179 +    	
   1.180 +	TGlyphSelectionState(TUtf32Iterator& aIter, const CFont* aFont, CFont::TPositionParam& aParam)
   1.181 +		: iCodePt(0xFFFF), iCodeChar(0xFFFF), iCombCls(-1), iCats(0),
   1.182 +		  iText(aIter), iFont(aFont), iParam(aParam),
   1.183 +		  iClusterState(EGClusterNotComplete), iPen(EPenAdvance_No),
   1.184 +		  iAdvance(), iLigaturePortionsRemaining(0), iGlyphPostCombine(EGPostCombine_No) { };
   1.185 +
   1.186 +	TBool IsCombiningClass() { return (iCats & 0xF0) ==  TChar::EMarkGroup; }
   1.187 +	void CombineLastGlyphToBase(const TRect& aBase, TInt aFirstDiacritic);
   1.188 +
   1.189 +	TBool AppendGlyphToCluster(TUint code);
   1.190 +
   1.191 +public:
   1.192 +	/** The properties of the current character being processed */
   1.193 +	TUint   iCodePt;
   1.194 +	TChar	iCodeChar;
   1.195 +	TInt	iCombCls;
   1.196 +	TUint	iCats;
   1.197 +
   1.198 +	/** The Unicode iterator to the text processed */ 
   1.199 +	TUtf32Iterator& iText;
   1.200 +
   1.201 +	/** The font to select glyphs from */
   1.202 +	const CFont* iFont;
   1.203 +
   1.204 +	/** The in/out parameter data to the glyph selection code from outside */
   1.205 +	CFont::TPositionParam& iParam;	
   1.206 +
   1.207 +	/** Result from the glyph selector class as to whether it thinks the 
   1.208 +	    cluster is complete or incomplete. 
   1.209 +	*/
   1.210 +	TGlyphClusterStateOverride	iClusterState;
   1.211 +	
   1.212 +	/** These hold the possible pen advance and if it should be applied */
   1.213 +	TPenAdvance iPen;
   1.214 +	TSize       iAdvance;
   1.215 +
   1.216 +	/** Can be used in any way or not at all by the processing function. It is
   1.217 +	set to 0 on intitialisation. Suggested use is to pass information about
   1.218 +	which part of a ligature is currently having diacritics attatched to it. */
   1.219 +	TInt iLigaturePortionsRemaining;
   1.220 +	/** Can be used in any way or not at all by the processing function. It is
   1.221 +	not initialised. Suggested use is to record the position in the output
   1.222 +	glyph array of the first diacritic on this portion of the ligature. */
   1.223 +	TInt iLigaturePortionFirstMark;
   1.224 +	
   1.225 +	/** 
   1.226 +	Result from the glyph selector class as to whether it needs to
   1.227 +	combine the diacritic with the base character.
   1.228 +	*/
   1.229 +	TGlyphPostCombine iGlyphPostCombine;
   1.230 +	};
   1.231 +
   1.232 +
   1.233 +// 
   1.234 +//
   1.235 +// GlyphSelector_SoftHyphen Class declaration
   1.236 +//
   1.237 +//
   1.238 +
   1.239 +class GlyphSelector_SoftHyphen
   1.240 +/**
   1.241 + This glyph selector class processes the Unicode soft hyphen U+00AD
   1.242 + character.
   1.243 + This is a discretionary hyphen, i.e. it is only rendered when required
   1.244 + and in Symbian OS that is when it is found at the end of a line.
   1.245 +@internalComponent
   1.246 +*/
   1.247 +	{
   1.248 +public:
   1.249 +
   1.250 +	static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&);
   1.251 +	};
   1.252 +
   1.253 +
   1.254 +// 
   1.255 +//
   1.256 +// GlyphSelector_Default Class declaration
   1.257 +//
   1.258 +//
   1.259 +
   1.260 +class GlyphSelector_Default
   1.261 +/**
   1.262 + This is the default glyph selector class which has the behaviour of outputting
   1.263 + all glyphs it is invoked to process.
   1.264 +@internalComponent
   1.265 +*/
   1.266 +	{
   1.267 +public:
   1.268 +
   1.269 +	static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&);
   1.270 +	};
   1.271 +
   1.272 +
   1.273 +// 
   1.274 +// TUtf32Iterator inline Function definitions.
   1.275 +//
   1.276 +
   1.277 +
   1.278 +inline TBool TUtf32Iterator::AtEnd() const
   1.279 +	{
   1.280 +	return iEnd == iCurrent;
   1.281 +	}
   1.282 +
   1.283 +inline TBool TUtf32Iterator::BeforeStart() const
   1.284 +	{
   1.285 +	return iStart > iCurrent;
   1.286 +	}
   1.287 +
   1.288 +inline TChar TUtf32Iterator::Get() const
   1.289 +	{
   1.290 +	__ASSERT_DEBUG(iCurrent >= iStart && iCurrent < iEnd, Panic(EGdiPanic_OutOfText));
   1.291 +
   1.292 +	return iChar;
   1.293 +	}
   1.294 +
   1.295 +#endif // __GLYPHSEL_H__