sl@0: // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #ifndef __GLYPHSEL_H__ sl@0: #define __GLYPHSEL_H__ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include "ShapeInfo.h" sl@0: sl@0: /** sl@0: Forward declarations. sl@0: @internalComponent sl@0: */ sl@0: void Panic(TGdiPanic aError); sl@0: sl@0: class TGlyphSelectionState; sl@0: sl@0: sl@0: /** sl@0: The Unicode char to use for glyph cluster without a base char sl@0: @internalComponent sl@0: */ sl@0: #define KUnicodeDottedCircle 0x25CC sl@0: sl@0: // sl@0: // sl@0: // TUtf32Iterator Class declaration sl@0: // sl@0: // sl@0: sl@0: class TUtf32Iterator sl@0: /* sl@0: Converts UTF16 encoded array of bytes into UTF32 characters, sl@0: ignoring non-characters and unpaired surrogates and sl@0: combining paired surrogates. sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: TUtf32Iterator(const TText16* aStart, const TText16* aEnd, TInt aOffset=0); sl@0: sl@0: inline TBool AtEnd() const; sl@0: inline TBool BeforeStart() const; sl@0: TChar Next(); sl@0: TChar Prev(); sl@0: void SetPos(TInt aOffset); sl@0: inline TChar Get() const; sl@0: TUint Get(TInt offset); sl@0: TChar GetThenNext(); sl@0: TChar GetThenPrev(); sl@0: const TText16* CurrentPosition() const; sl@0: void SetCurrentPosition(const TText16*); sl@0: sl@0: TInt LengthToStart() const; sl@0: TInt LengthToEnd() const; sl@0: sl@0: private: sl@0: TUint UTF16ToTChar(const TText16* a); sl@0: sl@0: private: sl@0: /** Start address of the UTF16 array */ sl@0: const TText16* iStart; sl@0: /** Address of current position in array */ sl@0: const TText16* iCurrent; sl@0: /** Address of the first entry past the end of the array */ sl@0: const TText16* iEnd; sl@0: sl@0: /** UTF32 value of the character at the current iterator position */ sl@0: TChar iChar; sl@0: }; sl@0: sl@0: sl@0: // sl@0: // sl@0: // GlyphSelUtils Namespace declaration sl@0: // sl@0: // sl@0: sl@0: sl@0: namespace GlyphSelUtils sl@0: /** sl@0: This namespace holds a collection of useful common utility sl@0: functions used in glyph selection. These functions are intended to be sl@0: used by the glyph selector classes. sl@0: @internalComponent sl@0: */ sl@0: { sl@0: inline TBool IsSurrogate(TText a) sl@0: { sl@0: return 0xD800 == (a & 0xF800); sl@0: } sl@0: sl@0: inline TBool IsHighSurrogate(TText a) sl@0: { sl@0: return 0xD800 == (a & 0xFC00); sl@0: } sl@0: sl@0: inline TBool IsLowSurrogate(TText a) sl@0: { sl@0: return 0xDC00 == (a & 0xFC00); sl@0: } sl@0: sl@0: inline TChar PairSurrogates(TText aHigh, TText aLow) sl@0: { sl@0: return ((aHigh - 0xd7f7) << 10) + aLow; sl@0: } sl@0: sl@0: inline TBool IsThaiCharacter(TUint code) sl@0: { sl@0: return ((code > 0x0E00 && code < 0x0E3B) || sl@0: (code > 0x0E3E && code < 0x0E5C)); sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: // sl@0: // sl@0: // TGlyphSelectionState Class declaration sl@0: // sl@0: // sl@0: sl@0: sl@0: class TGlyphSelectionState sl@0: /** sl@0: This container class holds the data for glyph selection algorithm and is sl@0: used to pass this data around the algorithm methods. sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: enum TPenAdvance sl@0: /** sl@0: Enum used in glyph selection code indicating if a pen advance is needed following sl@0: the processing of the current glyph. sl@0: */ sl@0: { sl@0: EPenAdvance_No, sl@0: EPenAdvance_Yes, sl@0: }; sl@0: sl@0: enum TGlyphClusterStateOverride sl@0: /** sl@0: These enumeration values are used by the glyph selector classes to indicated sl@0: back to the glyph selection algorithm when they find a cluster complete. sl@0: */ sl@0: { sl@0: EGClusterComplete, sl@0: EGClusterNotComplete sl@0: }; sl@0: sl@0: enum TGlyphPostCombine sl@0: /** sl@0: These enumeration values are used by the glyph selector classes to decide whether sl@0: post combining is needed to combine the diacritic to the base character. sl@0: */ sl@0: { sl@0: EGPostCombine_No, sl@0: EGPostCombine_Yes sl@0: }; sl@0: sl@0: sl@0: TGlyphSelectionState(TUtf32Iterator& aIter, const CFont* aFont, CFont::TPositionParam& aParam) sl@0: : iCodePt(0xFFFF), iCodeChar(0xFFFF), iCombCls(-1), iCats(0), sl@0: iText(aIter), iFont(aFont), iParam(aParam), sl@0: iClusterState(EGClusterNotComplete), iPen(EPenAdvance_No), sl@0: iAdvance(), iLigaturePortionsRemaining(0), iGlyphPostCombine(EGPostCombine_No) { }; sl@0: sl@0: TBool IsCombiningClass() { return (iCats & 0xF0) == TChar::EMarkGroup; } sl@0: void CombineLastGlyphToBase(const TRect& aBase, TInt aFirstDiacritic); sl@0: sl@0: TBool AppendGlyphToCluster(TUint code); sl@0: sl@0: public: sl@0: /** The properties of the current character being processed */ sl@0: TUint iCodePt; sl@0: TChar iCodeChar; sl@0: TInt iCombCls; sl@0: TUint iCats; sl@0: sl@0: /** The Unicode iterator to the text processed */ sl@0: TUtf32Iterator& iText; sl@0: sl@0: /** The font to select glyphs from */ sl@0: const CFont* iFont; sl@0: sl@0: /** The in/out parameter data to the glyph selection code from outside */ sl@0: CFont::TPositionParam& iParam; sl@0: sl@0: /** Result from the glyph selector class as to whether it thinks the sl@0: cluster is complete or incomplete. sl@0: */ sl@0: TGlyphClusterStateOverride iClusterState; sl@0: sl@0: /** These hold the possible pen advance and if it should be applied */ sl@0: TPenAdvance iPen; sl@0: TSize iAdvance; sl@0: sl@0: /** Can be used in any way or not at all by the processing function. It is sl@0: set to 0 on intitialisation. Suggested use is to pass information about sl@0: which part of a ligature is currently having diacritics attatched to it. */ sl@0: TInt iLigaturePortionsRemaining; sl@0: /** Can be used in any way or not at all by the processing function. It is sl@0: not initialised. Suggested use is to record the position in the output sl@0: glyph array of the first diacritic on this portion of the ligature. */ sl@0: TInt iLigaturePortionFirstMark; sl@0: sl@0: /** sl@0: Result from the glyph selector class as to whether it needs to sl@0: combine the diacritic with the base character. sl@0: */ sl@0: TGlyphPostCombine iGlyphPostCombine; sl@0: }; sl@0: sl@0: sl@0: // sl@0: // sl@0: // GlyphSelector_SoftHyphen Class declaration sl@0: // sl@0: // sl@0: sl@0: class GlyphSelector_SoftHyphen sl@0: /** sl@0: This glyph selector class processes the Unicode soft hyphen U+00AD sl@0: character. sl@0: This is a discretionary hyphen, i.e. it is only rendered when required sl@0: and in Symbian OS that is when it is found at the end of a line. sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: sl@0: static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&); sl@0: }; sl@0: sl@0: sl@0: // sl@0: // sl@0: // GlyphSelector_Default Class declaration sl@0: // sl@0: // sl@0: sl@0: class GlyphSelector_Default sl@0: /** sl@0: This is the default glyph selector class which has the behaviour of outputting sl@0: all glyphs it is invoked to process. sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: sl@0: static TBool Process(TGlyphSelectionState& aGss, RShapeInfo&); sl@0: }; sl@0: sl@0: sl@0: // sl@0: // TUtf32Iterator inline Function definitions. sl@0: // sl@0: sl@0: sl@0: inline TBool TUtf32Iterator::AtEnd() const sl@0: { sl@0: return iEnd == iCurrent; sl@0: } sl@0: sl@0: inline TBool TUtf32Iterator::BeforeStart() const sl@0: { sl@0: return iStart > iCurrent; sl@0: } sl@0: sl@0: inline TChar TUtf32Iterator::Get() const sl@0: { sl@0: __ASSERT_DEBUG(iCurrent >= iStart && iCurrent < iEnd, Panic(EGdiPanic_OutOfText)); sl@0: sl@0: return iChar; sl@0: } sl@0: sl@0: #endif // __GLYPHSEL_H__