Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 const TInt KBandSizeInBytes=0x8000; // 32k
22 EXPORT_C CBandedDevice::~CBandedDevice()
26 delete iBandBitmapDevice;
27 iBandBitmapDevice=NULL;
32 EXPORT_C CBandedDevice* CBandedDevice::NewL(TRect aRectInPixels,TSize aKPixelSizeInTwips,TDisplayMode aDisplayMode,TBandingDirection aBandingDirection,TInt aScanLinesPerBand)
34 CBandedDevice* device=new(ELeave) CBandedDevice(aRectInPixels,aBandingDirection,aScanLinesPerBand);
35 CleanupStack::PushL(device);
36 device->ConstructL(aDisplayMode,aKPixelSizeInTwips);
41 EXPORT_C TInt CBandedDevice::HorizontalTwipsToPixels(TInt aTwips) const
43 return iBandBitmapDevice->HorizontalTwipsToPixels(aTwips);
46 EXPORT_C TInt CBandedDevice::VerticalTwipsToPixels(TInt aTwips) const
48 return iBandBitmapDevice->VerticalTwipsToPixels(aTwips);
51 EXPORT_C TInt CBandedDevice::HorizontalPixelsToTwips(TInt aPixels) const
53 return iBandBitmapDevice->HorizontalPixelsToTwips(aPixels);
56 EXPORT_C TInt CBandedDevice::VerticalPixelsToTwips(TInt aPixels) const
58 return iBandBitmapDevice->VerticalPixelsToTwips(aPixels);
61 /** Creates a font from those available in the printer device's
62 typeface store that most closely matches a font specification.
64 When the font is no longer needed, call ReleaseFont().
66 This function is replaced by GetNearestFontToDesignHeightInTwips()
68 @param aFont On return, points to the font which most closely matches the
70 @param aFontSpec An absolute font specification. Its iHeight member is
71 interpreted as being in twips.
72 @return KErrNone if successful; otherwise, another one of the system-wide error
75 EXPORT_C TInt CBandedDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
77 return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
80 /** Creates a font from those available in the printer device's
81 typeface store that most closely matches a font specification.
83 When the font is no longer needed, call ReleaseFont().
85 This function replaces GetNearestFontInTwips()
87 @param aFont On return, points to the font which most closely matches the
89 @param aFontSpec An absolute font specification. Its iHeight member is
90 interpreted as being in twips.
91 @return KErrNone if successful; otherwise, another one of the system-wide error
93 EXPORT_C TInt CBandedDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
95 return iBandBitmapDevice->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
98 /** This call is defined because it had to be - it appeared as an abstract virtual in
99 the base class. But it should never actually get called for this class. */
100 EXPORT_C TInt CBandedDevice::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/)
102 return KErrNotSupported;
105 EXPORT_C void CBandedDevice::ReleaseFont(CFont* aFont)
107 iBandBitmapDevice->ReleaseFont(aFont);
110 EXPORT_C TDisplayMode CBandedDevice::DisplayMode() const
112 return iBandBitmapDevice->DisplayMode();
115 EXPORT_C TSize CBandedDevice::SizeInPixels() const
117 return iFullRectInPixels.Size();
120 EXPORT_C TSize CBandedDevice::SizeInTwips() const
122 TSize size=SizeInPixels();
123 size.iWidth=HorizontalPixelsToTwips(size.iWidth);
124 size.iHeight=VerticalPixelsToTwips(size.iHeight);
128 EXPORT_C TInt CBandedDevice::CreateContext(CGraphicsContext*& aGC)
130 TInt ret=iBandBitmapDevice->CreateContext(aGC);
133 TPoint origin=FullOriginToBandOrigin(TPoint(0,0));
134 aGC->SetOrigin(origin);
139 EXPORT_C TInt CBandedDevice::NumTypefaces() const
141 return iBandBitmapDevice->NumTypefaces();
144 EXPORT_C void CBandedDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
146 iBandBitmapDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
149 EXPORT_C TInt CBandedDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
151 return iBandBitmapDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex);
154 EXPORT_C void CBandedDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
156 iBandBitmapDevice->PaletteAttributes(aModifiable,aNumEntries);
159 EXPORT_C void CBandedDevice::SetPalette(CPalette* aPalette)
161 iBandBitmapDevice->SetPalette(aPalette);
164 EXPORT_C TInt CBandedDevice::GetPalette(CPalette*& aPalette) const
166 return iBandBitmapDevice->GetPalette(aPalette);
169 EXPORT_C TInt CBandedDevice::NumBands() const
172 if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
173 numbands = (iFullRectInPixels.Size().iHeight/iScanLinesPerBand)+1;
175 numbands = (iFullRectInPixels.Size().iWidth/iScanLinesPerBand)+1;
179 EXPORT_C TInt CBandedDevice::NextBand()
182 if (iBandIndex==NumBands())
188 EXPORT_C TRect CBandedDevice::BandRect() const
191 if (iBandingDirection==EBandingTopToBottom)
193 bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
194 bandrect.iTl.iY=iFullRectInPixels.iTl.iY+(iBandIndex*iScanLinesPerBand);
195 bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
196 bandrect.iBr.iY=bandrect.iTl.iY+iScanLinesPerBand;
197 if (bandrect.iBr.iY>iFullRectInPixels.iBr.iY)
198 bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
200 else if (iBandingDirection==EBandingBottomToTop)
202 bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
203 bandrect.iBr.iY=iFullRectInPixels.iBr.iY-(iBandIndex*iScanLinesPerBand);
204 bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
205 bandrect.iTl.iY=bandrect.iBr.iY-iScanLinesPerBand;
206 if (bandrect.iTl.iY<iFullRectInPixels.iTl.iY)
207 bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
209 else if (iBandingDirection==EBandingLeftToRight)
211 bandrect.iTl.iX=iFullRectInPixels.iTl.iX+(iBandIndex*iScanLinesPerBand);
212 bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
213 bandrect.iBr.iX=bandrect.iTl.iX+iScanLinesPerBand;
214 bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
215 if (bandrect.iBr.iX>iFullRectInPixels.iBr.iX)
216 bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
218 else if (iBandingDirection==EBandingRightToLeft)
220 bandrect.iBr.iX=iFullRectInPixels.iBr.iX-(iBandIndex*iScanLinesPerBand);
221 bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
222 bandrect.iTl.iX=bandrect.iBr.iX-iScanLinesPerBand;
223 bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
224 if (bandrect.iTl.iX<iFullRectInPixels.iTl.iX)
225 bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
230 EXPORT_C TPoint CBandedDevice::FullOriginToBandOrigin(const TPoint& aPoint) const
232 TRect rect=BandRect();
233 return aPoint-rect.iTl;
236 EXPORT_C void CBandedDevice::Reset()
241 CBandedDevice::CBandedDevice(TRect aRectInPixels,TBandingDirection aBandingDirection,TInt aScanLinesPerBand):
242 iFullRectInPixels(aRectInPixels),
243 iScanLinesPerBand(aScanLinesPerBand),
246 iBandBitmapDevice(NULL),
247 iBandingDirection(aBandingDirection)
251 void CBandedDevice::ConstructL(TDisplayMode aDisplayMode,TSize aKPixelSizeInTwips)
253 iBandBitmap=new(ELeave) CFbsBitmap;
254 if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
256 TInt widthinpixels=iFullRectInPixels.Size().iWidth;
257 if (!iScanLinesPerBand)
258 iScanLinesPerBand=KBandSizeInBytes/(CFbsBitmap::ScanLineLength(widthinpixels,aDisplayMode));
259 iScanLinesPerBand&=~1;
260 User::LeaveIfError(iBandBitmap->Create(TSize(widthinpixels,iScanLinesPerBand),aDisplayMode));
262 sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*widthinpixels)/1000;
263 sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*iScanLinesPerBand)/1000;
264 iBandBitmap->SetSizeInTwips(sizeintwips);
268 TInt heightinpixels=iFullRectInPixels.Size().iHeight;
269 if (!iScanLinesPerBand)
270 iScanLinesPerBand=KBandSizeInBytes/(CFbsBitmap::ScanLineLength(heightinpixels,aDisplayMode));
271 iScanLinesPerBand&=~1;
272 User::LeaveIfError(iBandBitmap->Create(TSize(iScanLinesPerBand,heightinpixels),aDisplayMode));
274 sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*iScanLinesPerBand)/1000;
275 sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*heightinpixels)/1000;
276 iBandBitmap->SetSizeInTwips(sizeintwips);
278 iBandBitmapDevice=CFbsBitmapDevice::NewL(iBandBitmap);
279 User::LeaveIfError(iBandBitmapDevice->CreateContext((CGraphicsContext*&) iClearGc));