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