os/graphics/printingservices/printerdriversupport/src/PDRDEV.CPP
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/printingservices/printerdriversupport/src/PDRDEV.CPP	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1057 @@
     1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +#include <banddev.h>
    1.20 +#include <pdrstore.h>
    1.21 +#include <bitdev.h>
    1.22 +#include <bitstd.h>
    1.23 +#include "PDRBODY.H"
    1.24 +#include "PDRSTD.H"
    1.25 +#include "pdrtext.h"
    1.26 +
    1.27 +EXPORT_C CPdrDevice::CPdrDevice():
    1.28 +	CPrinterDevice(),
    1.29 +	iStore(NULL),
    1.30 +	iModel(),
    1.31 +	iModelInfo(NULL),
    1.32 +	iTypefaceStore(NULL)
    1.33 +	{
    1.34 +	__DECLARE_NAME(_S("CPdrDevice"));
    1.35 +	}
    1.36 +
    1.37 +EXPORT_C CPdrDevice::~CPdrDevice()
    1.38 +	{
    1.39 +	DeleteControl();
    1.40 +	delete iModelInfo;
    1.41 +	delete iTypefaceStore;
    1.42 +	}
    1.43 +
    1.44 +EXPORT_C void CPdrDevice::SelectPageSpecInTwips(const TPageSpec& aPageSpec)
    1.45 +	{
    1.46 +	CPrinterDevice::SelectPageSpecInTwips(aPageSpec);
    1.47 +	iTypefaceStore->SetPageOrientation(aPageSpec.iOrientation);
    1.48 +	}
    1.49 +
    1.50 +EXPORT_C TDisplayMode CPdrDevice::DisplayMode() const
    1.51 +	{
    1.52 +	return iModelInfo->iDisplayMode;
    1.53 +	}
    1.54 +
    1.55 +EXPORT_C TSize CPdrDevice::SizeInPixels() const
    1.56 +	{
    1.57 +	TSize size;
    1.58 +	size.iWidth = HorizontalTwipsToPixels(SizeInTwips().iWidth);
    1.59 +	size.iHeight = VerticalTwipsToPixels(SizeInTwips().iHeight);
    1.60 +	return size;
    1.61 +	}
    1.62 +
    1.63 +EXPORT_C TSize CPdrDevice::SizeInTwips() const
    1.64 +	{
    1.65 +	TSize size;
    1.66 +	if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait)
    1.67 +		{
    1.68 +		size = iCurrentPageSpecInTwips.iPortraitPageSize;
    1.69 +		}
    1.70 +	else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape)
    1.71 +		{
    1.72 +		size.iWidth = iCurrentPageSpecInTwips.iPortraitPageSize.iHeight;
    1.73 +		size.iHeight = iCurrentPageSpecInTwips.iPortraitPageSize.iWidth;
    1.74 +		}
    1.75 +	return size;
    1.76 +	}
    1.77 +
    1.78 +EXPORT_C TRect CPdrDevice::PrintablePageInPixels() const
    1.79 +	{
    1.80 +	TRect rect;
    1.81 +	if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait)
    1.82 +		{
    1.83 +		rect.iTl.iX = iModelInfo->iPortraitOffsetInPixels.iX;
    1.84 +		rect.iTl.iY = iModelInfo->iMinMarginsInPixels.iTop;
    1.85 +		rect.iBr.iX = SizeInPixels().iWidth-iModelInfo->iPortraitOffsetInPixels.iX;
    1.86 +		rect.iBr.iY = SizeInPixels().iHeight-iModelInfo->iMinMarginsInPixels.iBottom;
    1.87 +		}
    1.88 +	else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape)
    1.89 +		{
    1.90 +		rect.iTl.iX = iModelInfo->iLandscapeOffsetInPixels.iX;
    1.91 +		rect.iTl.iY = iModelInfo->iMinMarginsInPixels.iLeft;
    1.92 +		rect.iBr.iX = SizeInPixels().iWidth-iModelInfo->iLandscapeOffsetInPixels.iX;
    1.93 +		rect.iBr.iY = SizeInPixels().iHeight-iModelInfo->iMinMarginsInPixels.iRight;
    1.94 +		}
    1.95 +	return rect;
    1.96 +	}
    1.97 +
    1.98 +EXPORT_C TInt CPdrDevice::HorizontalTwipsToPixels(TInt aTwips) const
    1.99 +	{
   1.100 +	return ((1000 * aTwips) + (KPixelSizeInTwips().iWidth / 2)) / KPixelSizeInTwips().iWidth;
   1.101 +	}
   1.102 +
   1.103 +EXPORT_C TInt CPdrDevice::VerticalTwipsToPixels(TInt aTwips) const
   1.104 +	{
   1.105 +	return ((1000 * aTwips) + (KPixelSizeInTwips().iHeight / 2)) / KPixelSizeInTwips().iHeight;
   1.106 +	}
   1.107 +
   1.108 +EXPORT_C TInt CPdrDevice::HorizontalPixelsToTwips(TInt aPixels) const
   1.109 +	{
   1.110 +	return ((aPixels * KPixelSizeInTwips().iWidth) + 500) / 1000;
   1.111 +	}
   1.112 +
   1.113 +EXPORT_C TInt CPdrDevice::VerticalPixelsToTwips(TInt aPixels) const
   1.114 +	{
   1.115 +	return ((aPixels * KPixelSizeInTwips().iHeight) + 500) / 1000;
   1.116 +	}
   1.117 +
   1.118 +/** Creates a font from those available in the printer device's 
   1.119 +typeface store that most closely matches a font specification. 
   1.120 +
   1.121 +When the font is no longer needed, call ReleaseFont().
   1.122 +
   1.123 +This function is replaced by GetNearestFontToDesignHeightInTwips()
   1.124 +
   1.125 +@param aFont On return, points to the font which most closely matches the 
   1.126 +specified font.
   1.127 +@param aFontSpec An absolute font specification. Its iHeight member is 
   1.128 +interpreted as being in twips.
   1.129 +@return KErrNone if successful; otherwise, another one of the system-wide error 
   1.130 +codes.
   1.131 +@deprecated */
   1.132 +EXPORT_C TInt CPdrDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
   1.133 +	{
   1.134 +	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
   1.135 +	}
   1.136 +
   1.137 +/** Creates a font from those available in the printer device's 
   1.138 +typeface store that most closely matches a font specification. 
   1.139 +
   1.140 +When the font is no longer needed, call ReleaseFont().
   1.141 +
   1.142 +This function replaces GetNearestFontInTwips()
   1.143 +
   1.144 +@param aFont On return, points to the font which most closely matches the 
   1.145 +specified font.
   1.146 +@param aFontSpec An absolute font specification. Its iHeight member is 
   1.147 +interpreted as being in twips.
   1.148 +@return KErrNone if successful; otherwise, another one of the system-wide error 
   1.149 +codes. */
   1.150 +EXPORT_C TInt CPdrDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
   1.151 +	{
   1.152 +	return iTypefaceStore->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
   1.153 +	}
   1.154 +
   1.155 +/** This call is defined because it had to be - it appeared as an abstract virtual in
   1.156 +the base class. But it should never actually get called for this class. */
   1.157 +EXPORT_C TInt CPdrDevice::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/)
   1.158 +	{
   1.159 +	return KErrNotSupported;
   1.160 +	}
   1.161 +
   1.162 +EXPORT_C TInt CPdrDevice::NumTypefaces() const
   1.163 +	{
   1.164 +	return iTypefaceStore->NumTypefaces();
   1.165 +	}
   1.166 +
   1.167 +EXPORT_C void CPdrDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, TInt aTypefaceIndex) const
   1.168 +	{
   1.169 +	iTypefaceStore->TypefaceSupport(aTypefaceSupport, aTypefaceIndex);
   1.170 +	}
   1.171 +
   1.172 +EXPORT_C TInt CPdrDevice::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const
   1.173 +	{
   1.174 +	return iTypefaceStore->FontHeightInTwips(aTypefaceIndex, aHeightIndex);
   1.175 +	}
   1.176 +
   1.177 +EXPORT_C void CPdrDevice::PaletteAttributes(TBool& aModifiable, TInt& aNumEntries) const
   1.178 +	{
   1.179 +	aModifiable = EFalse;
   1.180 +	aNumEntries = 0;
   1.181 +	}
   1.182 +
   1.183 +EXPORT_C void CPdrDevice::SetPalette(CPalette* /*aPalette*/)
   1.184 +	{
   1.185 +	}
   1.186 +	
   1.187 +EXPORT_C TInt CPdrDevice::GetPalette(CPalette*& /*aPalette*/) const
   1.188 +	{
   1.189 +	return KErrNotSupported;
   1.190 +	}
   1.191 +
   1.192 +EXPORT_C TPrinterModelEntry CPdrDevice::Model() const
   1.193 +	{
   1.194 +	return iModel.iEntry;
   1.195 +	}
   1.196 +
   1.197 +EXPORT_C TInt CPdrDevice::Flags() const
   1.198 +	{
   1.199 +	return iModelInfo->iFlags;
   1.200 +	}
   1.201 +
   1.202 +EXPORT_C TInt CPdrDevice::SetModel(const TPrinterModelHeader& aModel, CStreamStore& aStore)
   1.203 +	{
   1.204 +	iModel = aModel;
   1.205 +	iStore = &aStore;
   1.206 +	TRAPD(ret, DoSetModelL());
   1.207 +	return ret;
   1.208 +	}
   1.209 +
   1.210 +EXPORT_C void CPdrDevice::ReleaseFont(CFont* aFont)
   1.211 +	{
   1.212 +	iTypefaceStore->ReleaseFont(aFont);
   1.213 +	}
   1.214 +
   1.215 +EXPORT_C TPoint CPdrDevice::OffsetInPixels()
   1.216 +	{
   1.217 +	TPoint offset;
   1.218 +	if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait)
   1.219 +		offset = iModelInfo->iPortraitOffsetInPixels;
   1.220 +	else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape)
   1.221 +		offset = iModelInfo->iLandscapeOffsetInPixels;
   1.222 +	return offset;
   1.223 +	}
   1.224 +
   1.225 +EXPORT_C TSize CPdrDevice::KPixelSizeInTwips() const
   1.226 +	{
   1.227 +	TSize size; 
   1.228 +	if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait)
   1.229 +		size = TSize(iModelInfo->iKPixelWidthInTwips, iModelInfo->iKPixelHeightInTwips);
   1.230 +	else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape)
   1.231 +		size = TSize(iModelInfo->iKPixelHeightInTwips, iModelInfo->iKPixelWidthInTwips);
   1.232 +	return size;
   1.233 +	}
   1.234 +
   1.235 +void CPdrDevice::DoSetModelL()
   1.236 +	{
   1.237 +	RStoreReadStream stream;
   1.238 +	stream.OpenLC(*iStore, iModel.iModelDataStreamId);
   1.239 +	iModelInfo = new(ELeave) CPdrModelInfo();
   1.240 +	iModelInfo->InternalizeL(stream);
   1.241 +	CleanupStack::PopAndDestroy();
   1.242 +	iTypefaceStore = CPdrTypefaceStore::NewL(*iStore, iModelInfo->iNumTypefaceFonts, iModelInfo->iTypefaceFontsEntryList, iCurrentPageSpecInTwips.iOrientation, iModelInfo->iKPixelHeightInTwips, this);
   1.243 +	}
   1.244 +
   1.245 +EXPORT_C CPdrControl::CPdrControl(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort):
   1.246 +	CPrinterControl(aPrinterPort),
   1.247 +	iPdrDevice(aPdrDevice),
   1.248 +	iPageBuffer(NULL),
   1.249 +	iResources(NULL),
   1.250 +	iBandedDevice(NULL),
   1.251 +	iPageText(NULL),
   1.252 +	iBandIndex(0),
   1.253 +	iEntryIndex(0),
   1.254 +	iPosition(iPdrDevice->OffsetInPixels()),
   1.255 +	iTextFormat()
   1.256 +	{
   1.257 +	__DECLARE_NAME(_S("CPdrControl"));
   1.258 +	}
   1.259 +
   1.260 +EXPORT_C CPdrControl::~CPdrControl()
   1.261 +	{
   1.262 +	delete iPageBuffer;
   1.263 +	delete iResources;
   1.264 +	delete iBandedDevice;
   1.265 +	delete iPageText;
   1.266 +	}
   1.267 +
   1.268 +EXPORT_C TInt CPdrControl::CreateContext(CGraphicsContext*& aGC)
   1.269 +	{
   1.270 +	__ASSERT_DEBUG(iState == EPrinting, Panic(EPdrNotPrinting));
   1.271 +	TRAPD(ret, aGC = CPdrGc::NewL(iPdrDevice));
   1.272 +	return ret;
   1.273 +	}
   1.274 +
   1.275 +EXPORT_C TInt CPdrControl::BandsPerPage()
   1.276 +	{
   1.277 +	TInt numbands = {iBandedDevice ? iBandedDevice->NumBands() + 1 : 1};
   1.278 +	return numbands;
   1.279 +	}
   1.280 +
   1.281 +/**
   1.282 + @return EMoreOnPage if more to print on the current page,
   1.283 + otherwise ENoMoreOnPage.
   1.284 +*/
   1.285 +EXPORT_C CPrinterControl::TMoreOnPage CPdrControl::QueueGetBand(TRequestStatus& aStatus, TBandAttributes& aBand)
   1.286 +	{
   1.287 +	TMoreOnPage moreonpage = ENoMoreOnPage;
   1.288 +
   1.289 +	TRAPD(ret, DoQueueGetBandL());
   1.290 +	if (ret != KErrNone)
   1.291 +		{
   1.292 +		TRequestStatus* status = &aStatus;
   1.293 +		User::RequestComplete(status, ret);
   1.294 +		}
   1.295 +	else
   1.296 +		{
   1.297 +		if (IsGraphicsBand())
   1.298 +			{
   1.299 +			aBand.iRect = iBandedDevice->BandRect();
   1.300 +			aBand.iTextIsIgnored = ETrue;
   1.301 +			aBand.iGraphicsIsIgnored = EFalse;
   1.302 +			aBand.iFirstBandOnPage = EFalse;
   1.303 +			}
   1.304 +		else
   1.305 +			{
   1.306 +			aBand.iRect = iPdrDevice->PrintablePageInPixels();
   1.307 +			aBand.iTextIsIgnored = EFalse;
   1.308 +			aBand.iGraphicsIsIgnored = ETrue;
   1.309 +			aBand.iFirstBandOnPage = ETrue;
   1.310 +			}
   1.311 +		if (iBandIndex == (BandsPerPage() - 1))
   1.312 +			moreonpage = ENoMoreOnPage;
   1.313 +		else
   1.314 +			moreonpage = EMoreOnPage;
   1.315 +		iPageBuffer->StartFlush(aStatus);
   1.316 +		}
   1.317 +	return moreonpage;
   1.318 +	}
   1.319 +
   1.320 +EXPORT_C void CPdrControl::QueueEndPrint(TRequestStatus& aStatus)
   1.321 +	{
   1.322 +	TRAPD(ret, DoQueueEndPrintL());
   1.323 +	iState = ENotPrinting;
   1.324 +	if (ret != KErrNone)
   1.325 +		{
   1.326 +		TRequestStatus* status = &aStatus;
   1.327 +		User::RequestComplete(status, ret);
   1.328 +		}
   1.329 +	else
   1.330 +		iPageBuffer->StartFlush(aStatus);
   1.331 +	}
   1.332 +
   1.333 +/**
   1.334 + Tidy up synchronously in a short time.
   1.335 +*/
   1.336 +EXPORT_C void CPdrControl::AbortPrint() // tidy up synchronously in a short time, return success code
   1.337 +	{
   1.338 +	iPageBuffer->Cancel(); // dont call DoCancel()
   1.339 +	iState = ENotPrinting;
   1.340 +	}
   1.341 +
   1.342 +EXPORT_C void CPdrControl::DrawTextL(const TPoint& aPoint, const TFontUnderline aUnderlineStyle, const TFontStrikethrough aStrikethroughStyle, const TRgb& aColor, const CInfoFont* aFont, const TDesC& aString)
   1.343 +	{
   1.344 +	__ASSERT_DEBUG(iState == EPrinting,Panic(EPdrNotPrinting));
   1.345 +	if (iPageText)
   1.346 +		iPageText->AddEntryL(aPoint, aUnderlineStyle, aStrikethroughStyle, aColor, aFont, aString);
   1.347 +	else
   1.348 +		{
   1.349 +		HBufC8* string = aFont->TranslateStringL(aString);
   1.350 +		CleanupStack::PushL(string);
   1.351 +		TTextFormat textformat(aUnderlineStyle, aStrikethroughStyle, aColor, aFont->CommandString(), aFont->FontSpecInTwips().iFontStyle);
   1.352 +		OutputTextL(aPoint + TPoint(0, aFont->BaselineOffsetInPixels()), aFont->MeasureText(aString), textformat,string->Des());
   1.353 +		CleanupStack::PopAndDestroy();
   1.354 +		}
   1.355 +	}
   1.356 +
   1.357 +EXPORT_C TBool CPdrControl::IsGraphicsBand() const
   1.358 +	{
   1.359 +	return iBandIndex;
   1.360 +	}
   1.361 +
   1.362 +EXPORT_C void CPdrControl::MoveToL(const TPoint& aPoint) 
   1.363 +	{
   1.364 +	// PCL, at least, treats move command strings with an explicit
   1.365 +	// sign as being relative, so if the offset is negative then
   1.366 +	// set the absolute position to zero first.
   1.367 +
   1.368 +	TPoint offset = iPdrDevice->OffsetInPixels();
   1.369 +	TCommandString des;
   1.370 +	if (aPoint.iX - iPosition.iX)
   1.371 +		{
   1.372 +		if (aPoint.iX - iPosition.iX < 0)
   1.373 +			{
   1.374 +			des.Format(iResources->ResourceString(EPdrSetXPos), 0);
   1.375 +			iPageBuffer->AddBytesL(des);
   1.376 +			}
   1.377 +
   1.378 +		des.Format(iResources->ResourceString(EPdrSetXPos), aPoint.iX - offset.iX);
   1.379 +		iPageBuffer->AddBytesL(des);
   1.380 +		}
   1.381 +	if (aPoint.iY - iPosition.iY)
   1.382 +		{
   1.383 +		if (aPoint.iY - iPosition.iY < 0)
   1.384 +			{
   1.385 +			des.Format(iResources->ResourceString(EPdrSetYPos), 0);
   1.386 +			iPageBuffer->AddBytesL(des);
   1.387 +			}
   1.388 +
   1.389 +		des.Format(iResources->ResourceString(EPdrSetYPos), aPoint.iY - offset.iY);
   1.390 +		iPageBuffer->AddBytesL(des);
   1.391 +		}
   1.392 +	iPosition = aPoint;
   1.393 +	}
   1.394 +
   1.395 +EXPORT_C void CPdrControl::MoveByL(const TPoint& aVector) 
   1.396 +	{
   1.397 +	TCommandString resource;
   1.398 +	TCommandString des;
   1.399 +	TPoint vector = aVector;
   1.400 +	if (vector.iX)
   1.401 +		{
   1.402 +		if (aVector.iX < 0)
   1.403 +			{
   1.404 +			CommandL(EPdrCarriageReturn);
   1.405 +			vector.iX += iPosition.iX - iPdrDevice->OffsetInPixels().iX;
   1.406 +			}
   1.407 +		resource.Copy(iResources->ResourceString(EPdrIncrementXPos));
   1.408 +		__ASSERT_DEBUG(resource.Length() >= 2, Panic(EPdrBadResourceString));
   1.409 +		if (resource[0] == '*')
   1.410 +			{
   1.411 +			for (; vector.iX > 0; vector.iX--)
   1.412 +				iPageBuffer->AddBytesL(resource.Mid(1));
   1.413 +			}
   1.414 +		else
   1.415 +			{
   1.416 +			des.Format(resource, vector.iX);
   1.417 +			iPageBuffer->AddBytesL(des);
   1.418 +			}
   1.419 +		}
   1.420 +	resource.Copy(iResources->ResourceString(EPdrIncrementYPos));
   1.421 +	if (vector.iY)
   1.422 +		{
   1.423 +		__ASSERT_DEBUG(resource.Length() >= 2, Panic(EPdrBadResourceString));
   1.424 +		if (resource[0] == '*')
   1.425 +			{
   1.426 +			for (; vector.iY > 0; vector.iY--)
   1.427 +				iPageBuffer->AddBytesL(resource.Mid(1));
   1.428 +			}
   1.429 +		else
   1.430 +			{
   1.431 +			des.Format(resource, vector.iY);
   1.432 +			iPageBuffer->AddBytesL(des);
   1.433 +			}
   1.434 +		}
   1.435 +	iPosition += aVector;
   1.436 +	}
   1.437 +
   1.438 +EXPORT_C void CPdrControl::OutputTextL(const TPoint& aPoint, TInt aWidthInPixels, const TTextFormat& aTextFormat, const TDesC8& aString)
   1.439 +	{
   1.440 +	__ASSERT_DEBUG(iState == EPrinting,Panic(EPdrNotPrinting));
   1.441 +
   1.442 +	if (iTextFormat.iFontString.Compare(aTextFormat.iFontString))
   1.443 +		iPageBuffer->AddBytesL(aTextFormat.iFontString);
   1.444 +
   1.445 +	if (iTextFormat.iFontStyle.Posture() != aTextFormat.iFontStyle.Posture())
   1.446 +		SetFontPostureL(aTextFormat.iFontStyle.Posture());
   1.447 +
   1.448 +	if (iTextFormat.iFontStyle.StrokeWeight() != aTextFormat.iFontStyle.StrokeWeight())
   1.449 +		SetFontStrokeWeightL(aTextFormat.iFontStyle.StrokeWeight());
   1.450 +
   1.451 +	if (iTextFormat.iColor != aTextFormat.iColor)
   1.452 +		SetTextColorL(aTextFormat.iColor);
   1.453 +
   1.454 +	iTextFormat = aTextFormat;
   1.455 +
   1.456 +	MoveToL(aPoint);
   1.457 +
   1.458 +	if (aTextFormat.iUnderlineStyle == EUnderlineOn)
   1.459 +		CommandL(EPdrUnderlineOn);
   1.460 +
   1.461 +	if (aTextFormat.iStrikethroughStyle == EStrikethroughOn)
   1.462 +		CommandL(EPdrStrikethroughOn);
   1.463 +
   1.464 +	iPageBuffer->AddBytesL(aString);
   1.465 +
   1.466 +	iPosition.iX += aWidthInPixels;
   1.467 +
   1.468 +	if (aTextFormat.iUnderlineStyle == EUnderlineOn)
   1.469 +		CommandL(EPdrUnderlineOff);
   1.470 +
   1.471 +	if (aTextFormat.iStrikethroughStyle == EStrikethroughOn)
   1.472 +		CommandL(EPdrStrikethroughOff);
   1.473 +	}
   1.474 +
   1.475 +EXPORT_C void CPdrControl::DoQueueGetBandL()
   1.476 +	{
   1.477 +	if (iState == ENotPrinting)
   1.478 +		{
   1.479 +		iState = EPrinting;
   1.480 +		iBandIndex = 0;
   1.481 +		if (iBandedDevice)
   1.482 +			iBandedDevice->Reset();
   1.483 +		CommandL(EPdrReset);
   1.484 +		SetPageSizeL();
   1.485 +		CommandL(EPdrPreAmble);
   1.486 +		SetPageOrientationL();
   1.487 +		SetTextColorL(KRgbBlack);	
   1.488 +		}
   1.489 + 	else 
   1.490 +		{
   1.491 +		OutputBandL();
   1.492 +		if (iBandIndex == (BandsPerPage() - 1))
   1.493 +			{
   1.494 +			iBandIndex = 0;
   1.495 +			iEntryIndex = 0;
   1.496 +			if (iPageText)
   1.497 +				iPageText->Reset(); 
   1.498 +			CommandL(EPdrNewPage);
   1.499 +			iPosition = iPdrDevice->OffsetInPixels();
   1.500 +			}
   1.501 +		else
   1.502 +			iBandIndex = iBandedDevice->NextBand() + 1;
   1.503 +		}
   1.504 +	}
   1.505 +
   1.506 +EXPORT_C void CPdrControl::DoQueueEndPrintL()
   1.507 +	{
   1.508 +	OutputBandL();
   1.509 +	CommandL(EPdrPostAmble);
   1.510 +	}
   1.511 +
   1.512 +EXPORT_C void CPdrControl::ConstructL(CStreamStore& aStore, TStreamId aStreamId)
   1.513 +	{
   1.514 +	__ASSERT_ALWAYS(iPrinterPort, Panic(EPdrRequiresPrinterPort));
   1.515 +	iPageBuffer = CPageBuffer::NewL(iPrinterPort);
   1.516 +	iResources = new(ELeave) CPdrResources();
   1.517 +	iResources->RestoreL(aStore, aStreamId);
   1.518 +	}
   1.519 +
   1.520 +EXPORT_C void CPdrControl::SetPageSizeL()
   1.521 +	{
   1.522 +	}
   1.523 +	 
   1.524 +EXPORT_C void CPdrControl::SetPageOrientationL()
   1.525 +	{
   1.526 +	TPageSpec::TPageOrientation orientation = iPdrDevice->CurrentPageSpecInTwips().iOrientation;
   1.527 +	if (orientation == TPageSpec::EPortrait)
   1.528 +		CommandL(EPdrPortrait);
   1.529 +	else
   1.530 +		CommandL(EPdrLandscape);
   1.531 +	}
   1.532 +
   1.533 +EXPORT_C void CPdrControl::SetFontStrokeWeightL(const TFontStrokeWeight aStrokeWeight)
   1.534 +	{
   1.535 +	if (aStrokeWeight == EStrokeWeightNormal)
   1.536 +		CommandL(EPdrBoldOff);
   1.537 +	else 
   1.538 +		CommandL(EPdrBoldOn);
   1.539 +	}
   1.540 +
   1.541 +EXPORT_C void CPdrControl::SetFontPostureL(const TFontPosture aPosture)
   1.542 +	{
   1.543 +	if (aPosture == EPostureUpright)
   1.544 +		CommandL(EPdrItalicOff);
   1.545 +	else 
   1.546 +		CommandL(EPdrItalicOn);
   1.547 +	}
   1.548 +
   1.549 +EXPORT_C void CPdrControl::SetTextColorL(const TRgb& /*aColor*/) 
   1.550 +	{
   1.551 +	}
   1.552 +
   1.553 +EXPORT_C void CPdrControl::CommandL(const TInt anId) 
   1.554 +	{
   1.555 +	iPageBuffer->AddBytesL(iResources->ResourceString(anId));
   1.556 +	}
   1.557 +
   1.558 +void CPdrGc::ConstructL()
   1.559 +	{
   1.560 +	if (PdrControl()->BandedDevice())
   1.561 +		{
   1.562 +		User::LeaveIfError(PdrControl()->BandedDevice()->CreateContext((CGraphicsContext*&)iBandedGc));
   1.563 +		TFontSpec spec;
   1.564 +		User::LeaveIfError(PdrControl()->BandedDevice()->GetNearestFontToDesignHeightInTwips((CFont*&)iFbsFont, spec));
   1.565 +		iBandedGc->UseFont(iFbsFont);
   1.566 +		}
   1.567 +	}
   1.568 +
   1.569 +CPdrGc::CPdrGc(CPdrDevice* aDevice):
   1.570 +	iPdrDevice(aDevice),
   1.571 +	iBandedGc(NULL),
   1.572 +	iFbsFont(NULL),
   1.573 +	iBandedFont(NULL),
   1.574 +	iFont(NULL),
   1.575 +	iOrigin(0, 0),
   1.576 +	iPosition(0, 0),
   1.577 +	iUnderlineStyle(EUnderlineOff),
   1.578 +	iStrikethroughStyle(EStrikethroughOff),
   1.579 +	iClippingRect(iPdrDevice->PrintablePageInPixels()),
   1.580 +	iWordExcessWidthInPixels(0),
   1.581 +	iNumGaps(0),
   1.582 +	iCharExcessWidthInPixels(0),
   1.583 +	iNumChars(0),
   1.584 +	iPenColor(KRgbBlack)
   1.585 +	{
   1.586 +	}
   1.587 +
   1.588 +CPdrGc* CPdrGc::NewL(CPdrDevice* aDevice)
   1.589 +	{
   1.590 +	CPdrGc* gc = new(ELeave) CPdrGc(aDevice);
   1.591 +	CleanupStack::PushL(gc);
   1.592 +	gc->ConstructL();
   1.593 +	CleanupStack::Pop();
   1.594 +	return gc;
   1.595 +	}
   1.596 +
   1.597 +EXPORT_C CPdrGc::~CPdrGc()
   1.598 +	{
   1.599 +	if (iBandedGc)
   1.600 +		{
   1.601 +		if (iBandedGc->IsFontUsed())
   1.602 +			{
   1.603 +			iBandedGc->DiscardFont();
   1.604 +			iBandedFont = NULL;
   1.605 +			}
   1.606 +		delete iBandedGc;
   1.607 +		PdrControl()->BandedDevice()->ReleaseFont(iFbsFont);
   1.608 +		}
   1.609 +	}
   1.610 +
   1.611 +EXPORT_C CGraphicsDevice* CPdrGc::Device() const
   1.612 +	{
   1.613 +	return iPdrDevice;
   1.614 +	}
   1.615 +
   1.616 +EXPORT_C void CPdrGc::SetOrigin(const TPoint& aPos)
   1.617 +	{
   1.618 +	if (!PdrControl()->IsGraphicsBand())
   1.619 +		iOrigin = aPos;
   1.620 +	TPoint pos = PdrControl()->BandedDevice()->FullOriginToBandOrigin(aPos);
   1.621 +	iBandedGc->SetOrigin(pos);
   1.622 +	}
   1.623 +
   1.624 +EXPORT_C void CPdrGc::SetDrawMode(TDrawMode aDrawingMode)
   1.625 +	{
   1.626 +	iBandedGc->SetDrawMode(aDrawingMode);
   1.627 +	}
   1.628 +
   1.629 +EXPORT_C void CPdrGc::SetClippingRect(const TRect& aRect)
   1.630 +	{
   1.631 +	if (!PdrControl()->IsGraphicsBand())
   1.632 +		{
   1.633 +		iClippingRect = aRect;
   1.634 +		iClippingRect.Move(TPoint(0, 0) + iOrigin);	//  Recorded in original coordinates
   1.635 +		}
   1.636 +	iBandedGc->SetClippingRect(aRect);
   1.637 +	}
   1.638 +
   1.639 +EXPORT_C void CPdrGc::CancelClippingRect()
   1.640 +	{
   1.641 +	if (!PdrControl()->IsGraphicsBand())
   1.642 +		iClippingRect = iPdrDevice->PrintablePageInPixels();
   1.643 +	iBandedGc->CancelClippingRect();
   1.644 +	}
   1.645 +
   1.646 +EXPORT_C void CPdrGc::Reset()
   1.647 +	{
   1.648 +	if (iBandedGc->IsFontUsed())
   1.649 +		{
   1.650 +		iBandedGc->DiscardFont();
   1.651 +		iBandedFont = NULL;
   1.652 +		}
   1.653 +	iBandedGc->Reset();
   1.654 +	iBandedGc->UseFont(iFbsFont);
   1.655 +	SetOrigin(TPoint(0, 0));
   1.656 +	CancelClippingRect();
   1.657 +	}
   1.658 +
   1.659 +EXPORT_C void CPdrGc::UseFont(const CFont* aFont)
   1.660 +	{
   1.661 +	if (aFont->TypeUid() == TUid::Uid(KCInfoFontUidVal))
   1.662 +		{
   1.663 +		iFont = (CInfoFont*)aFont;
   1.664 +		iPrintTextUsingBitmaps = EFalse;
   1.665 +		// We may have to use bitmaps - so set the font up in the bitmap gc as well
   1.666 +		if (iBandedGc->IsFontUsed())
   1.667 +			iBandedGc->DiscardFont();
   1.668 +		iBandedFont = iFont->RealFont();
   1.669 +		iBandedGc->UseFont(iBandedFont);
   1.670 +		}
   1.671 +	else 
   1.672 +		{
   1.673 +		if (iBandedGc->IsFontUsed())
   1.674 +			{
   1.675 +			iBandedGc->DiscardFont();
   1.676 +			iBandedFont = NULL;
   1.677 +			}
   1.678 +		iBandedGc->UseFont(aFont);
   1.679 +		iPrintTextUsingBitmaps = ETrue;
   1.680 +		}
   1.681 +	}
   1.682 +
   1.683 +EXPORT_C void CPdrGc::DiscardFont()
   1.684 +	{
   1.685 +	iFont = NULL;
   1.686 +	if (iBandedFont)
   1.687 +		{
   1.688 +		iBandedGc->DiscardFont();
   1.689 +		iBandedFont = NULL;
   1.690 +		iBandedGc->UseFont(iFbsFont);
   1.691 +		}
   1.692 +	}
   1.693 +
   1.694 +EXPORT_C void CPdrGc::SetPenColor(const TRgb& aColor)
   1.695 +	{
   1.696 +	if (!PdrControl()->IsGraphicsBand())
   1.697 +		iPenColor = aColor;
   1.698 +	iBandedGc->SetPenColor(aColor);
   1.699 +	}
   1.700 +
   1.701 +EXPORT_C void CPdrGc::SetPenStyle(TPenStyle aPenStyle)
   1.702 +	{
   1.703 +	iBandedGc->SetPenStyle(aPenStyle);
   1.704 +	}
   1.705 +
   1.706 +EXPORT_C void CPdrGc::SetPenSize(const TSize& aSize)
   1.707 +	{
   1.708 +	iBandedGc->SetPenSize(aSize);
   1.709 +	}
   1.710 +
   1.711 +EXPORT_C void CPdrGc::SetBrushColor(const TRgb& aColor)
   1.712 +	{
   1.713 +	if (PdrControl()->IsGraphicsBand())
   1.714 +		iBandedGc->SetBrushColor(aColor);
   1.715 +	}
   1.716 +
   1.717 +EXPORT_C void CPdrGc::SetBrushStyle(TBrushStyle aBrushStyle)
   1.718 +	{
   1.719 +	if (PdrControl()->IsGraphicsBand())
   1.720 +		iBandedGc->SetBrushStyle(aBrushStyle);
   1.721 +	}
   1.722 +
   1.723 +EXPORT_C void CPdrGc::SetBrushOrigin(const TPoint& aOrigin)
   1.724 +	{
   1.725 +	if (PdrControl()->IsGraphicsBand())
   1.726 +		iBandedGc->SetBrushOrigin(aOrigin);
   1.727 +	}
   1.728 +
   1.729 +EXPORT_C void CPdrGc::UseBrushPattern(const CFbsBitmap* aBitmap)
   1.730 +	{
   1.731 +	if (PdrControl()->IsGraphicsBand())
   1.732 +		iBandedGc->UseBrushPattern(aBitmap);
   1.733 +	}
   1.734 +
   1.735 +EXPORT_C void CPdrGc::DiscardBrushPattern()
   1.736 +	{
   1.737 +	if (PdrControl()->IsGraphicsBand())
   1.738 +		iBandedGc->DiscardBrushPattern();
   1.739 +	}
   1.740 +
   1.741 +EXPORT_C void CPdrGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle)
   1.742 +	{
   1.743 +	if (!PdrControl()->IsGraphicsBand())
   1.744 +		iUnderlineStyle = aUnderlineStyle;
   1.745 +	iBandedGc->SetUnderlineStyle(aUnderlineStyle);
   1.746 +	}
   1.747 +
   1.748 +EXPORT_C void CPdrGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle)
   1.749 +	{
   1.750 +	if (!PdrControl()->IsGraphicsBand())
   1.751 +		iStrikethroughStyle = aStrikethroughStyle;
   1.752 +	iBandedGc->SetStrikethroughStyle(aStrikethroughStyle);
   1.753 +	}
   1.754 +
   1.755 +EXPORT_C void CPdrGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps)
   1.756 +	{
   1.757 +	if (!PdrControl()->IsGraphicsBand())
   1.758 +		{
   1.759 +		iWordExcessWidthInPixels = aExcessWidth;
   1.760 +		iNumGaps = aNumGaps;
   1.761 +		}
   1.762 +	iBandedGc->SetWordJustification(aExcessWidth, aNumGaps);
   1.763 +	}
   1.764 +
   1.765 +EXPORT_C void CPdrGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars)
   1.766 +	{
   1.767 +	if (!PdrControl()->IsGraphicsBand())
   1.768 +		{
   1.769 +		iCharExcessWidthInPixels = aExcessWidth;
   1.770 +		iNumChars = aNumChars;
   1.771 +		}
   1.772 +	iBandedGc->SetCharJustification(aExcessWidth, aNumChars);
   1.773 +	}
   1.774 +
   1.775 +EXPORT_C void CPdrGc::MoveTo(const TPoint& aPoint)
   1.776 +	{
   1.777 +	if (!PdrControl()->IsGraphicsBand())
   1.778 +		iPosition = aPoint;
   1.779 +	iBandedGc->MoveTo(aPoint);
   1.780 +	}
   1.781 +
   1.782 +EXPORT_C void CPdrGc::MoveBy(const TPoint& aVector)
   1.783 +	{
   1.784 +	if (!PdrControl()->IsGraphicsBand())
   1.785 +		iPosition += aVector;
   1.786 +	iBandedGc->MoveBy(aVector);
   1.787 +	}
   1.788 +
   1.789 +EXPORT_C void CPdrGc::Plot(const TPoint& aPoint)
   1.790 +	{
   1.791 +	if (PdrControl()->IsGraphicsBand())
   1.792 +		iBandedGc->Plot(aPoint);
   1.793 +	}
   1.794 +
   1.795 +EXPORT_C void CPdrGc::DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd)
   1.796 +	{
   1.797 +	if (PdrControl()->IsGraphicsBand())
   1.798 +		iBandedGc->DrawArc(aRect, aStart, aEnd);
   1.799 +	}
   1.800 +
   1.801 +EXPORT_C void CPdrGc::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2)
   1.802 +	{
   1.803 +	if (PdrControl()->IsGraphicsBand())
   1.804 +		iBandedGc->DrawLine(aPoint1, aPoint2);
   1.805 +	}
   1.806 +
   1.807 +EXPORT_C void CPdrGc::DrawLineTo(const TPoint& aPoint)
   1.808 +	{
   1.809 +	if (PdrControl()->IsGraphicsBand())
   1.810 +		iBandedGc->DrawLineTo(aPoint);
   1.811 +	}
   1.812 +
   1.813 +EXPORT_C void CPdrGc::DrawLineBy(const TPoint& aVector)
   1.814 +	{
   1.815 +	if (PdrControl()->IsGraphicsBand())
   1.816 +		iBandedGc->DrawLineBy(aVector);
   1.817 +	}
   1.818 +
   1.819 +EXPORT_C void CPdrGc::DrawPolyLine(const CArrayFix<TPoint>* aPointList)
   1.820 +	{
   1.821 +	if (PdrControl()->IsGraphicsBand())
   1.822 +		iBandedGc->DrawPolyLine(aPointList);
   1.823 +	}
   1.824 +
   1.825 +EXPORT_C void CPdrGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints)
   1.826 +	{
   1.827 +	if (PdrControl()->IsGraphicsBand())
   1.828 +		iBandedGc->DrawPolyLine(aPointList, aNumPoints);
   1.829 +	}
   1.830 +
   1.831 +EXPORT_C void CPdrGc::DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd)
   1.832 +	{
   1.833 +	if (PdrControl()->IsGraphicsBand())
   1.834 +		iBandedGc->DrawPie(aRect, aStart, aEnd);
   1.835 +	}
   1.836 +
   1.837 +EXPORT_C void CPdrGc::DrawEllipse(const TRect& aRect)
   1.838 +	{
   1.839 +	if (PdrControl()->IsGraphicsBand())
   1.840 +		iBandedGc->DrawEllipse(aRect);
   1.841 +	}
   1.842 +
   1.843 +EXPORT_C void CPdrGc::DrawRect(const TRect& aRect)
   1.844 +	{
   1.845 +	if (PdrControl()->IsGraphicsBand())
   1.846 +		iBandedGc->DrawRect(aRect);
   1.847 +	}
   1.848 +
   1.849 +EXPORT_C void CPdrGc::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize)
   1.850 +	{
   1.851 +	if (PdrControl()->IsGraphicsBand())
   1.852 +		iBandedGc->DrawRoundRect(aRect, aCornerSize);
   1.853 +	}
   1.854 +
   1.855 +EXPORT_C TInt CPdrGc::DrawPolygon(const CArrayFix<TPoint>* aPointList, TFillRule aFillRule)
   1.856 +	{
   1.857 +	TInt ret = KErrNone;
   1.858 +	if (PdrControl()->IsGraphicsBand())
   1.859 +		ret = iBandedGc->DrawPolygon(aPointList, aFillRule);
   1.860 +	return ret;
   1.861 +	}
   1.862 +
   1.863 +EXPORT_C TInt CPdrGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule)
   1.864 +	{
   1.865 +	TInt ret = KErrNone;
   1.866 +	if (PdrControl()->IsGraphicsBand())
   1.867 +		ret = iBandedGc->DrawPolygon(aPointList, aNumPoints, aFillRule);
   1.868 +	return ret;
   1.869 +	}
   1.870 +
   1.871 +EXPORT_C void CPdrGc::DrawBitmap(const TPoint& aTopLeft, const CFbsBitmap* aSource)
   1.872 +	{
   1.873 +	if (PdrControl()->IsGraphicsBand())
   1.874 +		iBandedGc->DrawBitmap(aTopLeft, aSource);
   1.875 +	}
   1.876 +
   1.877 +EXPORT_C void CPdrGc::DrawBitmap(const TRect& aDestRect, const CFbsBitmap* aSource)
   1.878 +	{
   1.879 +	if (PdrControl()->IsGraphicsBand())
   1.880 +		iBandedGc->DrawBitmap(aDestRect, aSource);
   1.881 +	}
   1.882 +
   1.883 +EXPORT_C void CPdrGc::DrawBitmap(const TRect& aDestRect, const CFbsBitmap* aSource, const TRect& aSourceRect)
   1.884 +	{
   1.885 +	if (PdrControl()->IsGraphicsBand())
   1.886 +		iBandedGc->DrawBitmap(aDestRect, aSource, aSourceRect);
   1.887 +	}
   1.888 +
   1.889 +EXPORT_C void CPdrGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CFbsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CFbsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
   1.890 +	{}
   1.891 +
   1.892 +EXPORT_C void CPdrGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CWsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CWsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/)
   1.893 +	{}
   1.894 +		
   1.895 +EXPORT_C void CPdrGc::MapColors(const TRect& /*aRect*/,const TRgb* /*aColors*/,TInt /*aNumPairs*/,TBool /*aMapForwards*/)
   1.896 +	{
   1.897 +	}
   1.898 +
   1.899 +EXPORT_C TInt CPdrGc::SetClippingRegion(const TRegion &/*aRegion*/)
   1.900 +	{	
   1.901 +		return KErrNone;
   1.902 +	}
   1.903 +
   1.904 +EXPORT_C void CPdrGc::CancelClippingRegion()
   1.905 +	{}
   1.906 +
   1.907 +EXPORT_C void CPdrGc::DrawTextVertical(const TDesC& /*aText*/,const TPoint& /*aPos*/,TBool /*aUp*/)
   1.908 +	{}
   1.909 +	
   1.910 +EXPORT_C void CPdrGc::DrawTextVertical(const TDesC& /*aText*/,const TRect& /*aBox*/,TInt /*aBaselineOffset*/,TBool /*aUp*/,TTextAlign /*aVert*/,TInt /*aMargin*/)
   1.911 +	{}
   1.912 +
   1.913 +EXPORT_C TInt CPdrGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CFbsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CFbsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/) 
   1.914 +	{
   1.915 +		return KErrNone;
   1.916 +	}
   1.917 +	
   1.918 +EXPORT_C TInt CPdrGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CWsBitmap* /*aSrcBmp*/,  const TRect& /*aSrcRect*/, const CWsBitmap*  /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/)
   1.919 +	{
   1.920 +		return KErrNone;
   1.921 +	}
   1.922 +
   1.923 +CPdrControl* CPdrGc::PdrControl() const 
   1.924 +{
   1.925 +	return ((CPdrControl*) iPdrDevice->iControl);
   1.926 +}
   1.927 +
   1.928 +/**
   1.929 +@deprecated Interface is deprecated because it is unsafe as it may leave. It is available for backward compatibility reasons only.
   1.930 +@see CPdrGc::DrawTextL
   1.931 +*/
   1.932 +
   1.933 +EXPORT_C void CPdrGc::DrawText(const TDesC& aString, const TPoint& aPosition)
   1.934 +	{
   1.935 +	TRAP_IGNORE(DrawTextL(aString, aPosition));
   1.936 +	}
   1.937 +
   1.938 +EXPORT_C void CPdrGc::DrawTextL(const TDesC& aString, const TPoint& aPosition)
   1.939 +	{
   1.940 +	if (!iPrintTextUsingBitmaps)
   1.941 +		{
   1.942 +		TInt firstCharNot = 0;
   1.943 +		TInt length = 0;
   1.944 +		__ASSERT_DEBUG(iFont, Panic(EPdrNoFontInUse));
   1.945 +		if (iFont->AllCharsInFontRepertoire(aString, firstCharNot, length))
   1.946 +			{
   1.947 +			iPosition = aPosition;
   1.948 +			TInt start = 0;
   1.949 +			TPtrC ptr;  // Checks to see iWordExcessWidthInPixels > 0 to avoid panic in JustificationInPixels()
   1.950 +			for (TInt i = 0; (i < aString.Length()) && iNumGaps && iWordExcessWidthInPixels; i++)
   1.951 +				{
   1.952 +				if (aString[i] == ' ')
   1.953 +					{
   1.954 +					ptr.Set(aString.Mid(start, i - start + 1));
   1.955 +					if (!PdrControl()->IsGraphicsBand())
   1.956 +						{
   1.957 +						PdrControl()->DrawTextL(iPosition + iOrigin, iUnderlineStyle, iStrikethroughStyle, iPenColor, iFont, ptr);
   1.958 +						}
   1.959 +					iPosition += TPoint(iFont->MeasureText(ptr) + JustificationInPixels(iWordExcessWidthInPixels, iNumGaps), 0);
   1.960 +					start = i + 1;
   1.961 +					}
   1.962 +				}
   1.963 +			if (start < aString.Length())
   1.964 +				{
   1.965 +				ptr.Set(aString.Mid(start));
   1.966 +				if (!PdrControl()->IsGraphicsBand())
   1.967 +					{
   1.968 +					PdrControl()->DrawTextL(iPosition + iOrigin, iUnderlineStyle, iStrikethroughStyle, iPenColor, iFont, ptr);
   1.969 +					}
   1.970 +				iPosition += TPoint(iFont->MeasureText(ptr), 0);
   1.971 +				}
   1.972 +			}
   1.973 +		else
   1.974 +			{
   1.975 +			if (firstCharNot > 0)
   1.976 +				{	// Take text substring and draw it
   1.977 +				TPtrC ptr;
   1.978 +				ptr.Set(aString.Mid(0, firstCharNot));
   1.979 +				DrawText(ptr, aPosition);
   1.980 +				// Whole string wasn't text so there must be some (bitmap) string left
   1.981 +				// Update drawing position
   1.982 +				TPoint position = iPosition;
   1.983 +				// Take rest of string and try again
   1.984 +				ptr.Set(aString.Mid(firstCharNot));
   1.985 +				DrawText(ptr, position);
   1.986 +				}
   1.987 +			else
   1.988 +				{	// Take bitmap substring and draw it
   1.989 +				TPtrC ptr;
   1.990 +				ptr.Set(aString.Mid(0, length));
   1.991 +				if (PdrControl()->IsGraphicsBand())
   1.992 +					{
   1.993 +					iPrintTextUsingBitmaps = ETrue;
   1.994 +					DrawText(ptr, aPosition);
   1.995 +					iPrintTextUsingBitmaps = EFalse;
   1.996 +					}
   1.997 +				if (length < aString.Length())
   1.998 +					{
   1.999 +					// There must be some (text) string left
  1.1000 +					// Update drawing position
  1.1001 +					iPosition = aPosition;
  1.1002 +					TPtrC ptr2;
  1.1003 +					TInt start = 0;
  1.1004 +					// Checks to see iWordExcessWidthInPixels > 0 to avoid panic in JustificationInPixels()
  1.1005 +					for (TInt i = 0; (i < ptr.Length()) && iNumGaps && iWordExcessWidthInPixels; i++)
  1.1006 +						{
  1.1007 +						if (ptr[i] == ' ')
  1.1008 +							{
  1.1009 +							ptr2.Set(ptr.Mid(start, i - start + 1));
  1.1010 +							iPosition += TPoint(iFont->MeasureText(ptr2) + JustificationInPixels(iWordExcessWidthInPixels, iNumGaps), 0);
  1.1011 +							start = i + 1;
  1.1012 +							}
  1.1013 +						}
  1.1014 +					if (start < ptr.Length())
  1.1015 +						{
  1.1016 +						ptr2.Set(ptr.Mid(start));
  1.1017 +						iPosition += TPoint(iFont->MeasureText(ptr2), 0);
  1.1018 +						}
  1.1019 +					TPoint position = iPosition;
  1.1020 +					// Take rest of string and try again
  1.1021 +					ptr.Set(aString.Mid(length));
  1.1022 +					DrawText(ptr, position);
  1.1023 +					}
  1.1024 +				}
  1.1025 +			}
  1.1026 +		}
  1.1027 +	else
  1.1028 +		{
  1.1029 +		if (PdrControl()->IsGraphicsBand())
  1.1030 +			iBandedGc->DrawText(aString, aPosition);
  1.1031 +		}
  1.1032 +	}
  1.1033 +
  1.1034 +EXPORT_C void CPdrGc::DrawText(const TDesC& aString, const TRect& aBox, TInt aBaselineOffset, TTextAlign aHoriz, TInt aLeftMrg)
  1.1035 +	{
  1.1036 +	if (!iPrintTextUsingBitmaps)
  1.1037 +		{
  1.1038 +		__ASSERT_DEBUG(iFont, Panic(EPdrNoFontInUse));
  1.1039 +		if (!PdrControl()->IsGraphicsBand())
  1.1040 +			{
  1.1041 +			TInt width = iFont->MeasureText(aString);
  1.1042 +			TPoint pos;
  1.1043 +			pos.iY = aBox.iTl.iY + aBaselineOffset;
  1.1044 +			if (aHoriz == ELeft)
  1.1045 +				pos.iX = aBox.iTl.iX + aLeftMrg;
  1.1046 +			else if (aHoriz == ERight)
  1.1047 +				pos.iX = aBox.iBr.iX - aLeftMrg - width;
  1.1048 +			else if (aHoriz == ECenter)
  1.1049 +				pos.iX = (aBox.iTl.iX + aBox.iBr.iX - width) / 2;
  1.1050 +			DrawText(aString, pos);
  1.1051 +			}
  1.1052 +		else
  1.1053 +			iBandedGc->DrawText(KNullDesC, aBox, aBaselineOffset, aHoriz, aLeftMrg);
  1.1054 +		}
  1.1055 +	else
  1.1056 +		{
  1.1057 +		if (PdrControl()->IsGraphicsBand())
  1.1058 +			iBandedGc->DrawText(aString, aBox, aBaselineOffset, aHoriz, aLeftMrg);
  1.1059 +		}
  1.1060 +	}