Update contrib.
1 // Copyright (c) 2010 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 "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Contains utility classes/functions which are
15 // shared across multiple tests.
20 #include <ecom/ecom.h>
21 #include <ecom/implementationproxy.h>
22 #include <graphics/openfontconstants.h>
23 #include <graphics/openfontrasterizer.h>
24 #include <test/graphicsfontutils.h>
26 // The width of 1000 pixels, in twips
27 const TInt KDefaultWidthInTwips = 11860;
28 const TInt KDefaultHeightInTwips = 11860;
31 Used for cleanup of RImplInfoArray implementationArray
32 in CCharCodeConverter::LoadOpenFontLibraries().
34 void ResetAndDestroyRImplInfoPtrArray(TAny* aPtr)
36 RImplInfoPtrArray* array = reinterpret_cast <RImplInfoPtrArray*> (aPtr);
37 array->ResetAndDestroy();
41 CCharCodeConverter::CCharCodeConverter()
45 EXPORT_C CCharCodeConverter::~CCharCodeConverter()
49 iFontStore->ReleaseFont(iFont);
52 REComSession::FinalClose();
55 EXPORT_C CCharCodeConverter* CCharCodeConverter::NewL()
57 CCharCodeConverter* self = new(ELeave) CCharCodeConverter();
58 CleanupStack::PushL(self);
60 CleanupStack::Pop(1); // self;
64 EXPORT_C CCharCodeConverter* CCharCodeConverter::NewLC()
66 CCharCodeConverter* self = new(ELeave) CCharCodeConverter();
67 CleanupStack::PushL(self);
72 void CCharCodeConverter::ConstructL()
75 iFontStore = CFontStore::NewL(&User::Heap());
76 iFontStore->iKPixelWidthInTwips = KDefaultWidthInTwips;
77 iFontStore->iKPixelHeightInTwips = KDefaultHeightInTwips;
78 //load all ecom implemented rasterizer dlls. installs the rasterizer.
79 LoadOpenFontLibraries(iFontStore);
80 //add any required font files
81 iFontStore->LoadFontsAtStartupL();
84 void CCharCodeConverter::LoadOpenFontLibraries(CFontStore* aFontStore)
86 RImplInfoPtrArray implementationArray;
87 TCleanupItem cleanup(ResetAndDestroyRImplInfoPtrArray, &implementationArray);
88 CleanupStack::PushL(cleanup);
92 TUid uid = {KUidOpenFontRasterizerPlunginInterface};
94 // Making sure that no race situation arises
95 // If ECom is not ready, give it another chance and try again. if it still doesn't work
96 // after the third try, then it just carries on quietly and fails...
97 for (ecomnotready = 0; ecomnotready < 3; ecomnotready++)
99 TRAP(ecomerror,REComSession::ListImplementationsL(uid, implementationArray));
100 if (ecomerror == KErrNone)
106 ecomerror = KErrNone;
111 const TInt availCount = implementationArray.Count();
112 for (TInt count = 0; count < availCount; ++count)
114 const CImplementationInformation* info = implementationArray[count];
115 TUid rasterizerUid = info->ImplementationUid();
116 // Create a rasterizer
117 COpenFontRasterizer* rasterizer = 0;
118 TRAP(error,rasterizer = COpenFontRasterizer::NewL(rasterizerUid));
121 // Install it in the font store.
122 TRAP(error,aFontStore->InstallRasterizerL(rasterizer));
129 CleanupStack::PopAndDestroy(&implementationArray);
133 Tells the converter which font object is to be used when
134 converting character codes to glyph codes.
135 @param aFont The font to use for conversion of codes
137 EXPORT_C void CCharCodeConverter::UseFontL(CFbsFont* aFont)
139 User::LeaveIfNull(iFontStore);
142 iFontStore->ReleaseFont(iFont);
144 iGlyphIndexExt = NULL;
146 // Setup font interface...
147 TFontSpec testFontSpec(aFont->FontSpecInTwips().iTypeface.Name(), aFont->HeightInPixels());
149 iFontStore->GetNearestFontToDesignHeightInPixels(*&cfont, testFontSpec);
150 iFont = (CBitmapFont*)cfont;
151 User::LeaveIfNull(iFont);
153 // This is the interface used to get the glyph code index from the rasterizer..
154 iFont->OpenFont()->ExtendedInterface(KUidOpenFontShapingExtension, ext);
155 iGlyphIndexExt = reinterpret_cast<MOpenFontShapingExtension*>(ext);
156 User::LeaveIfNull(ext);
160 Returns the glyph code for the given character code, for the
161 font that this object was constructed with. No shaping of
162 the characters is performed by this function.
163 @param aCharCode The character code to request the glyph code for.
164 @return The glyph code
166 EXPORT_C TInt CCharCodeConverter::GlyphCodeL(TInt aCharCode) const
168 // If a leave occurs, it's because UseFontL() has
169 // not been successfully called.
170 User::LeaveIfNull(iGlyphIndexExt);
171 TInt glyphCode = iGlyphIndexExt->GlyphIndex(aCharCode);