epoc32/include/fntstore.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 fntstore.h
     1 // Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef FNTSTORE_H__
       
    17 #define FNTSTORE_H__
       
    18 
       
    19 #include <e32std.h>
       
    20 #include <f32file.h>
       
    21 #include <gdi.h>
       
    22 #include <openfont.h>
       
    23 
       
    24 class CLinkedTypefaceSpecification;
       
    25 class CLinkedFontSpecification;
       
    26 class TLinkedTypefaceSpecArgs;
       
    27 class CFbClient;
       
    28 class CFontStoreFile;
       
    29 class CFontBitmap;
       
    30 class RReadStream;
       
    31 class TTypefaceFontBitmap;
       
    32 class TShapeHeader;
       
    33 class TShapeMessageParameters;
       
    34 class CTypefaceSupportInfo;
       
    35 
       
    36 
       
    37 /**
       
    38 @internalTechnology
       
    39 */
       
    40 class TCharacterMetrics
       
    41 	{
       
    42 	public:
       
    43 	IMPORT_C TCharacterMetrics();
       
    44 
       
    45 	TInt16 iAscentInPixels;
       
    46 	TInt16 iHeightInPixels;
       
    47 	TInt16 iLeftAdjustInPixels;
       
    48 	TInt16 iMoveInPixels;
       
    49 	TInt16 iRightAdjustInPixels;
       
    50 	};
       
    51 
       
    52 class TAlgStyle
       
    53 /** 
       
    54 An algorithmic style for how a font is drawn.
       
    55 
       
    56 Holds attributes such as whether the font is bold or italic, and the width 
       
    57 and height factors. This is used as an input parameter for the GetFontById() method
       
    58 of some font management classes. See CWsScreenDevice::GetFontById() for more information.
       
    59 @publishedAll
       
    60 @released
       
    61 @see CWsScreenDevice::GetFontById()
       
    62 @see CFbsTypefaceStore::GetFontById()
       
    63 @see CFbsDevice::GetFontById()
       
    64 */
       
    65 	{
       
    66 public:
       
    67 	IMPORT_C TAlgStyle();
       
    68 	IMPORT_C void SetIsBold(TBool aIsBold);
       
    69 	IMPORT_C void SetIsItalic(TBool aIsItalic);
       
    70 	IMPORT_C void SetIsMono(TBool aIsMono);
       
    71 	IMPORT_C void SetWidthFactor(TInt aWidthFactor);
       
    72 	IMPORT_C void SetHeightFactor(TInt aHeightFactor);
       
    73 	IMPORT_C TBool IsBold() const;
       
    74 	IMPORT_C TBool IsItalic() const;
       
    75 	IMPORT_C TBool IsMono() const;
       
    76 	IMPORT_C TInt WidthFactor() const;
       
    77 	IMPORT_C TInt HeightFactor() const;
       
    78 	IMPORT_C TBool operator==(const TAlgStyle& aAlgStyle) const;
       
    79 	TBool operator!=(const TAlgStyle& aAlgStyle) const;
       
    80 public:
       
    81 	/** Baseline offset in pixels. */
       
    82 	TInt iBaselineOffsetInPixels;
       
    83 private:
       
    84 	enum
       
    85 		{
       
    86 		EBold=1,
       
    87 		EItalic=2,
       
    88 		EMono=4,
       
    89 		};
       
    90 	/** This member is private and not intended for use. */
       
    91 	TInt8 iFlags;
       
    92 	/** This member is private and not intended for use. */
       
    93 	TInt8 iWidthFactor;
       
    94 	/** This member is private and not intended for use. */
       
    95 	TInt8 iHeightFactor;
       
    96 	};
       
    97 
       
    98 class CLinkedFontInformation;
       
    99 
       
   100 /** 
       
   101 Bitmap font class.
       
   102 An object of this class may either access and use a bitmap font (a CFontBitmap)
       
   103 or an open font (a COpenFont).
       
   104 Stored in a CFontStore.
       
   105 @publishedAll
       
   106 @released
       
   107 */
       
   108 class CBitmapFont : public CFont
       
   109 	{
       
   110 	friend class CFontStore;
       
   111 	friend class CLinkedFontSpecification;
       
   112 	friend class CLinkedFontInformation;
       
   113 public:
       
   114 	// New functions
       
   115 	TUid Uid() const;
       
   116 	IMPORT_C TCharacterMetrics CharacterMetrics(TInt aCode,const TUint8*& aBytes) const;
       
   117 	IMPORT_C TBool GetCharacterData(TInt aSessionHandle, TInt aCode, TOpenFontCharMetrics& aMetrics, const TUint8*& aBitmap) const;
       
   118 	IMPORT_C TBool Rasterize(TInt aSessionHandle,TInt aCode,TOpenFontGlyphData* aGlyphData) const;
       
   119 	IMPORT_C void GetFontMetrics(TOpenFontMetrics& aMetrics) const;
       
   120 	IMPORT_C TBool GetFaceAttrib(TOpenFontFaceAttrib& aAttrib) const;
       
   121 	IMPORT_C TInt BitmapEncoding() const;
       
   122 	IMPORT_C TBool HasCharacterL(TInt aCode) const;
       
   123 	IMPORT_C TBool CharacterNeedsToBeRasterized(TInt aSessionHandle,TInt aCode) const;
       
   124 	IMPORT_C TShapeHeader* ShapeTextL(const TDesC16& aText,
       
   125 		TInt aSessionHandle, const TShapeMessageParameters& aParams);
       
   126 	IMPORT_C void DeleteShape(TInt aSessionHandle,TShapeHeader* aHeader);
       
   127 	IMPORT_C void operator delete(TAny*);
       
   128 	inline TBool IsOpenFont() const;
       
   129 	inline COpenFont* OpenFont() const;
       
   130 	inline TGlyphBitmapType GlyphBitmapType() const;
       
   131 	IMPORT_C CLinkedFontInformation* LinkedFontInformation() const;
       
   132 	IMPORT_C CBitmapFont* NextFontClientSpace() const;
       
   133 	IMPORT_C TBool IsLinkedFont()const;
       
   134 	IMPORT_C CBitmapFont* FontWithCharacter(TInt aCode, CLinkedFontInformation *&aInfo, TBool aSearchAllFonts, TBool aGetCanonicalDefault) const;
       
   135 	
       
   136 private:
       
   137 	// From CFont
       
   138 	IMPORT_C virtual TUid DoTypeUid() const;
       
   139 	IMPORT_C virtual TInt DoHeightInPixels() const;
       
   140 	IMPORT_C virtual TInt DoAscentInPixels() const;
       
   141 	IMPORT_C virtual TInt DoCharWidthInPixels(TChar aChar) const;
       
   142 	IMPORT_C virtual TInt DoTextWidthInPixels(const TDesC &aText) const;
       
   143 	IMPORT_C virtual TInt DoBaselineOffsetInPixels() const;
       
   144 	IMPORT_C virtual TInt DoTextCount(const TDesC &aText, TInt aWidthInPixels) const;
       
   145 	IMPORT_C virtual TInt DoTextCount(const TDesC &aText, TInt aWidthInPixels, TInt &aExcessWidthInPixels) const;
       
   146 	IMPORT_C virtual TInt DoMaxCharWidthInPixels() const;
       
   147 	IMPORT_C virtual TInt DoMaxNormalCharWidthInPixels() const;
       
   148 	IMPORT_C virtual TFontSpec DoFontSpecInTwips() const;
       
   149 	IMPORT_C virtual TInt DoExtendedFunction(TUid aFunctionId, TAny* aParam = NULL) const;
       
   150 
       
   151 private:
       
   152 	CBitmapFont(RHeap* aHeap,const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, CFontBitmap* aFontBitmap);
       
   153 	CBitmapFont(RHeap* aHeap,const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, COpenFont* aOpenFont);
       
   154 	void ConstructL();
       
   155 	~CBitmapFont();
       
   156 	static CBitmapFont* NewL(RHeap* aHeap, const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, CFontBitmap* aFontBitmap);
       
   157 	static CBitmapFont* NewL(RHeap* aHeap, const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, COpenFont* aOpenFont);
       
   158 	inline void operator delete(TAny*, TAny*) {}
       
   159 	TInt Width(TInt aNum) const;
       
   160 	TInt Height(TInt aNum) const;
       
   161 	CFontBitmap* FontBitmap() const;
       
   162 	void InstallOpenFontShaper(COpenFont* aOpenFont, CShaper::TInput& aShaperInput);
       
   163 
       
   164 private:
       
   165 	TFontSpec iFontSpecInTwips;
       
   166 
       
   167 public:
       
   168 	/** The algorithmic font style. */
       
   169 	TAlgStyle iAlgStyle;	// must not move this member
       
   170 
       
   171 private:
       
   172 	// Binary Compatibility warning - data member iOpenFont is referenced by inline methods
       
   173 	RHeap* iHeap;
       
   174 	TInt iFontBitmapOffset;
       
   175 	COpenFont* iOpenFont;	// if iOpenFont is non-null this is an open font and many functions are forwarded to it
       
   176 
       
   177 #ifdef SYMBIAN_SUPPORT_LINKED_FONTS	
       
   178 	CLinkedFontInformation *iFontLinkage;
       
   179 #endif	
       
   180 	};
       
   181 	
       
   182 class CFontStore : public CTypefaceStore
       
   183 /** 
       
   184 A store for fonts.
       
   185 
       
   186 Stores and handles both open and fixed-size fonts. Open fonts are made from 
       
   187 open (scalable) typefaces by Open Font plug-in rasterizers. Fonts of other 
       
   188 typefaces are stored in a limited number of fixed sizes. However, which is 
       
   189 being used is transparent to the user of this class. For example the GetNearestFont...() 
       
   190 functions get a bitmap font which may be retrieved from memory or generated 
       
   191 via a rasterizer.
       
   192 @publishedAll
       
   193 @released
       
   194 */
       
   195     {
       
   196 #ifdef SYMBIAN_SUPPORT_LINKED_FONTS    
       
   197 friend class CLinkedFonts;
       
   198 friend class CLinkedFontSpecification;
       
   199 friend class CLinkedTypefaceSpecification; 
       
   200 #endif
       
   201 
       
   202 public:
       
   203 	IMPORT_C static CFontStore* NewL(RHeap* aHeap);
       
   204 	IMPORT_C ~CFontStore();
       
   205 	IMPORT_C TUid AddFileL(const TDesC& aName);
       
   206 	IMPORT_C void RemoveFile(TUid aFileUid);
       
   207 	IMPORT_C TInt GetNearestFontInTwips(CFont *&aFont, const TFontSpec& aFontSpec);
       
   208 	IMPORT_C TInt GetNearestFontInPixels(CFont *&aFont, const TFontSpec &aFontSpec);
       
   209 	IMPORT_C TInt GetNearestFontToDesignHeightInTwips(CFont *&aFont, const TFontSpec& aFontSpec);
       
   210 	IMPORT_C TInt GetNearestFontToDesignHeightInPixels(CFont *&aFont, const TFontSpec& aFontSpec);
       
   211 	IMPORT_C TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
       
   212 	IMPORT_C TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
       
   213 	IMPORT_C TInt GetNearestFontInTwips(CFont *&aFont, const TOpenFontSpec& aFontSpec);
       
   214 	IMPORT_C TInt GetNearestFontInPixels(CFont *&aFont, const TOpenFontSpec &aFontSpec);
       
   215 	IMPORT_C TInt GetNearestFontToDesignHeightInTwips(CFont *&aFont, const TOpenFontSpec& aFontSpec);
       
   216 	IMPORT_C TInt GetNearestFontToDesignHeightInPixels(CFont *&aFont, const TOpenFontSpec& aFontSpec);
       
   217 	IMPORT_C TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
       
   218 	IMPORT_C TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
       
   219 	IMPORT_C TInt GetFontById(CFont *&aFont,TUid aUid,const TAlgStyle& aAlgStyle);
       
   220 	IMPORT_C TInt NumTypefaces() const;
       
   221 	IMPORT_C void TypefaceSupport(TTypefaceSupport &aTypefaceSupport,TInt aTypefaceIndex) const;
       
   222 	IMPORT_C TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
       
   223 	IMPORT_C TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
       
   224 	IMPORT_C void InstallRasterizerL(COpenFontRasterizer* aRasterizer);
       
   225 	IMPORT_C void DeleteSessionCache(TInt aSessionHandle);
       
   226 	inline TGlyphBitmapType DefaultBitmapType() const;
       
   227 	inline void SetDefaultBitmapType(TGlyphBitmapType aType);
       
   228 	IMPORT_C void InstallShaperFactoryL(CShaperFactory* aShaperFactory);
       
   229 	const CArrayPtrFlat<CShaperFactory>* ShaperFactoryList() const;
       
   230 	COpenFontSessionCacheList* GetSessionCacheList();
       
   231 	TInt GetShaperCacheMemUsage();
       
   232 	void SetShaperCacheMemUsage(TInt aUsage);
       
   233 	CArrayPtrFlat<COpenFontFile>* GetOpenFontFileList();
       
   234 	void IncNumShaperCaches();
       
   235 	void DecNumShaperCaches();
       
   236 	TInt GetNumShaperCaches();
       
   237 	IMPORT_C TInt CreateLinkedTypeface(const TLinkedTypefaceSpecArgs &aLinkedTypefaceSpec, TInt aSession, TInt& aId);
       
   238 	IMPORT_C void RemoveLinkedFont(CBitmapFont *aFont);		
       
   239 	IMPORT_C TBool IsValidLinkedFontSpecification(TInt aHandle);
       
   240 	IMPORT_C TBool HaveTypefaceFamilyName(const TDesC& aName);
       
   241 private:
       
   242 	CFontStore(RHeap* aHeap);
       
   243 	void ConstructL();
       
   244 	void InternalizeFontStoreFileL(CFontStoreFile* aFontStoreFile, TInt aFontVersion);
       
   245 	TTypeface* GetNearestTypeface(const TTypeface& aTypeface) const;
       
   246 	TTypefaceFontBitmap GetNearestTypefaceFontBitmap(const TFontSpec& aFontSpecInPixels, TInt aMaxHeight);
       
   247 	CFontBitmap* GetFontBitmapById(TUid aUid);
       
   248 	TBool IsFontLoaded(CFont*& aFont, const TAlgStyle& aAlgStyle, const TFontSpec& aFontSpecInPixels, TUid aUid, TInt aMaxHeight = 0) const;
       
   249 	TBool IsFontLoaded(CFont*& aFont, const TAlgStyle& aAlgStyle, const TOpenFontSpec& aFontSpecInPixels, TInt aMaxHeight) const;
       
   250 	CBitmapFont* NewFontL(const TFontSpec& aFontSpecInTwips,const TAlgStyle& aAlgStyle,CFontBitmap* aFontBitmap);
       
   251 	CBitmapFont* NewFontL(const TOpenFontSpec& aFontSpecInTwips,const TAlgStyle& aAlgStyle,COpenFont* aOpenFont);
       
   252 	TInt VerticalPixelsToTwips(TInt aPixelHeight) const;
       
   253 	TInt VerticalTwipsToPixels(TInt aTwipsHeight) const;
       
   254 	void GetNearestBitmapFontInPixelsL(CFont*& aFont, TFontSpec& aFontSpec, TInt aMaxHeight);
       
   255 	void GetNearestOpenFontInPixelsL(
       
   256 	CFont*& aFont, TOpenFontSpec& aActualFontSpec, const TOpenFontSpec& aDesiredFontSpec, TInt aMaxHeight);
       
   257 #ifdef SYMBIAN_SUPPORT_LINKED_FONTS	
       
   258 	TInt GetNearestRealFontInPixels(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
       
   259 	TInt GetNearestFontInPixelsL(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
       
   260 	TInt CreateLinkedTypefaceL(const TLinkedTypefaceSpecArgs &aLinkedTypefaceSpec, TInt aSession, TInt& aId);
       
   261 	TInt GetCanonicalIndex(TInt aTypefaceIndex) const;
       
   262 	void TypefaceSupportLinked(TTypefaceSupport &aTypefaceSupport, TInt aTypefaceIndex) const;
       
   263 #endif	
       
   264 	TInt GetNearestFontInPixels(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
       
   265 	void SanityCheckForTtfL(RFile& aFile, TUint aFontFileSize, TBool aStrictChecking);
       
   266 	void SanityCheckFontFileL(TParse& aParse);
       
   267 	TInt GetNearestOpenFontInPixelsByFontName(COpenFont*& aNearestOpenFont, TOpenFontSpec& aActualFontSpec, const TOpenFontSpec& aDesiredFontSpec, TInt aMaxHeight);
       
   268 	TInt GetNearestOpenFontInPixelsBySimilarity(COpenFont*& aNearestOpenFont, TOpenFontSpec& aActualFontSpec, const TOpenFontSpec& aDesiredFontSpec, TInt aMaxHeight);
       
   269 	TInt AddTypefacesToSupportList(COpenFontFile* aOpenFontFile);
       
   270 	void RemoveTypefacesFromSupportList(COpenFontFile* aOpenFontFile);
       
   271 	TInt FindBitmapFontFileIndexByUid(TUid aUid);
       
   272 	TBool IncRefCountOfLoadedFont(const TDesC& aFullName, TUid& aFontUid);
       
   273 	TBool LoadFileAsOpenFontL(const TDesC& aFullName, TUid& aFontUid);
       
   274 	TUid LoadFileAsBitmapFontL(TParse& aParse);
       
   275 	static void CleanupRemoveFontFile(TAny* aCleanupInfo);
       
   276 
       
   277 public:
       
   278 	/** The width of 1000 pixels in twips.
       
   279 	
       
   280 	This is set in the constructor. If the appropriate HALData attributes are 
       
   281 	set (EDisplayXPixels and EDisplayXTwips) then the value is calculated using 
       
   282 	these; otherwise the value is set to 11860. */
       
   283 	TInt iKPixelWidthInTwips;
       
   284 	
       
   285 	/** The height of 1000 pixels in twips.
       
   286 	
       
   287 	This is set in the constructor. If the appropriate HALData attributes are 
       
   288 	set (EDisplayYPixels and EDisplayYTwips) then the value is calculated using 
       
   289 	these; otherwise the value is set to 11860. */
       
   290 	TInt iKPixelHeightInTwips;
       
   291 
       
   292 private:
       
   293 	// Binary Compatibility warning - data member iDefaultBitmapType is referenced by inline methods
       
   294 	RFs iFs;
       
   295 	RHeap* iHeap;
       
   296 	CArrayPtrFlat<CFontStoreFile> iFontStoreFileList;
       
   297 	CArrayPtrFlat<TTypeface> iTypefaceList;
       
   298 	CArrayPtrFlat<CFontBitmap> iFontBitmapList;
       
   299 	CArrayFixFlat<TTypefaceFontBitmap> iTypefaceFontBitmapList;
       
   300 	CArrayPtrFlat<COpenFontFile> iOpenFontFileList;
       
   301 	TInt iReserved[6];		// keep iDefaultBitmapType at the correct offset
       
   302 	CArrayPtrFlat<COpenFontRasterizer> iOpenFontRasterizerList;
       
   303 	COpenFontSessionCacheList* iOpenFontSessionCacheList;
       
   304 	TInt iOpenFontUid;
       
   305 	TGlyphBitmapType iDefaultBitmapType;
       
   306 	CArrayPtrFlat<CShaperFactory> iShaperFactoryList;
       
   307 	TInt iOpenFontShaperCacheMemUsage;
       
   308 	TInt iNumberOfShaperCaches;
       
   309 	RPointerArray<CTypefaceSupportInfo> iOpenFontTypefaceSupportList;
       
   310 #ifdef SYMBIAN_SUPPORT_LINKED_FONTS	
       
   311 	RPointerArray<CLinkedTypefaceSpecification> *iLinkedTypefaceSpecificationList;
       
   312 	RPointerArray<CLinkedFontSpecification> *iLinkedFontSpecificationList;
       
   313 #endif	
       
   314 	};
       
   315 
       
   316 // inline functions start here
       
   317 
       
   318 /** Returns whether the bitmap font object is an open font (a COpenFont) rather 
       
   319 than a bitmap font (a CFontBitmap).
       
   320 
       
   321 @return ETrue if the bitmap font object is using an open font (a COpenFont);
       
   322 EFalse if it is using a bitmap font (a CFontBitmap).
       
   323 @see OpenFont()
       
   324 */
       
   325 inline TBool CBitmapFont::IsOpenFont() const
       
   326 	{
       
   327 	return iOpenFont != NULL;
       
   328 	}
       
   329 
       
   330 /** Returns a pointer to the open font being used by the bitmap font object.
       
   331 
       
   332 @return A pointer to an open font.
       
   333 @see IsOpenFont()
       
   334 */
       
   335 inline COpenFont* CBitmapFont::OpenFont() const
       
   336 	{ 
       
   337 	return iOpenFont;
       
   338 	}
       
   339 
       
   340 /** Gets the anti-aliasing setting for the font, see TGlyphBitmapType for 
       
   341 the range of values.
       
   342 
       
   343 This is only applicable to open fonts (COpenFonts) not bitmap fonts (CBitmapFonts).
       
   344 
       
   345 Note that this setting is stored in the device-independent font specification 
       
   346 which is set when the bitmap font object is constructed.
       
   347 
       
   348 @return The anti-aliasing setting for the font.
       
   349 @see IsOpenFont()
       
   350 @see TGlyphBitmapType
       
   351 @see COpenFont
       
   352 @see CBitmapFont
       
   353 */
       
   354 inline TGlyphBitmapType CBitmapFont::GlyphBitmapType() const
       
   355 	{
       
   356 	return iFontSpecInTwips.iFontStyle.BitmapType();
       
   357 	}
       
   358 
       
   359 /** Returns a default bitmap type.
       
   360 
       
   361 @return A default bitmap type.
       
   362 @see TGlyphBitmapType
       
   363 */
       
   364 inline TGlyphBitmapType CFontStore::DefaultBitmapType() const
       
   365 	{
       
   366 	return iDefaultBitmapType;
       
   367 	}
       
   368 
       
   369 /** Sets a default bitmap type.
       
   370 
       
   371 @param aType A default bitmap type.
       
   372 @see TGlyphBitmapType
       
   373 */
       
   374 inline void CFontStore::SetDefaultBitmapType(TGlyphBitmapType aType)
       
   375 	{
       
   376 	iDefaultBitmapType = aType;
       
   377 	}
       
   378 
       
   379 #endif