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