03.01.2013 Views

Chapter 1

Chapter 1

Chapter 1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

� work more efficiently by treating text and graphics separately so that, for instance, all<br />

text is covered in one band, while graphics are covered in several small bands.<br />

As the implementer of PrintBandL(), you clearly have to honor the page number, so that<br />

you print the relevant text on every page.<br />

Whether you take any notice of the band attributes is rather like whether you take any notice<br />

of the bounding rectangle passed to CCoeControl::Draw(): if you ignore these<br />

parameters, your code may work fine. But you may be able to substantially speed printing up<br />

by printing only what's necessary for each band.<br />

Anyway, you could reuse the view code in CExampleHelloView to implement<br />

PrintBandL() for a single-page print:<br />

void CMyApplication::PrintBandL(CGraphicsDevice* aDevice,<br />

aBandInPixels */)<br />

{<br />

//Allocate the font<br />

TInt /* aPageNo */<br />

TFontSpec fontSpec(_L("Arial"), 6*10);<br />

const TBandAttributes& /*<br />

fontSpec.iFontStyle=TFontStyle(EPostureUpright,<br />

EStrokeWeightBold,<br />

EPrintPosNormal);<br />

CFont* font;<br />

User::LeaveIfError(aDevice.GetNearestFontInTwips(font,<br />

fontSpec));<br />

//Draw the view<br />

CGraphicsContext* gc;<br />

User::LeaveIfError(aDevice->CreateContext(gc));<br />

TRect rectInTwips(2880, 2880, 2880, 1440):<br />

TRect rect(aDevice->HorizontalTwipsToPixels(rectInTwips.iTl.iX),<br />

aDevice->VerticalTwipsToPixels(rectInTwips.iTl.iY),<br />

aDevice->HorizontalTwipsToPixels(rectInTwips.iBr.iX),<br />

aDevice->VerticalTwipsToPixels(rectInTwips.iBr.iY));<br />

iView->DrawInRect(*aDevice, *gc, rect, font);<br />

delete gc;<br />

//Release the font<br />

aDevice.ReleaseFont(font);<br />

}<br />

Because PrintBandL(~) is a leave function, we are able to allocate the font within it.<br />

This prints the text in a rectangle 2 × 1 inches big, whose top-left corner is 2 inches down, 2<br />

inches right, from the edge of the paper – regardless of paper size and margins. More

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!