24 #include "openfontsprivate.h" |
24 #include "openfontsprivate.h" |
25 #include <linkedfonts.h> |
25 #include <linkedfonts.h> |
26 #include "linkedfontsprivate.h" |
26 #include "linkedfontsprivate.h" |
27 #include <graphics/openfontrasterizer.h> |
27 #include <graphics/openfontrasterizer.h> |
28 #include <graphics/gdi/glyphsample.h> |
28 #include <graphics/gdi/glyphsample.h> |
|
29 #include <e32math.h> |
29 |
30 |
30 #include "OstTraceDefinitions.h" |
31 #include "OstTraceDefinitions.h" |
31 #ifdef OST_TRACE_COMPILER_IN_USE |
32 #ifdef OST_TRACE_COMPILER_IN_USE |
32 #include "OPENFONTTraces.h" |
33 #include "OPENFONTTraces.h" |
33 #endif |
34 #endif |
902 void COpenFont::OnFileDeleted() |
903 void COpenFont::OnFileDeleted() |
903 { |
904 { |
904 iFileOffset = 0; |
905 iFileOffset = 0; |
905 } |
906 } |
906 |
907 |
907 COpenFontGlyphCache* COpenFont::GetGlyphCache() |
908 COpenFontGlyphCache* COpenFont::GetGlyphCache() const |
908 { |
909 { |
909 if (iGlyphCacheOffset == 0) |
910 if (iGlyphCacheOffset == 0) |
910 { |
911 { |
911 return NULL; |
912 return NULL; |
912 } |
913 } |
913 return reinterpret_cast<COpenFontGlyphCache*>(PtrAdd(this, iGlyphCacheOffset)); |
914 return reinterpret_cast<COpenFontGlyphCache*>(PtrAdd(const_cast<COpenFont*>(this), iGlyphCacheOffset)); |
914 } |
915 } |
915 |
916 |
916 const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const |
917 const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const |
917 { |
918 { |
918 const COpenFontGlyph* glyph = const_cast<COpenFont*>(this)->FontCacheGlyph(aCode); |
919 const COpenFontGlyph* glyph = const_cast<COpenFont*>(this)->FontCacheGlyph(aCode); |
947 be resized - this is not allowed by the kernel. |
948 be resized - this is not allowed by the kernel. |
948 The cache is now created in COpenFont::Rasterize which can only be called within the context of FBSERV |
949 The cache is now created in COpenFont::Rasterize which can only be called within the context of FBSERV |
949 @param aCode The code for the glpyh to look for in the cache |
950 @param aCode The code for the glpyh to look for in the cache |
950 @return A pointer to the requested glyph if it was found in the glyph cache, NULL if it was not found. |
951 @return A pointer to the requested glyph if it was found in the glyph cache, NULL if it was not found. |
951 */ |
952 */ |
952 const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) |
953 const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) const |
953 { |
954 { |
954 if (COpenFontGlyphCache* glyphCache = GetGlyphCache()) |
955 if (COpenFontGlyphCache* glyphCache = GetGlyphCache()) |
955 { |
956 { |
956 if ((aCode & 0x80000000) != 0) |
957 if ((aCode & 0x80000000) != 0) |
957 { |
958 { |
1110 } |
1111 } |
1111 } |
1112 } |
1112 iEntryArray.Close(aHeap); |
1113 iEntryArray.Close(aHeap); |
1113 } |
1114 } |
1114 |
1115 |
1115 const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) |
1116 const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) const |
1116 { |
1117 { |
1117 aIndex = -1; |
1118 aIndex = -1; |
1118 TInt oldest = KMaxTInt; |
|
1119 TInt oldest_index = 0; |
|
1120 TInt numEntries = iEntryArray.Count(); |
1119 TInt numEntries = iEntryArray.Count(); |
1121 TInt index = GLYPH_CODE(aCode) % numEntries; // simple hash function to shorten searches |
1120 TInt index = GLYPH_CODE(aCode) % numEntries; // simple hash function to shorten searches |
1122 for (TInt i = 0; i < numEntries; ++i, ++index) |
1121 for (TInt i = 0; i < numEntries; ++i, ++index) |
1123 { |
1122 { |
1124 if (index >= numEntries) |
1123 if (index >= numEntries) |
|
1124 { |
1125 index = 0; |
1125 index = 0; |
1126 COpenFontSessionCacheEntry* entry = iEntryArray[index]; |
1126 } |
|
1127 const COpenFontSessionCacheEntry* entry = iEntryArray[index]; |
1127 if (entry == NULL) |
1128 if (entry == NULL) |
1128 { |
1129 { |
1129 if (aIndex == -1) |
1130 if (aIndex < 0) |
|
1131 { |
1130 aIndex = index; |
1132 aIndex = index; |
1131 } |
|
1132 else |
|
1133 { |
|
1134 if (entry->Font() == aFont && entry->iCode == aCode) |
|
1135 { |
|
1136 entry->iLastAccess = iLastAccess++; |
|
1137 return entry; |
|
1138 } |
|
1139 if (entry->iLastAccess < oldest) |
|
1140 { |
|
1141 oldest = entry->iLastAccess; |
|
1142 oldest_index = index; |
|
1143 } |
1133 } |
1144 } |
1134 } |
1145 } |
1135 else if (entry->Font() == aFont && entry->iCode == aCode) |
1146 if (aIndex == -1) |
1136 { |
1147 aIndex = oldest_index; |
1137 return entry; |
|
1138 } |
|
1139 } |
1148 return NULL; |
1140 return NULL; |
1149 } |
1141 } |
1150 |
1142 |
1151 |
1143 |
1152 void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex) |
1144 void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex) |
1153 { |
1145 { |
1154 if (aIndex < 0 || aIndex >= iEntryArray.Count()) |
1146 if (aIndex >= iEntryArray.Count()) |
1155 { |
1147 { |
1156 Panic(EFntSessionCacheIndexOutOfRange); |
1148 Panic(EFntSessionCacheIndexOutOfRange); |
1157 } |
1149 } |
|
1150 if (aIndex < 0) |
|
1151 { |
|
1152 aIndex = Math::Rand(iRandomSeed) % iEntryArray.Count(); |
|
1153 } |
1158 COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]); |
1154 COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]); |
1159 iEntryArray.SetAt(aIndex, aEntry); |
1155 iEntryArray.SetAt(aIndex, aEntry); |
1160 aEntry->iLastAccess = iLastAccess++; |
|
1161 } |
1156 } |
1162 |
1157 |
1163 COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle): |
1158 COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle): |
1164 iSessionHandle(aSessionHandle), |
1159 iSessionHandle(aSessionHandle), |
1165 iLastAccess(0) |
1160 iRandomSeed(0) |
1166 { |
1161 { |
1167 } |
1162 } |
1168 |
1163 |
1169 TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache) |
1164 TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache) |
1170 { |
1165 { |
1171 for (TInt index = 0; index < EMaxNumCaches; ++index) |
1166 for (TInt index = 0; index < EMaxNumCaches; ++index) |