fontservices/fontstore/src/OPENFONT.CPP
branchRCL_3
changeset 17 336bee5c2d35
parent 16 748ec5531811
child 18 dd58c6eee052
equal deleted inserted replaced
16:748ec5531811 17:336bee5c2d35
    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 
       
    31 #include "OstTraceDefinitions.h"
       
    32 #ifdef OST_TRACE_COMPILER_IN_USE
       
    33 #include "OPENFONTTraces.h"
       
    34 #endif
       
    35 
       
    36 
    29 
    37 const TInt KSessionCacheEntries = 512;
    30 const TInt KSessionCacheEntries = 512;
    38 const TInt KDefaultSlantFactor = 20480;
    31 const TInt KDefaultSlantFactor = 20480;
    39 const TInt KOneIn16Dot16FixedPointFormat = 65536;
    32 const TInt KOneIn16Dot16FixedPointFormat = 65536;
    40 
    33 
   525 */
   518 */
   526 EXPORT_C COpenFont::~COpenFont()
   519 EXPORT_C COpenFont::~COpenFont()
   527 	{
   520 	{
   528 	//Delete the shaper
   521 	//Delete the shaper
   529 	delete iShaper;
   522 	delete iShaper;
   530 
       
   531 	File()->GetFontStore()->CleanupCacheOnOpenFontRemoval(this);
       
   532 	
   523 	
   533 	COpenFontGlyphCache* glyphCache = GetGlyphCache();
   524 	COpenFontGlyphCache* glyphCache = GetGlyphCache();
   534 	if (glyphCache != NULL)
   525 	if (glyphCache != NULL)
   535 		{
   526 		{
   536 		glyphCache->iGlyphTreeById.ResetAndDestroy();
   527 		glyphCache->iGlyphTreeById.ResetAndDestroy();
   793 void COpenFont::DeleteShaper() const
   784 void COpenFont::DeleteShaper() const
   794 	{
   785 	{
   795 	delete iShaper;
   786 	delete iShaper;
   796 	}
   787 	}
   797 
   788 
   798 TInt COpenFont::GetFontTable(TUint32 aTag, TAny*& aTableContent, TInt& aLength) 
       
   799     {
       
   800     // get the extension API for GetTrueTypeTable() if available
       
   801     TAny* ext = NULL;
       
   802     ExtendedInterface(KUidOpenFontTrueTypeExtension, ext);
       
   803     MOpenFontTrueTypeExtension* extensionInterface = 
       
   804         reinterpret_cast<MOpenFontTrueTypeExtension*>(ext);
       
   805 
       
   806     TInt ret = KErrNone;
       
   807     if (extensionInterface == NULL)
       
   808         {
       
   809         ret = KErrNotSupported;
       
   810         }
       
   811     else 
       
   812         {
       
   813         TUint32 tag = aTag;
       
   814         TInt len = 0;
       
   815         aTableContent = extensionInterface->GetTrueTypeTable(ret, tag, &len);
       
   816         if (KErrNone == ret) 
       
   817             {
       
   818             aLength = len;
       
   819             }
       
   820         }
       
   821     return ret;
       
   822     }
       
   823 
       
   824 TInt COpenFont::GetGlyphOutline(TUint aCode, 
       
   825         TBool aHinted, TAny*& aOutline, TInt &aLength) 
       
   826     {
       
   827     // get the extension API for GetTrueTypeTable() if available
       
   828     TAny* ext = NULL;
       
   829     ExtendedInterface(KUidOpenFontGlyphOutlineExtension, ext);
       
   830     MOpenFontGlyphOutlineExtension *extensionInterface = 
       
   831         reinterpret_cast<MOpenFontGlyphOutlineExtension*>(ext);
       
   832 
       
   833     TInt ret = KErrNone;
       
   834     if (extensionInterface == NULL)
       
   835         {
       
   836         ret = KErrNotSupported;
       
   837         }
       
   838     else 
       
   839         {
       
   840         ret = extensionInterface->GetGlyphOutline(aCode, ETrue, 
       
   841                 aHinted, aOutline, aLength);
       
   842         }
       
   843     return ret;
       
   844     }
       
   845 
       
   846 
   789 
   847 /**
   790 /**
   848 A constructor initialised with a TCharacterMetrics object.
   791 A constructor initialised with a TCharacterMetrics object.
   849 
   792 
   850 This is the old-style character metrics object. As for other T classes, there 
   793 This is the old-style character metrics object. As for other T classes, there 
   903 void COpenFont::OnFileDeleted()
   846 void COpenFont::OnFileDeleted()
   904 	{
   847 	{
   905     iFileOffset = 0;
   848     iFileOffset = 0;
   906 	}
   849 	}
   907 
   850 
   908 COpenFontGlyphCache* COpenFont::GetGlyphCache() const
   851 COpenFontGlyphCache* COpenFont::GetGlyphCache()
   909 	{
   852 	{
   910     if (iGlyphCacheOffset == 0)
   853     if (iGlyphCacheOffset == 0)
   911         {
   854         {
   912         return NULL;
   855         return NULL;
   913         }
   856         }
   914     return reinterpret_cast<COpenFontGlyphCache*>(PtrAdd(const_cast<COpenFont*>(this), iGlyphCacheOffset));
   857     return reinterpret_cast<COpenFontGlyphCache*>(PtrAdd(this, iGlyphCacheOffset));
   915 	}
   858 	}
   916 
   859 
   917 const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const
   860 const COpenFontGlyph* COpenFont::Glyph(TInt aSessionHandle, TInt aCode) const
   918 	{	
   861 	{	
   919 	const COpenFontGlyph* glyph = const_cast<COpenFont*>(this)->FontCacheGlyph(aCode);
   862 	const COpenFontGlyph* glyph = const_cast<COpenFont*>(this)->FontCacheGlyph(aCode);
   948 be resized - this is not allowed by the kernel.
   891 be resized - this is not allowed by the kernel.
   949 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
   950 @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
   951 @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.
   952 */
   895 */
   953 const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode) const
   896 const COpenFontGlyph* COpenFont::FontCacheGlyph(TInt aCode)
   954 	{
   897 	{
   955 	if (COpenFontGlyphCache* glyphCache = GetGlyphCache())
   898 	if (COpenFontGlyphCache* glyphCache = GetGlyphCache())
   956 		{
   899 		{
   957 		if ((aCode & 0x80000000) != 0)
   900 		if ((aCode & 0x80000000) != 0)
   958 			{
   901 			{
  1111             }
  1054             }
  1112         }
  1055         }
  1113     iEntryArray.Close(aHeap);
  1056     iEntryArray.Close(aHeap);
  1114     }
  1057     }
  1115 
  1058 
  1116 const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex) const
  1059 const COpenFontGlyph* COpenFontSessionCache::Glyph(const COpenFont* aFont, TInt aCode, TInt& aIndex)
  1117 	{
  1060 	{
  1118     aIndex = -1;
  1061     aIndex = -1;
       
  1062     TInt oldest = KMaxTInt;
       
  1063     TInt oldest_index = 0;
  1119     TInt numEntries = iEntryArray.Count();
  1064     TInt numEntries = iEntryArray.Count();
  1120     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
  1121     for (TInt i = 0; i < numEntries; ++i, ++index)
  1066     for (TInt i = 0; i < numEntries; ++i, ++index)
  1122         {
  1067         {
  1123         if (index >= numEntries)
  1068         if (index >= numEntries)
  1124             {
       
  1125             index = 0;
  1069             index = 0;
  1126             }
  1070         COpenFontSessionCacheEntry* entry = iEntryArray[index];
  1127         const COpenFontSessionCacheEntry* entry = iEntryArray[index];
       
  1128         if (entry == NULL)
  1071         if (entry == NULL)
  1129             {
  1072             {
  1130             if (aIndex < 0)
  1073             if (aIndex == -1)
       
  1074                 aIndex = index;
       
  1075             }
       
  1076         else
       
  1077             { 
       
  1078             if (entry->Font() == aFont && entry->iCode == aCode)
  1131                 {
  1079                 {
  1132                 aIndex = index;
  1080                 entry->iLastAccess = iLastAccess++;
       
  1081                 return entry;
       
  1082                 }
       
  1083             if (entry->iLastAccess < oldest)
       
  1084                 {
       
  1085                 oldest = entry->iLastAccess;
       
  1086                 oldest_index = index;
  1133                 }
  1087                 }
  1134             }
  1088             }
  1135         else if (entry->Font() == aFont && entry->iCode == aCode)
       
  1136             {
       
  1137             return entry;
       
  1138             }
       
  1139         }
  1089         }
       
  1090     if (aIndex == -1)
       
  1091         aIndex = oldest_index;
  1140     return NULL;
  1092     return NULL;
  1141 	}
  1093 	}
  1142 
  1094 
  1143 
  1095 
  1144 void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex)
  1096 void COpenFontSessionCache::Insert(RHeap* aHeap, COpenFontSessionCacheEntry* aEntry, TInt aIndex)
  1145 	{
  1097 	{
  1146     if (aIndex >= iEntryArray.Count())
  1098     if (aIndex < 0 || aIndex >= iEntryArray.Count())
  1147         {
  1099         {
  1148         Panic(EFntSessionCacheIndexOutOfRange);
  1100         Panic(EFntSessionCacheIndexOutOfRange);
  1149         }
  1101         }
  1150     if (aIndex < 0)
       
  1151         {
       
  1152         aIndex = Math::Rand(iRandomSeed) % iEntryArray.Count();
       
  1153         }
       
  1154     COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]);
  1102     COpenFontSessionCacheEntry::Delete(aHeap, iEntryArray[aIndex]);
  1155     iEntryArray.SetAt(aIndex, aEntry);
  1103     iEntryArray.SetAt(aIndex, aEntry);
       
  1104     aEntry->iLastAccess = iLastAccess++;
  1156 	}
  1105 	}
  1157 
  1106 
  1158 COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle):
  1107 COpenFontSessionCache::COpenFontSessionCache(TInt aSessionHandle):
  1159     iSessionHandle(aSessionHandle),
  1108     iSessionHandle(aSessionHandle),
  1160     iRandomSeed(0)
  1109     iLastAccess(0)
  1161     {
  1110     {    
  1162     }
  1111     }
  1163 
  1112 
  1164 TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache)
  1113 TInt COpenFontSessionCacheList::AddCache(COpenFontSessionCache* aCache)
  1165 	{
  1114 	{
  1166 	for (TInt index = 0; index < EMaxNumCaches; ++index)
  1115 	for (TInt index = 0; index < EMaxNumCaches; ++index)
  1292 const TUint16 KSignBit = 1<<(KBitsForUnderline-1); //sign bit for the lower number, which can be signed
  1241 const TUint16 KSignBit = 1<<(KBitsForUnderline-1); //sign bit for the lower number, which can be signed
  1293 const TUint32 KTop16Of32Bits = 0xffff0000; 
  1242 const TUint32 KTop16Of32Bits = 0xffff0000; 
  1294 
  1243 
  1295 EXPORT_C void TOpenFontMetrics::SetBaselineCorrection(TInt aBaselineCorrection)
  1244 EXPORT_C void TOpenFontMetrics::SetBaselineCorrection(TInt aBaselineCorrection)
  1296 	{
  1245 	{
  1297 	if (aBaselineCorrection >= (1<<(KBitsForUnderline-1)))
  1246 	__ASSERT_DEBUG(aBaselineCorrection<(1<<(KBitsForUnderline-1)), Panic(EFntOverFlow));
  1298 	    {
  1247 	__ASSERT_DEBUG(aBaselineCorrection>(0-(1<<(KBitsForUnderline-1))), Panic(EFntOverFlow));
  1299 	    OstTrace1( TRACE_FATAL, TOPENFONTMETRICS_SETBASELINECORRECTION, "aBaselineCorrection=%d, Panic(EFntOverFlow)", aBaselineCorrection );
       
  1300 	    __ASSERT_DEBUG(0, Panic(EFntOverFlow));
       
  1301 	    }
       
  1302 	if (aBaselineCorrection <= (0-(1<<(KBitsForUnderline-1))))
       
  1303 	    {
       
  1304 	    OstTrace1( TRACE_FATAL, DUP1_TOPENFONTMETRICS_SETBASELINECORRECTION, "aBaselineCorrection=%d, Panic(EFntOverFlow)", aBaselineCorrection );
       
  1305 	    __ASSERT_DEBUG(0, Panic(EFntOverFlow));
       
  1306 	    }
       
  1307 	
  1248 	
  1308 	TUint16 value = iBaselineCorrection;
  1249 	TUint16 value = iBaselineCorrection;
  1309 	value &=~KMaskUnderline; //zero all the underline position bits
  1250 	value &=~KMaskUnderline; //zero all the underline position bits
  1310 	if (aBaselineCorrection<0)
  1251 	if (aBaselineCorrection<0)
  1311 		{
  1252 		{
  1373 It is not allowed that file is deleted before its fonts
  1314 It is not allowed that file is deleted before its fonts
  1374 and the logic is handled in CFontStore::RemoveFile().
  1315 and the logic is handled in CFontStore::RemoveFile().
  1375 */
  1316 */
  1376 EXPORT_C COpenFontFile::~COpenFontFile()
  1317 EXPORT_C COpenFontFile::~COpenFontFile()
  1377 	{
  1318 	{
  1378     CFontStore *fs = GetFontStore();
       
  1379     if (fs != NULL)
       
  1380         {
       
  1381         fs->CleanupCacheOnOpenFontFileRemoval(this);
       
  1382         }
       
  1383 	delete iData;
  1319 	delete iData;
  1384 	}
  1320 	}
  1385 
  1321 
  1386 /**
  1322 /**
  1387 Gets the nearest font in pixels.
  1323 Gets the nearest font in pixels.
  1945 TBool TOpenFontSpec::ApplyRatio(TInt& aValue, TInt aNumerator, TInt aDenominator)
  1881 TBool TOpenFontSpec::ApplyRatio(TInt& aValue, TInt aNumerator, TInt aDenominator)
  1946 	{
  1882 	{
  1947 	TInt64 value(aValue);
  1883 	TInt64 value(aValue);
  1948 	value = (value * aNumerator) / aDenominator;
  1884 	value = (value * aNumerator) / aDenominator;
  1949 	aValue = I64LOW(value);
  1885 	aValue = I64LOW(value);
  1950 	if (I64HIGH(value) != 0)
  1886 	__ASSERT_DEBUG(I64HIGH(value) == 0, Panic(EFntOverFlow));
  1951 	    {
       
  1952 	    OstTrace1( TRACE_FATAL, TOPENFONTSPEC_APPLYRATIO, "value=%ld, Panic(EFntOverFlow)", value );
       
  1953 	    __ASSERT_DEBUG(0, Panic(EFntOverFlow));
       
  1954 	    }
       
  1955 	return I64HIGH(value) != 0;
  1887 	return I64HIGH(value) != 0;
  1956 	}
  1888 	}
  1957 
  1889 
  1958 /**
  1890 /**
  1959 Same as above function but this takes a TInt32 not a TInt
  1891 Same as above function but this takes a TInt32 not a TInt