sl@0
|
1 |
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// Contains utility classes/functions which are
|
sl@0
|
15 |
// shared across multiple tests.
|
sl@0
|
16 |
|
sl@0
|
17 |
#include <gdi.h>
|
sl@0
|
18 |
#include <fbs.h>
|
sl@0
|
19 |
#include <fntstore.h>
|
sl@0
|
20 |
#include <ecom/ecom.h>
|
sl@0
|
21 |
#include <ecom/implementationproxy.h>
|
sl@0
|
22 |
#include <graphics/openfontconstants.h>
|
sl@0
|
23 |
#include <graphics/openfontrasterizer.h>
|
sl@0
|
24 |
#include <test/graphicsfontutils.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
// The width of 1000 pixels, in twips
|
sl@0
|
27 |
const TInt KDefaultWidthInTwips = 11860;
|
sl@0
|
28 |
const TInt KDefaultHeightInTwips = 11860;
|
sl@0
|
29 |
|
sl@0
|
30 |
/*
|
sl@0
|
31 |
Used for cleanup of RImplInfoArray implementationArray
|
sl@0
|
32 |
in CCharCodeConverter::LoadOpenFontLibraries().
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
void ResetAndDestroyRImplInfoPtrArray(TAny* aPtr)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
RImplInfoPtrArray* array = reinterpret_cast <RImplInfoPtrArray*> (aPtr);
|
sl@0
|
37 |
array->ResetAndDestroy();
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
|
sl@0
|
41 |
CCharCodeConverter::CCharCodeConverter()
|
sl@0
|
42 |
{
|
sl@0
|
43 |
}
|
sl@0
|
44 |
|
sl@0
|
45 |
EXPORT_C CCharCodeConverter::~CCharCodeConverter()
|
sl@0
|
46 |
{
|
sl@0
|
47 |
if (iFont)
|
sl@0
|
48 |
{
|
sl@0
|
49 |
iFontStore->ReleaseFont(iFont);
|
sl@0
|
50 |
}
|
sl@0
|
51 |
delete iFontStore;
|
sl@0
|
52 |
REComSession::FinalClose();
|
sl@0
|
53 |
}
|
sl@0
|
54 |
|
sl@0
|
55 |
EXPORT_C CCharCodeConverter* CCharCodeConverter::NewL()
|
sl@0
|
56 |
{
|
sl@0
|
57 |
CCharCodeConverter* self = new(ELeave) CCharCodeConverter();
|
sl@0
|
58 |
CleanupStack::PushL(self);
|
sl@0
|
59 |
self->ConstructL();
|
sl@0
|
60 |
CleanupStack::Pop(1); // self;
|
sl@0
|
61 |
return self;
|
sl@0
|
62 |
}
|
sl@0
|
63 |
|
sl@0
|
64 |
EXPORT_C CCharCodeConverter* CCharCodeConverter::NewLC()
|
sl@0
|
65 |
{
|
sl@0
|
66 |
CCharCodeConverter* self = new(ELeave) CCharCodeConverter();
|
sl@0
|
67 |
CleanupStack::PushL(self);
|
sl@0
|
68 |
self->ConstructL();
|
sl@0
|
69 |
return self;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
void CCharCodeConverter::ConstructL()
|
sl@0
|
73 |
{
|
sl@0
|
74 |
// Setup fontstore...
|
sl@0
|
75 |
iFontStore = CFontStore::NewL(&User::Heap());
|
sl@0
|
76 |
iFontStore->iKPixelWidthInTwips = KDefaultWidthInTwips;
|
sl@0
|
77 |
iFontStore->iKPixelHeightInTwips = KDefaultHeightInTwips;
|
sl@0
|
78 |
//load all ecom implemented rasterizer dlls. installs the rasterizer.
|
sl@0
|
79 |
LoadOpenFontLibraries(iFontStore);
|
sl@0
|
80 |
//add any required font files
|
sl@0
|
81 |
iFontStore->LoadFontsAtStartupL();
|
sl@0
|
82 |
}
|
sl@0
|
83 |
|
sl@0
|
84 |
void CCharCodeConverter::LoadOpenFontLibraries(CFontStore* aFontStore)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
RImplInfoPtrArray implementationArray;
|
sl@0
|
87 |
TCleanupItem cleanup(ResetAndDestroyRImplInfoPtrArray, &implementationArray);
|
sl@0
|
88 |
CleanupStack::PushL(cleanup);
|
sl@0
|
89 |
TInt error;
|
sl@0
|
90 |
TInt ecomerror;
|
sl@0
|
91 |
TInt ecomnotready;
|
sl@0
|
92 |
TUid uid = {KUidOpenFontRasterizerPlunginInterface};
|
sl@0
|
93 |
|
sl@0
|
94 |
// Making sure that no race situation arises
|
sl@0
|
95 |
// If ECom is not ready, give it another chance and try again. if it still doesn't work
|
sl@0
|
96 |
// after the third try, then it just carries on quietly and fails...
|
sl@0
|
97 |
for (ecomnotready = 0; ecomnotready < 3; ecomnotready++)
|
sl@0
|
98 |
{
|
sl@0
|
99 |
TRAP(ecomerror,REComSession::ListImplementationsL(uid, implementationArray));
|
sl@0
|
100 |
if (ecomerror == KErrNone)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
break;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
else
|
sl@0
|
105 |
{
|
sl@0
|
106 |
ecomerror = KErrNone;
|
sl@0
|
107 |
User::After(0);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
const TInt availCount = implementationArray.Count();
|
sl@0
|
112 |
for (TInt count = 0; count < availCount; ++count)
|
sl@0
|
113 |
{
|
sl@0
|
114 |
const CImplementationInformation* info = implementationArray[count];
|
sl@0
|
115 |
TUid rasterizerUid = info->ImplementationUid();
|
sl@0
|
116 |
// Create a rasterizer
|
sl@0
|
117 |
COpenFontRasterizer* rasterizer = 0;
|
sl@0
|
118 |
TRAP(error,rasterizer = COpenFontRasterizer::NewL(rasterizerUid));
|
sl@0
|
119 |
if (!error)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
// Install it in the font store.
|
sl@0
|
122 |
TRAP(error,aFontStore->InstallRasterizerL(rasterizer));
|
sl@0
|
123 |
if (error)
|
sl@0
|
124 |
{
|
sl@0
|
125 |
delete rasterizer;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
}
|
sl@0
|
128 |
}
|
sl@0
|
129 |
CleanupStack::PopAndDestroy(&implementationArray);
|
sl@0
|
130 |
}
|
sl@0
|
131 |
|
sl@0
|
132 |
/**
|
sl@0
|
133 |
Tells the converter which font object is to be used when
|
sl@0
|
134 |
converting character codes to glyph codes.
|
sl@0
|
135 |
@param aFont The font to use for conversion of codes
|
sl@0
|
136 |
*/
|
sl@0
|
137 |
EXPORT_C void CCharCodeConverter::UseFontL(CFbsFont* aFont)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
User::LeaveIfNull(iFontStore);
|
sl@0
|
140 |
if (iFont)
|
sl@0
|
141 |
{
|
sl@0
|
142 |
iFontStore->ReleaseFont(iFont);
|
sl@0
|
143 |
iFont = NULL;
|
sl@0
|
144 |
iGlyphIndexExt = NULL;
|
sl@0
|
145 |
}
|
sl@0
|
146 |
// Setup font interface...
|
sl@0
|
147 |
TFontSpec testFontSpec(aFont->FontSpecInTwips().iTypeface.Name(), aFont->HeightInPixels());
|
sl@0
|
148 |
CFont* cfont = 0;
|
sl@0
|
149 |
iFontStore->GetNearestFontToDesignHeightInPixels(*&cfont, testFontSpec);
|
sl@0
|
150 |
iFont = (CBitmapFont*)cfont;
|
sl@0
|
151 |
User::LeaveIfNull(iFont);
|
sl@0
|
152 |
TAny* ext = 0;
|
sl@0
|
153 |
// This is the interface used to get the glyph code index from the rasterizer..
|
sl@0
|
154 |
iFont->OpenFont()->ExtendedInterface(KUidOpenFontShapingExtension, ext);
|
sl@0
|
155 |
iGlyphIndexExt = reinterpret_cast<MOpenFontShapingExtension*>(ext);
|
sl@0
|
156 |
User::LeaveIfNull(ext);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
/**
|
sl@0
|
160 |
Returns the glyph code for the given character code, for the
|
sl@0
|
161 |
font that this object was constructed with. No shaping of
|
sl@0
|
162 |
the characters is performed by this function.
|
sl@0
|
163 |
@param aCharCode The character code to request the glyph code for.
|
sl@0
|
164 |
@return The glyph code
|
sl@0
|
165 |
*/
|
sl@0
|
166 |
EXPORT_C TInt CCharCodeConverter::GlyphCodeL(TInt aCharCode) const
|
sl@0
|
167 |
{
|
sl@0
|
168 |
// If a leave occurs, it's because UseFontL() has
|
sl@0
|
169 |
// not been successfully called.
|
sl@0
|
170 |
User::LeaveIfNull(iGlyphIndexExt);
|
sl@0
|
171 |
TInt glyphCode = iGlyphIndexExt->GlyphIndex(aCharCode);
|
sl@0
|
172 |
return glyphCode;
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
|