fontservices/fontstore/src/FNTBODY.H
changeset 0 1fb32624e06b
child 1 e96e8a131979
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __FNTBODY_H__
       
    20 #define __FNTBODY_H__
       
    21 
       
    22 #include <e32std.h>
       
    23 #include "FNTSTD.H"
       
    24 
       
    25 /**
       
    26 @internalComponent
       
    27 */
       
    28 
       
    29 const TInt KFontStoreFileUidVal = 0x10000039;
       
    30 const TInt KCBitmapFontUidVal = 0x10000043;
       
    31 const TInt KFnttranVersion = 42;
       
    32 const TInt KFnttran7650Version = 39;
       
    33 
       
    34 class CDirectFileStore;
       
    35 NONSHARABLE_CLASS(CFontStoreFile) : public CBase
       
    36 /**
       
    37 @internalComponent
       
    38 */
       
    39 	{
       
    40 protected:
       
    41 	CFontStoreFile();
       
    42 	void ConstructL(const TParse& aParse, RFs& aFs);
       
    43 public:
       
    44 	static CFontStoreFile* NewL(const TParse& aParse, RFs& aFs);
       
    45 	~CFontStoreFile();
       
    46 	inline const TDesC& FullName() const;
       
    47 public:
       
    48 	TUid iCollectionUid;
       
    49 	TInt iKPixelAspectRatio;
       
    50 	TInt iUsageCount;
       
    51 	CDirectFileStore* iFileStore;
       
    52 	TInt iFileAddress;
       
    53 	TStreamId iDataStreamId;
       
    54 	TInt iFontVersion;
       
    55 	HBufC* iFullName;
       
    56 	};
       
    57 
       
    58 class TBitmapCodeSection : public TCodeSection
       
    59 /**
       
    60 @internalComponent
       
    61 */
       
    62 	{
       
    63 public:
       
    64 	TBitmapCodeSection();
       
    65 	void InternalizeL(RReadStream& aStream);
       
    66 	void InternalizeOffsetsL(const CStreamStore& aStreamStore, RHeap* aHeap, TInt& aAllocMemCounter);
       
    67 	void InternalizeBitmapL(const CStreamStore& aStreamStore, RHeap* aHeap, TInt& aAllocMemCounter);
       
    68 	void FixUpComponents(TInt aFileAddress);
       
    69 	void DeleteOffsets(RHeap* aHeap);
       
    70 	void DeleteBitmap(RHeap* aHeap);
       
    71 	TBitmapFontCharacterOffset* CharacterOffsetsList(TBool aIsInRAM) const;
       
    72 	TUint8* Bitmap(TBool aIsInRAM) const;
       
    73 
       
    74 private:
       
    75 	union TCharacterData
       
    76 		{
       
    77 		TCharacterData() : iOffsetsId(KNullStreamIdValue) {}
       
    78 		TUint32 iOffsetsId;
       
    79 		TInt iCharacterOffsetsListOffset;
       
    80 		} iCharacterData;
       
    81 	//iCharacterData is interpreted either as StreamId(casted from TUint32) or as TInt offset;
       
    82 	union TBitmapData
       
    83 		{
       
    84 		TBitmapData() : iBitmapId(KNullStreamIdValue) {}
       
    85 		TUint32 iBitmapId;
       
    86 		TInt iBitmapOffset;
       
    87 		} iBitmapData;
       
    88 	//iBitmapData is interpreted either as StreamId(casted from TUint32) or as TInt offset;
       
    89 	//The size of the original TBitmapCodeSection was 24 bytes.
       
    90 	//Using the unions above (and removing RHeap* member) we reduce TBitmapCodeSection size 
       
    91 	//to be 12 bytes per instance.
       
    92 	//It is possible to do that because iCharacterData and iBitmapData are treated as IDs during 
       
    93 	//initialization stage and as offsets during all the time after initialization.
       
    94 	//So we can use the same memory for IDs and for offsets.
       
    95 	};
       
    96 
       
    97 class TCharacterMetricsTable
       
    98 /**
       
    99 Class to store the list of Character Metrics used in this font
       
   100 @since 7.0s
       
   101 @internalComponent
       
   102 */
       
   103 	{
       
   104 public:
       
   105 	TCharacterMetricsTable(RHeap* aHeap);
       
   106 	void InternalizeL(RReadStream& aStream);
       
   107 	void InternalizeMetricsL(RReadStream& aStream);
       
   108 	void RestoreL(const CStreamStore& aStreamStore);
       
   109 	void FixUp(TInt aFileAddress);
       
   110 	void Delete();
       
   111 	const TBitmapFontCharacterMetrics* Metric(TInt aIndex) const;
       
   112 	TInt NumberOfMetrics() const;
       
   113 private:
       
   114 	RHeap* iHeap;
       
   115 	TStreamId iMetricsStartId;
       
   116 	TInt iCharacterMetricsStartPtr;	// Sometimes this address is on the metrics heap and sometimes in a ROM file
       
   117 	TInt iNumberOfMetrics;
       
   118 	};
       
   119 
       
   120 NONSHARABLE_CLASS(CFontBitmap) : public CBase
       
   121 /**
       
   122 @internalComponent
       
   123 */
       
   124 	{
       
   125 public:
       
   126 	CFontBitmap(RHeap* aHeap,CFontStoreFile* aFontStoreFile);
       
   127 	void InternalizeL(RReadStream &aStream, TInt aFontversion);
       
   128 	void UseL();
       
   129 	void Release();
       
   130 	TBitmapFontCharacterMetrics CharacterMetrics(TInt aCode,const TUint8*& aBytes) const;
       
   131 	void operator delete(TAny*);
       
   132 	inline void operator delete(TAny*, TAny*) {}
       
   133 	void SetPosture(TFontPosture aPosture);
       
   134 	TFontPosture Posture() const;
       
   135 	void SetStrokeWeight(TFontStrokeWeight aStrokeWeight);
       
   136 	TFontStrokeWeight StrokeWeight() const;
       
   137 	void SetIsProportional(TBool aIsProportional);
       
   138 	TBool IsProportional() const;
       
   139 	CFontStoreFile* FontStoreFile() const;
       
   140 	inline TInt FontCapitalAscent() const;
       
   141 	inline TInt FontMaxAscent() const;
       
   142 	inline TInt FontStandardDescent() const;
       
   143 	inline TInt FontMaxDescent() const;
       
   144 	inline TInt FontLineGap() const;
       
   145 	inline TInt FontMaxHeight() const;
       
   146 protected:
       
   147 	~CFontBitmap();
       
   148 	void RestoreComponentsL();	 //  Has reference to FontStoreFile
       
   149 	void DeleteComponents();
       
   150 	TBitmapCodeSection* CodeSectionList() const;
       
   151 	TCharacterMetricsTable* MetricsTable() const;
       
   152 public:
       
   153 	RHeap* iHeap;
       
   154 	TInt iFontStoreFileOffset;
       
   155 	TUid iUid;
       
   156 protected:
       
   157 	TInt8 iPosture;
       
   158 	TInt8 iStrokeWeight;
       
   159 	TInt8 iIsProportional;
       
   160 	TBool iIsInRAM;
       
   161 	TInt iUsageCount;
       
   162 public:
       
   163 	TInt8 iCellHeightInPixels;
       
   164 	TInt8 iAscentInPixels;
       
   165 	TInt8 iMaxCharWidthInPixels;
       
   166 	TInt8 iMaxNormalCharWidthInPixels;
       
   167 	TInt iBitmapEncoding;
       
   168 	TInt iNumCodeSections;
       
   169 	TInt iCodeSectionListOffset;
       
   170 private:
       
   171 	TCharacterMetricsTable iCharacterMetricsTable;
       
   172 	TBool iComponentsRestored;
       
   173 	TInt iAllocMemCounter_Offsets;
       
   174 	TInt iAllocMemCounter_Bitmaps;
       
   175 	TInt iFontCapitalAscent;		// The positive distance in pixels from the baseline to
       
   176 									// the top of an ANSI capital (whether or not there are
       
   177 									// ANSI capitals in the font)
       
   178 	TInt iFontMaxAscent;			// The positive distance in pixels from the baseline to
       
   179 									// the top of the highest pre-composed glyph in the font
       
   180 	TInt iFontStandardDescent;		// The positive distance in pixels from the baseline to
       
   181 									// the bottom of the lowest ANSI descender (whether or
       
   182 									// not there are ANSI chars in the font)
       
   183 	TInt iFontMaxDescent;			// The positive distance in pixels from the baseline to
       
   184 									// the bottom of the lowest pre-composed glyph in the font
       
   185 	TInt iFontLineGap;				// The recommended baseline to baseline gap for successive
       
   186 									// lines of text in the font
       
   187 	};
       
   188 
       
   189 class TTypefaceFontBitmap
       
   190 /**
       
   191 @internalComponent
       
   192 */
       
   193 	{
       
   194 public:
       
   195 	TTypefaceFontBitmap();
       
   196 	TTypefaceFontBitmap(TTypeface* aTypeface,CFontBitmap* aFontBitmap);
       
   197 	TInt HeightInPixels() const;
       
   198 public:
       
   199 	TTypeface* iTypeface;
       
   200 	CFontBitmap* iFontBitmap;
       
   201 	TInt8 iHeightFactor;
       
   202 	TInt8 iWidthFactor;
       
   203 	};
       
   204 	
       
   205 
       
   206 /** Gets the ascent of an ANSI capital letter in the font whether or not
       
   207 there are any ANSI capitals in the font.
       
   208 @return The positive distance from the font baseline to the top of a
       
   209 standard ANSI capital letter
       
   210 @internalComponent
       
   211 @released
       
   212 @see AscentInPixels()
       
   213 @see FontMaxAscent()
       
   214 */
       
   215 inline TInt CFontBitmap::FontCapitalAscent() const
       
   216 	{
       
   217 	return iFontCapitalAscent;
       
   218 	}
       
   219 
       
   220 /** Gets the max ascent of any pre-composed glyph in the font. This will
       
   221 include accents or diacritics that form part of pre-composed glyphs. It is
       
   222 not guaranteed to cover the max ascent of composite glyphs that have to be
       
   223 created by a layout engine. This is also the recommended distance between
       
   224 the top of a text box and the baseline of the first line of text. 
       
   225 @return The positive distance from the font baseline to the top of the
       
   226 highest pre-composed glyph (including accents) above the baseline
       
   227 @internalComponent
       
   228 @released
       
   229 @see AscentInPixels()
       
   230 @see FontCapitalAscent()
       
   231 */
       
   232 inline TInt CFontBitmap::FontMaxAscent() const
       
   233 	{
       
   234 	return iFontMaxAscent;
       
   235 	}
       
   236 
       
   237 /** Gets the descent of an ANSI descending character in the font.
       
   238 Whether or not there are any ANSI descenders in the font.
       
   239 @return The positive distance from the font baseline to the bottom of the
       
   240 lowest ANSI descender
       
   241 @internalComponent
       
   242 @released
       
   243 @see DescentInPixels()
       
   244 */
       
   245 inline TInt CFontBitmap::FontStandardDescent() const
       
   246 	{
       
   247 	return iFontStandardDescent;
       
   248 	}
       
   249 
       
   250 /** Gets the max descent of any pre-composed glyph in the font. This will
       
   251 include accents or diacritics that form part of pre-composed glyphs. It is
       
   252 not guaranteed to cover the max descent of composite glyphs that have to be
       
   253 created by a layout engine.
       
   254 @return The positive distance from the font baseline to the bottom of the
       
   255 lowest pre-composed glyph (including accents) below the baseline
       
   256 @internalComponent
       
   257 @released
       
   258 @see DescentInPixels()
       
   259 */
       
   260 inline TInt CFontBitmap::FontMaxDescent() const
       
   261 	{
       
   262 	return iFontMaxDescent;
       
   263 	}
       
   264 
       
   265 /** Gets the suggested line gap for the font. This is the recommended
       
   266 baseline to baseline distance between successive lines of text in the font.
       
   267 @return The positive recommended gap between successive lines
       
   268 @internalComponent
       
   269 @released
       
   270 */
       
   271 inline TInt CFontBitmap::FontLineGap() const
       
   272 	{
       
   273 	return iFontLineGap;
       
   274 	}
       
   275 
       
   276 /** Gets the maximum height for the font. This is the sum of the max ascent 
       
   277 of the font and the max descent of the font.
       
   278 @return The positive maximum height of the font
       
   279 @internalComponent
       
   280 @released
       
   281 @see HeightInPixels()
       
   282 */
       
   283 inline TInt CFontBitmap::FontMaxHeight() const
       
   284 	{
       
   285 	return iFontMaxAscent + iFontMaxDescent;
       
   286 	}
       
   287 
       
   288 
       
   289 /** Full filename that the bitmap font was loaded from.
       
   290 @internalComponent
       
   291 */
       
   292 inline const TDesC& CFontStoreFile::FullName() const
       
   293 	{
       
   294 	return *iFullName;
       
   295 	}
       
   296 
       
   297 
       
   298 #endif // __FNTBODY_H__