Update contrib.
2 * Copyright (c) 2006-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.
19 #ifndef __OPENFONTS_PRIVATE_H__
20 #define __OPENFONTS_PRIVATE_H__
23 #include <e32hashtab.h>
25 class COpenFontShaperCacheEntry;
27 /* MSB is set to indicate a glyph code rather than a unicode value
28 This is used for extracting the code value */
29 #define GLYPH_CODE(code) (code & 0x7fffffff)
31 /** COpenFontFile owned container for extra data. May be extended without affecting Binary Compatibility.
36 class TOpenFontFileData
39 CFontStore* iFontStore; // pointer to the CFontStore instance that loaded the COpenFontFile
43 Note: this class must be self-contained, since instances are added to an RHexTree,
44 that is, it must be possible to destroy instances simply with RHeap::Free().
50 static COpenFontGlyph* New(RHeap* aHeap, TInt aCode, TInt aGlyphIndex,
51 const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
52 inline static void Delete(RHeap* aHeap, COpenFontGlyph* aGlyph);
53 inline const TUint8* Bitmap() const;
56 COpenFontGlyph(TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics)
57 : iCode(aCode), iGlyphIndex(aGlyphIndex), iMetrics(aMetrics), iBitmapOffset(0) {}
59 void SetBitmap(const TAny* aBitmap);
62 const TInt iCode; // the Unicode value of the character
63 const TInt iGlyphIndex; // the glyph index
64 const TOpenFontCharMetrics iMetrics; // the metrics
67 // an offset from this COpenFontGlyph object to a pointer to the run-length-encoded bitmap,
68 // calculated as (bitmapPointer)-(this)
73 * Template for offset implementation of pointer array
81 TInt Create(RHeap* aHeap, TInt aCount);
82 void Close(RHeap* aHeap);
84 T* operator[](TInt aIndex) const;
85 void SetAt(TInt aIndex, T* aEntry);
93 The per-font glyph cache. For now, just the members that used to be directly in
94 COpenFont. Now it is a private class it can be elaborated to do character-to-glyph-index
95 mapping when that is needed.
99 class COpenFontGlyphCache
102 COpenFontGlyphCache(RHeap* aHeap)
103 : iGlyphTreeById(aHeap),
104 iGlyphTreeByUnicode(aHeap),
105 iGlyphCacheMemory(0),
106 iShaperCacheSentinel(NULL),
107 iShapingInfoCacheMemory(0),
108 iNumberOfShaperCacheEntries(0)
110 TShapeHeader* SearchShaperCache(TInt aSessionHandle, TFontShapeFunctionParameters*& aParams);
111 TShapeHeader* Insert(TInt aSessionHandle, RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader, TInt& aAddedBytes);
112 TInt DeleteLeastRecentlyUsedEntry(RHeap* aHeap);
113 TBool ShaperCacheIsEmpty();
116 RHexTree<COpenFontGlyph> iGlyphTreeById; // a hex tree of glyphs indexed by glyph ID
117 RHexTree<COpenFontGlyph> iGlyphTreeByUnicode; // a hex tree of glyphs indexed by Unicode code point
118 TInt iGlyphCacheMemory; // memory used by the glyph tree in bytes
119 COpenFontShaperCacheEntry* iShaperCacheSentinel;
120 TInt iShapingInfoCacheMemory;
121 TInt iNumberOfShaperCacheEntries;
127 class COpenFontSessionCacheEntry: public COpenFontGlyph
130 static COpenFontSessionCacheEntry* New(RHeap* aHeap, const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,
131 const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
132 inline static void Delete(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry);
133 inline const COpenFont* Font()const;
136 inline COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics);
137 ~COpenFontSessionCacheEntry();
140 TInt iFontOffset; // offset of the font that contains this glyph, (not owned by this class!)
144 A glyph cache for a particular session.
145 Because session caches are not shared they can shrink as well as grow.
149 class COpenFontSessionCache
151 friend class COpenFontSessionCacheList;
153 static COpenFontSessionCache* NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries);
154 void Delete(RHeap* aHeap);
156 TInt SessionHandle() { return iSessionHandle; }
157 const COpenFontGlyph* Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) const;
158 void Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex);
161 COpenFontSessionCache(TInt aSessionHandle);
162 ~COpenFontSessionCache();
166 ROffsetArray<COpenFontSessionCacheEntry> iEntryArray;
170 class TFontTableGlyphOutlineCacheMemMonitor
173 TFontTableGlyphOutlineCacheMemMonitor();
174 void Inc(TInt aBytes);
175 void Dec(TInt aBytes);
181 struct TCacheUserInfo {
184 TCacheUserInfo(TInt aSessionHandle, TInt aRefCount = 0):
185 iSessionHandle(aSessionHandle), iRefCount(aRefCount) { }
188 class CFontTableCache;
190 class CFontTableCacheItem
192 friend class CFontTableCache ;
195 CFontTableCacheItem(TUid &aFileUid, const TUint32 aTag,
196 TInt aOffset, TInt aLength);
197 ~CFontTableCacheItem();
199 TInt DecRefCount(TInt aSessionHandle);
200 TInt IncRefCount(TInt aSessionHandle);
202 TBool HasOutstandingRefCount();
203 TInt FindUser(TInt aSessionHandle, TInt *id);
206 void SetUser(RPointerArray<TCacheUserInfo> users)
208 TInt len = users.Count();
209 for( TInt i = 0; i < len ; i++ )
211 iUsers.Append(users[i]);
217 CFontTableCacheItem(const CFontTableCacheItem &); // disallow copy construction.
218 CFontTableCacheItem& operator =(const CFontTableCacheItem &); // disallow assignment.
226 RPointerArray<TCacheUserInfo> iUsers;
230 class CFontTableCache
233 CFontTableCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
235 TInt Append(TUid aFileUid, TUint32 aTag,
236 TAny*& aContent, TInt aLength);
237 TInt Find(TUid aFileUid, TUint32 aTag, TAny*& aContent, TInt& aLength, TInt* id);
238 TInt IncRefCount(TUid FileUid, TUint32 aTag, TInt aSessionHandle);
239 TInt DecRefCount(TUid aFileUid, TUint32 aTag, TInt aSessionHandle);
240 TBool HasOutstandingRefCount();
241 TBool HasOutstandingRefCountWithUid(TUid aFileUid);
242 void CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
243 void CleanupCacheOnOpenFontFileRemoval(COpenFontFile*);
245 void SetFontItem(RPointerArray<CFontTableCacheItem> cacheItems)
247 TInt len = cacheItems.Count();
248 for(TInt i = 0; i < len; i++)
250 iCacheItems.Append(cacheItems[i]);
256 CFontTableCache(const CFontTableCache &); // no copy construction.
257 CFontTableCache& operator =(const CFontTableCache &); // no assignment.
259 TInt GetCacheState(const char *func);
262 TFontTableGlyphOutlineCacheMemMonitor &iCacheMemMon;
264 RPointerArray<CFontTableCacheItem> iCacheItems;
268 class TUnhintedOutlineCache;
270 class TUnhintedOutlineId
273 TUnhintedOutlineId(TUid aFileUid, TInt aFaceIndex, TUint aId);
279 class COutlineCacheItem {
280 friend class CUnhintedOutlineCache;
281 friend class CHintedOutlineCache;
284 COutlineCacheItem(TInt aOffset, TInt aLength);
285 ~COutlineCacheItem() ;
287 TInt DecRefCount(TInt aSessionHandle);
288 TInt IncRefCount(TInt aSessionHandle);
290 void SetUser(RPointerArray<TCacheUserInfo> users)
292 TInt len = users.Count();
293 for( TInt i = 0; i < len ; i++ )
295 iUsers.Append(users[i]);
301 TInt FindUser(TInt aSessionHandle, TInt *id);
306 RPointerArray<TCacheUserInfo> iUsers;
309 class CUnhintedOutlineCache {
311 CUnhintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
312 TInt Find(const TUnhintedOutlineId &aOutlineId, TAny*& aData, TInt& aLength);
313 TInt IncRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
314 TInt DecRefCount(const TUnhintedOutlineId& aOutlineId, TInt aSessionHandle);
315 TInt CacheUnhintedOutline(const TUnhintedOutlineId& aOutlineId,
316 TAny * const aData, const TInt aLength, TAny*& aOutline, TInt &aLen);
317 TInt CleanupCacheOnOpenFontFileRemoval(COpenFontFile* aFontFile);
318 TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
320 TInt GetCacheState(const char *func);
322 ~CUnhintedOutlineCache();
325 void SetUnHintedItem(TUnhintedOutlineId id, COutlineCacheItem* item)
327 iItemIdMap.Insert(id, item);
332 // disallow assignment and copy-construction
333 CUnhintedOutlineCache(const CUnhintedOutlineCache &);
334 CUnhintedOutlineCache& operator =(const CUnhintedOutlineCache &);
336 static TUint32 IdHash(const TUnhintedOutlineId& aOutlineId);
337 static TBool IdIdentity(const TUnhintedOutlineId& id1, const TUnhintedOutlineId& id2);
339 TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
341 RHashMap<TUnhintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
344 class CHintedOutlineCache;
346 class THintedOutlineId
349 THintedOutlineId(COpenFont* aFont, TUint aId);
355 class CHintedOutlineCache {
357 CHintedOutlineCache(RHeap* aHeap, TFontTableGlyphOutlineCacheMemMonitor& aMon);
358 TInt Find(const THintedOutlineId& aOutlineId, TAny*& aData, TInt& aLength);
359 TInt IncRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
360 TInt DecRefCount(const THintedOutlineId& aOutlineId, TInt aSessionHandle);
361 TInt CacheHintedOutline(const THintedOutlineId& aOutlineId,
362 TAny* aData, TInt aLength, TAny*& aOutline, TInt& aLen);
363 TInt CleanupCacheOnOpenFontRemoval(COpenFont* aFont);
364 TInt CleanupCacheOnFbsSessionTermination(TInt aSessionHandle);
366 TInt GetCacheState(const char *func);
367 void SetHintedItem(THintedOutlineId id, COutlineCacheItem* item)
369 iItemIdMap.Insert(id, item);
371 RHashMap<THintedOutlineId, COutlineCacheItem*> GetHintedMap()
378 // disallow assignment and copy-construction
379 CHintedOutlineCache(const CHintedOutlineCache &);
380 CHintedOutlineCache& operator =(const CHintedOutlineCache &);
381 static TUint32 IdHash(const THintedOutlineId& aOutlineId);
382 static TBool IdIdentity(const THintedOutlineId& id1, const THintedOutlineId& id2);
384 TFontTableGlyphOutlineCacheMemMonitor& iCacheMemMon;
386 RHashMap<THintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
392 inline void COpenFontGlyph::Delete(RHeap* aHeap, COpenFontGlyph* aGlyph)
398 @return A pointer to the bitmap data stored with this glyph, or NULL
399 if no bitmap has been stored with this glyph.
401 inline const TUint8* COpenFontGlyph::Bitmap() const
405 return reinterpret_cast<const TUint8*>(PtrAdd(this, iBitmapOffset));
410 inline COpenFontSessionCacheEntry::COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,const TOpenFontCharMetrics& aMetrics) :
411 COpenFontGlyph(aCode, aGlyphIndex, aMetrics)
413 iFontOffset = aFont ? reinterpret_cast<TInt>(aFont) - reinterpret_cast<TInt>(this) : 0;
416 inline void COpenFontSessionCacheEntry::Delete(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry)
418 COpenFontGlyph::Delete(aHeap, aEntry);
421 inline const COpenFont* COpenFontSessionCacheEntry::Font() const
425 return reinterpret_cast<const COpenFont*> (PtrAdd(this, iFontOffset));
430 #endif // __OPENFONTSPRIVATE_H__