os/textandloc/textrendering/textformatting/test/src/TBitmapDoc.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/textrendering/textformatting/test/src/TBitmapDoc.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,234 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* @file
    1.19 +* @internalComponent 
    1.20 +*
    1.21 +*/
    1.22 +
    1.23 +
    1.24 +#include "TBitmapDoc.h"
    1.25 +
    1.26 +EXPORT_C CTestBitmapFile* CTestBitmapFile::NewLC(const TRect& aDisplayRect, TCharFormat aCharFormat)
    1.27 +    {
    1.28 +    CTestBitmapFile* retVal = new(ELeave)CTestBitmapFile();
    1.29 +    CleanupStack::PushL(retVal);
    1.30 +    retVal->iDisplayRect = aDisplayRect;
    1.31 +    retVal->iCharFormat = aCharFormat;
    1.32 +    retVal->ConstructL();
    1.33 +    return retVal;
    1.34 +    }
    1.35 +
    1.36 +CTestBitmapFile::CTestBitmapFile()
    1.37 +:CActive(CActive::EPriorityStandard), iSaveUtil(0), iCharFormat(_L("NewTimes"),300)
    1.38 +    {
    1.39 +    }
    1.40 +
    1.41 +void CTestBitmapFile::ConstructL()
    1.42 +	{
    1.43 +	//create bitmap from rectangle
    1.44 +	const TInt twipFactor = 10;
    1.45 +	iBitmap = new(ELeave)CFbsBitmap;
    1.46 +	CleanupStack::PushL(iBitmap);
    1.47 +	iBitmap->Create(iDisplayRect.Size(),EColor16);
    1.48 +	iBitmap->SetSizeInTwips(TSize(iDisplayRect.iBr.iX * twipFactor, iDisplayRect.iBr.iY * twipFactor));
    1.49 +
    1.50 +	//create bitmap device from bitmap
    1.51 +	iDevice = CFbsBitmapDevice::NewL(iBitmap);
    1.52 +	CleanupStack::PushL(iDevice);
    1.53 +
    1.54 +	//create rich text document model using a test font
    1.55 +	iParaFormat = CParaFormat::NewLC();
    1.56 +	iParaFormatLayer = CParaFormatLayer::NewL(iParaFormat,iParaFormatMask);
    1.57 +	CleanupStack::PushL(iParaFormatLayer);
    1.58 +	iCharFormatMask.SetAll(); //needed otherwise no font gets set
    1.59 +	iCharFormatLayer = CCharFormatLayer::NewL(iCharFormat,iCharFormatMask);
    1.60 +	CleanupStack::PushL(iCharFormatLayer);
    1.61 +	iDocModel = CRichText::NewL(iParaFormatLayer,iCharFormatLayer);
    1.62 +	CleanupStack::PushL(iDocModel);
    1.63 +
    1.64 +	//create text layout from document model and rectangle
    1.65 +	iLayout = CTextLayout::NewL(iDocModel, iDisplayRect.Width());
    1.66 +	CleanupStack::PushL(iLayout);
    1.67 +	
    1.68 +	//create text view from layout, rectangle and device
    1.69 +	iView = CTextView::NewL(iLayout, iDisplayRect, iDevice, iDevice, 0, 0, 0);
    1.70 +	CleanupStack::PushL(iView);
    1.71 +	
    1.72 + 	//Initialise text content
    1.73 +	iView->SetDocPosL(0);         //seem to need this otherwise
    1.74 + 	iView->HandleGlobalChangeL(); //not all text is displayed
    1.75 +
    1.76 +	//set up file server
    1.77 +	User::LeaveIfError(iFs.Connect());
    1.78 +	CleanupClosePushL(iFs);
    1.79 +
    1.80 +	CActiveScheduler::Add(this);
    1.81 +
    1.82 +	CleanupStack::Pop(9,iBitmap);
    1.83 +	}
    1.84 +
    1.85 +void CTestBitmapFile::Delete(void* aObj)
    1.86 +    {
    1.87 +    if(aObj)
    1.88 +    	{
    1.89 +    	delete aObj;
    1.90 +	    aObj = NULL;
    1.91 +    	}
    1.92 +    }
    1.93 +
    1.94 +EXPORT_C CTestBitmapFile::~CTestBitmapFile()
    1.95 +    {
    1.96 +    Delete(iSaveUtil);
    1.97 +    Delete(iView);
    1.98 +    Delete(iLayout);
    1.99 +    Delete(iDocModel);
   1.100 +    Delete(iCharFormatLayer);
   1.101 +    Delete(iParaFormatLayer);
   1.102 +    Delete(iParaFormat);
   1.103 +    Delete(iDevice);
   1.104 +    Delete(iBitmap);
   1.105 +    iFs.Close();
   1.106 +    }
   1.107 +
   1.108 +EXPORT_C TBool CTestBitmapFile::CompareL(const TDes8& aData)
   1.109 +    {
   1.110 +    __ASSERT_ALWAYS(!IsActive(),User::Invariant());
   1.111 +	HBufC8* buf = NULL;
   1.112 +    // create a CImageEncoder to create a bitmap descriptor
   1.113 +    if(iSaveUtil)
   1.114 +    	{
   1.115 +    	delete iSaveUtil;
   1.116 +		iSaveUtil = NULL;
   1.117 +    	}
   1.118 +    iSaveUtil = CImageEncoder::DataNewL(buf, CImageEncoder::EOptionNone, KImageTypeBMPUid);
   1.119 +    // start reading the bitmap: RunL called when complete
   1.120 +    iSaveUtil->Convert(&iStatus, *iBitmap);
   1.121 +    SetActive();
   1.122 +    CActiveScheduler::Start();
   1.123 +    TBool ret = aData.CompareC(buf->Des()) == 0;
   1.124 +    if (buf)
   1.125 +    	{
   1.126 +    	delete buf;
   1.127 +    	buf = NULL;
   1.128 +    	}
   1.129 +    return ret;
   1.130 +    }
   1.131 +
   1.132 +// This was used to create the bitmap files for comparison - not used in actual testing
   1.133 +EXPORT_C void CTestBitmapFile::SaveFileL(const TDesC& aFileName)
   1.134 +    {
   1.135 +    __ASSERT_ALWAYS(!IsActive(),User::Invariant());
   1.136 +    // create a CImageEncoder to save the bitmap to the specified file in the specified format
   1.137 +    if(iSaveUtil)
   1.138 +    	{
   1.139 +    	delete iSaveUtil;
   1.140 +		iSaveUtil = NULL;
   1.141 +    	}
   1.142 +    iSaveUtil = CImageEncoder::FileNewL(iFs, aFileName, CImageEncoder::EOptionNone, KImageTypeBMPUid);
   1.143 +    // start saving the bitmap: RunL called when complete
   1.144 +    iSaveUtil->Convert(&iStatus, *iBitmap);
   1.145 +    SetActive();
   1.146 +    CActiveScheduler::Start();
   1.147 +    }
   1.148 +
   1.149 +EXPORT_C void CTestBitmapFile::AppendL(const TDesC& aString)
   1.150 +	{
   1.151 +	iDocModel->InsertL(iDocModel->DocumentLength(),aString);
   1.152 +	}
   1.153 +
   1.154 +EXPORT_C void CTestBitmapFile::AppendL(CPicture* aPic)
   1.155 +	{
   1.156 +	TPictureHeader header;
   1.157 +   	header.iPicture=aPic;
   1.158 + 		
   1.159 +	//CRichText::InsertL (iDocModel) takes ownership of the picture via TPictureHeader
   1.160 +	TInt docLength = iDocModel->DocumentLength();
   1.161 +	iDocModel->InsertL(docLength,header);
   1.162 + 	iView->FormatTextL();
   1.163 +	CFbsBitGc* gc = CFbsBitGc::NewL();
   1.164 +	iDevice->CreateContext(gc);
   1.165 +	iView->DrawL(iDisplayRect, *gc);
   1.166 +	iView->SetDocPosL(docLength+1, EFalse);
   1.167 + 	}
   1.168 +
   1.169 +void CTestBitmapFile::RunL()
   1.170 +    {
   1.171 +    CActiveScheduler::Stop();
   1.172 +    }
   1.173 +     
   1.174 +void CTestBitmapFile::DoCancel()
   1.175 +    {
   1.176 +    // Cancel everything possible
   1.177 +    if (iSaveUtil) iSaveUtil->Cancel();
   1.178 +    }
   1.179 +
   1.180 +EXPORT_C CTestBitmapZipFileExtractor* CTestBitmapZipFileExtractor::NewLC(const TDesC& aZipFile)
   1.181 +	{
   1.182 +	CTestBitmapZipFileExtractor* retVal = new(ELeave)CTestBitmapZipFileExtractor;
   1.183 +	CleanupStack::PushL(retVal);
   1.184 +	retVal->ConstructL(aZipFile);
   1.185 +	return retVal;
   1.186 +	}
   1.187 +	
   1.188 +void CTestBitmapZipFileExtractor::ConstructL(const TDesC& aZipFile)
   1.189 +	{
   1.190 +	User::LeaveIfError(iFs.Connect());
   1.191 +	iZipFile = CZipFile::NewL(iFs,aZipFile);
   1.192 +	}
   1.193 +
   1.194 +CTestBitmapZipFileExtractor::CTestBitmapZipFileExtractor():iBuf(0)
   1.195 +	{
   1.196 +	}
   1.197 +
   1.198 +EXPORT_C CTestBitmapZipFileExtractor::~CTestBitmapZipFileExtractor()
   1.199 +    {
   1.200 +    if(iZipFile)
   1.201 +    	{
   1.202 +    	delete iZipFile;
   1.203 +		iZipFile = NULL;
   1.204 +    	}
   1.205 +	if(iBuf)
   1.206 +		{
   1.207 +		delete iBuf;
   1.208 +		iBuf = NULL;
   1.209 +		}
   1.210 +	iFs.Close();
   1.211 +    }
   1.212 +    
   1.213 +EXPORT_C TPtr8 CTestBitmapZipFileExtractor::BitmapFileL(const TDesC& aFilename)
   1.214 +	{
   1.215 +	//Get a pointer to the bitmap data (member) from the zip file
   1.216 +	CZipFileMember* member = iZipFile->MemberL(aFilename);
   1.217 +	CleanupStack::PushL(member);
   1.218 +	User::LeaveIfNull(member);
   1.219 +	//Get the bitmap data as a filestream
   1.220 +	RZipFileMemberReaderStream* fileStream;
   1.221 +	iZipFile->GetInputStreamL(member,fileStream);
   1.222 +	CleanupStack::PushL(fileStream);
   1.223 +	TUint32 usize = member->UncompressedSize();
   1.224 +	if(iBuf)
   1.225 +		{
   1.226 +		delete iBuf;
   1.227 +		iBuf = NULL;
   1.228 +		}
   1.229 +	iBuf = HBufC8::New(usize);
   1.230 +	CleanupStack::PushL(iBuf);
   1.231 +	//Convert the filestream to a descriptor
   1.232 +	TPtr8 ptr = iBuf->Des();
   1.233 +	User::LeaveIfError(fileStream->Read(ptr,usize));
   1.234 +	CleanupStack::Pop(iBuf);
   1.235 +	CleanupStack::PopAndDestroy(2,member);
   1.236 +	return ptr;
   1.237 +	}