fontservices/fontstore/inc/openfontsprivate.h
branchRCL_3
changeset 1 e96e8a131979
parent 0 1fb32624e06b
child 2 6971d1c87c9a
equal deleted inserted replaced
0:1fb32624e06b 1:e96e8a131979
    18 
    18 
    19 #ifndef __OPENFONTS_PRIVATE_H__
    19 #ifndef __OPENFONTS_PRIVATE_H__
    20 #define __OPENFONTS_PRIVATE_H__
    20 #define __OPENFONTS_PRIVATE_H__
    21 
    21 
    22 #include <e32hashtab.h>
    22 #include <e32hashtab.h>
    23 
       
    24 class COpenFontShaperCacheEntry;
    23 class COpenFontShaperCacheEntry;
    25 
    24 
    26 /* MSB is set to indicate a glyph code rather than a unicode value
    25 /* MSB is set to indicate a glyph code rather than a unicode value
    27    This is used for extracting the code value */
    26    This is used for extracting the code value */
    28 #define GLYPH_CODE(code) (code & 0x7fffffff)
    27 #define GLYPH_CODE(code) (code & 0x7fffffff)
    36 	{
    35 	{
    37 public:
    36 public:
    38 	CFontStore* iFontStore;			// pointer to the CFontStore instance that loaded the COpenFontFile
    37 	CFontStore* iFontStore;			// pointer to the CFontStore instance that loaded the COpenFontFile
    39 	};
    38 	};
    40 
    39 
    41 #ifdef FNTSTORE_SUPPORT_FMM
       
    42 /**
    40 /**
    43  @internalComponent
    41  @internalComponent
    44  */
    42  */
    45 class COpenFontGlyph
    43 class COpenFontGlyph
    46 	{
    44 	{
    65 private:
    63 private:
    66 	// an offset from this COpenFontGlyph object to a pointer to the run-length-encoded bitmap, 
    64 	// an offset from this COpenFontGlyph object to a pointer to the run-length-encoded bitmap, 
    67 	// calculated as (bitmapPointer)-(this)
    65 	// calculated as (bitmapPointer)-(this)
    68 	TInt iBitmapOffset;				
    66 	TInt iBitmapOffset;				
    69 	};
    67 	};
    70 #else
       
    71 /**
       
    72  @internalComponent
       
    73  */
       
    74 class COpenFontGlyph
       
    75 	{
       
    76 public:
       
    77 	COpenFontGlyph(TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics):
       
    78 		iCode(aCode), iGlyphIndex(aGlyphIndex), iMetrics(aMetrics), iBitmap(NULL) { }
       
    79 	
       
    80 	static COpenFontGlyph* NewL(RHeap* aHeap, TInt aCode, TInt aGlyphIndex,
       
    81 								const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
       
    82 
       
    83 	static void Delete(RHeap* aHeap, COpenFontGlyph* aGlyph);
       
    84 
       
    85 	TInt iCode;						// the Unicode value of the character
       
    86 	TInt iGlyphIndex;				// the glyph index
       
    87 	TOpenFontCharMetrics iMetrics;	// the metrics
       
    88 	TUint8* iBitmap;				// the run-length-encoded bitmap
       
    89 
       
    90 protected:
       
    91 	TBool SetBitmap(RHeap* aHeap, const TDesC8& aBitmap);
       
    92 	~COpenFontGlyph();
       
    93 	};
       
    94 #endif // FNTSTORE_SUPPORT_FMM
       
    95 
       
    96 #ifdef FNTSTORE_SUPPORT_FMM
       
    97 /**
    68 /**
    98  Binary tree of glyphs. Each glyph can have left and right child nodes which are added
    69  Binary tree of glyphs. Each glyph can have left and right child nodes which are added
    99  depending on the value of their glyph code relative to the parent's glyph code.
    70  depending on the value of their glyph code relative to the parent's glyph code.
   100 
    71 
   101  @internalComponent
    72  @internalComponent
   108 	static COpenFontGlyphTreeEntry* New(RHeap* aHeap, TInt aCode, TInt aGlyphIndex,
    79 	static COpenFontGlyphTreeEntry* New(RHeap* aHeap, TInt aCode, TInt aGlyphIndex,
   109 										const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
    80 										const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
   110 
    81 
   111 private:
    82 private:
   112 	/** The left COpenFontGlyphTreeEntry from this entry. Represented by an offset from the
    83 	/** The left COpenFontGlyphTreeEntry from this entry. Represented by an offset from the
   113 	current heap base. Use COpenFont::ThisOffsetToPointer() to convert to a valid 
    84      current heap base. Use COpenFont::ThisOffsetToPointer() to convert to a valid 
   114 	COpenFontGlyphTreeEntry pointer. */
    85      COpenFontGlyphTreeEntry pointer. */
   115 	TInt iLeftOffset; 
    86     TInt iLeftOffset;
   116 	/** The right COpenFontGlyphTreeEntry from this entry. Represented by an offset from the
    87     /** The right COpenFontGlyphTreeEntry from this entry. Represented by an offset from the
   117 	current heap base. Use COpenFont::ThisOffsetToPointer() to convert to a valid 
    88      current heap base. Use COpenFont::ThisOffsetToPointer() to convert to a valid 
   118 	COpenFontGlyphTreeEntry pointer. */
    89      COpenFontGlyphTreeEntry pointer. */
   119 	TInt iRightOffset;
    90     TInt iRightOffset;
       
    91     /** Pointer to next glyph that was added to the glyph cache.  This enables 
       
    92      non-recursive deletion of the cache. This is only ever accessed from server
       
    93      process, so can be a direct pointer, not an offset. */
       
    94     COpenFontGlyphTreeEntry* iNext;
   120 
    95 
   121 private:
    96 private:
   122 	COpenFontGlyphTreeEntry(TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics)
    97 	COpenFontGlyphTreeEntry(TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics)
   123 	 :	COpenFontGlyph(aCode, aGlyphIndex, aMetrics), iLeftOffset(0), iRightOffset(0) {}
    98 	 :	COpenFontGlyph(aCode, aGlyphIndex, aMetrics), iLeftOffset(0), iRightOffset(0),iNext(NULL){}
   124 
    99 
   125 	~COpenFontGlyphTreeEntry();
   100 	~COpenFontGlyphTreeEntry();
   126 	};
   101 	};
   127 #else
   102 
   128 /**
   103 /**
   129  binary tree of glyphs
   104  * Template for offset implementation of pointer to pointer
   130 
   105  @internalComponent
   131  @internalComponent
   106  */
   132  */
   107 template<class T>
   133 class COpenFontGlyphTreeEntry: public COpenFontGlyph
   108 class ROffsetArray
   134 	{
   109     {
   135 public:
   110 public:
   136 	static COpenFontGlyphTreeEntry* New(RHeap* aHeap, TInt aCode, TInt aGlyphIndex,
   111     ROffsetArray();
   137 										const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
   112     TInt Create(RHeap* aHeap, TInt aCount);
   138 
   113     void Close(RHeap* aHeap);
   139 	COpenFontGlyphTreeEntry* iLeft;		// pointer to left node in tree
   114     TInt Count() const;
   140 	COpenFontGlyphTreeEntry* iRight;	// pointer to right node in tree
   115     T* operator[](TInt aIndex) const;
   141 	COpenFontGlyphTreeEntry* iNext;		// pointer to next glyph in the list; so that the cache can be deleted non-recursively
   116     void SetAt(TInt aIndex, T* aEntry);
   142 
   117 private:
   143 private:
   118     TInt iOffset;
   144 	COpenFontGlyphTreeEntry(TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics)
   119     TInt iCount;
   145 	 :	COpenFontGlyph(aCode, aGlyphIndex, aMetrics), iLeft(NULL), iRight(NULL), iNext(NULL) { }
   120     };
   146 	
   121 
   147 	~COpenFontGlyphTreeEntry();
   122 
   148 	};
       
   149 #endif // FNTSTORE_SUPPORT_FMM
       
   150 
       
   151 #ifdef FNTSTORE_SUPPORT_FMM
       
   152 /**
       
   153  RArray for storing offsets to COpenFontGlyphTreeEntry objects. Stores each
       
   154  COpenFontGlyphTreeEntry as an offset from the "this" pointer of this object.
       
   155  Allows glyph entries to be added, accessed and deleted from the glyph array
       
   156  from different processes.  
       
   157  
       
   158  @internalComponent
       
   159  */
       
   160 class RArrayGlyphEntries : public RArray<TInt>
       
   161 	{
       
   162 public:
       
   163 	inline const COpenFontGlyphTreeEntry& operator[](TInt anIndex) const;
       
   164 	inline COpenFontGlyphTreeEntry& operator[](TInt anIndex);
       
   165 	TInt Append(COpenFontGlyphTreeEntry& anEntry);
       
   166 private:
       
   167 	inline const COpenFontGlyphTreeEntry* Entry(TInt anIndex) const;
       
   168 	inline COpenFontGlyphTreeEntry** EntryMemberOffSet() const;
       
   169 	inline TAny** EntryMember() const;
       
   170 private:
       
   171 	TInt iEntriesOffset;
       
   172 	};
       
   173 #endif // FNTSTORE_SUPPORT_FMM
       
   174 
       
   175 #ifdef FNTSTORE_SUPPORT_FMM
       
   176 /**
   123 /**
   177  The per-font glyph cache. For now, just the members that used to be directly in
   124  The per-font glyph cache. For now, just the members that used to be directly in
   178  COpenFont. Now it is a private class it can be elaborated to do character-to-glyph-index
   125  COpenFont. Now it is a private class it can be elaborated to do character-to-glyph-index
   179  mapping when that is needed.
   126  mapping when that is needed.
   180 
   127 
   181  @internalComponent
   128  @internalComponent
   182  */
   129  */
   183 class COpenFontGlyphCache
   130 class COpenFontGlyphCache
   184 	{
   131 	{
   185 public:
   132 public:
   186 	COpenFontGlyphCache(): iGlyphTreeOffset(0), iGlyphCacheMemory(0), iShaperCacheSentinel(NULL), iShapingInfoCacheMemory(0), iNumberOfShaperCacheEntries(0) { }
   133 	COpenFontGlyphCache(): iGlyphTreeOffset(0), iGlyphCacheMemory(0),iGlyphList(NULL),iShaperCacheSentinel(NULL), iShapingInfoCacheMemory(0), iNumberOfShaperCacheEntries(0) { }
   187 	TShapeHeader* SearchShaperCache(TInt aSessionHandle, TFontShapeFunctionParameters*& aParams);
   134 	TShapeHeader* SearchShaperCache(TInt aSessionHandle, TFontShapeFunctionParameters*& aParams);
   188 	TShapeHeader* Insert(TInt aSessionHandle, RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader, TInt& aAddedBytes);
   135 	TShapeHeader* Insert(TInt aSessionHandle, RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader, TInt& aAddedBytes);
   189 	TInt DeleteLeastRecentlyUsedEntry(RHeap* aHeap);
   136 	TInt DeleteLeastRecentlyUsedEntry(RHeap* aHeap);
   190 	TBool ShaperCacheIsEmpty();
   137 	TBool ShaperCacheIsEmpty();
   191 	
   138 	
   192 public:
   139 public:
   193 	TInt iGlyphTreeOffset;									// an offset to root of the glyph cache; a binary tree
   140 	TInt iGlyphTreeOffset;									// an offset to root of the glyph cache; a binary tree
   194 	TInt iGlyphCacheMemory;									// memory used by the glyph tree in bytes
   141 	TInt iGlyphCacheMemory;									// memory used by the glyph tree in bytes
       
   142 	COpenFontGlyphTreeEntry* iGlyphList;                   // the glyphs, organized as a list
   195 	COpenFontShaperCacheEntry* iShaperCacheSentinel;
   143 	COpenFontShaperCacheEntry* iShaperCacheSentinel;
   196 	TInt iShapingInfoCacheMemory;
   144 	TInt iShapingInfoCacheMemory;
   197 	TInt iNumberOfShaperCacheEntries;
   145 	TInt iNumberOfShaperCacheEntries;	
   198 	RArrayGlyphEntries iGlyphArray;
   146 	};
   199 	};
   147 
   200 #else
   148 /**
   201 /**
   149  @internalComponent
   202  The per-font glyph cache. For now, just the members that used to be directly in
   150  */
   203  COpenFont. Now it is a private class it can be elaborated to do character-to-glyph-index
   151 
   204  mapping when that is needed.
       
   205 
       
   206  @internalComponent
       
   207  */
       
   208 class COpenFontGlyphCache
       
   209 	{
       
   210 public:
       
   211 	COpenFontGlyphCache(): iGlyphTree(NULL), iGlyphCacheMemory(0), iGlyphList(NULL), iShaperCacheSentinel(NULL), iShapingInfoCacheMemory(0), iNumberOfShaperCacheEntries(0) { }
       
   212 	TShapeHeader* SearchShaperCache(TInt aSessionHandle, TFontShapeFunctionParameters*& aParams);
       
   213 	TShapeHeader* Insert(TInt aSessionHandle, RHeap* aHeap, CShaper::TInput aInput, TShapeHeader* aShapeHeader, TInt& aAddedBytes);
       
   214 	TInt DeleteLeastRecentlyUsedEntry(RHeap* aHeap);
       
   215 	TBool ShaperCacheIsEmpty();
       
   216 	
       
   217 public:
       
   218 	COpenFontGlyphTreeEntry* iGlyphTree;					// the root of the glyph cache; a binary tree
       
   219 	TInt iGlyphCacheMemory;									// memory used by the glyph tree in bytes
       
   220 	COpenFontGlyphTreeEntry* iGlyphList;					// the glyphs, organized as a list
       
   221 	COpenFontShaperCacheEntry* iShaperCacheSentinel;
       
   222 	TInt iShapingInfoCacheMemory;
       
   223 	TInt iNumberOfShaperCacheEntries;
       
   224 	};
       
   225 #endif // FNTSTORE_SUPPORT_FMM
       
   226 
       
   227 /**
       
   228  @internalComponent
       
   229  */
       
   230 #ifdef FNTSTORE_SUPPORT_FMM
       
   231 class COpenFontSessionCacheEntry: public COpenFontGlyph
   152 class COpenFontSessionCacheEntry: public COpenFontGlyph
   232 	{
   153 	{
   233 public:
   154 public:
   234 	static COpenFontSessionCacheEntry* New(RHeap* aHeap, const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,
   155 	static COpenFontSessionCacheEntry* New(RHeap* aHeap, const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,
   235 										   const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
   156 										   const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
   236 	inline COpenFont* Font()const;
   157 	inline const COpenFont* Font()const;
   237 
   158 
   238 private:
   159 private:
   239 	COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics):
   160 	inline COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics);
   240 		COpenFontGlyph(aCode, aGlyphIndex, aMetrics)
       
   241 		, iFontOffset(reinterpret_cast<TInt>(aFont) - reinterpret_cast<TInt>(this))	
       
   242 		    { }
       
   243 	~COpenFontSessionCacheEntry();
   161 	~COpenFontSessionCacheEntry();
   244 public:
   162 public:
   245     TInt iLastAccess;               // serial number of the last access to the glyph
   163     TInt iLastAccess;               // serial number of the last access to the glyph
   246 
   164 
   247 private: 
   165 private: 
   248     const TInt iFontOffset;          // offset of the font that contains this glyph, (not owned by this class!)    
   166     TInt iFontOffset;          // offset of the font that contains this glyph, (not owned by this class!)    
   249 	};
   167 	};
   250 
       
   251 #else
       
   252 class COpenFontSessionCacheEntry: public COpenFontGlyph
       
   253     {
       
   254 public:
       
   255     static COpenFontSessionCacheEntry* New(RHeap* aHeap, const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,
       
   256                                            const TOpenFontCharMetrics& aMetrics, const TDesC8& aBitmap);
       
   257 
       
   258 private:
       
   259     COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex, const TOpenFontCharMetrics& aMetrics):
       
   260         COpenFontGlyph(aCode, aGlyphIndex, aMetrics), iFont(aFont) { }
       
   261     ~COpenFontSessionCacheEntry();
       
   262 public:
       
   263     const COpenFont* iFont;         // the font that contains this glyph, (not owned by this class!)
       
   264     TInt iLastAccess;               // serial number of the last access to the glyph
       
   265     };
       
   266    
       
   267 #endif    //FNTSTORE_SUPPORT_FMM
       
   268 
   168 
   269 /**
   169 /**
   270  A glyph cache for a particular session.
   170  A glyph cache for a particular session.
   271  Because session caches are not shared they can shrink as well as grow.
   171  Because session caches are not shared they can shrink as well as grow.
   272 
   172 
   273  @internalComponent
   173  @internalComponent
   274  */
   174  */
   275 #ifdef FNTSTORE_SUPPORT_FMM
       
   276 class COpenFontSessionCache
   175 class COpenFontSessionCache
   277     {
   176     {
   278 public:
   177 public:
   279     static COpenFontSessionCache* NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries);
   178     static COpenFontSessionCache* NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries);
   280     void Delete(RHeap* aHeap);
   179     void Delete(RHeap* aHeap);
   281     
   180     
   282     TInt SessionHandle() { return iSessionHandle; }
   181     TInt SessionHandle() { return iSessionHandle; }
   283     const COpenFontGlyph* Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex);
   182     const COpenFontGlyph* Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex);
   284     void Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex);
   183     void Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex);
   285     inline TInt* Entry()const;
   184     
   286     inline COpenFontSessionCacheEntry* ToCOpenFontSessionCacheEntryPointer(TInt aOffset)const;
   185 private:
   287     
   186     COpenFontSessionCache(TInt aSessionHandle);
   288 private:
       
   289     COpenFontSessionCache(TInt aSessionHandle, TInt aEntries);
       
   290     ~COpenFontSessionCache();
   187     ~COpenFontSessionCache();
   291 public:
   188 public:
   292     TInt iSessionHandle;    
   189     TInt iSessionHandle;    
   293     TInt iEntries;
       
   294     TInt iLastAccess;
   190     TInt iLastAccess;
   295 private:    
   191     ROffsetArray<COpenFontSessionCacheEntry> iEntryArray;
   296     TInt iEntryOffset;    // Offset of the pointer to an offset array which is of COpenFontSessionCacheEntry*    
   192     };
   297     };
   193 
   298 #else
   194 /**
   299 class COpenFontSessionCache
   195  @internalComponent
   300 	{
   196  */
   301 public:
       
   302 	static COpenFontSessionCache* NewL(RHeap* aHeap, TInt aSessionHandle, TInt aEntries);
       
   303 	void Delete(RHeap* aHeap);
       
   304 	
       
   305 	TInt SessionHandle() { return iSessionHandle; }
       
   306 	const COpenFontGlyph* Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex);
       
   307 	void Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex);
       
   308 
       
   309 private:
       
   310 	COpenFontSessionCache(TInt aSessionHandle, TInt aEntries);
       
   311 	~COpenFontSessionCache();
       
   312 public:
       
   313 	TInt iSessionHandle;
       
   314 	TInt iEntries;
       
   315 	TInt iLastAccess;
       
   316 	COpenFontSessionCacheEntry** iEntry;
       
   317 	};
       
   318 #endif //FNTSTORE_SUPPORT_FMM
       
   319 /**
       
   320  @internalComponent
       
   321  */
       
   322 #ifdef FNTSTORE_SUPPORT_FMM
       
   323 class COpenFontSessionCacheListItem
   197 class COpenFontSessionCacheListItem
   324 	{
   198 	{
   325 public:
   199 public:
   326 	COpenFontSessionCacheListItem(COpenFontSessionCache* aCache);
   200 	COpenFontSessionCacheListItem(COpenFontSessionCache* aCache);
   327 
   201 
   334 	~COpenFontSessionCacheListItem();
   208 	~COpenFontSessionCacheListItem();
   335 private:
   209 private:
   336 	TInt iNextOffset;
   210 	TInt iNextOffset;
   337 	TInt iCacheOffset;
   211 	TInt iCacheOffset;
   338 	};
   212 	};
   339 #else
       
   340 class COpenFontSessionCacheListItem
       
   341 	{
       
   342 public:
       
   343 	COpenFontSessionCacheListItem(COpenFontSessionCache* aCache): iNext(NULL), iCache(aCache) { }
       
   344 	void Delete(RHeap* aHeap);
       
   345 private:
       
   346 	~COpenFontSessionCacheListItem();
       
   347 public:
       
   348 	COpenFontSessionCacheListItem* iNext;	// the next cache in the list
       
   349 	COpenFontSessionCache* iCache;			// the cache if non-null;
       
   350 	};	
       
   351 #endif // FNTSTORE_SUPPORT_FMM
       
   352 
       
   353 
   213 
   354 class TFontTableGlyphOutlineCacheMemMonitor
   214 class TFontTableGlyphOutlineCacheMemMonitor
   355     {
   215     {
   356 public:
   216 public:
   357     TFontTableGlyphOutlineCacheMemMonitor();
   217     TFontTableGlyphOutlineCacheMemMonitor();
   569     RHeap* iHeap; 
   429     RHeap* iHeap; 
   570     RHashMap<THintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
   430     RHashMap<THintedOutlineId, COutlineCacheItem*> iItemIdMap; // map the identity to an index in 'iCacheItems'.
   571     };
   431     };
   572 
   432 
   573 
   433 
       
   434 // inline functions
       
   435 inline COpenFontSessionCacheEntry::COpenFontSessionCacheEntry(const COpenFont* aFont, TInt aCode, TInt aGlyphIndex,const TOpenFontCharMetrics& aMetrics) :
       
   436     COpenFontGlyph(aCode, aGlyphIndex, aMetrics)
       
   437     {
       
   438     iFontOffset = aFont ? reinterpret_cast<TInt>(aFont) - reinterpret_cast<TInt>(this) : 0;
       
   439     }
       
   440 
       
   441 
       
   442 inline const COpenFont* COpenFontSessionCacheEntry::Font() const
       
   443     {
       
   444     if (iFontOffset)
       
   445         {
       
   446         return reinterpret_cast<const COpenFont*> (PtrAdd(this, iFontOffset));
       
   447         }
       
   448     else
       
   449         {
       
   450         return NULL;
       
   451         }
       
   452     }
       
   453 
   574 #endif	// __OPENFONTSPRIVATE_H__
   454 #endif	// __OPENFONTSPRIVATE_H__