1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/printingservices/printerdriversupport/src/BANDDEV.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,281 @@
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 <bitdev.h>
1.20 +#include <bitstd.h>
1.21 +#include <banddev.h>
1.22 +
1.23 +const TInt KBandSizeInBytes=0x8000; // 32k
1.24 +
1.25 +EXPORT_C CBandedDevice::~CBandedDevice()
1.26 + {
1.27 + delete iClearGc;
1.28 + iClearGc=NULL;
1.29 + delete iBandBitmapDevice;
1.30 + iBandBitmapDevice=NULL;
1.31 + delete iBandBitmap;
1.32 + iBandBitmap=NULL;
1.33 + }
1.34 +
1.35 +EXPORT_C CBandedDevice* CBandedDevice::NewL(TRect aRectInPixels,TSize aKPixelSizeInTwips,TDisplayMode aDisplayMode,TBandingDirection aBandingDirection,TInt aScanLinesPerBand)
1.36 + {
1.37 + CBandedDevice* device=new(ELeave) CBandedDevice(aRectInPixels,aBandingDirection,aScanLinesPerBand);
1.38 + CleanupStack::PushL(device);
1.39 + device->ConstructL(aDisplayMode,aKPixelSizeInTwips);
1.40 + CleanupStack::Pop();
1.41 + return device;
1.42 + }
1.43 +
1.44 +EXPORT_C TInt CBandedDevice::HorizontalTwipsToPixels(TInt aTwips) const
1.45 + {
1.46 + return iBandBitmapDevice->HorizontalTwipsToPixels(aTwips);
1.47 + }
1.48 +
1.49 +EXPORT_C TInt CBandedDevice::VerticalTwipsToPixels(TInt aTwips) const
1.50 + {
1.51 + return iBandBitmapDevice->VerticalTwipsToPixels(aTwips);
1.52 + }
1.53 +
1.54 +EXPORT_C TInt CBandedDevice::HorizontalPixelsToTwips(TInt aPixels) const
1.55 + {
1.56 + return iBandBitmapDevice->HorizontalPixelsToTwips(aPixels);
1.57 + }
1.58 +
1.59 +EXPORT_C TInt CBandedDevice::VerticalPixelsToTwips(TInt aPixels) const
1.60 + {
1.61 + return iBandBitmapDevice->VerticalPixelsToTwips(aPixels);
1.62 + }
1.63 +
1.64 +/** Creates a font from those available in the printer device's
1.65 +typeface store that most closely matches a font specification.
1.66 +
1.67 +When the font is no longer needed, call ReleaseFont().
1.68 +
1.69 +This function is replaced by GetNearestFontToDesignHeightInTwips()
1.70 +
1.71 +@param aFont On return, points to the font which most closely matches the
1.72 +specified font.
1.73 +@param aFontSpec An absolute font specification. Its iHeight member is
1.74 +interpreted as being in twips.
1.75 +@return KErrNone if successful; otherwise, another one of the system-wide error
1.76 +codes.
1.77 +@deprecated */
1.78 +EXPORT_C TInt CBandedDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.79 + {
1.80 + return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
1.81 + }
1.82 +
1.83 +/** Creates a font from those available in the printer device's
1.84 +typeface store that most closely matches a font specification.
1.85 +
1.86 +When the font is no longer needed, call ReleaseFont().
1.87 +
1.88 +This function replaces GetNearestFontInTwips()
1.89 +
1.90 +@param aFont On return, points to the font which most closely matches the
1.91 +specified font.
1.92 +@param aFontSpec An absolute font specification. Its iHeight member is
1.93 +interpreted as being in twips.
1.94 +@return KErrNone if successful; otherwise, another one of the system-wide error
1.95 +codes. */
1.96 +EXPORT_C TInt CBandedDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
1.97 + {
1.98 + return iBandBitmapDevice->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
1.99 + }
1.100 +
1.101 +/** This call is defined because it had to be - it appeared as an abstract virtual in
1.102 +the base class. But it should never actually get called for this class. */
1.103 +EXPORT_C TInt CBandedDevice::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/)
1.104 + {
1.105 + return KErrNotSupported;
1.106 + }
1.107 +
1.108 +EXPORT_C void CBandedDevice::ReleaseFont(CFont* aFont)
1.109 + {
1.110 + iBandBitmapDevice->ReleaseFont(aFont);
1.111 + }
1.112 +
1.113 +EXPORT_C TDisplayMode CBandedDevice::DisplayMode() const
1.114 + {
1.115 + return iBandBitmapDevice->DisplayMode();
1.116 + }
1.117 +
1.118 +EXPORT_C TSize CBandedDevice::SizeInPixels() const
1.119 + {
1.120 + return iFullRectInPixels.Size();
1.121 + }
1.122 +
1.123 +EXPORT_C TSize CBandedDevice::SizeInTwips() const
1.124 + {
1.125 + TSize size=SizeInPixels();
1.126 + size.iWidth=HorizontalPixelsToTwips(size.iWidth);
1.127 + size.iHeight=VerticalPixelsToTwips(size.iHeight);
1.128 + return size;
1.129 + }
1.130 +
1.131 +EXPORT_C TInt CBandedDevice::CreateContext(CGraphicsContext*& aGC)
1.132 + {
1.133 + TInt ret=iBandBitmapDevice->CreateContext(aGC);
1.134 + if (ret==KErrNone)
1.135 + {
1.136 + TPoint origin=FullOriginToBandOrigin(TPoint(0,0));
1.137 + aGC->SetOrigin(origin);
1.138 + }
1.139 + return ret;
1.140 + }
1.141 +
1.142 +EXPORT_C TInt CBandedDevice::NumTypefaces() const
1.143 + {
1.144 + return iBandBitmapDevice->NumTypefaces();
1.145 + }
1.146 +
1.147 +EXPORT_C void CBandedDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
1.148 + {
1.149 + iBandBitmapDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
1.150 + }
1.151 +
1.152 +EXPORT_C TInt CBandedDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
1.153 + {
1.154 + return iBandBitmapDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex);
1.155 + }
1.156 +
1.157 +EXPORT_C void CBandedDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
1.158 + {
1.159 + iBandBitmapDevice->PaletteAttributes(aModifiable,aNumEntries);
1.160 + }
1.161 +
1.162 +EXPORT_C void CBandedDevice::SetPalette(CPalette* aPalette)
1.163 + {
1.164 + iBandBitmapDevice->SetPalette(aPalette);
1.165 + }
1.166 +
1.167 +EXPORT_C TInt CBandedDevice::GetPalette(CPalette*& aPalette) const
1.168 + {
1.169 + return iBandBitmapDevice->GetPalette(aPalette);
1.170 + }
1.171 +
1.172 +EXPORT_C TInt CBandedDevice::NumBands() const
1.173 + {
1.174 + TInt numbands;
1.175 + if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
1.176 + numbands = (iFullRectInPixels.Size().iHeight/iScanLinesPerBand)+1;
1.177 + else
1.178 + numbands = (iFullRectInPixels.Size().iWidth/iScanLinesPerBand)+1;
1.179 + return numbands;
1.180 + }
1.181 +
1.182 +EXPORT_C TInt CBandedDevice::NextBand()
1.183 + {
1.184 + iBandIndex++;
1.185 + if (iBandIndex==NumBands())
1.186 + iBandIndex=0;
1.187 + iClearGc->Clear();
1.188 + return iBandIndex;
1.189 + }
1.190 +
1.191 +EXPORT_C TRect CBandedDevice::BandRect() const
1.192 + {
1.193 + TRect bandrect;
1.194 + if (iBandingDirection==EBandingTopToBottom)
1.195 + {
1.196 + bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
1.197 + bandrect.iTl.iY=iFullRectInPixels.iTl.iY+(iBandIndex*iScanLinesPerBand);
1.198 + bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
1.199 + bandrect.iBr.iY=bandrect.iTl.iY+iScanLinesPerBand;
1.200 + if (bandrect.iBr.iY>iFullRectInPixels.iBr.iY)
1.201 + bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
1.202 + }
1.203 + else if (iBandingDirection==EBandingBottomToTop)
1.204 + {
1.205 + bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
1.206 + bandrect.iBr.iY=iFullRectInPixels.iBr.iY-(iBandIndex*iScanLinesPerBand);
1.207 + bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
1.208 + bandrect.iTl.iY=bandrect.iBr.iY-iScanLinesPerBand;
1.209 + if (bandrect.iTl.iY<iFullRectInPixels.iTl.iY)
1.210 + bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
1.211 + }
1.212 + else if (iBandingDirection==EBandingLeftToRight)
1.213 + {
1.214 + bandrect.iTl.iX=iFullRectInPixels.iTl.iX+(iBandIndex*iScanLinesPerBand);
1.215 + bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
1.216 + bandrect.iBr.iX=bandrect.iTl.iX+iScanLinesPerBand;
1.217 + bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
1.218 + if (bandrect.iBr.iX>iFullRectInPixels.iBr.iX)
1.219 + bandrect.iBr.iX=iFullRectInPixels.iBr.iX;
1.220 + }
1.221 + else if (iBandingDirection==EBandingRightToLeft)
1.222 + {
1.223 + bandrect.iBr.iX=iFullRectInPixels.iBr.iX-(iBandIndex*iScanLinesPerBand);
1.224 + bandrect.iBr.iY=iFullRectInPixels.iBr.iY;
1.225 + bandrect.iTl.iX=bandrect.iBr.iX-iScanLinesPerBand;
1.226 + bandrect.iTl.iY=iFullRectInPixels.iTl.iY;
1.227 + if (bandrect.iTl.iX<iFullRectInPixels.iTl.iX)
1.228 + bandrect.iTl.iX=iFullRectInPixels.iTl.iX;
1.229 + }
1.230 + return bandrect;
1.231 + }
1.232 +
1.233 +EXPORT_C TPoint CBandedDevice::FullOriginToBandOrigin(const TPoint& aPoint) const
1.234 + {
1.235 + TRect rect=BandRect();
1.236 + return aPoint-rect.iTl;
1.237 + }
1.238 +
1.239 +EXPORT_C void CBandedDevice::Reset()
1.240 + {
1.241 + iBandIndex=-1;
1.242 + }
1.243 +
1.244 +CBandedDevice::CBandedDevice(TRect aRectInPixels,TBandingDirection aBandingDirection,TInt aScanLinesPerBand):
1.245 + iFullRectInPixels(aRectInPixels),
1.246 + iScanLinesPerBand(aScanLinesPerBand),
1.247 + iBandIndex(-1),
1.248 + iBandBitmap(NULL),
1.249 + iBandBitmapDevice(NULL),
1.250 + iBandingDirection(aBandingDirection)
1.251 + {
1.252 + }
1.253 +
1.254 +void CBandedDevice::ConstructL(TDisplayMode aDisplayMode,TSize aKPixelSizeInTwips)
1.255 + {
1.256 + iBandBitmap=new(ELeave) CFbsBitmap;
1.257 + if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
1.258 + {
1.259 + TInt widthinpixels=iFullRectInPixels.Size().iWidth;
1.260 + if (!iScanLinesPerBand)
1.261 + iScanLinesPerBand=KBandSizeInBytes/(CFbsBitmap::ScanLineLength(widthinpixels,aDisplayMode));
1.262 + iScanLinesPerBand&=~1;
1.263 + User::LeaveIfError(iBandBitmap->Create(TSize(widthinpixels,iScanLinesPerBand),aDisplayMode));
1.264 + TSize sizeintwips;
1.265 + sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*widthinpixels)/1000;
1.266 + sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*iScanLinesPerBand)/1000;
1.267 + iBandBitmap->SetSizeInTwips(sizeintwips);
1.268 + }
1.269 + else
1.270 + {
1.271 + TInt heightinpixels=iFullRectInPixels.Size().iHeight;
1.272 + if (!iScanLinesPerBand)
1.273 + iScanLinesPerBand=KBandSizeInBytes/(CFbsBitmap::ScanLineLength(heightinpixels,aDisplayMode));
1.274 + iScanLinesPerBand&=~1;
1.275 + User::LeaveIfError(iBandBitmap->Create(TSize(iScanLinesPerBand,heightinpixels),aDisplayMode));
1.276 + TSize sizeintwips;
1.277 + sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*iScanLinesPerBand)/1000;
1.278 + sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*heightinpixels)/1000;
1.279 + iBandBitmap->SetSizeInTwips(sizeintwips);
1.280 + }
1.281 + iBandBitmapDevice=CFbsBitmapDevice::NewL(iBandBitmap);
1.282 + User::LeaveIfError(iBandBitmapDevice->CreateContext((CGraphicsContext*&) iClearGc));
1.283 + }
1.284 +