Update contrib.
2 * Copyright (c) 1995-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
26 #include <linkedfonts.h>
29 /** Defines the maximum number of linked typefaces that may be placed in a linked typeface specification
30 WARNING: Constant for internal use ONLY. Compatibility is not guaranteed in future releases.
34 const TInt KMaxLinkedTypefaces = 12;
35 /** Defines the maximum number of linked typeface groups that may be placed in a linked typeface specification
36 WARNING: Constant for internal use ONLY. Compatibility is not guaranteed in future releases.
40 const TInt KMaxLinkedTypefaceGroups = 12;
42 class CLinkedTypefaceSpecification;
43 class TLinkedTypefaceSpecificationArgs;
48 class TTypefaceFontBitmap;
50 class TShapeMessageParameters;
51 class CTypefaceSupportInfo;
52 class COpenFontRasterizer;
53 class CLinkedTypefaceGroup;
54 IMPORT_C extern const TInt8 KLinkedFontDrive;
55 IMPORT_C extern const TUint32 KFontTable_GlyphOutline_CacheMaxMem;
58 WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases.
62 class TCharacterMetrics
65 IMPORT_C TCharacterMetrics();
68 TInt16 iAscentInPixels;
69 TInt16 iHeightInPixels;
70 TInt16 iLeftAdjustInPixels;
72 TInt16 iRightAdjustInPixels;
76 An algorithmic style for how a font is drawn.
78 Holds attributes such as whether the font is bold or italic, and the width
79 and height factors. This is used as an input parameter for the GetFontById() method
80 of some font management classes. See CWsScreenDevice::GetFontById() for more information.
83 @see CWsScreenDevice::GetFontById()
84 @see CFbsTypefaceStore::GetFontById()
85 @see CFbsDevice::GetFontById()
91 IMPORT_C void SetIsBold(TBool aIsBold);
92 IMPORT_C void SetIsItalic(TBool aIsItalic);
93 IMPORT_C void SetIsMono(TBool aIsMono);
94 IMPORT_C void SetWidthFactor(TInt aWidthFactor);
95 IMPORT_C void SetHeightFactor(TInt aHeightFactor);
96 IMPORT_C TBool IsBold() const;
97 IMPORT_C TBool IsItalic() const;
98 IMPORT_C TBool IsMono() const;
99 IMPORT_C TInt WidthFactor() const;
100 IMPORT_C TInt HeightFactor() const;
101 IMPORT_C TBool operator==(const TAlgStyle& aAlgStyle) const;
102 TBool operator!=(const TAlgStyle& aAlgStyle) const;
104 /** Baseline offset in pixels. */
105 TInt iBaselineOffsetInPixels;
113 /** This member is private and not intended for use. */
115 /** This member is private and not intended for use. */
117 /** This member is private and not intended for use. */
123 An object of this class may either access and use a bitmap font (a CFontBitmap)
124 or an open font (a COpenFont).
125 Stored in a CFontStore.
129 class CBitmapFont : public CFont
131 friend class CFbsFont;
132 friend class CFontStore;
133 friend class CFbsBitGc;
137 IMPORT_C TCharacterMetrics CharacterMetrics(TInt aCode,const TUint8*& aBytes) const;
138 IMPORT_C TBool GetCharacterData(TInt aSessionHandle, TInt aCode, TOpenFontCharMetrics& aMetrics, const TUint8*& aBitmap) const;
139 IMPORT_C TBool Rasterize(TInt aSessionHandle,TInt aCode,TOpenFontGlyphData* aGlyphData) const;
140 IMPORT_C void GetFontMetrics(TOpenFontMetrics& aMetrics) const;
141 IMPORT_C TBool GetFaceAttrib(TOpenFontFaceAttrib& aAttrib) const;
142 IMPORT_C TInt BitmapEncoding() const;
143 IMPORT_C TBool HasCharacterL(TInt aCode) const;
144 IMPORT_C TBool CharacterNeedsToBeRasterized(TInt aSessionHandle,TInt aCode) const;
145 IMPORT_C TShapeHeader* ShapeTextL(const TDesC16& aText,
146 TInt aSessionHandle, const TShapeMessageParameters& aParams);
147 IMPORT_C void DeleteShape(TInt aSessionHandle,TShapeHeader* aHeader);
148 IMPORT_C void operator delete(TAny*);
149 inline TBool IsOpenFont() const;
150 inline COpenFont* OpenFont() const;
151 inline TGlyphBitmapType GlyphBitmapType() const;
152 IMPORT_C TUint32 UniqueFontId();
153 IMPORT_C TInt GetFontTable(TUint32 aTag, TAny*& aTableContent,
154 TInt& aLength, TInt aSessionHandle);
155 IMPORT_C TInt GetGlyphOutline(TUint aCode,
156 TBool aHinted, TAny*& aOutline, TInt& aLength, TInt aSessionHandle);
157 IMPORT_C void ReleaseGlyphOutlines(TInt aCount, const TUint* aCodes,
158 TBool aHinted, TInt aSessionHandle);
159 IMPORT_C void ReleaseFontTable(TUint32 aTag, TInt aSessionHandle);
163 IMPORT_C virtual TUid DoTypeUid() const;
164 IMPORT_C virtual TInt DoHeightInPixels() const;
165 IMPORT_C virtual TInt DoAscentInPixels() const;
166 IMPORT_C virtual TInt DoCharWidthInPixels(TChar aChar) const;
167 IMPORT_C virtual TInt DoTextWidthInPixels(const TDesC &aText) const;
168 IMPORT_C virtual TInt DoBaselineOffsetInPixels() const;
169 IMPORT_C virtual TInt DoTextCount(const TDesC &aText, TInt aWidthInPixels) const;
170 IMPORT_C virtual TInt DoTextCount(const TDesC &aText, TInt aWidthInPixels, TInt &aExcessWidthInPixels) const;
171 IMPORT_C virtual TInt DoMaxCharWidthInPixels() const;
172 IMPORT_C virtual TInt DoMaxNormalCharWidthInPixels() const;
173 IMPORT_C virtual TFontSpec DoFontSpecInTwips() const;
174 IMPORT_C virtual TInt DoExtendedFunction(TUid aFunctionId, TAny* aParam = NULL) const;
177 CBitmapFont(RHeap* aHeap,const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, CFontBitmap* aFontBitmap);
178 CBitmapFont(RHeap* aHeap,const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, COpenFont* aOpenFont);
181 static CBitmapFont* NewL(RHeap* aHeap, const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, CFontBitmap* aFontBitmap);
182 static CBitmapFont* NewL(RHeap* aHeap, const TFontSpec& aFontSpecInTwips, const TAlgStyle& aAlgStyle, COpenFont* aOpenFont);
183 inline void operator delete(TAny*, TAny*) {}
184 TInt Width(TInt aNum) const;
185 TInt Height(TInt aNum) const;
186 CFontBitmap* FontBitmap() const;
187 void InstallOpenFontShaper(COpenFont* aOpenFont, CShaper::TInput& aShaperInput);
188 TInt DoTextWidthInPixels(const TDesC &aText, const TMeasureTextInput* aParam) const;
189 void SetUniqueFontId(TUint32 aUniqueFontId);
192 TFontSpec iFontSpecInTwips;
195 /** The algorithmic font style. */
196 TAlgStyle iAlgStyle; // must not move this member
199 // Binary Compatibility warning - data member iOpenFont is referenced by inline methods
201 TInt iFontBitmapOffset;
203 // In order to be able to work with the flexible memory model, iOpenFont is
204 // actually an offset from the address of this class.
205 // iOpenFont's type remains unchanged.
206 // As Qt code that uses OpenFont() must be able to run on new and old versions
207 // of Symbian OS, it must be able to determine whether iOpenFont is a pointer or
208 // an offset at run-time. Therefore an offset will have its lowest significant bit set to 1.
209 // If iOpenFont is null, this object is not an open font.
210 // Assumption: a pointer always has least significant bit value of zero.
211 COpenFont* iOpenFont; // if iOpenFont is non-null this is an open font and many functions are forwarded to it
214 TUint32 iUniqueFontId; // unique id for this instance of this font
218 WARNING: Class for internal and partner use ONLY. Compatibility is not guaranteed in future releases.
222 class TLinkedTypefaceGroupArgs
226 CLinkedTypefaceGroup::TScalingOption iScalingOption;
227 CLinkedTypefaceGroup::TBaselineShift iBaselineShift;
228 TInt iAntialiasingThreshold;
229 TInt iBoldnessPercentage;
232 void operator =(const CLinkedTypefaceGroup* aRhs);
235 class COpenFontLinkedTypefaceElementSpec;
236 class COpenFontLinkedTypefaceSpecification;
239 WARNING: Class for internal and partner use ONLY. Compatibility is not guaranteed in future releases.
243 class TLinkedTypefaceElementSpecArgs
246 TBufC<KMaxTypefaceNameLength> iName;
250 void operator = (const CLinkedTypefaceElementSpec* aRhs);
251 void operator = (const COpenFontLinkedTypefaceElementSpec* aRhs);
255 WARNING: Class for internal and partner use ONLY. Compatibility is not guaranteed in future releases.
259 class TLinkedTypefaceSpecificationArgs
262 TBufC<KMaxTypefaceNameLength> iName;
263 TLinkedTypefaceElementSpecArgs iTypefaces[KMaxLinkedTypefaces];
264 TLinkedTypefaceGroupArgs iGroups[KMaxLinkedTypefaceGroups];
267 TInt iCanonicalIndex;
269 IMPORT_C void operator = (const CLinkedTypefaceSpecification& aRhs);
270 IMPORT_C void operator = (const COpenFontLinkedTypefaceSpecification& aRhs);
275 class TUnhintedOutlineId;
276 class THintedOutlineId;
277 class CFontTableCache;
278 class CUnhintedOutlineCache;
279 class CHintedOutlineCache;
280 class TFontTableGlyphOutlineCacheMemMonitor;
282 class CFontStore : public CTypefaceStore
286 Stores and handles both open and fixed-size fonts. Open fonts are made from
287 open (scalable) typefaces by Open Font plug-in rasterizers. Fonts of other
288 typefaces are stored in a limited number of fixed sizes. However, which is
289 being used is transparent to the user of this class. For example the GetNearestFont...()
290 functions get a bitmap font which may be retrieved from memory or generated
296 friend class CLinkedFonts;
297 friend class CLinkedTypefaceSpecification;
300 IMPORT_C static CFontStore* NewL(RHeap* aHeap);
301 IMPORT_C ~CFontStore();
302 IMPORT_C TUid AddFileL(const TDesC& aName);
303 IMPORT_C void RemoveFile(TUid aFileUid);
304 IMPORT_C TInt GetNearestFontInTwips(CFont *&aFont, const TFontSpec& aFontSpec);
305 IMPORT_C TInt GetNearestFontInPixels(CFont *&aFont, const TFontSpec &aFontSpec);
306 IMPORT_C TInt GetNearestFontToDesignHeightInTwips(CFont *&aFont, const TFontSpec& aFontSpec);
307 IMPORT_C TInt GetNearestFontToDesignHeightInPixels(CFont *&aFont, const TFontSpec& aFontSpec);
308 IMPORT_C TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
309 IMPORT_C TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TFontSpec& aFontSpec, TInt aMaxHeight);
310 IMPORT_C TInt GetNearestFontInTwips(CFont *&aFont, const TOpenFontSpec& aFontSpec);
311 IMPORT_C TInt GetNearestFontInPixels(CFont *&aFont, const TOpenFontSpec &aFontSpec);
312 IMPORT_C TInt GetNearestFontToDesignHeightInTwips(CFont *&aFont, const TOpenFontSpec& aFontSpec);
313 IMPORT_C TInt GetNearestFontToDesignHeightInPixels(CFont *&aFont, const TOpenFontSpec& aFontSpec);
314 IMPORT_C TInt GetNearestFontToMaxHeightInTwips(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
315 IMPORT_C TInt GetNearestFontToMaxHeightInPixels(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
316 IMPORT_C TInt GetFontById(CFont *&aFont,TUid aUid,const TAlgStyle& aAlgStyle);
317 IMPORT_C TInt NumTypefaces() const;
318 IMPORT_C void TypefaceSupport(TTypefaceSupport &aTypefaceSupport,TInt aTypefaceIndex) const;
319 IMPORT_C TInt FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const;
320 IMPORT_C TInt FontHeightInPixels(TInt aTypefaceIndex,TInt aHeightIndex) const;
321 IMPORT_C void InstallRasterizerL(COpenFontRasterizer* aRasterizer);
322 IMPORT_C void DeleteSessionCache(TInt aSessionHandle);
323 inline TGlyphBitmapType DefaultBitmapType() const;
324 inline void SetDefaultBitmapType(TGlyphBitmapType aType);
325 IMPORT_C void InstallShaperFactoryL(CShaperFactory* aShaperFactory);
326 const CArrayPtrFlat<CShaperFactory>* ShaperFactoryList() const;
327 COpenFontSessionCacheList* GetSessionCacheList();
328 TInt GetShaperCacheMemUsage();
329 void SetShaperCacheMemUsage(TInt aUsage);
330 CArrayPtrFlat<COpenFontFile>* GetOpenFontFileList();
331 void IncNumShaperCaches();
332 void DecNumShaperCaches();
333 TInt GetNumShaperCaches();
334 IMPORT_C TInt CreateLinkedTypeface(const TLinkedTypefaceSpecificationArgs &aLinkedTypefaceSpec, TInt aSession, TInt& aId);
335 IMPORT_C void GetLinkedTypefaceL(TLinkedTypefaceSpecificationArgs &aLinkedTypefaceSpec);
336 IMPORT_C TBool HaveTypefaceFamilyName(const TDesC& aName);
337 IMPORT_C void UpdateLinkedTypefaceL(const TLinkedTypefaceSpecificationArgs& aLinkedTypefaceSpec);
338 IMPORT_C void LoadFontsAtStartupL();
339 IMPORT_C TBool GetFontFilePath(const TDesC& aFontName, TFileName& aFilePath) const;
340 IMPORT_C void CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
342 TInt CacheFontTable(TUid aFileUid, TUint32 aTag, TAny*& aContent, TInt aLength);
343 TInt ReleaseFontTable(TUid aFileUid, TUint32 aTag, TInt aSessionHandle);
344 TInt FindFontTableInCache(TUid aFileUid, TUint32 aTag, TAny*& aContent, TInt& aLength);
345 TInt IncFontTableRefCount(TUid aFileUid, TUint32 aTag, TInt aSessionHandle);
346 TInt DecFontTableRefCount(TUid aFileUid, TUint32 aTag, TInt aSessionHandle);
347 TInt CacheUnhintedOutline(const TUnhintedOutlineId& aOutlineId, TAny* aData,
348 TInt aLength, TAny*& aOutline, TInt& aLen);
349 TInt CacheHintedOutline(const THintedOutlineId& aOutlineId, TAny* aData, TInt aLength,
350 TAny*& aOutline, TInt& aLen);
351 TInt ReleaseUnhintedOutline(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
352 TInt ReleaseHintedOutline(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
353 TInt IncreaseUnhintedOutlineRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
354 TInt IncreaseHintedOutlineRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
355 TInt FindUnhintedOutlineInCache(const TUnhintedOutlineId& aOutlineId, TAny*& aData,
357 TInt FindHintedOutlineInCache(const THintedOutlineId& aOutlineId, TAny*& aData, TInt& aLength);
358 void CleanupCacheOnOpenFontRemoval(COpenFont* aFont);
359 void CleanupCacheOnOpenFontFileRemoval(COpenFontFile* aFontFile);
362 CFontStore(RHeap* aHeap);
364 void InternalizeFontStoreFileL(CFontStoreFile* aFontStoreFile, TInt aFontVersion);
365 TTypeface* GetNearestTypeface(const TTypeface& aTypeface) const;
366 TTypefaceFontBitmap GetNearestTypefaceFontBitmap(const TFontSpec& aFontSpecInPixels, TInt aMaxHeight);
367 CFontBitmap* GetFontBitmapById(TUid aUid);
368 TBool IsFontLoaded(CFont*& aFont, const TAlgStyle& aAlgStyle, const TFontSpec& aFontSpecInPixels, TUid aUid, TInt aMaxHeight = 0) const;
369 TBool IsFontLoaded(CFont*& aFont, const TAlgStyle& aAlgStyle, const TOpenFontSpec& aFontSpecInPixels, TInt aMaxHeight) const;
370 CBitmapFont* NewFontL(const TFontSpec& aFontSpecInTwips,const TAlgStyle& aAlgStyle,CFontBitmap* aFontBitmap);
371 CBitmapFont* NewFontL(const TOpenFontSpec& aFontSpecInTwips,const TAlgStyle& aAlgStyle,COpenFont* aOpenFont);
372 TInt VerticalPixelsToTwips(TInt aPixelHeight) const;
373 TInt VerticalTwipsToPixels(TInt aTwipsHeight) const;
374 void GetNearestBitmapFontInPixelsL(CFont*& aFont, TFontSpec& aFontSpec, TInt aMaxHeight);
375 void GetNearestOpenFontInPixelsL(
376 CFont*& aFont, TOpenFontSpec& aActualFontSpec, const TOpenFontSpec& aDesiredFontSpec, TInt aMaxHeight);
377 TInt GetNearestRealFontInPixels(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
378 TInt GetNearestFontInPixelsL(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
379 TInt CreateLinkedTypefaceL(const TLinkedTypefaceSpecificationArgs &aLinkedTypefaceSpec, TInt aSession, TInt& aId);
380 TInt GetCanonicalIndex(TInt aTypefaceIndex) const;
381 void TypefaceSupportLinked(TTypefaceSupport &aTypefaceSupport, TInt aTypefaceIndex) const;
382 TInt GetNearestFontInPixels(CFont*& aFont, const TOpenFontSpec& aFontSpec, TInt aMaxHeight);
383 void SanityCheckForTtfL(RFile& aFile, TUint aFontFileSize, TBool aStrictChecking);
384 void SanityCheckFontFileL(TParse& aParse);
385 TInt GetNearestOpenFontInPixelsByFontName(COpenFont*& aNearestOpenFont, TOpenFontSpec& aActualFontSpec, const TOpenFontSpec& aDesiredFontSpec, TInt aMaxHeight);
386 TInt GetNearestOpenFontInPixelsBySimilarity(COpenFont*& aNearestOpenFont, TOpenFontSpec& aActualFontSpec, const TOpenFontSpec& aDesiredFontSpec, TInt aMaxHeight);
387 TInt AddTypefacesToSupportList(COpenFontFile* aOpenFontFile);
388 void RemoveTypefacesFromSupportList(COpenFontFile* aOpenFontFile);
389 TInt FindBitmapFontFileIndexByUid(TUid aUid);
390 TBool IncRefCountOfLoadedFont(const TParse& aFileName, TUid& aFontUid);
391 TBool LoadFileAsOpenFontL(const TParse& aFileName, TUid& aFontUid);
392 TUid LoadFileAsBitmapFontL(const TParse& aParse);
393 static void CleanupRemoveFontFile(TAny* aCleanupInfo);
394 const TAny* FontLinkingInterface() const;
395 TInt ValidateLinkedFontSpecificationL(COpenFontLinkedTypefaceSpecification& aSpec, TBool aOverwrite) const;
396 void GenerateLinkedFontFileL(COpenFontLinkedTypefaceSpecification& aSpec, const TAny* aExtension, TBool aUpdate);
397 void LoadFontsL(const TDesC& aFontsDir);
398 void AddSanityCheckedFontL(const TParse& aFileName, TUid& aUid);
400 /** The width of 1000 pixels in twips.
402 This is set in the constructor. If the appropriate HALData attributes are
403 set (EDisplayXPixels and EDisplayXTwips) then the value is calculated using
404 these; otherwise the value is set to 11860. */
405 TInt iKPixelWidthInTwips;
407 /** The height of 1000 pixels in twips.
409 This is set in the constructor. If the appropriate HALData attributes are
410 set (EDisplayYPixels and EDisplayYTwips) then the value is calculated using
411 these; otherwise the value is set to 11860. */
412 TInt iKPixelHeightInTwips;
415 // Binary Compatibility warning - data member iDefaultBitmapType is referenced by inline methods
418 CArrayPtrFlat<CFontStoreFile> iFontStoreFileList;
419 CArrayPtrFlat<TTypeface> iTypefaceList;
420 CArrayPtrFlat<CFontBitmap> iFontBitmapList;
421 CArrayFixFlat<TTypefaceFontBitmap> iTypefaceFontBitmapList;
422 CArrayPtrFlat<COpenFontFile> iOpenFontFileList;
423 TInt iReserved[2]; // keep iDefaultBitmapType at the correct offset
424 CFontTableCache *iFontTableCache;
425 CUnhintedOutlineCache *iUnhintedOutlineCache;
426 CHintedOutlineCache *iHintedOutlineCache;
427 TFontTableGlyphOutlineCacheMemMonitor *iCacheMemMon;
428 CArrayPtrFlat<COpenFontRasterizer> iOpenFontRasterizerList;
429 COpenFontSessionCacheList* iOpenFontSessionCacheList;
431 TGlyphBitmapType iDefaultBitmapType;
432 CArrayPtrFlat<CShaperFactory> iShaperFactoryList;
433 TInt iOpenFontShaperCacheMemUsage;
434 TInt iNumberOfShaperCaches;
435 RPointerArray<CTypefaceSupportInfo> iOpenFontTypefaceSupportList;
438 TUint32 iUniqueFontIdCount;
441 // inline functions start here
443 /** Returns whether the bitmap font object is an open font (a COpenFont) rather
444 than a bitmap font (a CFontBitmap).
446 @return ETrue if the bitmap font object is using an open font (a COpenFont);
447 EFalse if it is using a bitmap font (a CFontBitmap).
450 inline TBool CBitmapFont::IsOpenFont() const
452 return iOpenFont != NULL;
456 /** Returns a pointer to the open font being used by the bitmap font object.
458 @return A pointer to an open font.
461 inline COpenFont* CBitmapFont::OpenFont() const
463 if (reinterpret_cast<TInt>(iOpenFont) & 1)
465 return reinterpret_cast<COpenFont*>(const_cast<CBitmapFont*>(PtrAdd(this, reinterpret_cast<TInt>(iOpenFont) & ~1)));
473 /** Gets the anti-aliasing setting for the font, see TGlyphBitmapType for
476 This is only applicable to open fonts (COpenFonts) not bitmap fonts (CBitmapFonts).
478 Note that this setting is stored in the device-independent font specification
479 which is set when the bitmap font object is constructed.
481 @return The anti-aliasing setting for the font.
483 @see TGlyphBitmapType
487 inline TGlyphBitmapType CBitmapFont::GlyphBitmapType() const
489 return iFontSpecInTwips.iFontStyle.BitmapType();
492 /** Returns a default bitmap type.
494 @return A default bitmap type.
495 @see TGlyphBitmapType
497 inline TGlyphBitmapType CFontStore::DefaultBitmapType() const
499 return iDefaultBitmapType;
502 /** Sets a default bitmap type.
504 @param aType A default bitmap type.
505 @see TGlyphBitmapType
507 inline void CFontStore::SetDefaultBitmapType(TGlyphBitmapType aType)
509 iDefaultBitmapType = aType;