printingservices/printerdriversupport/src/BANDDEV.CPP
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <bitdev.h>
       
    17 #include <bitstd.h>
       
    18 #include <banddev.h>
       
    19 
       
    20 const TInt KBandSizeInBytes=0x8000; // 32k
       
    21 
       
    22 EXPORT_C CBandedDevice::~CBandedDevice()
       
    23 	{
       
    24 	delete iClearGc;
       
    25 	iClearGc=NULL;
       
    26 	delete iBandBitmapDevice;
       
    27 	iBandBitmapDevice=NULL;
       
    28 	delete iBandBitmap;
       
    29 	iBandBitmap=NULL;
       
    30 	}
       
    31 
       
    32 EXPORT_C CBandedDevice* CBandedDevice::NewL(TRect aRectInPixels,TSize aKPixelSizeInTwips,TDisplayMode aDisplayMode,TBandingDirection aBandingDirection,TInt aScanLinesPerBand)
       
    33 	{
       
    34 	CBandedDevice* device=new(ELeave) CBandedDevice(aRectInPixels,aBandingDirection,aScanLinesPerBand);
       
    35 	CleanupStack::PushL(device);
       
    36 	device->ConstructL(aDisplayMode,aKPixelSizeInTwips);
       
    37 	CleanupStack::Pop();
       
    38 	return device;
       
    39 	}
       
    40 
       
    41 EXPORT_C TInt CBandedDevice::HorizontalTwipsToPixels(TInt aTwips) const
       
    42 	{
       
    43 	return iBandBitmapDevice->HorizontalTwipsToPixels(aTwips);
       
    44 	}
       
    45 
       
    46 EXPORT_C TInt CBandedDevice::VerticalTwipsToPixels(TInt aTwips) const
       
    47 	{
       
    48 	return iBandBitmapDevice->VerticalTwipsToPixels(aTwips);
       
    49 	}
       
    50 
       
    51 EXPORT_C TInt CBandedDevice::HorizontalPixelsToTwips(TInt aPixels) const
       
    52 	{
       
    53 	return iBandBitmapDevice->HorizontalPixelsToTwips(aPixels);
       
    54 	}
       
    55 
       
    56 EXPORT_C TInt CBandedDevice::VerticalPixelsToTwips(TInt aPixels) const
       
    57 	{
       
    58 	return iBandBitmapDevice->VerticalPixelsToTwips(aPixels);
       
    59 	}
       
    60 
       
    61 /** Creates a font from those available in the printer device's 
       
    62 typeface store that most closely matches a font specification. 
       
    63 
       
    64 When the font is no longer needed, call ReleaseFont().
       
    65 
       
    66 This function is replaced by GetNearestFontToDesignHeightInTwips()
       
    67 
       
    68 @param aFont On return, points to the font which most closely matches the 
       
    69 specified font.
       
    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 
       
    73 codes.
       
    74 @deprecated */
       
    75 EXPORT_C TInt CBandedDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
       
    76 	{
       
    77 	return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
       
    78 	}
       
    79 
       
    80 /** Creates a font from those available in the printer device's 
       
    81 typeface store that most closely matches a font specification. 
       
    82 
       
    83 When the font is no longer needed, call ReleaseFont().
       
    84 
       
    85 This function replaces GetNearestFontInTwips()
       
    86 
       
    87 @param aFont On return, points to the font which most closely matches the 
       
    88 specified font.
       
    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 
       
    92 codes. */
       
    93 EXPORT_C TInt CBandedDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec)
       
    94 	{
       
    95 	return iBandBitmapDevice->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec);
       
    96 	}
       
    97 
       
    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*/)
       
   101 	{
       
   102 	return KErrNotSupported;
       
   103 	}
       
   104 
       
   105 EXPORT_C void CBandedDevice::ReleaseFont(CFont* aFont)
       
   106 	{
       
   107 	iBandBitmapDevice->ReleaseFont(aFont);
       
   108 	}
       
   109 
       
   110 EXPORT_C TDisplayMode CBandedDevice::DisplayMode() const
       
   111 	{
       
   112 	return iBandBitmapDevice->DisplayMode();
       
   113 	}
       
   114 
       
   115 EXPORT_C TSize CBandedDevice::SizeInPixels() const
       
   116 	{
       
   117 	return iFullRectInPixels.Size();
       
   118 	}
       
   119 
       
   120 EXPORT_C TSize CBandedDevice::SizeInTwips() const
       
   121 	{
       
   122 	TSize size=SizeInPixels();
       
   123 	size.iWidth=HorizontalPixelsToTwips(size.iWidth);
       
   124 	size.iHeight=VerticalPixelsToTwips(size.iHeight);
       
   125 	return size;
       
   126 	}
       
   127 
       
   128 EXPORT_C TInt CBandedDevice::CreateContext(CGraphicsContext*& aGC)
       
   129 	{
       
   130 	TInt ret=iBandBitmapDevice->CreateContext(aGC);
       
   131 	if (ret==KErrNone)
       
   132 		{
       
   133 		TPoint origin=FullOriginToBandOrigin(TPoint(0,0));
       
   134 		aGC->SetOrigin(origin);
       
   135 		}
       
   136 	return ret;
       
   137 	}
       
   138 
       
   139 EXPORT_C TInt CBandedDevice::NumTypefaces() const
       
   140 	{
       
   141 	return iBandBitmapDevice->NumTypefaces();
       
   142 	}
       
   143 
       
   144 EXPORT_C void CBandedDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const
       
   145 	{
       
   146 	iBandBitmapDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex);
       
   147 	}
       
   148 
       
   149 EXPORT_C TInt CBandedDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const
       
   150 	{
       
   151 	return iBandBitmapDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex);
       
   152 	}
       
   153 
       
   154 EXPORT_C void CBandedDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const
       
   155 	{
       
   156 	iBandBitmapDevice->PaletteAttributes(aModifiable,aNumEntries);
       
   157 	}
       
   158 
       
   159 EXPORT_C void CBandedDevice::SetPalette(CPalette* aPalette)
       
   160 	{
       
   161 	iBandBitmapDevice->SetPalette(aPalette);
       
   162 	}
       
   163 
       
   164 EXPORT_C TInt CBandedDevice::GetPalette(CPalette*& aPalette) const
       
   165 	{
       
   166 	return iBandBitmapDevice->GetPalette(aPalette);
       
   167 	}
       
   168 
       
   169 EXPORT_C TInt CBandedDevice::NumBands() const
       
   170 	{
       
   171 	TInt numbands;
       
   172 	if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
       
   173 		numbands = (iFullRectInPixels.Size().iHeight/iScanLinesPerBand)+1;
       
   174 	else
       
   175 		numbands = (iFullRectInPixels.Size().iWidth/iScanLinesPerBand)+1;
       
   176 	return numbands;
       
   177 	}
       
   178 
       
   179 EXPORT_C TInt CBandedDevice::NextBand()
       
   180 	{
       
   181 	iBandIndex++;
       
   182 	if (iBandIndex==NumBands())
       
   183 		iBandIndex=0;
       
   184 	iClearGc->Clear();
       
   185 	return iBandIndex;
       
   186 	}
       
   187 
       
   188 EXPORT_C TRect CBandedDevice::BandRect() const
       
   189 	{
       
   190 	TRect bandrect;
       
   191 	if (iBandingDirection==EBandingTopToBottom)
       
   192 		{
       
   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;
       
   199 		}
       
   200 	else if (iBandingDirection==EBandingBottomToTop)
       
   201 		{
       
   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;
       
   208 		}
       
   209 	else if (iBandingDirection==EBandingLeftToRight)
       
   210 		{
       
   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;
       
   217 		}
       
   218 	else if (iBandingDirection==EBandingRightToLeft)
       
   219 		{
       
   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;
       
   226 		}
       
   227 	return bandrect;
       
   228 	}
       
   229 
       
   230 EXPORT_C TPoint CBandedDevice::FullOriginToBandOrigin(const TPoint& aPoint) const
       
   231 	{
       
   232 	TRect rect=BandRect();
       
   233 	return aPoint-rect.iTl;
       
   234 	}
       
   235 
       
   236 EXPORT_C void CBandedDevice::Reset()
       
   237 	{
       
   238 	iBandIndex=-1;
       
   239 	}
       
   240 
       
   241 CBandedDevice::CBandedDevice(TRect aRectInPixels,TBandingDirection aBandingDirection,TInt aScanLinesPerBand):
       
   242 	iFullRectInPixels(aRectInPixels),
       
   243 	iScanLinesPerBand(aScanLinesPerBand),
       
   244 	iBandIndex(-1),
       
   245 	iBandBitmap(NULL),
       
   246 	iBandBitmapDevice(NULL),
       
   247 	iBandingDirection(aBandingDirection)
       
   248 	{
       
   249 	}
       
   250 
       
   251 void CBandedDevice::ConstructL(TDisplayMode aDisplayMode,TSize aKPixelSizeInTwips)
       
   252 	{
       
   253 	iBandBitmap=new(ELeave)	CFbsBitmap;
       
   254 	if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop))
       
   255 		{
       
   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));
       
   261 		TSize sizeintwips;
       
   262 		sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*widthinpixels)/1000;
       
   263 		sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*iScanLinesPerBand)/1000;
       
   264 		iBandBitmap->SetSizeInTwips(sizeintwips);
       
   265 		}
       
   266 	else
       
   267 		{
       
   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));
       
   273 		TSize sizeintwips;
       
   274 		sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*iScanLinesPerBand)/1000;
       
   275 		sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*heightinpixels)/1000;
       
   276 		iBandBitmap->SetSizeInTwips(sizeintwips);
       
   277 		}
       
   278 	iBandBitmapDevice=CFbsBitmapDevice::NewL(iBandBitmap);
       
   279 	User::LeaveIfError(iBandBitmapDevice->CreateContext((CGraphicsContext*&) iClearGc));
       
   280 	}
       
   281