sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: const TInt KBandSizeInBytes=0x8000; // 32k sl@0: sl@0: EXPORT_C CBandedDevice::~CBandedDevice() sl@0: { sl@0: delete iClearGc; sl@0: iClearGc=NULL; sl@0: delete iBandBitmapDevice; sl@0: iBandBitmapDevice=NULL; sl@0: delete iBandBitmap; sl@0: iBandBitmap=NULL; sl@0: } sl@0: sl@0: EXPORT_C CBandedDevice* CBandedDevice::NewL(TRect aRectInPixels,TSize aKPixelSizeInTwips,TDisplayMode aDisplayMode,TBandingDirection aBandingDirection,TInt aScanLinesPerBand) sl@0: { sl@0: CBandedDevice* device=new(ELeave) CBandedDevice(aRectInPixels,aBandingDirection,aScanLinesPerBand); sl@0: CleanupStack::PushL(device); sl@0: device->ConstructL(aDisplayMode,aKPixelSizeInTwips); sl@0: CleanupStack::Pop(); sl@0: return device; sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::HorizontalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return iBandBitmapDevice->HorizontalTwipsToPixels(aTwips); sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::VerticalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return iBandBitmapDevice->VerticalTwipsToPixels(aTwips); sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::HorizontalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return iBandBitmapDevice->HorizontalPixelsToTwips(aPixels); sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::VerticalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return iBandBitmapDevice->VerticalPixelsToTwips(aPixels); sl@0: } sl@0: sl@0: /** Creates a font from those available in the printer device's sl@0: typeface store that most closely matches a font specification. sl@0: sl@0: When the font is no longer needed, call ReleaseFont(). sl@0: sl@0: This function is replaced by GetNearestFontToDesignHeightInTwips() sl@0: sl@0: @param aFont On return, points to the font which most closely matches the sl@0: specified font. sl@0: @param aFontSpec An absolute font specification. Its iHeight member is sl@0: interpreted as being in twips. sl@0: @return KErrNone if successful; otherwise, another one of the system-wide error sl@0: codes. sl@0: @deprecated */ sl@0: EXPORT_C TInt CBandedDevice::GetNearestFontInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** Creates a font from those available in the printer device's sl@0: typeface store that most closely matches a font specification. sl@0: sl@0: When the font is no longer needed, call ReleaseFont(). sl@0: sl@0: This function replaces GetNearestFontInTwips() sl@0: sl@0: @param aFont On return, points to the font which most closely matches the sl@0: specified font. sl@0: @param aFontSpec An absolute font specification. Its iHeight member is sl@0: interpreted as being in twips. sl@0: @return KErrNone if successful; otherwise, another one of the system-wide error sl@0: codes. */ sl@0: EXPORT_C TInt CBandedDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return iBandBitmapDevice->GetNearestFontToDesignHeightInTwips(aFont, aFontSpec); sl@0: } sl@0: sl@0: /** This call is defined because it had to be - it appeared as an abstract virtual in sl@0: the base class. But it should never actually get called for this class. */ sl@0: EXPORT_C TInt CBandedDevice::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: EXPORT_C void CBandedDevice::ReleaseFont(CFont* aFont) sl@0: { sl@0: iBandBitmapDevice->ReleaseFont(aFont); sl@0: } sl@0: sl@0: EXPORT_C TDisplayMode CBandedDevice::DisplayMode() const sl@0: { sl@0: return iBandBitmapDevice->DisplayMode(); sl@0: } sl@0: sl@0: EXPORT_C TSize CBandedDevice::SizeInPixels() const sl@0: { sl@0: return iFullRectInPixels.Size(); sl@0: } sl@0: sl@0: EXPORT_C TSize CBandedDevice::SizeInTwips() const sl@0: { sl@0: TSize size=SizeInPixels(); sl@0: size.iWidth=HorizontalPixelsToTwips(size.iWidth); sl@0: size.iHeight=VerticalPixelsToTwips(size.iHeight); sl@0: return size; sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::CreateContext(CGraphicsContext*& aGC) sl@0: { sl@0: TInt ret=iBandBitmapDevice->CreateContext(aGC); sl@0: if (ret==KErrNone) sl@0: { sl@0: TPoint origin=FullOriginToBandOrigin(TPoint(0,0)); sl@0: aGC->SetOrigin(origin); sl@0: } sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::NumTypefaces() const sl@0: { sl@0: return iBandBitmapDevice->NumTypefaces(); sl@0: } sl@0: sl@0: EXPORT_C void CBandedDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport,TInt aTypefaceIndex) const sl@0: { sl@0: iBandBitmapDevice->TypefaceSupport(aTypefaceSupport,aTypefaceIndex); sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::FontHeightInTwips(TInt aTypefaceIndex,TInt aHeightIndex) const sl@0: { sl@0: return iBandBitmapDevice->FontHeightInTwips(aTypefaceIndex,aHeightIndex); sl@0: } sl@0: sl@0: EXPORT_C void CBandedDevice::PaletteAttributes(TBool& aModifiable,TInt& aNumEntries) const sl@0: { sl@0: iBandBitmapDevice->PaletteAttributes(aModifiable,aNumEntries); sl@0: } sl@0: sl@0: EXPORT_C void CBandedDevice::SetPalette(CPalette* aPalette) sl@0: { sl@0: iBandBitmapDevice->SetPalette(aPalette); sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::GetPalette(CPalette*& aPalette) const sl@0: { sl@0: return iBandBitmapDevice->GetPalette(aPalette); sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::NumBands() const sl@0: { sl@0: TInt numbands; sl@0: if ((iBandingDirection==EBandingTopToBottom) || (iBandingDirection==EBandingBottomToTop)) sl@0: numbands = (iFullRectInPixels.Size().iHeight/iScanLinesPerBand)+1; sl@0: else sl@0: numbands = (iFullRectInPixels.Size().iWidth/iScanLinesPerBand)+1; sl@0: return numbands; sl@0: } sl@0: sl@0: EXPORT_C TInt CBandedDevice::NextBand() sl@0: { sl@0: iBandIndex++; sl@0: if (iBandIndex==NumBands()) sl@0: iBandIndex=0; sl@0: iClearGc->Clear(); sl@0: return iBandIndex; sl@0: } sl@0: sl@0: EXPORT_C TRect CBandedDevice::BandRect() const sl@0: { sl@0: TRect bandrect; sl@0: if (iBandingDirection==EBandingTopToBottom) sl@0: { sl@0: bandrect.iTl.iX=iFullRectInPixels.iTl.iX; sl@0: bandrect.iTl.iY=iFullRectInPixels.iTl.iY+(iBandIndex*iScanLinesPerBand); sl@0: bandrect.iBr.iX=iFullRectInPixels.iBr.iX; sl@0: bandrect.iBr.iY=bandrect.iTl.iY+iScanLinesPerBand; sl@0: if (bandrect.iBr.iY>iFullRectInPixels.iBr.iY) sl@0: bandrect.iBr.iY=iFullRectInPixels.iBr.iY; sl@0: } sl@0: else if (iBandingDirection==EBandingBottomToTop) sl@0: { sl@0: bandrect.iBr.iX=iFullRectInPixels.iBr.iX; sl@0: bandrect.iBr.iY=iFullRectInPixels.iBr.iY-(iBandIndex*iScanLinesPerBand); sl@0: bandrect.iTl.iX=iFullRectInPixels.iTl.iX; sl@0: bandrect.iTl.iY=bandrect.iBr.iY-iScanLinesPerBand; sl@0: if (bandrect.iTl.iYiFullRectInPixels.iBr.iX) sl@0: bandrect.iBr.iX=iFullRectInPixels.iBr.iX; sl@0: } sl@0: else if (iBandingDirection==EBandingRightToLeft) sl@0: { sl@0: bandrect.iBr.iX=iFullRectInPixels.iBr.iX-(iBandIndex*iScanLinesPerBand); sl@0: bandrect.iBr.iY=iFullRectInPixels.iBr.iY; sl@0: bandrect.iTl.iX=bandrect.iBr.iX-iScanLinesPerBand; sl@0: bandrect.iTl.iY=iFullRectInPixels.iTl.iY; sl@0: if (bandrect.iTl.iXCreate(TSize(widthinpixels,iScanLinesPerBand),aDisplayMode)); sl@0: TSize sizeintwips; sl@0: sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*widthinpixels)/1000; sl@0: sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*iScanLinesPerBand)/1000; sl@0: iBandBitmap->SetSizeInTwips(sizeintwips); sl@0: } sl@0: else sl@0: { sl@0: TInt heightinpixels=iFullRectInPixels.Size().iHeight; sl@0: if (!iScanLinesPerBand) sl@0: iScanLinesPerBand=KBandSizeInBytes/(CFbsBitmap::ScanLineLength(heightinpixels,aDisplayMode)); sl@0: iScanLinesPerBand&=~1; sl@0: User::LeaveIfError(iBandBitmap->Create(TSize(iScanLinesPerBand,heightinpixels),aDisplayMode)); sl@0: TSize sizeintwips; sl@0: sizeintwips.iWidth=(aKPixelSizeInTwips.iWidth*iScanLinesPerBand)/1000; sl@0: sizeintwips.iHeight=(aKPixelSizeInTwips.iHeight*heightinpixels)/1000; sl@0: iBandBitmap->SetSizeInTwips(sizeintwips); sl@0: } sl@0: iBandBitmapDevice=CFbsBitmapDevice::NewL(iBandBitmap); sl@0: User::LeaveIfError(iBandBitmapDevice->CreateContext((CGraphicsContext*&) iClearGc)); sl@0: } sl@0: