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