sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
#include <bitdev.h>
|
sl@0
|
17 |
#include <bitstd.h>
|
sl@0
|
18 |
#include <banddev.h>
|
sl@0
|
19 |
|
sl@0
|
20 |
const TInt KBandSizeInBytes=0x8000; // 32k
|
sl@0
|
21 |
|
sl@0
|
22 |
EXPORT_C CBandedDevice::~CBandedDevice()
|
sl@0
|
23 |
{
|
sl@0
|
24 |
delete iClearGc;
|
sl@0
|
25 |
iClearGc=NULL;
|
sl@0
|
26 |
delete iBandBitmapDevice;
|
sl@0
|
27 |
iBandBitmapDevice=NULL;
|
sl@0
|
28 |
delete iBandBitmap;
|
sl@0
|
29 |
iBandBitmap=NULL;
|
sl@0
|
30 |
}
|
sl@0
|
31 |
|
sl@0
|
32 |
EXPORT_C CBandedDevice* CBandedDevice::NewL(TRect aRectInPixels,TSize aKPixelSizeInTwips,TDisplayMode aDisplayMode,TBandingDirection aBandingDirection,TInt aScanLinesPerBand)
|
sl@0
|
33 |
{
|
sl@0
|
34 |
CBandedDevice* device=new(ELeave) CBandedDevice(aRectInPixels,aBandingDirection,aScanLinesPerBand);
|
sl@0
|
35 |
CleanupStack::PushL(device);
|
sl@0
|
36 |
device->ConstructL(aDisplayMode,aKPixelSizeInTwips);
|
sl@0
|
37 |
CleanupStack::Pop();
|
sl@0
|
38 |
return device;
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
EXPORT_C TInt CBandedDevice::HorizontalTwipsToPixels(TInt aTwips) const
|
sl@0
|
42 |
{
|
sl@0
|
43 |
return iBandBitmapDevice->HorizontalTwipsToPixels(aTwips);
|
sl@0
|
44 |
}
|
sl@0
|
45 |
|
sl@0
|
46 |
EXPORT_C TInt CBandedDevice::VerticalTwipsToPixels(TInt aTwips) const
|
sl@0
|
47 |
{
|
sl@0
|
48 |
return iBandBitmapDevice->VerticalTwipsToPixels(aTwips);
|
sl@0
|
49 |
}
|
sl@0
|
50 |
|
sl@0
|
51 |
EXPORT_C TInt CBandedDevice::HorizontalPixelsToTwips(TInt aPixels) const
|
sl@0
|
52 |
{
|
sl@0
|
53 |
return iBandBitmapDevice->HorizontalPixelsToTwips(aPixels);
|
sl@0
|
54 |
}
|
sl@0
|
55 |
|
sl@0
|
56 |
EXPORT_C TInt CBandedDevice::VerticalPixelsToTwips(TInt aPixels) const
|
sl@0
|
57 |
{
|
sl@0
|
58 |
return iBandBitmapDevice->VerticalPixelsToTwips(aPixels);
|
sl@0
|
59 |
}
|
sl@0
|
60 |
|
sl@0
|
61 |
/** Creates a font from those available in the printer device's
|
sl@0
|
62 |
typeface store that most closely matches a font specification.
|
sl@0
|
63 |
|
sl@0
|
64 |
When the font is no longer needed, call ReleaseFont().
|
sl@0
|
65 |
|
sl@0
|
66 |
This function is replaced by GetNearestFontToDesignHeightInTwips()
|
sl@0
|
67 |
|
sl@0
|
68 |
@param aFont On return, points to the font which most closely matches the
|
sl@0
|
69 |
specified font.
|
sl@0
|
70 |
@param aFontSpec An absolute font specification. Its iHeight member is
|
sl@0
|
71 |
interpreted as being in twips.
|
sl@0
|
72 |
@return KErrNone if successful; otherwise, another one of the system-wide error
|
sl@0
|
73 |
codes.
|
sl@0
|
74 |
@deprecated */
|
sl@0
|
75 |
EXPORT_C TInt CBandedDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
|
sl@0
|
76 |
{
|
sl@0
|
77 |
return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
|
sl@0
|
78 |
}
|
sl@0
|
79 |
|
sl@0
|
80 |
/** Creates a font from those available in the printer device's
|
sl@0
|
81 |
typeface store that most closely matches a font specification.
|
sl@0
|
82 |
|
sl@0
|
83 |
When the font is no longer needed, call ReleaseFont().
|
sl@0
|
84 |
|
sl@0
|
85 |
This function replaces GetNearestFontInTwips()
|
sl@0
|
86 |
|
sl@0
|
87 |
@param aFont On return, points to the font which most closely matches the
|
sl@0
|
88 |
specified font.
|
sl@0
|
89 |
@param aFontSpec An absolute font specification. Its iHeight member is
|
sl@0
|
90 |
interpreted as being in twips.
|
sl@0
|
91 |
@return KErrNone if successful; otherwise, another one of the system-wide error
|
sl@0
|
92 |
codes. */
|
sl@0
|
93 |
EXPORT_C TInt CBandedDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
return iBandBitmapDevice->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
/** This call is defined because it had to be - it appeared as an abstract virtual in
|
sl@0
|
99 |
the base class. But it should never actually get called for this class. */
|
sl@0
|
100 |
EXPORT_C TInt CBandedDevice::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
return KErrNotSupported;
|
sl@0
|
103 |
}
|
sl@0
|
104 |
|
sl@0
|
105 |
EXPORT_C void CBandedDevice::ReleaseFont(CFont* aFont)
|
sl@0
|
106 |
{
|
sl@0
|
107 |
iBandBitmapDevice->ReleaseFont(aFont);
|
sl@0
|
108 |
}
|
sl@0
|
109 |
|
sl@0
|
110 |
EXPORT_C TDisplayMode CBandedDevice::DisplayMode() const
|
sl@0
|
111 |
{
|
sl@0
|
112 |
return iBandBitmapDevice->DisplayMode();
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
EXPORT_C TSize CBandedDevice::SizeInPixels() const
|
sl@0
|
116 |
{
|
sl@0
|
117 |
return iFullRectInPixels.Size();
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
EXPORT_C TSize CBandedDevice::SizeInTwips() const
|
sl@0
|
121 |
{
|
sl@0
|
122 |
TSize size=SizeInPixels();
|
sl@0
|
123 |
size.iWidth=HorizontalPixelsToTwips(size.iWidth);
|
sl@0
|
124 |
size.iHeight=VerticalPixelsToTwips(size.iHeight);
|
sl@0
|
125 |
return size;
|
sl@0
|
126 |
}
|
sl@0
|
127 |
|
sl@0
|
128 |
EXPORT_C TInt CBandedDevice::CreateContext(CGraphicsContext*& aGC)
|
sl@0
|
129 |
{
|
sl@0
|
130 |
TInt ret=iBandBitmapDevice->CreateContext(aGC);
|
sl@0
|
131 |
if (ret==KErrNone)
|
sl@0
|
132 |
{
|
sl@0
|
133 |
TPoint origin=FullOriginToBandOrigin(TPoint(0,0));
|
sl@0
|
134 |
aGC->SetOrigin(origin);
|
sl@0
|
135 |
}
|
sl@0
|
136 |
return ret;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
EXPORT_C TInt CBandedDevice::NumTypefaces() const
|
sl@0
|
140 |
{
|
sl@0
|
141 |
return iBandBitmapDevice->NumTypefaces();
|
sl@0
|
142 |
}
|
sl@0
|
143 |
|
sl@0
|
144 |
EXPORT_C void CBandedDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
|
sl@0
|
145 |
{
|
sl@0
|
146 |
iBandBitmapDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
EXPORT_C TInt CBandedDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
|
sl@0
|
150 |
{
|
sl@0
|
151 |
return iBandBitmapDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex);
|
sl@0
|
152 |
}
|
sl@0
|
153 |
|
sl@0
|
154 |
EXPORT_C void CBandedDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
|
sl@0
|
155 |
{
|
sl@0
|
156 |
iBandBitmapDevice->PaletteAttributes(aModifiable,aNumEntries);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
EXPORT_C void CBandedDevice::SetPalette(CPalette* aPalette)
|
sl@0
|
160 |
{
|
sl@0
|
161 |
iBandBitmapDevice->SetPalette(aPalette);
|
sl@0
|
162 |
}
|
sl@0
|
163 |
|
sl@0
|
164 |
EXPORT_C TInt CBandedDevice::GetPalette(CPalette*& aPalette) const
|
sl@0
|
165 |
{
|
sl@0
|
166 |
return iBandBitmapDevice->GetPalette(aPalette);
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
EXPORT_C TInt CBandedDevice::NumBands() const
|
sl@0
|
170 |
{
|
sl@0
|
171 |
TInt numbands;
|
sl@0
|
172 |
if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
|
sl@0
|
173 |
numbands = (iFullRectInPixels.Size().iHeight/iScanLinesPerBand)+1;
|
sl@0
|
174 |
else
|
sl@0
|
175 |
numbands = (iFullRectInPixels.Size().iWidth/iScanLinesPerBand)+1;
|
sl@0
|
176 |
return numbands;
|
sl@0
|
177 |
}
|
sl@0
|
178 |
|
sl@0
|
179 |
EXPORT_C TInt CBandedDevice::NextBand()
|
sl@0
|
180 |
{
|
sl@0
|
181 |
iBandIndex++;
|
sl@0
|
182 |
if (iBandIndex==NumBands())
|
sl@0
|
183 |
iBandIndex=0;
|
sl@0
|
184 |
iClearGc->Clear();
|
sl@0
|
185 |
return iBandIndex;
|
sl@0
|
186 |
}
|
sl@0
|
187 |
|
sl@0
|
188 |
EXPORT_C TRect CBandedDevice::BandRect() const
|
sl@0
|
189 |
{
|
sl@0
|
190 |
TRect bandrect;
|
sl@0
|
191 |
if (iBandingDirection==EBandingTopToBottom)
|
sl@0
|
192 |
{
|
sl@0
|
193 |
bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
|
sl@0
|
194 |
bandrect.iTl.iY=iFullRectInPixels.iTl.iY+(iBandIndex*iScanLinesPerBand);
|
sl@0
|
195 |
bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
|
sl@0
|
196 |
bandrect.iBr.iY=bandrect.iTl.iY+iScanLinesPerBand;
|
sl@0
|
197 |
if (bandrect.iBr.iY>iFullRectInPixels.iBr.iY)
|
sl@0
|
198 |
bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
else if (iBandingDirection==EBandingBottomToTop)
|
sl@0
|
201 |
{
|
sl@0
|
202 |
bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
|
sl@0
|
203 |
bandrect.iBr.iY=iFullRectInPixels.iBr.iY-(iBandIndex*iScanLinesPerBand);
|
sl@0
|
204 |
bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
|
sl@0
|
205 |
bandrect.iTl.iY=bandrect.iBr.iY-iScanLinesPerBand;
|
sl@0
|
206 |
if (bandrect.iTl.iY<iFullRectInPixels.iTl.iY)
|
sl@0
|
207 |
bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
|
sl@0
|
208 |
}
|
sl@0
|
209 |
else if (iBandingDirection==EBandingLeftToRight)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
bandrect.iTl.iX=iFullRectInPixels.iTl.iX+(iBandIndex*iScanLinesPerBand);
|
sl@0
|
212 |
bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
|
sl@0
|
213 |
bandrect.iBr.iX=bandrect.iTl.iX+iScanLinesPerBand;
|
sl@0
|
214 |
bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
|
sl@0
|
215 |
if (bandrect.iBr.iX>iFullRectInPixels.iBr.iX)
|
sl@0
|
216 |
bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
|
sl@0
|
217 |
}
|
sl@0
|
218 |
else if (iBandingDirection==EBandingRightToLeft)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
bandrect.iBr.iX=iFullRectInPixels.iBr.iX-(iBandIndex*iScanLinesPerBand);
|
sl@0
|
221 |
bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
|
sl@0
|
222 |
bandrect.iTl.iX=bandrect.iBr.iX-iScanLinesPerBand;
|
sl@0
|
223 |
bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
|
sl@0
|
224 |
if (bandrect.iTl.iX<iFullRectInPixels.iTl.iX)
|
sl@0
|
225 |
bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
|
sl@0
|
226 |
}
|
sl@0
|
227 |
return bandrect;
|
sl@0
|
228 |
}
|
sl@0
|
229 |
|
sl@0
|
230 |
EXPORT_C TPoint CBandedDevice::FullOriginToBandOrigin(const TPoint& aPoint) const
|
sl@0
|
231 |
{
|
sl@0
|
232 |
TRect rect=BandRect();
|
sl@0
|
233 |
return aPoint-rect.iTl;
|
sl@0
|
234 |
}
|
sl@0
|
235 |
|
sl@0
|
236 |
EXPORT_C void CBandedDevice::Reset()
|
sl@0
|
237 |
{
|
sl@0
|
238 |
iBandIndex=-1;
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
CBandedDevice::CBandedDevice(TRect aRectInPixels,TBandingDirection aBandingDirection,TInt aScanLinesPerBand):
|
sl@0
|
242 |
iFullRectInPixels(aRectInPixels),
|
sl@0
|
243 |
iScanLinesPerBand(aScanLinesPerBand),
|
sl@0
|
244 |
iBandIndex(-1),
|
sl@0
|
245 |
iBandBitmap(NULL),
|
sl@0
|
246 |
iBandBitmapDevice(NULL),
|
sl@0
|
247 |
iBandingDirection(aBandingDirection)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
void CBandedDevice::ConstructL(TDisplayMode aDisplayMode,TSize aKPixelSizeInTwips)
|
sl@0
|
252 |
{
|
sl@0
|
253 |
iBandBitmap=new(ELeave) CFbsBitmap;
|
sl@0
|
254 |
if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
|
sl@0
|
255 |
{
|
sl@0
|
256 |
TInt widthinpixels=iFullRectInPixels.Size().iWidth;
|
sl@0
|
257 |
if (!iScanLinesPerBand)
|
sl@0
|
258 |
iScanLinesPerBand=KBandSizeInBytes/(CFbsBitmap::ScanLineLength(widthinpixels,aDisplayMode));
|
sl@0
|
259 |
iScanLinesPerBand&=~1;
|
sl@0
|
260 |
User::LeaveIfError(iBandBitmap->Create(TSize(widthinpixels,iScanLinesPerBand),aDisplayMode));
|
sl@0
|
261 |
TSize sizeintwips;
|
sl@0
|
262 |
sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*widthinpixels)/1000;
|
sl@0
|
263 |
sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*iScanLinesPerBand)/1000;
|
sl@0
|
264 |
iBandBitmap->SetSizeInTwips(sizeintwips);
|
sl@0
|
265 |
}
|
sl@0
|
266 |
else
|
sl@0
|
267 |
{
|
sl@0
|
268 |
TInt heightinpixels=iFullRectInPixels.Size().iHeight;
|
sl@0
|
269 |
if (!iScanLinesPerBand)
|
sl@0
|
270 |
iScanLinesPerBand=KBandSizeInBytes/(CFbsBitmap::ScanLineLength(heightinpixels,aDisplayMode));
|
sl@0
|
271 |
iScanLinesPerBand&=~1;
|
sl@0
|
272 |
User::LeaveIfError(iBandBitmap->Create(TSize(iScanLinesPerBand,heightinpixels),aDisplayMode));
|
sl@0
|
273 |
TSize sizeintwips;
|
sl@0
|
274 |
sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*iScanLinesPerBand)/1000;
|
sl@0
|
275 |
sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*heightinpixels)/1000;
|
sl@0
|
276 |
iBandBitmap->SetSizeInTwips(sizeintwips);
|
sl@0
|
277 |
}
|
sl@0
|
278 |
iBandBitmapDevice=CFbsBitmapDevice::NewL(iBandBitmap);
|
sl@0
|
279 |
User::LeaveIfError(iBandBitmapDevice->CreateContext((CGraphicsContext*&) iClearGc));
|
sl@0
|
280 |
}
|
sl@0
|
281 |
|