sl@0: /* sl@0: * Copyright (c) 1996-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: sl@0: sl@0: #ifndef __FNTBODY_H__ sl@0: #define __FNTBODY_H__ sl@0: sl@0: #include sl@0: #include "FNTSTD.H" sl@0: sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: sl@0: const TInt KFontStoreFileUidVal = 0x10000039; sl@0: const TInt KCBitmapFontUidVal = 0x10000043; sl@0: const TInt KFnttranVersion = 42; sl@0: const TInt KFnttran7650Version = 39; sl@0: sl@0: class CDirectFileStore; sl@0: NONSHARABLE_CLASS(CFontStoreFile) : public CBase sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: protected: sl@0: CFontStoreFile(); sl@0: void ConstructL(const TParse& aParse, RFs& aFs); sl@0: public: sl@0: static CFontStoreFile* NewL(const TParse& aParse, RFs& aFs); sl@0: ~CFontStoreFile(); sl@0: inline const TDesC& FullName() const; sl@0: public: sl@0: TUid iCollectionUid; sl@0: TInt iKPixelAspectRatio; sl@0: TInt iUsageCount; sl@0: CDirectFileStore* iFileStore; sl@0: TInt iFileAddress; sl@0: TStreamId iDataStreamId; sl@0: TInt iFontVersion; sl@0: HBufC* iFullName; sl@0: }; sl@0: sl@0: class TBitmapCodeSection : public TCodeSection sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: TBitmapCodeSection(); sl@0: void InternalizeL(RReadStream& aStream); sl@0: void InternalizeOffsetsL(const CStreamStore& aStreamStore, RHeap* aHeap, TInt& aAllocMemCounter); sl@0: void InternalizeBitmapL(const CStreamStore& aStreamStore, RHeap* aHeap, TInt& aAllocMemCounter); sl@0: void FixUpComponents(TInt aFileAddress); sl@0: void DeleteOffsets(RHeap* aHeap); sl@0: void DeleteBitmap(RHeap* aHeap); sl@0: TBitmapFontCharacterOffset* CharacterOffsetsList(TBool aIsInRAM) const; sl@0: TUint8* Bitmap(TBool aIsInRAM) const; sl@0: sl@0: private: sl@0: union TCharacterData sl@0: { sl@0: TCharacterData() : iOffsetsId(KNullStreamIdValue) {} sl@0: TUint32 iOffsetsId; sl@0: TInt iCharacterOffsetsListOffset; sl@0: } iCharacterData; sl@0: //iCharacterData is interpreted either as StreamId(casted from TUint32) or as TInt offset; sl@0: union TBitmapData sl@0: { sl@0: TBitmapData() : iBitmapId(KNullStreamIdValue) {} sl@0: TUint32 iBitmapId; sl@0: TInt iBitmapOffset; sl@0: } iBitmapData; sl@0: //iBitmapData is interpreted either as StreamId(casted from TUint32) or as TInt offset; sl@0: //The size of the original TBitmapCodeSection was 24 bytes. sl@0: //Using the unions above (and removing RHeap* member) we reduce TBitmapCodeSection size sl@0: //to be 12 bytes per instance. sl@0: //It is possible to do that because iCharacterData and iBitmapData are treated as IDs during sl@0: //initialization stage and as offsets during all the time after initialization. sl@0: //So we can use the same memory for IDs and for offsets. sl@0: }; sl@0: sl@0: class TCharacterMetricsTable sl@0: /** sl@0: Class to store the list of Character Metrics used in this font sl@0: @since 7.0s sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: TCharacterMetricsTable(RHeap* aHeap); sl@0: void InternalizeL(RReadStream& aStream); sl@0: void InternalizeMetricsL(RReadStream& aStream); sl@0: void RestoreL(const CStreamStore& aStreamStore); sl@0: void FixUp(TInt aFileAddress); sl@0: void Delete(); sl@0: const TBitmapFontCharacterMetrics* Metric(TInt aIndex) const; sl@0: TInt NumberOfMetrics() const; sl@0: private: sl@0: TBitmapFontCharacterMetrics* MetricsFromOffset(TInt aIndex) const; sl@0: private: sl@0: RHeap* iHeap; sl@0: TStreamId iMetricsStartId; sl@0: // Sometimes this address is on the metrics heap and sometimes in a ROM file sl@0: // If the address is on the heap, then this is actually an offset from sl@0: // the address of this class. sl@0: TInt iCharacterMetricsStartPtr; sl@0: TInt iNumberOfMetrics; sl@0: TBool iMetricsOnHeap; sl@0: }; sl@0: sl@0: NONSHARABLE_CLASS(CFontBitmap) : public CBase sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: CFontBitmap(RHeap* aHeap,CFontStoreFile* aFontStoreFile); sl@0: void InternalizeL(RReadStream &aStream, TInt aFontversion); sl@0: void UseL(); sl@0: void Release(); sl@0: TBitmapFontCharacterMetrics CharacterMetrics(TInt aCode,const TUint8*& aBytes) const; sl@0: void operator delete(TAny*); sl@0: inline void operator delete(TAny*, TAny*) {} sl@0: void SetPosture(TFontPosture aPosture); sl@0: TFontPosture Posture() const; sl@0: void SetStrokeWeight(TFontStrokeWeight aStrokeWeight); sl@0: TFontStrokeWeight StrokeWeight() const; sl@0: void SetIsProportional(TBool aIsProportional); sl@0: TBool IsProportional() const; sl@0: CFontStoreFile* FontStoreFile() const; 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: protected: sl@0: ~CFontBitmap(); sl@0: void RestoreComponentsL(); // Has reference to FontStoreFile sl@0: void DeleteComponents(); sl@0: TBitmapCodeSection* CodeSectionList() const; sl@0: TCharacterMetricsTable* MetricsTable() const; sl@0: public: sl@0: RHeap* iHeap; sl@0: TInt iFontStoreFileOffset; sl@0: TUid iUid; sl@0: protected: sl@0: TInt8 iPosture; sl@0: TInt8 iStrokeWeight; sl@0: TInt8 iIsProportional; sl@0: TBool iIsInRAM; sl@0: TInt iUsageCount; sl@0: public: sl@0: TInt8 iCellHeightInPixels; sl@0: TInt8 iAscentInPixels; sl@0: TInt8 iMaxCharWidthInPixels; sl@0: TInt8 iMaxNormalCharWidthInPixels; sl@0: TInt iBitmapEncoding; sl@0: TInt iNumCodeSections; sl@0: TInt iCodeSectionListOffset; sl@0: private: sl@0: TCharacterMetricsTable iCharacterMetricsTable; sl@0: TBool iComponentsRestored; sl@0: TInt iAllocMemCounter_Offsets; sl@0: TInt iAllocMemCounter_Bitmaps; sl@0: TInt iFontCapitalAscent; // The positive distance in pixels from the baseline to sl@0: // the top of an ANSI capital (whether or not there are sl@0: // ANSI capitals in the font) sl@0: TInt iFontMaxAscent; // The positive distance in pixels from the baseline to sl@0: // the top of the highest pre-composed glyph in the font sl@0: TInt iFontStandardDescent; // The positive distance in pixels from the baseline to sl@0: // the bottom of the lowest ANSI descender (whether or sl@0: // not there are ANSI chars in the font) sl@0: TInt iFontMaxDescent; // The positive distance in pixels from the baseline to sl@0: // the bottom of the lowest pre-composed glyph in the font sl@0: TInt iFontLineGap; // The recommended baseline to baseline gap for successive sl@0: // lines of text in the font sl@0: }; sl@0: sl@0: class TTypefaceFontBitmap sl@0: /** sl@0: @internalComponent sl@0: */ sl@0: { sl@0: public: sl@0: TTypefaceFontBitmap(); sl@0: TTypefaceFontBitmap(TTypeface* aTypeface,CFontBitmap* aFontBitmap); sl@0: TInt HeightInPixels() const; sl@0: public: sl@0: TTypeface* iTypeface; sl@0: CFontBitmap* iFontBitmap; sl@0: TInt8 iHeightFactor; sl@0: TInt8 iWidthFactor; sl@0: }; sl@0: sl@0: 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: @internalComponent sl@0: @released sl@0: @see AscentInPixels() sl@0: @see FontMaxAscent() sl@0: */ sl@0: inline TInt CFontBitmap::FontCapitalAscent() const sl@0: { sl@0: return iFontCapitalAscent; 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: @internalComponent sl@0: @released sl@0: @see AscentInPixels() sl@0: @see FontCapitalAscent() sl@0: */ sl@0: inline TInt CFontBitmap::FontMaxAscent() const sl@0: { sl@0: return iFontMaxAscent; 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: @internalComponent sl@0: @released sl@0: @see DescentInPixels() sl@0: */ sl@0: inline TInt CFontBitmap::FontStandardDescent() const sl@0: { sl@0: return iFontStandardDescent; 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: @internalComponent sl@0: @released sl@0: @see DescentInPixels() sl@0: */ sl@0: inline TInt CFontBitmap::FontMaxDescent() const sl@0: { sl@0: return iFontMaxDescent; 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: @internalComponent sl@0: @released sl@0: */ sl@0: inline TInt CFontBitmap::FontLineGap() const sl@0: { sl@0: return iFontLineGap; sl@0: } sl@0: sl@0: /** Gets the maximum height for the font. This is the sum of the max ascent sl@0: of the font and the max descent of the font. sl@0: @return The positive maximum height of the font sl@0: @internalComponent sl@0: @released sl@0: @see HeightInPixels() sl@0: */ sl@0: inline TInt CFontBitmap::FontMaxHeight() const sl@0: { sl@0: return iFontMaxAscent + iFontMaxDescent; sl@0: } sl@0: sl@0: sl@0: /** Full filename that the bitmap font was loaded from. sl@0: @internalComponent sl@0: */ sl@0: inline const TDesC& CFontStoreFile::FullName() const sl@0: { sl@0: return *iFullName; sl@0: } sl@0: sl@0: sl@0: #endif // __FNTBODY_H__