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