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> |
|
30 |
29 |
31 const TInt KSessionCacheEntries = 512; |
30 const TInt KSessionCacheEntries = 512; |
32 const TInt KDefaultSlantFactor = 20480; |
31 const TInt KDefaultSlantFactor = 20480; |
33 const TInt KOneIn16Dot16FixedPointFormat = 65536; |
32 const TInt KOneIn16Dot16FixedPointFormat = 65536; |
34 |
33 |
847 void COpenFont::OnFileDeleted() |
846 void COpenFont::OnFileDeleted() |
848 { |
847 { |
849 iFileOffset = 0; |
848 iFileOffset = 0; |
850 } |
849 } |
851 |
850 |
852 COpenFontGlyphCache* COpenFont::GetGlyphCache() const |
851 COpenFontGlyphCache* COpenFont::GetGlyphCache() |
853 { |
852 { |
854 if (iGlyphCacheOffset == 0) |
853 if (iGlyphCacheOffset == 0) |
855 { |
854 { |
856 return NULL; |
855 return NULL; |
857 } |
856 } |
858 return reinterpret_cast<COpenFontGlyphCache*>(PtrAdd(const_cast<COpenFont*>(this), iGlyphCacheOffset)); |
857 return reinterpret_cast<COpenFontGlyphCache*>(PtrAdd(this, iGlyphCacheOffset)); |
859 } |
858 } |
860 |
859 |
861 const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const |
860 const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const |
862 { |
861 { |
863 const COpenFontGlyph* glyph = const_cast<COpenFont*>(this)->FontCacheGlyph(aCode); |
862 const COpenFontGlyph* glyph = const_cast<COpenFont*>(this)->FontCacheGlyph(aCode); |
892 be resized - this is not allowed by the kernel. |
891 be resized - this is not allowed by the kernel. |
893 The cache is now created in COpenFont::Rasterize which can only be called within the context of FBSERV |
892 The cache is now created in COpenFont::Rasterize which can only be called within the context of FBSERV |
894 @param aCode The code for the glpyh to look for in the cache |
893 @param aCode The code for the glpyh to look for in the cache |
895 @return A pointer to the requested glyph if it was found in the glyph cache, NULL if it was not found. |
894 @return A pointer to the requested glyph if it was found in the glyph cache, NULL if it was not found. |
896 */ |
895 */ |
897 const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) const |
896 const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) |
898 { |
897 { |
899 if (COpenFontGlyphCache* glyphCache = GetGlyphCache()) |
898 if (COpenFontGlyphCache* glyphCache = GetGlyphCache()) |
900 { |
899 { |
901 if ((aCode & 0x80000000) != 0) |
900 if ((aCode & 0x80000000) != 0) |
902 { |
901 { |
1055 } |
1054 } |
1056 } |
1055 } |
1057 iEntryArray.Close(aHeap); |
1056 iEntryArray.Close(aHeap); |
1058 } |
1057 } |
1059 |
1058 |
1060 const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) const |
1059 const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) |
1061 { |
1060 { |
1062 aIndex = -1; |
1061 aIndex = -1; |
|
1062 TInt oldest = KMaxTInt; |
|
1063 TInt oldest_index = 0; |
1063 TInt numEntries = iEntryArray.Count(); |
1064 TInt numEntries = iEntryArray.Count(); |
1064 TInt index = GLYPH_CODE(aCode) % numEntries; // simple hash function to shorten searches |
1065 TInt index = GLYPH_CODE(aCode) % numEntries; // simple hash function to shorten searches |
1065 for (TInt i = 0; i < numEntries; ++i, ++index) |
1066 for (TInt i = 0; i < numEntries; ++i, ++index) |
1066 { |
1067 { |
1067 if (index >= numEntries) |
1068 if (index >= numEntries) |
1068 { |
|
1069 index = 0; |
1069 index = 0; |
1070 } |
1070 COpenFontSessionCacheEntry* entry = iEntryArray[index]; |
1071 const COpenFontSessionCacheEntry* entry = iEntryArray[index]; |
|
1072 if (entry == NULL) |
1071 if (entry == NULL) |
1073 { |
1072 { |
1074 if (aIndex < 0) |
1073 if (aIndex == -1) |
|
1074 aIndex = index; |
|
1075 } |
|
1076 else |
|
1077 { |
|
1078 if (entry->Font() == aFont && entry->iCode == aCode) |
1075 { |
1079 { |
1076 aIndex = index; |
1080 entry->iLastAccess = iLastAccess++; |
|
1081 return entry; |
|
1082 } |
|
1083 if (entry->iLastAccess < oldest) |
|
1084 { |
|
1085 oldest = entry->iLastAccess; |
|
1086 oldest_index = index; |
1077 } |
1087 } |
1078 } |
1088 } |
1079 else if (entry->Font() == aFont && entry->iCode == aCode) |
|
1080 { |
|
1081 return entry; |
|
1082 } |
|
1083 } |
1089 } |
|
1090 if (aIndex == -1) |
|
1091 aIndex = oldest_index; |
1084 return NULL; |
1092 return NULL; |
1085 } |
1093 } |
1086 |
1094 |
1087 |
1095 |
1088 void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex) |
1096 void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex) |
1089 { |
1097 { |
1090 if (aIndex >= iEntryArray.Count()) |
1098 if (aIndex < 0 || aIndex >= iEntryArray.Count()) |
1091 { |
1099 { |
1092 Panic(EFntSessionCacheIndexOutOfRange); |
1100 Panic(EFntSessionCacheIndexOutOfRange); |
1093 } |
1101 } |
1094 if (aIndex < 0) |
|
1095 { |
|
1096 aIndex = Math::Rand(iRandomSeed) % iEntryArray.Count(); |
|
1097 } |
|
1098 COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]); |
1102 COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]); |
1099 iEntryArray.SetAt(aIndex, aEntry); |
1103 iEntryArray.SetAt(aIndex, aEntry); |
|
1104 aEntry->iLastAccess = iLastAccess++; |
1100 } |
1105 } |
1101 |
1106 |
1102 COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle): |
1107 COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle): |
1103 iSessionHandle(aSessionHandle), |
1108 iSessionHandle(aSessionHandle), |
1104 iRandomSeed(0) |
1109 iLastAccess(0) |
1105 { |
1110 { |
1106 } |
1111 } |
1107 |
1112 |
1108 TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache) |
1113 TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache) |
1109 { |
1114 { |
1110 for (TInt index = 0; index < EMaxNumCaches; ++index) |
1115 for (TInt index = 0; index < EMaxNumCaches; ++index) |