os/textandloc/fontservices/fontstore/src/FNTBODY.H
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 	TBitmapFontCharacterMetrics* MetricsFromOffset(TInt aIndex) const;
   115 private:
   116 	RHeap* iHeap;
   117 	TStreamId iMetricsStartId;
   118     // Sometimes this address is on the metrics heap and sometimes in a ROM file
   119     // If the address is on the heap, then this is actually an offset from
   120     // the address of this class.
   121     TInt iCharacterMetricsStartPtr;	
   122 	TInt iNumberOfMetrics;
   123 	TBool iMetricsOnHeap;
   124 	};
   125 
   126 NONSHARABLE_CLASS(CFontBitmap) : public CBase
   127 /**
   128 @internalComponent
   129 */
   130 	{
   131 public:
   132 	CFontBitmap(RHeap* aHeap,CFontStoreFile* aFontStoreFile);
   133 	void InternalizeL(RReadStream &aStream, TInt aFontversion);
   134 	void UseL();
   135 	void Release();
   136 	TBitmapFontCharacterMetrics CharacterMetrics(TInt aCode,const TUint8*& aBytes) const;
   137 	void operator delete(TAny*);
   138 	inline void operator delete(TAny*, TAny*) {}
   139 	void SetPosture(TFontPosture aPosture);
   140 	TFontPosture Posture() const;
   141 	void SetStrokeWeight(TFontStrokeWeight aStrokeWeight);
   142 	TFontStrokeWeight StrokeWeight() const;
   143 	void SetIsProportional(TBool aIsProportional);
   144 	TBool IsProportional() const;
   145 	CFontStoreFile* FontStoreFile() const;
   146 	inline TInt FontCapitalAscent() const;
   147 	inline TInt FontMaxAscent() const;
   148 	inline TInt FontStandardDescent() const;
   149 	inline TInt FontMaxDescent() const;
   150 	inline TInt FontLineGap() const;
   151 	inline TInt FontMaxHeight() const;
   152 protected:
   153 	~CFontBitmap();
   154 	void RestoreComponentsL();	 //  Has reference to FontStoreFile
   155 	void DeleteComponents();
   156 	TBitmapCodeSection* CodeSectionList() const;
   157 	TCharacterMetricsTable* MetricsTable() const;
   158 public:
   159 	RHeap* iHeap;
   160 	TInt iFontStoreFileOffset;
   161 	TUid iUid;
   162 protected:
   163 	TInt8 iPosture;
   164 	TInt8 iStrokeWeight;
   165 	TInt8 iIsProportional;
   166 	TBool iIsInRAM;
   167 	TInt iUsageCount;
   168 public:
   169 	TInt8 iCellHeightInPixels;
   170 	TInt8 iAscentInPixels;
   171 	TInt8 iMaxCharWidthInPixels;
   172 	TInt8 iMaxNormalCharWidthInPixels;
   173 	TInt iBitmapEncoding;
   174 	TInt iNumCodeSections;
   175 	TInt iCodeSectionListOffset;
   176 private:
   177 	TCharacterMetricsTable iCharacterMetricsTable;
   178 	TBool iComponentsRestored;
   179 	TInt iAllocMemCounter_Offsets;
   180 	TInt iAllocMemCounter_Bitmaps;
   181 	TInt iFontCapitalAscent;		// The positive distance in pixels from the baseline to
   182 									// the top of an ANSI capital (whether or not there are
   183 									// ANSI capitals in the font)
   184 	TInt iFontMaxAscent;			// The positive distance in pixels from the baseline to
   185 									// the top of the highest pre-composed glyph in the font
   186 	TInt iFontStandardDescent;		// The positive distance in pixels from the baseline to
   187 									// the bottom of the lowest ANSI descender (whether or
   188 									// not there are ANSI chars in the font)
   189 	TInt iFontMaxDescent;			// The positive distance in pixels from the baseline to
   190 									// the bottom of the lowest pre-composed glyph in the font
   191 	TInt iFontLineGap;				// The recommended baseline to baseline gap for successive
   192 									// lines of text in the font
   193 	};
   194 
   195 class TTypefaceFontBitmap
   196 /**
   197 @internalComponent
   198 */
   199 	{
   200 public:
   201 	TTypefaceFontBitmap();
   202 	TTypefaceFontBitmap(TTypeface* aTypeface,CFontBitmap* aFontBitmap);
   203 	TInt HeightInPixels() const;
   204 public:
   205 	TTypeface* iTypeface;
   206 	CFontBitmap* iFontBitmap;
   207 	TInt8 iHeightFactor;
   208 	TInt8 iWidthFactor;
   209 	};
   210 	
   211 
   212 /** Gets the ascent of an ANSI capital letter in the font whether or not
   213 there are any ANSI capitals in the font.
   214 @return The positive distance from the font baseline to the top of a
   215 standard ANSI capital letter
   216 @internalComponent
   217 @released
   218 @see AscentInPixels()
   219 @see FontMaxAscent()
   220 */
   221 inline TInt CFontBitmap::FontCapitalAscent() const
   222 	{
   223 	return iFontCapitalAscent;
   224 	}
   225 
   226 /** Gets the max ascent of any pre-composed glyph in the font. This will
   227 include accents or diacritics that form part of pre-composed glyphs. It is
   228 not guaranteed to cover the max ascent of composite glyphs that have to be
   229 created by a layout engine. This is also the recommended distance between
   230 the top of a text box and the baseline of the first line of text. 
   231 @return The positive distance from the font baseline to the top of the
   232 highest pre-composed glyph (including accents) above the baseline
   233 @internalComponent
   234 @released
   235 @see AscentInPixels()
   236 @see FontCapitalAscent()
   237 */
   238 inline TInt CFontBitmap::FontMaxAscent() const
   239 	{
   240 	return iFontMaxAscent;
   241 	}
   242 
   243 /** Gets the descent of an ANSI descending character in the font.
   244 Whether or not there are any ANSI descenders in the font.
   245 @return The positive distance from the font baseline to the bottom of the
   246 lowest ANSI descender
   247 @internalComponent
   248 @released
   249 @see DescentInPixels()
   250 */
   251 inline TInt CFontBitmap::FontStandardDescent() const
   252 	{
   253 	return iFontStandardDescent;
   254 	}
   255 
   256 /** Gets the max descent of any pre-composed glyph in the font. This will
   257 include accents or diacritics that form part of pre-composed glyphs. It is
   258 not guaranteed to cover the max descent of composite glyphs that have to be
   259 created by a layout engine.
   260 @return The positive distance from the font baseline to the bottom of the
   261 lowest pre-composed glyph (including accents) below the baseline
   262 @internalComponent
   263 @released
   264 @see DescentInPixels()
   265 */
   266 inline TInt CFontBitmap::FontMaxDescent() const
   267 	{
   268 	return iFontMaxDescent;
   269 	}
   270 
   271 /** Gets the suggested line gap for the font. This is the recommended
   272 baseline to baseline distance between successive lines of text in the font.
   273 @return The positive recommended gap between successive lines
   274 @internalComponent
   275 @released
   276 */
   277 inline TInt CFontBitmap::FontLineGap() const
   278 	{
   279 	return iFontLineGap;
   280 	}
   281 
   282 /** Gets the maximum height for the font. This is the sum of the max ascent 
   283 of the font and the max descent of the font.
   284 @return The positive maximum height of the font
   285 @internalComponent
   286 @released
   287 @see HeightInPixels()
   288 */
   289 inline TInt CFontBitmap::FontMaxHeight() const
   290 	{
   291 	return iFontMaxAscent + iFontMaxDescent;
   292 	}
   293 
   294 
   295 /** Full filename that the bitmap font was loaded from.
   296 @internalComponent
   297 */
   298 inline const TDesC& CFontStoreFile::FullName() const
   299 	{
   300 	return *iFullName;
   301 	}
   302 
   303 
   304 #endif // __FNTBODY_H__