graphics/fntstore/src/T_TestOpenFont.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Creates a dummy rasterizer and a dummy shaper for FontStore APIs testing.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32std.h>
       
    19 #include <f32file.h>
       
    20 #include "T_TestOpenFont.h"
       
    21 
       
    22 CTestRasterizer* CTestRasterizer::NewL()
       
    23 	{
       
    24 	return new(ELeave) CTestRasterizer;
       
    25 	}
       
    26 
       
    27 COpenFontFile* CTestRasterizer::NewFontFileL(TInt aUid,const TDesC& aFileName,RFs& /*aFileSession*/)
       
    28 	{
       
    29 	TParse parse;
       
    30 	parse.Set(aFileName, NULL, NULL);
       
    31 
       
    32 	if (parse.Name().CompareF(KTestFont1) == 0 || parse.Name().CompareF(KTestFont2) == 0)
       
    33 		{
       
    34 		// create a dummy font.
       
    35 		return CTestFontFile::NewL(aUid,aFileName);
       
    36 		}
       
    37 	else
       
    38 		{
       
    39 		return NULL;	
       
    40 		}	
       
    41 	}
       
    42 
       
    43 CTestFontFile::CTestFontFile(TInt aUid, const TDesC& aFileName)
       
    44 : COpenFontFile(aUid, aFileName)
       
    45 	{
       
    46 	}
       
    47 
       
    48 CTestFontFile* CTestFontFile::NewL(TInt aUid, const TDesC& aFileName)
       
    49 	{
       
    50 	CTestFontFile* self = new(ELeave)CTestFontFile(aUid,aFileName);
       
    51 	CleanupStack::PushL(self);
       
    52 	self->ConstructL();
       
    53 	CleanupStack::Pop();
       
    54 	return self;
       
    55 	}
       
    56 
       
    57 TBool CTestFontFile::GetNearestFontHelper(const TOpenFontSpec& aDesiredFontSpec, TInt aPixelWidth, TInt aPixelHeight,
       
    58 											  TInt& aFaceIndex, TOpenFontSpec& aActualFontSpec) const
       
    59 	{
       
    60 	return COpenFontFile::GetNearestFontHelper(aDesiredFontSpec, aPixelWidth, aPixelHeight, aFaceIndex, aActualFontSpec);
       
    61 	}
       
    62 
       
    63 void CTestFontFile::ConstructL()
       
    64 	{
       
    65 	const TDesC& filename = FileName();
       
    66 	TOpenFontFaceAttrib attrib;
       
    67 
       
    68 	if (filename.CompareF(KTestFont1) == 0)
       
    69 		attrib.SetFullName(_L("Test Font1"));
       
    70 	else if (filename.CompareF(KTestFont2) == 0)
       
    71 		{
       
    72 		attrib.SetFullName(_L("Test Font2"));
       
    73 		attrib.SetBold(TRUE);
       
    74 		attrib.SetItalic(TRUE);
       
    75 		}
       
    76 	attrib.SetFamilyName(_L("Test"));
       
    77 	attrib.SetLocalFullName(attrib.FullName());
       
    78 	attrib.SetCoverage(TOpenFontFaceAttrib::ELatinSet);
       
    79 	attrib.SetMinSizeInPixels(8);
       
    80 	AddFaceL(attrib);
       
    81 	}
       
    82 
       
    83 void CTestFontFile::GetNearestFontInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
       
    84 											 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
       
    85 											 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec)
       
    86 	{
       
    87 	aFont = NULL;
       
    88 	TInt face_index = 0;
       
    89 	if (GetNearestFontHelper(aDesiredFontSpec,aPixelWidth,aPixelHeight,face_index,aActualFontSpec))
       
    90 		{
       
    91 		aFont = CTestFont::NewL(aHeap,aSessionCacheList,this,aActualFontSpec.Height());
       
    92 		}
       
    93 	}
       
    94 
       
    95 void CTestFontFile::GetNearestFontToDesignHeightInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
       
    96 											 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
       
    97 											 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec)
       
    98 	{
       
    99 	aFont = NULL;
       
   100 	TInt face_index = 0;
       
   101 	if (GetNearestFontHelper(aDesiredFontSpec,aPixelWidth,aPixelHeight,face_index,aActualFontSpec))
       
   102 		{
       
   103 		aFont = CTestFont::NewL(aHeap,aSessionCacheList,this,aActualFontSpec.Height());
       
   104 		}
       
   105 	}
       
   106 
       
   107 void CTestFontFile::GetNearestFontToMaxHeightInPixelsL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
       
   108 											 const TOpenFontSpec& aDesiredFontSpec,TInt aPixelWidth,TInt aPixelHeight,
       
   109 											 COpenFont*& aFont,TOpenFontSpec& aActualFontSpec,TInt /*aMaxHeight*/)
       
   110 	{
       
   111 	aFont = NULL;
       
   112 	TInt face_index = 0;
       
   113 	if (GetNearestFontHelper(aDesiredFontSpec,aPixelWidth,aPixelHeight,face_index,aActualFontSpec))
       
   114 		{
       
   115 		aFont = CTestFont::NewL(aHeap,aSessionCacheList,this,aActualFontSpec.Height());
       
   116 		}
       
   117 	}
       
   118 
       
   119 TBool CTestFontFile::HasUnicodeCharacterL(TInt /*aFaceIndex*/,TInt /*aCode*/) const
       
   120 	{
       
   121 	// has no characters
       
   122 	return EFalse;
       
   123 	}
       
   124 
       
   125 CTestFont* CTestFont::NewL(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,
       
   126 							 CTestFontFile* aFontFile,TInt aSizeInPixels)
       
   127 	{
       
   128 	CTestFont* f = (CTestFont*)aHeap->AllocL(sizeof(CTestFont));
       
   129 	new(f) CTestFont(aHeap,aSessionCacheList,aFontFile,aSizeInPixels);
       
   130 	return f;
       
   131 	}
       
   132 
       
   133 CTestFont::CTestFont(RHeap* aHeap,COpenFontSessionCacheList* aSessionCacheList,CTestFontFile* aFontFile,
       
   134 					   TInt aSizeInPixels):
       
   135 	COpenFont(aHeap,aSessionCacheList,aFontFile)
       
   136 	{
       
   137 	iMetrics.SetSize(aSizeInPixels);
       
   138 	iMetrics.SetAscent(aSizeInPixels * 3 / 4);
       
   139 	iMetrics.SetDescent(aSizeInPixels - iMetrics.Ascent());
       
   140 	iMetrics.SetMaxHeight(iMetrics.Ascent());
       
   141 	iMetrics.SetMaxDepth(iMetrics.Descent());
       
   142 	iMetrics.SetMaxWidth(aSizeInPixels * 2);
       
   143 	}
       
   144 
       
   145 void CTestFont::RasterizeL(TInt /*aCode*/,TOpenFontGlyphData* /*aGlyphData*/)
       
   146 	{
       
   147 	// has no glyphs
       
   148 	User::Leave(KErrNotSupported); 
       
   149 	}
       
   150 
       
   151 
       
   152 CTestShaperFactory* CTestShaperFactory::NewL()
       
   153 	{
       
   154 	return new(ELeave) CTestShaperFactory;	
       
   155 	}
       
   156 
       
   157 CTestShaperFactory::CTestShaperFactory()
       
   158 	{
       
   159 	}
       
   160 
       
   161 CTestShaperFactory::~CTestShaperFactory()
       
   162 	{	
       
   163 	}
       
   164 
       
   165 
       
   166 CShaper* CTestShaperFactory::NewShaperL(CBitmapFont* aBitmapfont, TInt aScript, TInt aLanguage, RHeap* aHeap)
       
   167 	{
       
   168 	return CTestShaper::NewL(aBitmapfont, aScript, aLanguage, aHeap);
       
   169 	} 
       
   170 
       
   171 void* CShaperFactory::ExtendedInterface(TUid /*aInterfaceId*/)
       
   172 	{
       
   173 	return 0;
       
   174 	}
       
   175 
       
   176 
       
   177 CShaper * CTestShaper::NewL(CBitmapFont* aBitmapfont, TInt aScript, TInt aLanguage, RHeap* aHeap)
       
   178 	{
       
   179 	CTestShaper* self = new(ELeave) CTestShaper();
       
   180 	CleanupStack::PushL(self);
       
   181 	TInt error = self->ConstructL(aBitmapfont, aScript, aLanguage, aHeap);
       
   182 	if (KErrNone == error)
       
   183 		{
       
   184 		CleanupStack::Pop();
       
   185 		return self;
       
   186 		}
       
   187 	else
       
   188 		{
       
   189 		CleanupStack::PopAndDestroy(); 
       
   190 		return NULL;		
       
   191 		}		
       
   192 	} 
       
   193 
       
   194  TInt CTestShaper::ConstructL(CBitmapFont* /*aBitmapfont*/, TInt /*aScript*/, TInt /*aLanguage*/, RHeap* /*aHeap*/ )
       
   195 	{
       
   196 	return KErrNone;
       
   197 	}
       
   198 
       
   199 CTestShaper::CTestShaper()
       
   200 	{
       
   201 	}	
       
   202 		
       
   203  CTestShaper::~CTestShaper()
       
   204 	{
       
   205 	}	
       
   206 
       
   207 TInt CTestShaper::ShapeText(TShapeHeader*& /*aOutput*/, const TInput& /*aInput*/, RHeap* /*aHeapForOutput*/)
       
   208 	{
       
   209  	return KErrNotSupported;
       
   210 	}
       
   211