sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
* @file
|
sl@0
|
16 |
* @internalComponent
|
sl@0
|
17 |
*
|
sl@0
|
18 |
*/
|
sl@0
|
19 |
|
sl@0
|
20 |
|
sl@0
|
21 |
#include "TBitmapDoc.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
EXPORT_C CTestBitmapFile* CTestBitmapFile::NewLC(const TRect& aDisplayRect, TCharFormat aCharFormat)
|
sl@0
|
24 |
{
|
sl@0
|
25 |
CTestBitmapFile* retVal = new(ELeave)CTestBitmapFile();
|
sl@0
|
26 |
CleanupStack::PushL(retVal);
|
sl@0
|
27 |
retVal->iDisplayRect = aDisplayRect;
|
sl@0
|
28 |
retVal->iCharFormat = aCharFormat;
|
sl@0
|
29 |
retVal->ConstructL();
|
sl@0
|
30 |
return retVal;
|
sl@0
|
31 |
}
|
sl@0
|
32 |
|
sl@0
|
33 |
CTestBitmapFile::CTestBitmapFile()
|
sl@0
|
34 |
:CActive(CActive::EPriorityStandard), iSaveUtil(0), iCharFormat(_L("NewTimes"),300)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
}
|
sl@0
|
37 |
|
sl@0
|
38 |
void CTestBitmapFile::ConstructL()
|
sl@0
|
39 |
{
|
sl@0
|
40 |
//create bitmap from rectangle
|
sl@0
|
41 |
const TInt twipFactor = 10;
|
sl@0
|
42 |
iBitmap = new(ELeave)CFbsBitmap;
|
sl@0
|
43 |
CleanupStack::PushL(iBitmap);
|
sl@0
|
44 |
iBitmap->Create(iDisplayRect.Size(),EColor16);
|
sl@0
|
45 |
iBitmap->SetSizeInTwips(TSize(iDisplayRect.iBr.iX * twipFactor, iDisplayRect.iBr.iY * twipFactor));
|
sl@0
|
46 |
|
sl@0
|
47 |
//create bitmap device from bitmap
|
sl@0
|
48 |
iDevice = CFbsBitmapDevice::NewL(iBitmap);
|
sl@0
|
49 |
CleanupStack::PushL(iDevice);
|
sl@0
|
50 |
|
sl@0
|
51 |
//create rich text document model using a test font
|
sl@0
|
52 |
iParaFormat = CParaFormat::NewLC();
|
sl@0
|
53 |
iParaFormatLayer = CParaFormatLayer::NewL(iParaFormat,iParaFormatMask);
|
sl@0
|
54 |
CleanupStack::PushL(iParaFormatLayer);
|
sl@0
|
55 |
iCharFormatMask.SetAll(); //needed otherwise no font gets set
|
sl@0
|
56 |
iCharFormatLayer = CCharFormatLayer::NewL(iCharFormat,iCharFormatMask);
|
sl@0
|
57 |
CleanupStack::PushL(iCharFormatLayer);
|
sl@0
|
58 |
iDocModel = CRichText::NewL(iParaFormatLayer,iCharFormatLayer);
|
sl@0
|
59 |
CleanupStack::PushL(iDocModel);
|
sl@0
|
60 |
|
sl@0
|
61 |
//create text layout from document model and rectangle
|
sl@0
|
62 |
iLayout = CTextLayout::NewL(iDocModel, iDisplayRect.Width());
|
sl@0
|
63 |
CleanupStack::PushL(iLayout);
|
sl@0
|
64 |
|
sl@0
|
65 |
//create text view from layout, rectangle and device
|
sl@0
|
66 |
iView = CTextView::NewL(iLayout, iDisplayRect, iDevice, iDevice, 0, 0, 0);
|
sl@0
|
67 |
CleanupStack::PushL(iView);
|
sl@0
|
68 |
|
sl@0
|
69 |
//Initialise text content
|
sl@0
|
70 |
iView->SetDocPosL(0); //seem to need this otherwise
|
sl@0
|
71 |
iView->HandleGlobalChangeL(); //not all text is displayed
|
sl@0
|
72 |
|
sl@0
|
73 |
//set up file server
|
sl@0
|
74 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
75 |
CleanupClosePushL(iFs);
|
sl@0
|
76 |
|
sl@0
|
77 |
CActiveScheduler::Add(this);
|
sl@0
|
78 |
|
sl@0
|
79 |
CleanupStack::Pop(9,iBitmap);
|
sl@0
|
80 |
}
|
sl@0
|
81 |
|
sl@0
|
82 |
void CTestBitmapFile::Delete(void* aObj)
|
sl@0
|
83 |
{
|
sl@0
|
84 |
if(aObj)
|
sl@0
|
85 |
{
|
sl@0
|
86 |
delete aObj;
|
sl@0
|
87 |
aObj = NULL;
|
sl@0
|
88 |
}
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
EXPORT_C CTestBitmapFile::~CTestBitmapFile()
|
sl@0
|
92 |
{
|
sl@0
|
93 |
Delete(iSaveUtil);
|
sl@0
|
94 |
Delete(iView);
|
sl@0
|
95 |
Delete(iLayout);
|
sl@0
|
96 |
Delete(iDocModel);
|
sl@0
|
97 |
Delete(iCharFormatLayer);
|
sl@0
|
98 |
Delete(iParaFormatLayer);
|
sl@0
|
99 |
Delete(iParaFormat);
|
sl@0
|
100 |
Delete(iDevice);
|
sl@0
|
101 |
Delete(iBitmap);
|
sl@0
|
102 |
iFs.Close();
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
EXPORT_C TBool CTestBitmapFile::CompareL(const TDes8& aData)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
|
sl@0
|
108 |
HBufC8* buf = NULL;
|
sl@0
|
109 |
// create a CImageEncoder to create a bitmap descriptor
|
sl@0
|
110 |
if(iSaveUtil)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
delete iSaveUtil;
|
sl@0
|
113 |
iSaveUtil = NULL;
|
sl@0
|
114 |
}
|
sl@0
|
115 |
iSaveUtil = CImageEncoder::DataNewL(buf, CImageEncoder::EOptionNone, KImageTypeBMPUid);
|
sl@0
|
116 |
// start reading the bitmap: RunL called when complete
|
sl@0
|
117 |
iSaveUtil->Convert(&iStatus, *iBitmap);
|
sl@0
|
118 |
SetActive();
|
sl@0
|
119 |
CActiveScheduler::Start();
|
sl@0
|
120 |
TBool ret = aData.CompareC(buf->Des()) == 0;
|
sl@0
|
121 |
if (buf)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
delete buf;
|
sl@0
|
124 |
buf = NULL;
|
sl@0
|
125 |
}
|
sl@0
|
126 |
return ret;
|
sl@0
|
127 |
}
|
sl@0
|
128 |
|
sl@0
|
129 |
// This was used to create the bitmap files for comparison - not used in actual testing
|
sl@0
|
130 |
EXPORT_C void CTestBitmapFile::SaveFileL(const TDesC& aFileName)
|
sl@0
|
131 |
{
|
sl@0
|
132 |
__ASSERT_ALWAYS(!IsActive(),User::Invariant());
|
sl@0
|
133 |
// create a CImageEncoder to save the bitmap to the specified file in the specified format
|
sl@0
|
134 |
if(iSaveUtil)
|
sl@0
|
135 |
{
|
sl@0
|
136 |
delete iSaveUtil;
|
sl@0
|
137 |
iSaveUtil = NULL;
|
sl@0
|
138 |
}
|
sl@0
|
139 |
iSaveUtil = CImageEncoder::FileNewL(iFs, aFileName, CImageEncoder::EOptionNone, KImageTypeBMPUid);
|
sl@0
|
140 |
// start saving the bitmap: RunL called when complete
|
sl@0
|
141 |
iSaveUtil->Convert(&iStatus, *iBitmap);
|
sl@0
|
142 |
SetActive();
|
sl@0
|
143 |
CActiveScheduler::Start();
|
sl@0
|
144 |
}
|
sl@0
|
145 |
|
sl@0
|
146 |
EXPORT_C void CTestBitmapFile::AppendL(const TDesC& aString)
|
sl@0
|
147 |
{
|
sl@0
|
148 |
iDocModel->InsertL(iDocModel->DocumentLength(),aString);
|
sl@0
|
149 |
}
|
sl@0
|
150 |
|
sl@0
|
151 |
EXPORT_C void CTestBitmapFile::AppendL(CPicture* aPic)
|
sl@0
|
152 |
{
|
sl@0
|
153 |
TPictureHeader header;
|
sl@0
|
154 |
header.iPicture=aPic;
|
sl@0
|
155 |
|
sl@0
|
156 |
//CRichText::InsertL (iDocModel) takes ownership of the picture via TPictureHeader
|
sl@0
|
157 |
TInt docLength = iDocModel->DocumentLength();
|
sl@0
|
158 |
iDocModel->InsertL(docLength,header);
|
sl@0
|
159 |
iView->FormatTextL();
|
sl@0
|
160 |
CFbsBitGc* gc = CFbsBitGc::NewL();
|
sl@0
|
161 |
iDevice->CreateContext(gc);
|
sl@0
|
162 |
iView->DrawL(iDisplayRect, *gc);
|
sl@0
|
163 |
iView->SetDocPosL(docLength+1, EFalse);
|
sl@0
|
164 |
}
|
sl@0
|
165 |
|
sl@0
|
166 |
void CTestBitmapFile::RunL()
|
sl@0
|
167 |
{
|
sl@0
|
168 |
CActiveScheduler::Stop();
|
sl@0
|
169 |
}
|
sl@0
|
170 |
|
sl@0
|
171 |
void CTestBitmapFile::DoCancel()
|
sl@0
|
172 |
{
|
sl@0
|
173 |
// Cancel everything possible
|
sl@0
|
174 |
if (iSaveUtil) iSaveUtil->Cancel();
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
EXPORT_C CTestBitmapZipFileExtractor* CTestBitmapZipFileExtractor::NewLC(const TDesC& aZipFile)
|
sl@0
|
178 |
{
|
sl@0
|
179 |
CTestBitmapZipFileExtractor* retVal = new(ELeave)CTestBitmapZipFileExtractor;
|
sl@0
|
180 |
CleanupStack::PushL(retVal);
|
sl@0
|
181 |
retVal->ConstructL(aZipFile);
|
sl@0
|
182 |
return retVal;
|
sl@0
|
183 |
}
|
sl@0
|
184 |
|
sl@0
|
185 |
void CTestBitmapZipFileExtractor::ConstructL(const TDesC& aZipFile)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
User::LeaveIfError(iFs.Connect());
|
sl@0
|
188 |
iZipFile = CZipFile::NewL(iFs,aZipFile);
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
CTestBitmapZipFileExtractor::CTestBitmapZipFileExtractor():iBuf(0)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
}
|
sl@0
|
194 |
|
sl@0
|
195 |
EXPORT_C CTestBitmapZipFileExtractor::~CTestBitmapZipFileExtractor()
|
sl@0
|
196 |
{
|
sl@0
|
197 |
if(iZipFile)
|
sl@0
|
198 |
{
|
sl@0
|
199 |
delete iZipFile;
|
sl@0
|
200 |
iZipFile = NULL;
|
sl@0
|
201 |
}
|
sl@0
|
202 |
if(iBuf)
|
sl@0
|
203 |
{
|
sl@0
|
204 |
delete iBuf;
|
sl@0
|
205 |
iBuf = NULL;
|
sl@0
|
206 |
}
|
sl@0
|
207 |
iFs.Close();
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
EXPORT_C TPtr8 CTestBitmapZipFileExtractor::BitmapFileL(const TDesC& aFilename)
|
sl@0
|
211 |
{
|
sl@0
|
212 |
//Get a pointer to the bitmap data (member) from the zip file
|
sl@0
|
213 |
CZipFileMember* member = iZipFile->MemberL(aFilename);
|
sl@0
|
214 |
CleanupStack::PushL(member);
|
sl@0
|
215 |
User::LeaveIfNull(member);
|
sl@0
|
216 |
//Get the bitmap data as a filestream
|
sl@0
|
217 |
RZipFileMemberReaderStream* fileStream;
|
sl@0
|
218 |
iZipFile->GetInputStreamL(member,fileStream);
|
sl@0
|
219 |
CleanupStack::PushL(fileStream);
|
sl@0
|
220 |
TUint32 usize = member->UncompressedSize();
|
sl@0
|
221 |
if(iBuf)
|
sl@0
|
222 |
{
|
sl@0
|
223 |
delete iBuf;
|
sl@0
|
224 |
iBuf = NULL;
|
sl@0
|
225 |
}
|
sl@0
|
226 |
iBuf = HBufC8::New(usize);
|
sl@0
|
227 |
CleanupStack::PushL(iBuf);
|
sl@0
|
228 |
//Convert the filestream to a descriptor
|
sl@0
|
229 |
TPtr8 ptr = iBuf->Des();
|
sl@0
|
230 |
User::LeaveIfError(fileStream->Read(ptr,usize));
|
sl@0
|
231 |
CleanupStack::Pop(iBuf);
|
sl@0
|
232 |
CleanupStack::PopAndDestroy(2,member);
|
sl@0
|
233 |
return ptr;
|
sl@0
|
234 |
}
|