sl@0: // Copyright (c) 2010 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: // This file is a subset of original gdi.h. sl@0: // sl@0: // IMPORTANT NOTE to maintainer: sl@0: // If you add new exports, to make sure they are exported by GDI.DLL, sl@0: // remember to update /graphics/graphicsdeviceinterface/gdi/sgdi/TextBaseStub.cpp. sl@0: // sl@0: // Text related types/consts are moved from gdi.h to this file, as listed below. sl@0: // sl@0: // enum TFontPosture sl@0: // enum TFontStrokeWeight sl@0: // enum TFontPrintPosition sl@0: // sl@0: // const KMaxTypefaceNameLength sl@0: // class TTypeface sl@0: // enum TGlyphBitmapType sl@0: // class FontEffect sl@0: // class TFontStyle sl@0: // class TFontSpec sl@0: // class TTypefaceSupport sl@0: // const KSuperSubScalingPercentage sl@0: // const KSuperscriptOffsetPercentage sl@0: // const KSubscriptOffsetPercentage sl@0: // class CTypefaceStore sl@0: // const KMaxFontCacheEntries sl@0: // class CFontCache sl@0: // sl@0: // const KFontCapitalAscent sl@0: // const KFontMaxAscent sl@0: // const KFontStandardDescent sl@0: // const KFontMaxDescent sl@0: // const KFontLineGap sl@0: // const KFontGetFontTable sl@0: // const KFontGetGlyphOutline sl@0: // const KFontReleaseGlyphOutline sl@0: // const KFontReleaseFontTable sl@0: // class CFont sl@0: sl@0: sl@0: #ifndef __TEXTBASE_H__ sl@0: #define __TEXTBASE_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: class TOpenFontCharMetrics; sl@0: class RShapeInfo; sl@0: sl@0: sl@0: #ifndef __GLYPHSEL_TEXTBASE_H__ sl@0: #define __GLYPHSEL_TEXTBASE_H__ sl@0: /** sl@0: This enumeration holds the possible panic codes that may be raised sl@0: by the TextBase API on detecting an unrecoverable error. */ sl@0: enum TTextBasePanic sl@0: { sl@0: /** Not used */ sl@0: ETextBasePanic_Unknown = 0, sl@0: /** One or more of the input parameters to the interface were invalid */ sl@0: ETextBasePanic_InvalidInputParam = 1, sl@0: /** Insufficient text for successful completion of the method */ sl@0: ETextBasePanic_OutOfText = 2, sl@0: /** Internal failure. */ sl@0: ETextBasePanic_Invariant = 3, sl@0: /** Reserved panic codes. Not to be used. */ sl@0: ETextBasePanic_Reserved1 = 4, sl@0: ETextBasePanic_Reserved2 = 5, sl@0: /** Setting a typeface name that is too long */ sl@0: ETextBasePanic_TypefaceNameOverflow = 6, sl@0: }; sl@0: #endif sl@0: sl@0: sl@0: /** sl@0: Font posture flags. sl@0: Fonts can be either upright or italic. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: enum TFontPosture sl@0: { sl@0: /** Font posture is normal (upright). */ sl@0: EPostureUpright, sl@0: /** Font posture is italic. */ sl@0: EPostureItalic sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Font stroke weight flags. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: enum TFontStrokeWeight sl@0: { sl@0: /** Font stroke weight is normal. */ sl@0: EStrokeWeightNormal, sl@0: /** Font stroke weight is bold. */ sl@0: EStrokeWeightBold sl@0: }; sl@0: sl@0: /** sl@0: Font print position flags. sl@0: Fonts can be normal, superscript or subscript. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: enum TFontPrintPosition sl@0: { sl@0: /** Font is normal. */ sl@0: EPrintPosNormal, sl@0: /** Font is superscript. */ sl@0: EPrintPosSuperscript, sl@0: /** Font is subscript. */ sl@0: EPrintPosSubscript sl@0: }; sl@0: sl@0: sl@0: /** sl@0: The maximum length of a typeface name (in characters). sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: const TInt KMaxTypefaceNameLength=0x18; sl@0: sl@0: sl@0: /** Typeface name and attributes. sl@0: sl@0: This class identifies a typeface by name, and contains the combination of sl@0: attributes of the typeface. These attributes define whether it is a symbol sl@0: typeface, whether the typeface is proportional, and whether it is serif or sl@0: sans-serif. sl@0: sl@0: The combination of attributes for a typeface are stored in a bitmask, with sl@0: the various bits indicating different attributes. The bitmask is calculated sl@0: for any particular attribute combination by ORing the enumerated value for sl@0: each individual attribute. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TTypeface sl@0: { sl@0: public: sl@0: enum sl@0: { sl@0: /** Typeface is a proportional typeface (e.g. Swiss) sl@0: */ sl@0: EProportional = 1, sl@0: /** Typeface is a serif typeface (e.g. Times) sl@0: */ sl@0: ESerif = 2, sl@0: /** Typeface is a symbol typeface (e.g. Symbol) sl@0: */ sl@0: ESymbol = 4, sl@0: }; sl@0: public: sl@0: IMPORT_C TTypeface(); sl@0: IMPORT_C TBool operator==(const TTypeface& aTypeface) const; sl@0: IMPORT_C void InternalizeL(RReadStream& aStream); sl@0: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; sl@0: IMPORT_C void SetAttributes(TInt aAttributes); sl@0: IMPORT_C void SetIsProportional(TBool aIsProportional); sl@0: IMPORT_C void SetIsSerif(TBool aIsSerif); sl@0: IMPORT_C void SetIsSymbol(TBool aIsSymbol); sl@0: IMPORT_C TInt Attributes() const; sl@0: IMPORT_C TBool IsProportional() const; sl@0: IMPORT_C TBool IsSerif() const; sl@0: IMPORT_C TBool IsSymbol() const; sl@0: IMPORT_C void SetScriptTypeForMetrics(TLanguage aLanguage); sl@0: IMPORT_C void SetScriptTypeForMetrics(TInt aScript); sl@0: IMPORT_C TInt ScriptTypeForMetrics() const; sl@0: IMPORT_C void SetName(const TDesC& aName); sl@0: IMPORT_C const TDesC& Name() const; sl@0: private: sl@0: void ResetAttributes(); sl@0: void ResetScriptType(); sl@0: public: sl@0: /** The typeface name. */ sl@0: TBufC iName; sl@0: private: sl@0: TUint32 iFlags; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: An enumerated type for the format of a glyph bitmap. This type is currently sl@0: used to indicate whether glyph bitmaps for scalable fonts are drawn anti-aliased. sl@0: Additional values may be defined in the future. sl@0: sl@0: @see TFontStyle::SetBitmapType() sl@0: @see CFbsTypefaceStore::SetDefaultBitmapType() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: enum TGlyphBitmapType sl@0: { sl@0: /** The font store's default glyph bitmap format is used. */ sl@0: EDefaultGlyphBitmap = 0, sl@0: /** The standard monochrome format: no anti-aliasing, 1 bit per pixel, sl@0: run-length encoded. */ sl@0: EMonochromeGlyphBitmap, sl@0: /** Standard 8-bits-per-pixel with anti-aliasing. */ sl@0: EAntiAliasedGlyphBitmap, sl@0: /** The format used when sub-pixel font rendering is used. */ sl@0: ESubPixelGlyphBitmap, sl@0: /** The format used when outline and shadow font rendering is used. sl@0: sl@0: If the raterizer supports the outline and shadow fonts, it will set the bitmaptype as sl@0: EFourColourBlendGlyphBitmap but only when glyph bitmap type is set as EAntiAliasedGlyphBitmap and sl@0: when any of the EDropShadow or EOutline effect is on. Only rasterizer providers can use this enum. sl@0: */ sl@0: EFourColourBlendGlyphBitmap, sl@0: /** sl@0: This is used for glyphs, and not fonts, and is needed to inform the font drawing routines sl@0: that the character should be drawn using the overall font setting. sl@0: For Internal Use Only. sl@0: */ sl@0: EGlyphBitmapTypeNotDefined, sl@0: /** sl@0: This is used to inform the rasterizer that the best match should be sl@0: found for the bitmap type based upon its knowledge. sl@0: For Internal Use Only. sl@0: */ sl@0: EAntiAliasedOrMonochromeGlyphBitmap, sl@0: }; sl@0: sl@0: /** sl@0: Defines a set of font effects flags. sl@0: sl@0: @publishedAll sl@0: @released sl@0: WARNING: This Class is for use by system/UI software ONLY. sl@0: */ sl@0: NONSHARABLE_CLASS(FontEffect) sl@0: { sl@0: public: sl@0: enum TEffect sl@0: { sl@0: ENone = 0x0, // No effects. sl@0: EAlgorithmicBold= 0x10, // Font is algorithmic bold (a.k.a pseudo bold.) sl@0: EDropShadow = 0x20, // Font has a drop shadow. sl@0: EOutline = 0x40, // Font is an outline font. sl@0: EEmbossed = 0x80, // Font is embossed. sl@0: EEngraved = 0x100, // Font is engraved. sl@0: ESoftEdge = 0x200, // Font is soft edged. sl@0: EReserved1 = 0x400, // Reserved for Symbian use. sl@0: EReserved2 = 0x800, // Reserved for Symbian use. sl@0: EReserved3 = 0x1000, // Reserved for Symbian use. sl@0: EReserved4 = 0x2000, // Reserved for Symbian use. sl@0: EReserved5 = 0x4000, // Reserved for Symbian use. sl@0: EReserved6 = 0x8000, // Reserved for Symbian use. sl@0: }; sl@0: public: sl@0: IMPORT_C static TBool IsEffectOn(TEffect aEffect, TUint32 aFontEffect); sl@0: IMPORT_C static void SetEffect(TEffect aEffect, TBool aOn, TUint32& aFontEffect); sl@0: }; sl@0: sl@0: /** Encapsulates a font style. sl@0: sl@0: The font style information is comprised of: sl@0: sl@0: the posture of the font upright or italic sl@0: sl@0: the stroke weight of the font normal or bold sl@0: sl@0: the print position of the font normal, subscript or superscript sl@0: sl@0: Note that the underline and strike-through attributes are not included in sl@0: this class, but are set in the graphics context. sl@0: sl@0: @see CGraphicsContext::SetUnderlineStyle() sl@0: @see CGraphicsContext::SetStrikethroughStyle() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TFontStyle sl@0: { sl@0: public: sl@0: IMPORT_C TFontStyle(); sl@0: IMPORT_C TFontStyle(TFontPosture aPost,TFontStrokeWeight aStrWgt,TFontPrintPosition aPrintPos); sl@0: IMPORT_C void InternalizeL(RReadStream& aStream); sl@0: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; sl@0: IMPORT_C TFontPosture Posture() const; sl@0: IMPORT_C TFontStrokeWeight StrokeWeight() const; sl@0: IMPORT_C TFontPrintPosition PrintPosition() const; sl@0: IMPORT_C void SetPosture(TFontPosture aPosture); sl@0: IMPORT_C void SetStrokeWeight(TFontStrokeWeight aStrokeWeight); sl@0: IMPORT_C void SetPrintPosition(TFontPrintPosition aPrintPosition); sl@0: inline TGlyphBitmapType BitmapType() const; sl@0: inline void SetBitmapType(TGlyphBitmapType aBitmapType); sl@0: IMPORT_C TBool operator==(const TFontStyle& aFontStyle) const; sl@0: IMPORT_C TUint32 Effects() const; sl@0: IMPORT_C TBool IsEffectOn(FontEffect::TEffect aEffect) const; sl@0: IMPORT_C void SetEffects(TUint32 aEffects); sl@0: IMPORT_C void SetEffects(FontEffect::TEffect aEffect, TBool aOn); sl@0: private: sl@0: enum sl@0: { sl@0: EItalic=0x1, sl@0: EBold=0x2, sl@0: ESuper=0x4, sl@0: ESub=0x8 sl@0: }; sl@0: private: sl@0: TUint32 iFlags; // bitmap type - 16 bits (high), font effects - 12 bits (middle), style - 4 bits (low) sl@0: TAny* iReserved1; sl@0: TAny* iReserved2; sl@0: }; sl@0: sl@0: sl@0: sl@0: /** sl@0: Specifies the font specification in device independent terms. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TFontSpec sl@0: { sl@0: public: sl@0: IMPORT_C TFontSpec(); sl@0: IMPORT_C TFontSpec(const TDesC& aTypefaceName,TInt aHeight); sl@0: IMPORT_C TBool operator==(const TFontSpec& aFontSpec) const; sl@0: IMPORT_C void InternalizeL(RReadStream& aStream); sl@0: IMPORT_C void ExternalizeL(RWriteStream& aStream) const; sl@0: IMPORT_C void SetScriptTypeForMetrics(TLanguage aLanguage); sl@0: IMPORT_C TInt ScriptTypeForMetrics() const; sl@0: public: sl@0: /** The typeface. */ sl@0: TTypeface iTypeface; sl@0: /** The height of the typeface (in twips). */ sl@0: TInt iHeight; sl@0: /** The font style of the typeface. */ sl@0: TFontStyle iFontStyle; sl@0: }; sl@0: sl@0: sl@0: sl@0: /** Typeface family support information. sl@0: sl@0: This data-only class includes the name and attributes of a typeface, how many sl@0: font heights are available, its minimum and maximum heights, and whether or sl@0: not it is scaleable a typeface is scaleable if it supports heights at sl@0: fixed intervals between the minimum and maximum heights. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TTypefaceSupport sl@0: { sl@0: public: sl@0: /** The name and attributes of the typeface. */ sl@0: TTypeface iTypeface; sl@0: /** The number of distinct font heights available in the typeface. */ sl@0: TInt iNumHeights; sl@0: /** The typeface's minimum font height, in twips. */ sl@0: TInt iMinHeightInTwips; sl@0: /** The typeface's maximum font height, in twips. */ sl@0: TInt iMaxHeightInTwips; sl@0: /** Whether the typeface is scaleable. ETrue if it is scaleable, otherwise sl@0: EFalse. */ sl@0: TBool iIsScalable; // supports heights from min to max at fixed interval sl@0: }; sl@0: sl@0: /** sl@0: The percentage used to multiply a normal font height when calculating its sl@0: superscript or subscript height. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: const TInt KSuperSubScalingPercentage=67; sl@0: sl@0: /** sl@0: The percentage of a font height used to calculate its baseline offset for a sl@0: superscript print position. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: const TInt KSuperscriptOffsetPercentage=-28; sl@0: sl@0: /** sl@0: The percentage of a font height used to calculate its baseline offset for a sl@0: subscript print position. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: const TInt KSubscriptOffsetPercentage=14; sl@0: sl@0: class CFont; sl@0: sl@0: /** Typeface store abstract base interface. sl@0: sl@0: This class provides the interface to a store for typefaces. sl@0: sl@0: See also CFontStore. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class CTypefaceStore : public CBase sl@0: { sl@0: public: sl@0: IMPORT_C ~CTypefaceStore(); sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: Note that this deprecated function is replaced by the new @c GetNearestFontToDesignHeightInTwips() sl@0: yielding (virtually) the same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of twips, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: @param aFont On return, contains a pointer to the nearest font. sl@0: @param aFontSpec The specification of the font to be matched. sl@0: @return KErrNone if successful; a system-wide error code otherwise. sl@0: @publishedAll sl@0: @deprecated Use GetNearestFontToDesignHeightInTwips sl@0: */ sl@0: virtual TInt GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec) = 0; sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: This new function replaces the deprecated @c GetNearestFontInTwips() yielding (virtually) the sl@0: same result. However clients are strongly encouraged to use the new sl@0: @c GetNearestFontToMaxHeightInTwips() function instead. This will guarantee that every sl@0: character within any given text string will fit within the given amount of twips, whereas the design sl@0: height is an aesthetic unit decided by the font designer without strict physical meaning, which sl@0: may result in cropped characters. sl@0: sl@0: @param aFont On return, contains a pointer to the nearest font. sl@0: @param aFontSpec The specification of the font to be matched. sl@0: @return KErrNone if successful; a system-wide error code otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: virtual TInt GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) = 0; sl@0: sl@0: /** sl@0: Gets the font which is the nearest to the given font specification. sl@0: sl@0: When the font is no longer needed, call @c ReleaseFont(). sl@0: sl@0: The font and bitmap server returns a pointer to the nearest matching font sl@0: from those available. Matches to max height of font - this does its best sl@0: to return a font that will fit within the maximum height specified (but sl@0: note that variations due to hinting algorithms may rarely result in this sl@0: height being exceeded by up to one pixel). Problems can also be sl@0: encountered with bitmap fonts where the typeface exists but doesn't have sl@0: a font small enough. sl@0: sl@0: @param aFont On return, contains a pointer to the nearest font. sl@0: @param aFontSpec The specification of the font to be matched. sl@0: @param aMaxHeight The maximum height within which the font must fit. sl@0: @return KErrNone if successful; a system-wide error code otherwise. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: virtual TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight) = 0; sl@0: sl@0: /** Gets the number of typefaces supported by the typeface store. sl@0: sl@0: @return The number of supported typefaces. */ sl@0: virtual TInt NumTypefaces() const=0; sl@0: sl@0: /** Gets typeface information for a specified typeface index. sl@0: sl@0: This information is returned in aTypefaceSupport, and sl@0: includes the typeface name and typeface attributes, the number of font sl@0: heights, the maximum and minimum font heights, and whether it is a sl@0: scaleable typeface. sl@0: sl@0: @param aTypefaceSupport On return, if the function executed successfully, sl@0: this object contains the typeface information. sl@0: @param aTypefaceIndex A typeface index number, in the range: zero to sl@0: (NumTypefaces() - 1). */ sl@0: virtual void TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const=0; sl@0: sl@0: /** Gets the height of the font with specified height and typeface indices, sl@0: in twips. sl@0: sl@0: The value returned is rounded up or down to the nearest font height in twips. sl@0: sl@0: @param aTypefaceIndex A typeface index number, in the range: 0 to sl@0: (NumTypefaces() - 1). sl@0: @param aHeightIndex A font height index number. sl@0: @return The height of the font, in twips. */ sl@0: virtual TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const=0; sl@0: IMPORT_C void ReleaseFont(CFont* aFont); sl@0: IMPORT_C static TInt BaselineOffset(TInt aHeight,TFontPrintPosition aPos); sl@0: IMPORT_C static TInt SuperSubHeight(TInt aHeight,TFontPrintPosition aPos); sl@0: protected: sl@0: IMPORT_C CTypefaceStore(); sl@0: IMPORT_C void ConstructL(); sl@0: IMPORT_C void AddFontL(CFont* aFont); sl@0: IMPORT_C TBool IncrementFontCount(const CFont* aFont); sl@0: private: sl@0: TBool FindFont(const CFont* aFont, TInt& aIdx) const; sl@0: NONSHARABLE_CLASS(TFontAccess) sl@0: /** sl@0: Pairs a font with a count of how many clients of the typeface store sl@0: are accessing that font. sl@0: */ sl@0: { sl@0: public: sl@0: /** A device specific font. */ sl@0: CFont* iFont; sl@0: /** The number of clients accessing the font. */ sl@0: TInt iAccessCount; sl@0: }; sl@0: protected: sl@0: /** A list of fonts accessed by clients of the typeface store, which pairs sl@0: a font with a count of the number of clients accessing the font. sl@0: sl@0: Implemented as an array of TFontAccess objects. sl@0: sl@0: An object is added to this array for every font accessed. If the font is sl@0: released by all clients, and the access count drops to zero, the font is sl@0: removed from the list. */ sl@0: CArrayFixFlat* iFontAccess; sl@0: }; sl@0: sl@0: /** The maximum number of entries in the font cache. sl@0: sl@0: @see CFontCache */ sl@0: const TInt KMaxFontCacheEntries=32; sl@0: sl@0: /** Font cache. sl@0: sl@0: When a CFont* needs to be found for a particular TFontSpec, the cache can sl@0: be searched to see if the TFontSpec is already in the cache. If the TFontSpec sl@0: is in the cache, its corresponding CFont* can be returned. Otherwise sl@0: GetNearestFontInTwips() must be used to search all of the available fonts for sl@0: the nearest CFont- a procedure which takes much longer than a simple cache sl@0: search. sl@0: sl@0: The current font cache should be destroyed and a new cache created whenever sl@0: the zoom factor or device map changes, as these changes break the relation sl@0: between CFont and TFontSpec. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class CFontCache : public CBase sl@0: { sl@0: public: sl@0: IMPORT_C CFontCache(); sl@0: IMPORT_C CFontCache(TInt aMaxEntries); sl@0: IMPORT_C ~CFontCache(); sl@0: IMPORT_C CFont* Search(const TFontSpec& aFontSpec); sl@0: IMPORT_C CFont* AddEntryL(CFont* aFont,const TFontSpec& aFontSpec); sl@0: IMPORT_C CFont* RemoveFirstEntry(); sl@0: public: sl@0: /** The number of cache hits since the font cache was created i.e. sl@0: successful results from CFontCache::Search(). */ sl@0: TInt iNumHits; sl@0: /** The number of cache misses since the font cache was created i.e. sl@0: unsuccessful results from CFontCache::Search(). */ sl@0: TInt iNumMisses; sl@0: private: sl@0: class CFontCacheEntry : public CBase sl@0: { sl@0: public: sl@0: CFontCacheEntry(CFont* aFont,const TFontSpec& aFontSpec,CFontCacheEntry* aNext); sl@0: public: sl@0: CFont* iFont; sl@0: TFontSpec iSpec; sl@0: CFontCacheEntry* iNext; sl@0: }; sl@0: private: sl@0: TInt iNumEntries; sl@0: TInt iMaxEntries; sl@0: CFontCacheEntry* iFirst; sl@0: }; sl@0: sl@0: /** sl@0: WARNING: this Class is for internal use ONLY. Compatibility is not guaranteed in future releases. sl@0: UIDs corresponding to the CFont API extension functions sl@0: @internalTechnology sl@0: */ sl@0: const TUid KFontCapitalAscent = {0x1020498E}; sl@0: const TUid KFontMaxAscent = {0x10204B10}; sl@0: const TUid KFontStandardDescent = {0x10204B11}; sl@0: const TUid KFontMaxDescent = {0x10205AFC}; sl@0: const TUid KFontLineGap = {0x10204B12}; sl@0: const TUid KFontGetFontTable = {0x102872C1}; sl@0: const TUid KFontGetGlyphOutline = {0x102872C2}; sl@0: const TUid KFontReleaseGlyphOutline = {0x2002A1FD}; sl@0: const TUid KFontReleaseFontTable = {0x2002AC24}; sl@0: sl@0: sl@0: /** Abstract font interface. sl@0: sl@0: The CFont class provides a device-independent interface to a device-dependent sl@0: font usually obtained from a call to GetNearestFont...() on a graphics device. sl@0: It is used as a handle in CGraphicsContext::UseFont() and to obtain sl@0: device-dependent information about the font - notably the pixel width of a text sl@0: string. sl@0: sl@0: @see CFbsFont sl@0: @see CGraphicsContext::UseFont() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class CFont : public CBase sl@0: { sl@0: friend class CTypefaceStore; sl@0: public: sl@0: sl@0: /** Text direction flags. sl@0: sl@0: This enum is used in TMeasureTextInput and determines whether the text is sl@0: drawn horizontally or vertically. Note: text is drawn vertically in some sl@0: styles of Japanese, etc. sl@0: sl@0: @see TMeasureTextInput */ sl@0: enum TTextDirection sl@0: { sl@0: /** Text is drawn horizontally. */ sl@0: /** Text is drawn horizontally. */ sl@0: EHorizontal, sl@0: /** Text is drawn vertically. */ sl@0: EVertical sl@0: }; sl@0: sl@0: /** Complicated parameter block used for contextual glyph selection, sl@0: ligature creation and diacritic placement when drawing text in complex sl@0: scripts sl@0: sl@0: This class declares a constructor, another scoped class, and several other sl@0: enums. However this class is unlikely to be useful to third party developers. sl@0: sl@0: @see CFont::GetCharacterPosition() sl@0: @see CFont::GetCharacterPosition2() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TPositionParam sl@0: { sl@0: public: sl@0: /** Standard constructor. */ sl@0: TPositionParam(): sl@0: iDirection(EHorizontal), sl@0: iFlags(0), sl@0: iPosInText(0), sl@0: iOutputGlyphs(0) sl@0: { sl@0: } sl@0: sl@0: enum sl@0: { sl@0: EMaxInputChars = 18, // ligatures cannot be made from more than 18 components sl@0: EMaxOutputGlyphs = 8 // output can consist of up to 8 characters (one base and 7 combining characters) sl@0: }; sl@0: sl@0: /**Flags for TPositionParam::iFlags. */ sl@0: enum TFlags sl@0: { sl@0: /** Input text is logically ordered not visually ordered. */ sl@0: EFLogicalOrder = 1 sl@0: }; sl@0: sl@0: /** Input: Orientation (EHorizontal or EVertical) in which to draw sl@0: the text. */ sl@0: TInt16 iDirection; sl@0: /** Input: Flags from TFlags. */ sl@0: TUint16 iFlags; sl@0: /** Input: Text containing the characters to be positioned. */ sl@0: TPtrC iText; sl@0: sl@0: /** Input and output: Position within iText to shape. On exit sl@0: it will index the first character not positioned */ sl@0: TInt iPosInText; sl@0: /** Input and output: Pen position. */ sl@0: TPoint iPen; sl@0: sl@0: /** Output of GetCharacterPosition and GetCharacterPosition2. sl@0: @see CFont::GetCharacterPosition sl@0: @see CFont::GetCharacterPosition2 sl@0: @publishedAll sl@0: @released */ sl@0: class TOutput sl@0: { sl@0: public: sl@0: /** Standard constructor. */ sl@0: TOutput() : iBitmapSize(TSize::EUninitialized), sl@0: iBounds(TRect::EUninitialized) {} sl@0: /** Character or glyph code. */ sl@0: TUint iCode; sl@0: /** Bitmap data for the glyph, if available */ sl@0: const TUint8* iBitmap; sl@0: /** Size of the bitmap before algorithmic bolding, size sl@0: multiplication, etc. */ sl@0: TSize iBitmapSize; sl@0: /** Bitmap bounds relative to the original pen position. */ sl@0: TRect iBounds; sl@0: }; sl@0: sl@0: /** Information about the glyphs that were output. */ sl@0: TOutput iOutput[EMaxOutputGlyphs]; sl@0: /** Number of glyphs actually output. */ sl@0: TInt iOutputGlyphs; sl@0: }; sl@0: sl@0: sl@0: /** Input parameter block. sl@0: sl@0: This is optionally used by CFont::MeasureText(), which is the powerful text sl@0: measurement function underlying all the other text measurement functions. sl@0: sl@0: @see CFont::MeasureText() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TMeasureTextInput sl@0: { sl@0: public: sl@0: TMeasureTextInput(): sl@0: iStartInputChar(0), sl@0: iEndInputChar(KMaxTInt), sl@0: iDirection(EHorizontal), sl@0: iFlags(0), sl@0: iMaxAdvance(KMaxTInt), sl@0: iMaxBounds(KMaxTInt), sl@0: iCharJustNum(0), sl@0: iCharJustExcess(0), sl@0: iWordJustNum(0), sl@0: iWordJustExcess(0) sl@0: { sl@0: } sl@0: sl@0: /**Flags for TMeasureTextInput::iFlags. */ sl@0: enum TFlags sl@0: { sl@0: /** Input text is visually ordered left-to-right. */ sl@0: EFVisualOrder = 1, sl@0: /** Input text is visually ordered right-to-left. sl@0: Overrides EFVisualOrder. */ sl@0: EFVisualOrderRightToLeft = 2, sl@0: /** Flag to consider side bearings when checking bounds for line-break */ sl@0: EFIncludePenPositionInBoundsCheck = 4 sl@0: }; sl@0: sl@0: /** Starting index specifying first input character in iText. sl@0: sl@0: Together with iEndInputChar, this allows some context before and sl@0: after the measured text to be supplied so that shaping can work sl@0: properly. */ sl@0: TInt iStartInputChar; sl@0: sl@0: /** Index specifying the final input character. sl@0: sl@0: Together with iStartInputChar, this allows some context before and sl@0: after the measured text to be supplied so that shaping can work sl@0: properly. */ sl@0: TInt iEndInputChar; sl@0: sl@0: /** The direction in which to draw the text. */ sl@0: TUint16 iDirection; sl@0: sl@0: /** Flags from TFlags. */ sl@0: TUint16 iFlags; sl@0: sl@0: /** The maximum advance. */ sl@0: TInt iMaxAdvance; sl@0: sl@0: /** The maximum width (or height if drawing vertically) of bounds. */ sl@0: TInt iMaxBounds; sl@0: sl@0: /** The number of glyph groups to be letter-spaced. */ sl@0: TInt iCharJustNum; sl@0: sl@0: /** The amount of space to be used for letter spacing. */ sl@0: TInt iCharJustExcess; sl@0: sl@0: /** The number of spaces to be used for word spacing. */ sl@0: TInt iWordJustNum; sl@0: sl@0: /** The amount of space to be used for word spacing. */ sl@0: TInt iWordJustExcess; sl@0: }; sl@0: sl@0: /** Output parameter block. sl@0: sl@0: This is optionally used by CFont::MeasureText(), which is the powerful text sl@0: measurement function underlying all the other text measurement functions. sl@0: sl@0: @see CFont::MeasureText() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: class TMeasureTextOutput sl@0: { sl@0: public: sl@0: /** The number of input characters that would be drawn. sl@0: sl@0: This may be less than the length of the text if a maximum advance or bounding sl@0: box size is specified. */ sl@0: TInt iChars; sl@0: /** The number of glyphs that would be drawn. */ sl@0: TInt iGlyphs; sl@0: /** The number of groups that would be drawn. sl@0: sl@0: A group is a base glyph plus one or more combining characters. */ sl@0: TInt iGroups; sl@0: /** The number of word spaces (U+0020) that would be drawn. */ sl@0: TInt iSpaces; sl@0: /** The bounding box of all the glyphs that would be drawn. */ sl@0: TRect iBounds; sl@0: /** The maximum width and height of any glyph. */ sl@0: TSize iMaxGlyphSize; sl@0: }; sl@0: sl@0: /** sl@0: Data availability flags. sl@0: sl@0: Some fonts like printer fonts may only have width information and can return sl@0: ECharacterWidthOnly to show this: the text drawing routines in CFont synthesize sl@0: the rest of the data if necessary. sl@0: sl@0: @see GetCharacterData() sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: enum TCharacterDataAvailability sl@0: { sl@0: /** No font information available. */ sl@0: ENoCharacterData, sl@0: /** Width information only is available. */ sl@0: ECharacterWidthOnly, sl@0: /** All character data is available. */ sl@0: EAllCharacterData sl@0: }; sl@0: sl@0: private: sl@0: // virtual functions have been made protected and public non-virtual ones sl@0: // added to convert CFont to a handle-body pattern. SC is kept throught the sl@0: // new functions and BC is kept by keeping the protected functions in the sl@0: // same place in the class, and therefore in the same place in the vtable sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TUid DoTypeUid() const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoHeightInPixels() const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoAscentInPixels() const=0; sl@0: IMPORT_C virtual TInt DoDescentInPixels() const; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoCharWidthInPixels(TChar aChar) const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoTextWidthInPixels(const TDesC& aText) const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoBaselineOffsetInPixels() const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels) const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoTextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoMaxCharWidthInPixels() const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TInt DoMaxNormalCharWidthInPixels() const=0; sl@0: /** sl@0: @publishedAll sl@0: WARNING: Function for internal use ONLY. Compatibility is not guaranteed in future releases. Please see derived class for implementation. sl@0: */ sl@0: virtual TFontSpec DoFontSpecInTwips() const=0; sl@0: sl@0: protected: sl@0: IMPORT_C virtual TCharacterDataAvailability DoGetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics,const TUint8*& aBitmap,TSize& aBitmapSize) const; sl@0: IMPORT_C virtual TBool DoGetCharacterPosition(TPositionParam& aParam) const; sl@0: IMPORT_C virtual TInt DoExtendedFunction(TUid aFunctionId, TAny* aParam = NULL) const; sl@0: sl@0: protected: sl@0: IMPORT_C virtual ~CFont(); sl@0: sl@0: public: sl@0: inline TInt FontCapitalAscent() const; sl@0: inline TInt FontMaxAscent() const; sl@0: inline TInt FontStandardDescent() const; sl@0: inline TInt FontMaxDescent() const; sl@0: inline TInt FontLineGap() const; sl@0: inline TInt FontMaxHeight() const; sl@0: sl@0: public: sl@0: /** Gets run-time identity of the actual font type. This enables safe casting to sl@0: a derived type. sl@0: sl@0: For example, if the derived type is a CFbsFont, the return value is KCFbsFontUid. sl@0: You would need to cast to a CFbsFont to get a character bounding box. Similarly, sl@0: a CBitmapFont returns KCBitmapFontUidVal. sl@0: sl@0: @return The font-type identifier. */ sl@0: IMPORT_C TUid TypeUid() const; sl@0: sl@0: /** Gets the font height in pixels. sl@0: Note that this deprecated function is replaced by the new @c FontMaxHeight(). sl@0: sl@0: @return The font height in pixels. sl@0: @see FontMaxHeight() sl@0: @deprecated */ sl@0: IMPORT_C TInt HeightInPixels() const; sl@0: sl@0: /** Gets the font ascent in pixels. sl@0: Note that this deprecated function is replaced by the new @c FontMaxAscent() sl@0: or in some cases @c FontCapitalAscent(). sl@0: sl@0: @return The font ascent in pixels. sl@0: @see FontCapitalAscent() sl@0: @see FontMaxAscent() sl@0: @deprecated */ sl@0: IMPORT_C TInt AscentInPixels() const; sl@0: sl@0: /** Gets the font descent in pixels. sl@0: Note that this deprecated function is replaced by the new @c FontMaxDescent() sl@0: or in some cases @c FontStandardDescent(). sl@0: sl@0: @return The font descent in pixels. sl@0: @see FontStandardDescent() sl@0: @see FontMaxDescent() sl@0: @deprecated */ sl@0: IMPORT_C TInt DescentInPixels() const; sl@0: sl@0: /** Gets the width in pixels in this font of the specified character. sl@0: sl@0: Note: For OpenType fonts this function returns the horizontal advance of sl@0: the character, which may be different from the actual width. sl@0: sl@0: @param aChar The character whose width should be determined. sl@0: @return The width in pixels of the specified character in this font. */ sl@0: IMPORT_C TInt CharWidthInPixels(TChar aChar) const; sl@0: sl@0: /** Gets the width in pixels of the specified descriptor when displayed in this sl@0: font. sl@0: sl@0: @param aText The descriptor whose width should be determined. sl@0: @return The width of the specified descriptor when displayed in this font, sl@0: in pixels. */ sl@0: IMPORT_C TInt TextWidthInPixels(const TDesC& aText) const; sl@0: sl@0: /** Gets the baseline offset in pixels. sl@0: sl@0: The baseline offset is how far a font is raised or lowered from its normal sl@0: baseline. sl@0: sl@0: @return Offset from normal baseline, in pixels. */ sl@0: IMPORT_C TInt BaselineOffsetInPixels() const; sl@0: sl@0: /** Gets how much of the specified descriptor can be displayed in this font without sl@0: exceeding the specified width. sl@0: sl@0: Note: sl@0: sl@0: This function does not display any of the descriptor itself - it is used sl@0: before display, to test whether the whole descriptor can be displayed. sl@0: sl@0: @param aText The descriptor. sl@0: @param aWidthInPixels The available width for character display. sl@0: @return The number of characters which will be able to be displayed without sl@0: exceeding the specified width. The count starts from the beginning of the sl@0: descriptor. */ sl@0: IMPORT_C TInt TextCount(const TDesC& aText,TInt aWidthInPixels) const; sl@0: sl@0: /** Gets how much of the specified descriptor can be displayed in this font without sl@0: exceeding the specified width. sl@0: sl@0: It also returns the excess width - defined as the specified available width sl@0: minus the width of the portion of the descriptor which can be displayed without sl@0: exceeding the available width. sl@0: sl@0: @param aText The descriptor. sl@0: @param aWidthInPixels The available width for character display. sl@0: @param aExcessWidthInPixels The excess width after displaying the portion of sl@0: the descriptor, in pixels. sl@0: @return The number of characters which will be able to be displayed without sl@0: exceeding the specified width. The count starts from the beginning of the sl@0: descriptor. */ sl@0: IMPORT_C TInt TextCount(const TDesC& aText,TInt aWidthInPixels,TInt& aExcessWidthInPixels) const; sl@0: sl@0: /** Gets the width in pixels of the widest character in this font. sl@0: sl@0: @return The width of the maximum width character, in pixels. */ sl@0: IMPORT_C TInt MaxCharWidthInPixels() const; sl@0: sl@0: /** Gets the width in pixels of the widest normal character in this font. sl@0: sl@0: Normal characters include all character in a character set except non-alphabetic sl@0: characters (e.g. the copyright symbol, or a block graphics symbol, for example). sl@0: sl@0: @return The width of the maximum width normal character, in pixels. */ sl@0: IMPORT_C TInt MaxNormalCharWidthInPixels() const; sl@0: sl@0: /** Gets the font specification of this font in twips. sl@0: sl@0: @return The font specification of this font (in twips). */ sl@0: IMPORT_C TFontSpec FontSpecInTwips() const; sl@0: IMPORT_C TCharacterDataAvailability GetCharacterData(TUint aCode, TOpenFontCharMetrics& aMetrics,const TUint8*& aBitmap,TSize& aBitmapSize) const; sl@0: IMPORT_C TBool GetCharacterPosition(TPositionParam& aParam) const; sl@0: IMPORT_C TInt WidthZeroInPixels() const; sl@0: IMPORT_C TInt MeasureText(const TDesC& aText, const TMeasureTextInput* aInput = NULL, TMeasureTextOutput* aOutput = NULL) const; sl@0: IMPORT_C static TBool CharactersJoin(TInt aLeftCharacter, TInt aRightCharacter); sl@0: IMPORT_C TInt ExtendedFunction(TUid aFunctionId, TAny* aParam = NULL) const; sl@0: IMPORT_C TBool GetCharacterPosition2(TPositionParam& aParam, RShapeInfo& aShapeInfo) const; sl@0: sl@0: /** Gets the width in pixels of the specified descriptor when displayed in this sl@0: font. sl@0: sl@0: @param aText The descriptor whose width should be determined. sl@0: @param aParam Parameter block that controls how much of aText is measured sl@0: @return The width of the specified descriptor when displayed in this font, sl@0: in pixels. */ sl@0: IMPORT_C TInt TextWidthInPixels(const TDesC& aText,const TMeasureTextInput* aParam) const; sl@0: }; sl@0: sl@0: sl@0: // inline functions from original gdi.inl sl@0: /** Gets the ascent of an ANSI capital letter in the font whether or not sl@0: there are any ANSI capitals in the font. sl@0: @return The positive distance from the font baseline to the top of a sl@0: standard ANSI capital letter sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: inline TInt CFont::FontCapitalAscent() const sl@0: { sl@0: return ExtendedFunction(KFontCapitalAscent); sl@0: } sl@0: sl@0: /** Gets the max ascent of any pre-composed glyph in the font. This will sl@0: include accents or diacritics that form part of pre-composed glyphs. It is sl@0: not guaranteed to cover the max ascent of composite glyphs that have to be sl@0: created by a layout engine. This is also the recommended distance between sl@0: the top of a text box and the baseline of the first line of text. sl@0: @return The positive distance from the font baseline to the top of the sl@0: highest pre-composed glyph (including accents) above the baseline sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: inline TInt CFont::FontMaxAscent() const sl@0: { sl@0: return ExtendedFunction(KFontMaxAscent); sl@0: } sl@0: sl@0: /** Gets the descent of an ANSI descending character in the font. sl@0: Whether or not there are any ANSI descenders in the font. sl@0: @return The positive distance from the font baseline to the bottom of the sl@0: lowest ANSI descender sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: inline TInt CFont::FontStandardDescent() const sl@0: { sl@0: return ExtendedFunction(KFontStandardDescent); sl@0: } sl@0: sl@0: /** Gets the max descent of any pre-composed glyph in the font. This will sl@0: include accents or diacritics that form part of pre-composed glyphs. It is sl@0: not guaranteed to cover the max descent of composite glyphs that have to be sl@0: created by a layout engine. sl@0: @return The positive distance from the font baseline to the bottom of the sl@0: lowest pre-composed glyph (including accents) below the baseline sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: inline TInt CFont::FontMaxDescent() const sl@0: { sl@0: return ExtendedFunction(KFontMaxDescent); sl@0: } sl@0: sl@0: /** Gets the suggested line gap for the font. This is the recommended sl@0: baseline to baseline distance between successive lines of text in the font. sl@0: @return The positive recommended gap between successive lines sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: inline TInt CFont::FontLineGap() const sl@0: { sl@0: return ExtendedFunction(KFontLineGap); sl@0: } sl@0: sl@0: /** sl@0: Gets the (positive) maximum height in pixels of the font. sl@0: This may differ from the design height. sl@0: sl@0: @return The maximum height of the font. sl@0: @publishedAll sl@0: @released sl@0: */ sl@0: inline TInt CFont::FontMaxHeight() const sl@0: { sl@0: return FontMaxAscent() + FontMaxDescent(); sl@0: } sl@0: sl@0: sl@0: // from original gdistruct.h sl@0: /* sl@0: Structure used to pass input/output parameters between RFontTable and CFbsFont. sl@0: @internalTechnology sl@0: */ sl@0: class TGetFontTableParam sl@0: { sl@0: public: sl@0: TUint32 iTag; sl@0: TAny *iContent; sl@0: TInt iLength; sl@0: }; sl@0: sl@0: /* sl@0: Structure used to pass input/output parameters between RGlyphOutlineIterator and CFbsFont. sl@0: Used when opening an outline iterator. sl@0: @internalTechnology sl@0: */ sl@0: class TGetGlyphOutlineParam sl@0: { sl@0: public: sl@0: TInt iCount; sl@0: const TUint *iCodes; sl@0: TBool iHinted; sl@0: TAny **iOutlines; sl@0: TInt *iLengths; sl@0: }; sl@0: sl@0: /* sl@0: Structure used to pass input/output parameters between RGlyphOutlineIterator and CFbsFont. sl@0: Used when closing an outline iterator. sl@0: @internalTechnology sl@0: */ sl@0: class TReleaseGlyphOutlineParam sl@0: { sl@0: public: sl@0: TInt iCount; sl@0: const TUint *iCodes; sl@0: TBool iHinted; sl@0: }; sl@0: sl@0: sl@0: #endif // __TEXTBASE_H__