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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
24 class CLinkedTypefaceSpecification;
25 class CLinkedFontSpecification;
26 class TLinkedTypefaceSpecArgs;
31 class TTypefaceFontBitmap;
33 class TShapeMessageParameters;
34 class CTypefaceSupportInfo;
40 class TCharacterMetrics
43 IMPORT_C TCharacterMetrics();
45 TInt16 iAscentInPixels;
46 TInt16 iHeightInPixels;
47 TInt16 iLeftAdjustInPixels;
49 TInt16 iRightAdjustInPixels;
54 An algorithmic style for how a font is drawn.
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.
61 @see CWsScreenDevice::GetFontById()
62 @see CFbsTypefaceStore::GetFontById()
63 @see CFbsDevice::GetFontById()
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;
81 /** Baseline offset in pixels. */
82 TInt iBaselineOffsetInPixels;
90 /** This member is private and not intended for use. */
92 /** This member is private and not intended for use. */
94 /** This member is private and not intended for use. */
98 class CLinkedFontInformation;
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.
108 class CBitmapFont : public CFont
110 friend class CFontStore;
111 friend class CLinkedFontSpecification;
112 friend class CLinkedFontInformation;
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;
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;
152 CBitmapFont(RHeap* aHeap,const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, CFontBitmap* aFontBitmap);
153 CBitmapFont(RHeap* aHeap,const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, COpenFont* aOpenFont);
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);
165 TFontSpec iFontSpecInTwips;
168 /** The algorithmic font style. */
169 TAlgStyle iAlgStyle; // must not move this member
172 // Binary Compatibility warning - data member iOpenFont is referenced by inline methods
174 TInt iFontBitmapOffset;
175 COpenFont* iOpenFont; // if iOpenFont is non-null this is an open font and many functions are forwarded to it
177 #ifdef SYMBIAN_SUPPORT_LINKED_FONTS
178 CLinkedFontInformation *iFontLinkage;
182 class CFontStore : public CTypefaceStore
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
196 #ifdef SYMBIAN_SUPPORT_LINKED_FONTS
197 friend class CLinkedFonts;
198 friend class CLinkedFontSpecification;
199 friend class CLinkedTypefaceSpecification;
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);
242 CFontStore(RHeap* aHeap);
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;
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);
278 /** The width of 1000 pixels in twips.
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;
285 /** The height of 1000 pixels in twips.
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;
293 // Binary Compatibility warning - data member iDefaultBitmapType is referenced by inline methods
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;
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;
316 // inline functions start here
318 /** Returns whether the bitmap font object is an open font (a COpenFont) rather
319 than a bitmap font (a CFontBitmap).
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).
325 inline TBool CBitmapFont::IsOpenFont() const
327 return iOpenFont != NULL;
330 /** Returns a pointer to the open font being used by the bitmap font object.
332 @return A pointer to an open font.
335 inline COpenFont* CBitmapFont::OpenFont() const
340 /** Gets the anti-aliasing setting for the font, see TGlyphBitmapType for
343 This is only applicable to open fonts (COpenFonts) not bitmap fonts (CBitmapFonts).
345 Note that this setting is stored in the device-independent font specification
346 which is set when the bitmap font object is constructed.
348 @return The anti-aliasing setting for the font.
350 @see TGlyphBitmapType
354 inline TGlyphBitmapType CBitmapFont::GlyphBitmapType() const
356 return iFontSpecInTwips.iFontStyle.BitmapType();
359 /** Returns a default bitmap type.
361 @return A default bitmap type.
362 @see TGlyphBitmapType
364 inline TGlyphBitmapType CFontStore::DefaultBitmapType() const
366 return iDefaultBitmapType;
369 /** Sets a default bitmap type.
371 @param aType A default bitmap type.
372 @see TGlyphBitmapType
374 inline void CFontStore::SetDefaultBitmapType(TGlyphBitmapType aType)
376 iDefaultBitmapType = aType;