Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 #include "TBitmapDoc.h"
23 EXPORT_C CTestBitmapFile* CTestBitmapFile::NewLC(const TRect& aDisplayRect, TCharFormat aCharFormat)
25 CTestBitmapFile* retVal = new(ELeave)CTestBitmapFile();
26 CleanupStack::PushL(retVal);
27 retVal->iDisplayRect = aDisplayRect;
28 retVal->iCharFormat = aCharFormat;
33 CTestBitmapFile::CTestBitmapFile()
34 :CActive(CActive::EPriorityStandard), iSaveUtil(0), iCharFormat(_L("NewTimes"),300)
38 void CTestBitmapFile::ConstructL()
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));
47 //create bitmap device from bitmap
48 iDevice = CFbsBitmapDevice::NewL(iBitmap);
49 CleanupStack::PushL(iDevice);
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);
61 //create text layout from document model and rectangle
62 iLayout = CTextLayout::NewL(iDocModel, iDisplayRect.Width());
63 CleanupStack::PushL(iLayout);
65 //create text view from layout, rectangle and device
66 iView = CTextView::NewL(iLayout, iDisplayRect, iDevice, iDevice, 0, 0, 0);
67 CleanupStack::PushL(iView);
69 //Initialise text content
70 iView->SetDocPosL(0); //seem to need this otherwise
71 iView->HandleGlobalChangeL(); //not all text is displayed
74 User::LeaveIfError(iFs.Connect());
75 CleanupClosePushL(iFs);
77 CActiveScheduler::Add(this);
79 CleanupStack::Pop(9,iBitmap);
82 void CTestBitmapFile::Delete(void* aObj)
91 EXPORT_C CTestBitmapFile::~CTestBitmapFile()
97 Delete(iCharFormatLayer);
98 Delete(iParaFormatLayer);
105 EXPORT_C TBool CTestBitmapFile::CompareL(const TDes8& aData)
107 __ASSERT_ALWAYS(!IsActive(),User::Invariant());
109 // create a CImageEncoder to create a bitmap descriptor
115 iSaveUtil = CImageEncoder::DataNewL(buf, CImageEncoder::EOptionNone, KImageTypeBMPUid);
116 // start reading the bitmap: RunL called when complete
117 iSaveUtil->Convert(&iStatus, *iBitmap);
119 CActiveScheduler::Start();
120 TBool ret = aData.CompareC(buf->Des()) == 0;
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)
132 __ASSERT_ALWAYS(!IsActive(),User::Invariant());
133 // create a CImageEncoder to save the bitmap to the specified file in the specified format
139 iSaveUtil = CImageEncoder::FileNewL(iFs, aFileName, CImageEncoder::EOptionNone, KImageTypeBMPUid);
140 // start saving the bitmap: RunL called when complete
141 iSaveUtil->Convert(&iStatus, *iBitmap);
143 CActiveScheduler::Start();
146 EXPORT_C void CTestBitmapFile::AppendL(const TDesC& aString)
148 iDocModel->InsertL(iDocModel->DocumentLength(),aString);
151 EXPORT_C void CTestBitmapFile::AppendL(CPicture* aPic)
153 TPictureHeader header;
154 header.iPicture=aPic;
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);
166 void CTestBitmapFile::RunL()
168 CActiveScheduler::Stop();
171 void CTestBitmapFile::DoCancel()
173 // Cancel everything possible
174 if (iSaveUtil) iSaveUtil->Cancel();
177 EXPORT_C CTestBitmapZipFileExtractor* CTestBitmapZipFileExtractor::NewLC(const TDesC& aZipFile)
179 CTestBitmapZipFileExtractor* retVal = new(ELeave)CTestBitmapZipFileExtractor;
180 CleanupStack::PushL(retVal);
181 retVal->ConstructL(aZipFile);
185 void CTestBitmapZipFileExtractor::ConstructL(const TDesC& aZipFile)
187 User::LeaveIfError(iFs.Connect());
188 iZipFile = CZipFile::NewL(iFs,aZipFile);
191 CTestBitmapZipFileExtractor::CTestBitmapZipFileExtractor():iBuf(0)
195 EXPORT_C CTestBitmapZipFileExtractor::~CTestBitmapZipFileExtractor()
210 EXPORT_C TPtr8 CTestBitmapZipFileExtractor::BitmapFileL(const TDesC& aFilename)
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();
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);