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: #include sl@0: #include "PDRBODY.H" sl@0: #include "PDRSTD.H" sl@0: #include "pdrtext.h" sl@0: sl@0: EXPORT_C CPdrDevice::CPdrDevice(): sl@0: CPrinterDevice(), sl@0: iStore(NULL), sl@0: iModel(), sl@0: iModelInfo(NULL), sl@0: iTypefaceStore(NULL) sl@0: { sl@0: __DECLARE_NAME(_S("CPdrDevice")); sl@0: } sl@0: sl@0: EXPORT_C CPdrDevice::~CPdrDevice() sl@0: { sl@0: DeleteControl(); sl@0: delete iModelInfo; sl@0: delete iTypefaceStore; sl@0: } sl@0: sl@0: EXPORT_C void CPdrDevice::SelectPageSpecInTwips(const TPageSpec& aPageSpec) sl@0: { sl@0: CPrinterDevice::SelectPageSpecInTwips(aPageSpec); sl@0: iTypefaceStore->SetPageOrientation(aPageSpec.iOrientation); sl@0: } sl@0: sl@0: EXPORT_C TDisplayMode CPdrDevice::DisplayMode() const sl@0: { sl@0: return iModelInfo->iDisplayMode; sl@0: } sl@0: sl@0: EXPORT_C TSize CPdrDevice::SizeInPixels() const sl@0: { sl@0: TSize size; sl@0: size.iWidth = HorizontalTwipsToPixels(SizeInTwips().iWidth); sl@0: size.iHeight = VerticalTwipsToPixels(SizeInTwips().iHeight); sl@0: return size; sl@0: } sl@0: sl@0: EXPORT_C TSize CPdrDevice::SizeInTwips() const sl@0: { sl@0: TSize size; sl@0: if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait) sl@0: { sl@0: size = iCurrentPageSpecInTwips.iPortraitPageSize; sl@0: } sl@0: else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape) sl@0: { sl@0: size.iWidth = iCurrentPageSpecInTwips.iPortraitPageSize.iHeight; sl@0: size.iHeight = iCurrentPageSpecInTwips.iPortraitPageSize.iWidth; sl@0: } sl@0: return size; sl@0: } sl@0: sl@0: EXPORT_C TRect CPdrDevice::PrintablePageInPixels() const sl@0: { sl@0: TRect rect; sl@0: if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait) sl@0: { sl@0: rect.iTl.iX = iModelInfo->iPortraitOffsetInPixels.iX; sl@0: rect.iTl.iY = iModelInfo->iMinMarginsInPixels.iTop; sl@0: rect.iBr.iX = SizeInPixels().iWidth-iModelInfo->iPortraitOffsetInPixels.iX; sl@0: rect.iBr.iY = SizeInPixels().iHeight-iModelInfo->iMinMarginsInPixels.iBottom; sl@0: } sl@0: else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape) sl@0: { sl@0: rect.iTl.iX = iModelInfo->iLandscapeOffsetInPixels.iX; sl@0: rect.iTl.iY = iModelInfo->iMinMarginsInPixels.iLeft; sl@0: rect.iBr.iX = SizeInPixels().iWidth-iModelInfo->iLandscapeOffsetInPixels.iX; sl@0: rect.iBr.iY = SizeInPixels().iHeight-iModelInfo->iMinMarginsInPixels.iRight; sl@0: } sl@0: return rect; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::HorizontalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return ((1000 * aTwips) + (KPixelSizeInTwips().iWidth / 2)) / KPixelSizeInTwips().iWidth; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::VerticalTwipsToPixels(TInt aTwips) const sl@0: { sl@0: return ((1000 * aTwips) + (KPixelSizeInTwips().iHeight / 2)) / KPixelSizeInTwips().iHeight; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::HorizontalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return ((aPixels * KPixelSizeInTwips().iWidth) + 500) / 1000; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::VerticalPixelsToTwips(TInt aPixels) const sl@0: { sl@0: return ((aPixels * KPixelSizeInTwips().iHeight) + 500) / 1000; 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 CPdrDevice::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 CPdrDevice::GetNearestFontToDesignHeightInTwips(CFont*& aFont, const TFontSpec& aFontSpec) sl@0: { sl@0: return iTypefaceStore->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 CPdrDevice::GetNearestFontToMaxHeightInTwips(CFont*& /*aFont*/, const TFontSpec& /*aFontSpec*/, TInt /*aMaxHeight*/) sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::NumTypefaces() const sl@0: { sl@0: return iTypefaceStore->NumTypefaces(); sl@0: } sl@0: sl@0: EXPORT_C void CPdrDevice::TypefaceSupport(TTypefaceSupport& aTypefaceSupport, TInt aTypefaceIndex) const sl@0: { sl@0: iTypefaceStore->TypefaceSupport(aTypefaceSupport, aTypefaceIndex); sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::FontHeightInTwips(TInt aTypefaceIndex, TInt aHeightIndex) const sl@0: { sl@0: return iTypefaceStore->FontHeightInTwips(aTypefaceIndex, aHeightIndex); sl@0: } sl@0: sl@0: EXPORT_C void CPdrDevice::PaletteAttributes(TBool& aModifiable, TInt& aNumEntries) const sl@0: { sl@0: aModifiable = EFalse; sl@0: aNumEntries = 0; sl@0: } sl@0: sl@0: EXPORT_C void CPdrDevice::SetPalette(CPalette* /*aPalette*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::GetPalette(CPalette*& /*aPalette*/) const sl@0: { sl@0: return KErrNotSupported; sl@0: } sl@0: sl@0: EXPORT_C TPrinterModelEntry CPdrDevice::Model() const sl@0: { sl@0: return iModel.iEntry; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::Flags() const sl@0: { sl@0: return iModelInfo->iFlags; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrDevice::SetModel(const TPrinterModelHeader& aModel, CStreamStore& aStore) sl@0: { sl@0: iModel = aModel; sl@0: iStore = &aStore; sl@0: TRAPD(ret, DoSetModelL()); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C void CPdrDevice::ReleaseFont(CFont* aFont) sl@0: { sl@0: iTypefaceStore->ReleaseFont(aFont); sl@0: } sl@0: sl@0: EXPORT_C TPoint CPdrDevice::OffsetInPixels() sl@0: { sl@0: TPoint offset; sl@0: if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait) sl@0: offset = iModelInfo->iPortraitOffsetInPixels; sl@0: else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape) sl@0: offset = iModelInfo->iLandscapeOffsetInPixels; sl@0: return offset; sl@0: } sl@0: sl@0: EXPORT_C TSize CPdrDevice::KPixelSizeInTwips() const sl@0: { sl@0: TSize size; sl@0: if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::EPortrait) sl@0: size = TSize(iModelInfo->iKPixelWidthInTwips, iModelInfo->iKPixelHeightInTwips); sl@0: else if (iCurrentPageSpecInTwips.iOrientation == TPageSpec::ELandscape) sl@0: size = TSize(iModelInfo->iKPixelHeightInTwips, iModelInfo->iKPixelWidthInTwips); sl@0: return size; sl@0: } sl@0: sl@0: void CPdrDevice::DoSetModelL() sl@0: { sl@0: RStoreReadStream stream; sl@0: stream.OpenLC(*iStore, iModel.iModelDataStreamId); sl@0: iModelInfo = new(ELeave) CPdrModelInfo(); sl@0: iModelInfo->InternalizeL(stream); sl@0: CleanupStack::PopAndDestroy(); sl@0: iTypefaceStore = CPdrTypefaceStore::NewL(*iStore, iModelInfo->iNumTypefaceFonts, iModelInfo->iTypefaceFontsEntryList, iCurrentPageSpecInTwips.iOrientation, iModelInfo->iKPixelHeightInTwips, this); sl@0: } sl@0: sl@0: EXPORT_C CPdrControl::CPdrControl(CPdrDevice* aPdrDevice, CPrinterPort* aPrinterPort): sl@0: CPrinterControl(aPrinterPort), sl@0: iPdrDevice(aPdrDevice), sl@0: iPageBuffer(NULL), sl@0: iResources(NULL), sl@0: iBandedDevice(NULL), sl@0: iPageText(NULL), sl@0: iBandIndex(0), sl@0: iEntryIndex(0), sl@0: iPosition(iPdrDevice->OffsetInPixels()), sl@0: iTextFormat() sl@0: { sl@0: __DECLARE_NAME(_S("CPdrControl")); sl@0: } sl@0: sl@0: EXPORT_C CPdrControl::~CPdrControl() sl@0: { sl@0: delete iPageBuffer; sl@0: delete iResources; sl@0: delete iBandedDevice; sl@0: delete iPageText; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrControl::CreateContext(CGraphicsContext*& aGC) sl@0: { sl@0: __ASSERT_DEBUG(iState == EPrinting, Panic(EPdrNotPrinting)); sl@0: TRAPD(ret, aGC = CPdrGc::NewL(iPdrDevice)); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrControl::BandsPerPage() sl@0: { sl@0: TInt numbands = {iBandedDevice ? iBandedDevice->NumBands() + 1 : 1}; sl@0: return numbands; sl@0: } sl@0: sl@0: /** sl@0: @return EMoreOnPage if more to print on the current page, sl@0: otherwise ENoMoreOnPage. sl@0: */ sl@0: EXPORT_C CPrinterControl::TMoreOnPage CPdrControl::QueueGetBand(TRequestStatus& aStatus, TBandAttributes& aBand) sl@0: { sl@0: TMoreOnPage moreonpage = ENoMoreOnPage; sl@0: sl@0: TRAPD(ret, DoQueueGetBandL()); sl@0: if (ret != KErrNone) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, ret); sl@0: } sl@0: else sl@0: { sl@0: if (IsGraphicsBand()) sl@0: { sl@0: aBand.iRect = iBandedDevice->BandRect(); sl@0: aBand.iTextIsIgnored = ETrue; sl@0: aBand.iGraphicsIsIgnored = EFalse; sl@0: aBand.iFirstBandOnPage = EFalse; sl@0: } sl@0: else sl@0: { sl@0: aBand.iRect = iPdrDevice->PrintablePageInPixels(); sl@0: aBand.iTextIsIgnored = EFalse; sl@0: aBand.iGraphicsIsIgnored = ETrue; sl@0: aBand.iFirstBandOnPage = ETrue; sl@0: } sl@0: if (iBandIndex == (BandsPerPage() - 1)) sl@0: moreonpage = ENoMoreOnPage; sl@0: else sl@0: moreonpage = EMoreOnPage; sl@0: iPageBuffer->StartFlush(aStatus); sl@0: } sl@0: return moreonpage; sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::QueueEndPrint(TRequestStatus& aStatus) sl@0: { sl@0: TRAPD(ret, DoQueueEndPrintL()); sl@0: iState = ENotPrinting; sl@0: if (ret != KErrNone) sl@0: { sl@0: TRequestStatus* status = &aStatus; sl@0: User::RequestComplete(status, ret); sl@0: } sl@0: else sl@0: iPageBuffer->StartFlush(aStatus); sl@0: } sl@0: sl@0: /** sl@0: Tidy up synchronously in a short time. sl@0: */ sl@0: EXPORT_C void CPdrControl::AbortPrint() // tidy up synchronously in a short time, return success code sl@0: { sl@0: iPageBuffer->Cancel(); // dont call DoCancel() sl@0: iState = ENotPrinting; sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::DrawTextL(const TPoint& aPoint, const TFontUnderline aUnderlineStyle, const TFontStrikethrough aStrikethroughStyle, const TRgb& aColor, const CInfoFont* aFont, const TDesC& aString) sl@0: { sl@0: __ASSERT_DEBUG(iState == EPrinting,Panic(EPdrNotPrinting)); sl@0: if (iPageText) sl@0: iPageText->AddEntryL(aPoint, aUnderlineStyle, aStrikethroughStyle, aColor, aFont, aString); sl@0: else sl@0: { sl@0: HBufC8* string = aFont->TranslateStringL(aString); sl@0: CleanupStack::PushL(string); sl@0: TTextFormat textformat(aUnderlineStyle, aStrikethroughStyle, aColor, aFont->CommandString(), aFont->FontSpecInTwips().iFontStyle); sl@0: OutputTextL(aPoint + TPoint(0, aFont->BaselineOffsetInPixels()), aFont->MeasureText(aString), textformat,string->Des()); sl@0: CleanupStack::PopAndDestroy(); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C TBool CPdrControl::IsGraphicsBand() const sl@0: { sl@0: return iBandIndex; sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::MoveToL(const TPoint& aPoint) sl@0: { sl@0: // PCL, at least, treats move command strings with an explicit sl@0: // sign as being relative, so if the offset is negative then sl@0: // set the absolute position to zero first. sl@0: sl@0: TPoint offset = iPdrDevice->OffsetInPixels(); sl@0: TCommandString des; sl@0: if (aPoint.iX - iPosition.iX) sl@0: { sl@0: if (aPoint.iX - iPosition.iX < 0) sl@0: { sl@0: des.Format(iResources->ResourceString(EPdrSetXPos), 0); sl@0: iPageBuffer->AddBytesL(des); sl@0: } sl@0: sl@0: des.Format(iResources->ResourceString(EPdrSetXPos), aPoint.iX - offset.iX); sl@0: iPageBuffer->AddBytesL(des); sl@0: } sl@0: if (aPoint.iY - iPosition.iY) sl@0: { sl@0: if (aPoint.iY - iPosition.iY < 0) sl@0: { sl@0: des.Format(iResources->ResourceString(EPdrSetYPos), 0); sl@0: iPageBuffer->AddBytesL(des); sl@0: } sl@0: sl@0: des.Format(iResources->ResourceString(EPdrSetYPos), aPoint.iY - offset.iY); sl@0: iPageBuffer->AddBytesL(des); sl@0: } sl@0: iPosition = aPoint; sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::MoveByL(const TPoint& aVector) sl@0: { sl@0: TCommandString resource; sl@0: TCommandString des; sl@0: TPoint vector = aVector; sl@0: if (vector.iX) sl@0: { sl@0: if (aVector.iX < 0) sl@0: { sl@0: CommandL(EPdrCarriageReturn); sl@0: vector.iX += iPosition.iX - iPdrDevice->OffsetInPixels().iX; sl@0: } sl@0: resource.Copy(iResources->ResourceString(EPdrIncrementXPos)); sl@0: __ASSERT_DEBUG(resource.Length() >= 2, Panic(EPdrBadResourceString)); sl@0: if (resource[0] == '*') sl@0: { sl@0: for (; vector.iX > 0; vector.iX--) sl@0: iPageBuffer->AddBytesL(resource.Mid(1)); sl@0: } sl@0: else sl@0: { sl@0: des.Format(resource, vector.iX); sl@0: iPageBuffer->AddBytesL(des); sl@0: } sl@0: } sl@0: resource.Copy(iResources->ResourceString(EPdrIncrementYPos)); sl@0: if (vector.iY) sl@0: { sl@0: __ASSERT_DEBUG(resource.Length() >= 2, Panic(EPdrBadResourceString)); sl@0: if (resource[0] == '*') sl@0: { sl@0: for (; vector.iY > 0; vector.iY--) sl@0: iPageBuffer->AddBytesL(resource.Mid(1)); sl@0: } sl@0: else sl@0: { sl@0: des.Format(resource, vector.iY); sl@0: iPageBuffer->AddBytesL(des); sl@0: } sl@0: } sl@0: iPosition += aVector; sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::OutputTextL(const TPoint& aPoint, TInt aWidthInPixels, const TTextFormat& aTextFormat, const TDesC8& aString) sl@0: { sl@0: __ASSERT_DEBUG(iState == EPrinting,Panic(EPdrNotPrinting)); sl@0: sl@0: if (iTextFormat.iFontString.Compare(aTextFormat.iFontString)) sl@0: iPageBuffer->AddBytesL(aTextFormat.iFontString); sl@0: sl@0: if (iTextFormat.iFontStyle.Posture() != aTextFormat.iFontStyle.Posture()) sl@0: SetFontPostureL(aTextFormat.iFontStyle.Posture()); sl@0: sl@0: if (iTextFormat.iFontStyle.StrokeWeight() != aTextFormat.iFontStyle.StrokeWeight()) sl@0: SetFontStrokeWeightL(aTextFormat.iFontStyle.StrokeWeight()); sl@0: sl@0: if (iTextFormat.iColor != aTextFormat.iColor) sl@0: SetTextColorL(aTextFormat.iColor); sl@0: sl@0: iTextFormat = aTextFormat; sl@0: sl@0: MoveToL(aPoint); sl@0: sl@0: if (aTextFormat.iUnderlineStyle == EUnderlineOn) sl@0: CommandL(EPdrUnderlineOn); sl@0: sl@0: if (aTextFormat.iStrikethroughStyle == EStrikethroughOn) sl@0: CommandL(EPdrStrikethroughOn); sl@0: sl@0: iPageBuffer->AddBytesL(aString); sl@0: sl@0: iPosition.iX += aWidthInPixels; sl@0: sl@0: if (aTextFormat.iUnderlineStyle == EUnderlineOn) sl@0: CommandL(EPdrUnderlineOff); sl@0: sl@0: if (aTextFormat.iStrikethroughStyle == EStrikethroughOn) sl@0: CommandL(EPdrStrikethroughOff); sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::DoQueueGetBandL() sl@0: { sl@0: if (iState == ENotPrinting) sl@0: { sl@0: iState = EPrinting; sl@0: iBandIndex = 0; sl@0: if (iBandedDevice) sl@0: iBandedDevice->Reset(); sl@0: CommandL(EPdrReset); sl@0: SetPageSizeL(); sl@0: CommandL(EPdrPreAmble); sl@0: SetPageOrientationL(); sl@0: SetTextColorL(KRgbBlack); sl@0: } sl@0: else sl@0: { sl@0: OutputBandL(); sl@0: if (iBandIndex == (BandsPerPage() - 1)) sl@0: { sl@0: iBandIndex = 0; sl@0: iEntryIndex = 0; sl@0: if (iPageText) sl@0: iPageText->Reset(); sl@0: CommandL(EPdrNewPage); sl@0: iPosition = iPdrDevice->OffsetInPixels(); sl@0: } sl@0: else sl@0: iBandIndex = iBandedDevice->NextBand() + 1; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::DoQueueEndPrintL() sl@0: { sl@0: OutputBandL(); sl@0: CommandL(EPdrPostAmble); sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::ConstructL(CStreamStore& aStore, TStreamId aStreamId) sl@0: { sl@0: __ASSERT_ALWAYS(iPrinterPort, Panic(EPdrRequiresPrinterPort)); sl@0: iPageBuffer = CPageBuffer::NewL(iPrinterPort); sl@0: iResources = new(ELeave) CPdrResources(); sl@0: iResources->RestoreL(aStore, aStreamId); sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::SetPageSizeL() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::SetPageOrientationL() sl@0: { sl@0: TPageSpec::TPageOrientation orientation = iPdrDevice->CurrentPageSpecInTwips().iOrientation; sl@0: if (orientation == TPageSpec::EPortrait) sl@0: CommandL(EPdrPortrait); sl@0: else sl@0: CommandL(EPdrLandscape); sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::SetFontStrokeWeightL(const TFontStrokeWeight aStrokeWeight) sl@0: { sl@0: if (aStrokeWeight == EStrokeWeightNormal) sl@0: CommandL(EPdrBoldOff); sl@0: else sl@0: CommandL(EPdrBoldOn); sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::SetFontPostureL(const TFontPosture aPosture) sl@0: { sl@0: if (aPosture == EPostureUpright) sl@0: CommandL(EPdrItalicOff); sl@0: else sl@0: CommandL(EPdrItalicOn); sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::SetTextColorL(const TRgb& /*aColor*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CPdrControl::CommandL(const TInt anId) sl@0: { sl@0: iPageBuffer->AddBytesL(iResources->ResourceString(anId)); sl@0: } sl@0: sl@0: void CPdrGc::ConstructL() sl@0: { sl@0: if (PdrControl()->BandedDevice()) sl@0: { sl@0: User::LeaveIfError(PdrControl()->BandedDevice()->CreateContext((CGraphicsContext*&)iBandedGc)); sl@0: TFontSpec spec; sl@0: User::LeaveIfError(PdrControl()->BandedDevice()->GetNearestFontToDesignHeightInTwips((CFont*&)iFbsFont, spec)); sl@0: iBandedGc->UseFont(iFbsFont); sl@0: } sl@0: } sl@0: sl@0: CPdrGc::CPdrGc(CPdrDevice* aDevice): sl@0: iPdrDevice(aDevice), sl@0: iBandedGc(NULL), sl@0: iFbsFont(NULL), sl@0: iBandedFont(NULL), sl@0: iFont(NULL), sl@0: iOrigin(0, 0), sl@0: iPosition(0, 0), sl@0: iUnderlineStyle(EUnderlineOff), sl@0: iStrikethroughStyle(EStrikethroughOff), sl@0: iClippingRect(iPdrDevice->PrintablePageInPixels()), sl@0: iWordExcessWidthInPixels(0), sl@0: iNumGaps(0), sl@0: iCharExcessWidthInPixels(0), sl@0: iNumChars(0), sl@0: iPenColor(KRgbBlack) sl@0: { sl@0: } sl@0: sl@0: CPdrGc* CPdrGc::NewL(CPdrDevice* aDevice) sl@0: { sl@0: CPdrGc* gc = new(ELeave) CPdrGc(aDevice); sl@0: CleanupStack::PushL(gc); sl@0: gc->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return gc; sl@0: } sl@0: sl@0: EXPORT_C CPdrGc::~CPdrGc() sl@0: { sl@0: if (iBandedGc) sl@0: { sl@0: if (iBandedGc->IsFontUsed()) sl@0: { sl@0: iBandedGc->DiscardFont(); sl@0: iBandedFont = NULL; sl@0: } sl@0: delete iBandedGc; sl@0: PdrControl()->BandedDevice()->ReleaseFont(iFbsFont); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C CGraphicsDevice* CPdrGc::Device() const sl@0: { sl@0: return iPdrDevice; sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetOrigin(const TPoint& aPos) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: iOrigin = aPos; sl@0: TPoint pos = PdrControl()->BandedDevice()->FullOriginToBandOrigin(aPos); sl@0: iBandedGc->SetOrigin(pos); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetDrawMode(TDrawMode aDrawingMode) sl@0: { sl@0: iBandedGc->SetDrawMode(aDrawingMode); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetClippingRect(const TRect& aRect) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: { sl@0: iClippingRect = aRect; sl@0: iClippingRect.Move(TPoint(0, 0) + iOrigin); // Recorded in original coordinates sl@0: } sl@0: iBandedGc->SetClippingRect(aRect); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::CancelClippingRect() sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: iClippingRect = iPdrDevice->PrintablePageInPixels(); sl@0: iBandedGc->CancelClippingRect(); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::Reset() sl@0: { sl@0: if (iBandedGc->IsFontUsed()) sl@0: { sl@0: iBandedGc->DiscardFont(); sl@0: iBandedFont = NULL; sl@0: } sl@0: iBandedGc->Reset(); sl@0: iBandedGc->UseFont(iFbsFont); sl@0: SetOrigin(TPoint(0, 0)); sl@0: CancelClippingRect(); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::UseFont(const CFont* aFont) sl@0: { sl@0: if (aFont->TypeUid() == TUid::Uid(KCInfoFontUidVal)) sl@0: { sl@0: iFont = (CInfoFont*)aFont; sl@0: iPrintTextUsingBitmaps = EFalse; sl@0: // We may have to use bitmaps - so set the font up in the bitmap gc as well sl@0: if (iBandedGc->IsFontUsed()) sl@0: iBandedGc->DiscardFont(); sl@0: iBandedFont = iFont->RealFont(); sl@0: iBandedGc->UseFont(iBandedFont); sl@0: } sl@0: else sl@0: { sl@0: if (iBandedGc->IsFontUsed()) sl@0: { sl@0: iBandedGc->DiscardFont(); sl@0: iBandedFont = NULL; sl@0: } sl@0: iBandedGc->UseFont(aFont); sl@0: iPrintTextUsingBitmaps = ETrue; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DiscardFont() sl@0: { sl@0: iFont = NULL; sl@0: if (iBandedFont) sl@0: { sl@0: iBandedGc->DiscardFont(); sl@0: iBandedFont = NULL; sl@0: iBandedGc->UseFont(iFbsFont); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetPenColor(const TRgb& aColor) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: iPenColor = aColor; sl@0: iBandedGc->SetPenColor(aColor); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetPenStyle(TPenStyle aPenStyle) sl@0: { sl@0: iBandedGc->SetPenStyle(aPenStyle); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetPenSize(const TSize& aSize) sl@0: { sl@0: iBandedGc->SetPenSize(aSize); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetBrushColor(const TRgb& aColor) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->SetBrushColor(aColor); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetBrushStyle(TBrushStyle aBrushStyle) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->SetBrushStyle(aBrushStyle); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetBrushOrigin(const TPoint& aOrigin) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->SetBrushOrigin(aOrigin); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::UseBrushPattern(const CFbsBitmap* aBitmap) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->UseBrushPattern(aBitmap); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DiscardBrushPattern() sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DiscardBrushPattern(); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetUnderlineStyle(TFontUnderline aUnderlineStyle) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: iUnderlineStyle = aUnderlineStyle; sl@0: iBandedGc->SetUnderlineStyle(aUnderlineStyle); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetStrikethroughStyle(TFontStrikethrough aStrikethroughStyle) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: iStrikethroughStyle = aStrikethroughStyle; sl@0: iBandedGc->SetStrikethroughStyle(aStrikethroughStyle); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetWordJustification(TInt aExcessWidth,TInt aNumGaps) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: { sl@0: iWordExcessWidthInPixels = aExcessWidth; sl@0: iNumGaps = aNumGaps; sl@0: } sl@0: iBandedGc->SetWordJustification(aExcessWidth, aNumGaps); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::SetCharJustification(TInt aExcessWidth,TInt aNumChars) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: { sl@0: iCharExcessWidthInPixels = aExcessWidth; sl@0: iNumChars = aNumChars; sl@0: } sl@0: iBandedGc->SetCharJustification(aExcessWidth, aNumChars); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::MoveTo(const TPoint& aPoint) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: iPosition = aPoint; sl@0: iBandedGc->MoveTo(aPoint); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::MoveBy(const TPoint& aVector) sl@0: { sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: iPosition += aVector; sl@0: iBandedGc->MoveBy(aVector); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::Plot(const TPoint& aPoint) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->Plot(aPoint); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawArc(const TRect& aRect,const TPoint& aStart,const TPoint& aEnd) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawArc(aRect, aStart, aEnd); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawLine(const TPoint& aPoint1,const TPoint& aPoint2) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawLine(aPoint1, aPoint2); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawLineTo(const TPoint& aPoint) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawLineTo(aPoint); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawLineBy(const TPoint& aVector) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawLineBy(aVector); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawPolyLine(const CArrayFix* aPointList) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawPolyLine(aPointList); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawPolyLine(const TPoint* aPointList,TInt aNumPoints) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawPolyLine(aPointList, aNumPoints); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawPie(const TRect& aRect, const TPoint& aStart, const TPoint& aEnd) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawPie(aRect, aStart, aEnd); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawEllipse(const TRect& aRect) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawEllipse(aRect); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawRect(const TRect& aRect) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawRect(aRect); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawRoundRect(const TRect& aRect,const TSize& aCornerSize) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawRoundRect(aRect, aCornerSize); sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrGc::DrawPolygon(const CArrayFix* aPointList, TFillRule aFillRule) sl@0: { sl@0: TInt ret = KErrNone; sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: ret = iBandedGc->DrawPolygon(aPointList, aFillRule); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrGc::DrawPolygon(const TPoint* aPointList,TInt aNumPoints,TFillRule aFillRule) sl@0: { sl@0: TInt ret = KErrNone; sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: ret = iBandedGc->DrawPolygon(aPointList, aNumPoints, aFillRule); sl@0: return ret; sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawBitmap(const TPoint& aTopLeft, const CFbsBitmap* aSource) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawBitmap(aTopLeft, aSource); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawBitmap(const TRect& aDestRect, const CFbsBitmap* aSource) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawBitmap(aDestRect, aSource); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawBitmap(const TRect& aDestRect, const CFbsBitmap* aSource, const TRect& aSourceRect) sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawBitmap(aDestRect, aSource, aSourceRect); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CFbsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CFbsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/) sl@0: {} sl@0: sl@0: EXPORT_C void CPdrGc::DrawBitmapMasked(const TRect& /*aDestRect*/,const CWsBitmap* /*aBitmap*/,const TRect& /*aSourceRect*/,const CWsBitmap* /*aMaskBitmap*/,TBool /*aInvertMask*/) sl@0: {} sl@0: sl@0: EXPORT_C void CPdrGc::MapColors(const TRect& /*aRect*/,const TRgb* /*aColors*/,TInt /*aNumPairs*/,TBool /*aMapForwards*/) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrGc::SetClippingRegion(const TRegion &/*aRegion*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::CancelClippingRegion() sl@0: {} sl@0: sl@0: EXPORT_C void CPdrGc::DrawTextVertical(const TDesC& /*aText*/,const TPoint& /*aPos*/,TBool /*aUp*/) sl@0: {} sl@0: sl@0: EXPORT_C void CPdrGc::DrawTextVertical(const TDesC& /*aText*/,const TRect& /*aBox*/,TInt /*aBaselineOffset*/,TBool /*aUp*/,TTextAlign /*aVert*/,TInt /*aMargin*/) sl@0: {} sl@0: sl@0: EXPORT_C TInt CPdrGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CFbsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CFbsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: EXPORT_C TInt CPdrGc::AlphaBlendBitmaps(const TPoint& /*aDestPt*/, const CWsBitmap* /*aSrcBmp*/, const TRect& /*aSrcRect*/, const CWsBitmap* /*aAlphaBmp*/, const TPoint& /*aAlphaPt*/) sl@0: { sl@0: return KErrNone; sl@0: } sl@0: sl@0: CPdrControl* CPdrGc::PdrControl() const sl@0: { sl@0: return ((CPdrControl*) iPdrDevice->iControl); sl@0: } sl@0: sl@0: /** sl@0: @deprecated Interface is deprecated because it is unsafe as it may leave. It is available for backward compatibility reasons only. sl@0: @see CPdrGc::DrawTextL sl@0: */ sl@0: sl@0: EXPORT_C void CPdrGc::DrawText(const TDesC& aString, const TPoint& aPosition) sl@0: { sl@0: TRAP_IGNORE(DrawTextL(aString, aPosition)); sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawTextL(const TDesC& aString, const TPoint& aPosition) sl@0: { sl@0: if (!iPrintTextUsingBitmaps) sl@0: { sl@0: TInt firstCharNot = 0; sl@0: TInt length = 0; sl@0: __ASSERT_DEBUG(iFont, Panic(EPdrNoFontInUse)); sl@0: if (iFont->AllCharsInFontRepertoire(aString, firstCharNot, length)) sl@0: { sl@0: iPosition = aPosition; sl@0: TInt start = 0; sl@0: TPtrC ptr; // Checks to see iWordExcessWidthInPixels > 0 to avoid panic in JustificationInPixels() sl@0: for (TInt i = 0; (i < aString.Length()) && iNumGaps && iWordExcessWidthInPixels; i++) sl@0: { sl@0: if (aString[i] == ' ') sl@0: { sl@0: ptr.Set(aString.Mid(start, i - start + 1)); sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: { sl@0: PdrControl()->DrawTextL(iPosition + iOrigin, iUnderlineStyle, iStrikethroughStyle, iPenColor, iFont, ptr); sl@0: } sl@0: iPosition += TPoint(iFont->MeasureText(ptr) + JustificationInPixels(iWordExcessWidthInPixels, iNumGaps), 0); sl@0: start = i + 1; sl@0: } sl@0: } sl@0: if (start < aString.Length()) sl@0: { sl@0: ptr.Set(aString.Mid(start)); sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: { sl@0: PdrControl()->DrawTextL(iPosition + iOrigin, iUnderlineStyle, iStrikethroughStyle, iPenColor, iFont, ptr); sl@0: } sl@0: iPosition += TPoint(iFont->MeasureText(ptr), 0); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if (firstCharNot > 0) sl@0: { // Take text substring and draw it sl@0: TPtrC ptr; sl@0: ptr.Set(aString.Mid(0, firstCharNot)); sl@0: DrawText(ptr, aPosition); sl@0: // Whole string wasn't text so there must be some (bitmap) string left sl@0: // Update drawing position sl@0: TPoint position = iPosition; sl@0: // Take rest of string and try again sl@0: ptr.Set(aString.Mid(firstCharNot)); sl@0: DrawText(ptr, position); sl@0: } sl@0: else sl@0: { // Take bitmap substring and draw it sl@0: TPtrC ptr; sl@0: ptr.Set(aString.Mid(0, length)); sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: { sl@0: iPrintTextUsingBitmaps = ETrue; sl@0: DrawText(ptr, aPosition); sl@0: iPrintTextUsingBitmaps = EFalse; sl@0: } sl@0: if (length < aString.Length()) sl@0: { sl@0: // There must be some (text) string left sl@0: // Update drawing position sl@0: iPosition = aPosition; sl@0: TPtrC ptr2; sl@0: TInt start = 0; sl@0: // Checks to see iWordExcessWidthInPixels > 0 to avoid panic in JustificationInPixels() sl@0: for (TInt i = 0; (i < ptr.Length()) && iNumGaps && iWordExcessWidthInPixels; i++) sl@0: { sl@0: if (ptr[i] == ' ') sl@0: { sl@0: ptr2.Set(ptr.Mid(start, i - start + 1)); sl@0: iPosition += TPoint(iFont->MeasureText(ptr2) + JustificationInPixels(iWordExcessWidthInPixels, iNumGaps), 0); sl@0: start = i + 1; sl@0: } sl@0: } sl@0: if (start < ptr.Length()) sl@0: { sl@0: ptr2.Set(ptr.Mid(start)); sl@0: iPosition += TPoint(iFont->MeasureText(ptr2), 0); sl@0: } sl@0: TPoint position = iPosition; sl@0: // Take rest of string and try again sl@0: ptr.Set(aString.Mid(length)); sl@0: DrawText(ptr, position); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: else sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawText(aString, aPosition); sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CPdrGc::DrawText(const TDesC& aString, const TRect& aBox, TInt aBaselineOffset, TTextAlign aHoriz, TInt aLeftMrg) sl@0: { sl@0: if (!iPrintTextUsingBitmaps) sl@0: { sl@0: __ASSERT_DEBUG(iFont, Panic(EPdrNoFontInUse)); sl@0: if (!PdrControl()->IsGraphicsBand()) sl@0: { sl@0: TInt width = iFont->MeasureText(aString); sl@0: TPoint pos; sl@0: pos.iY = aBox.iTl.iY + aBaselineOffset; sl@0: if (aHoriz == ELeft) sl@0: pos.iX = aBox.iTl.iX + aLeftMrg; sl@0: else if (aHoriz == ERight) sl@0: pos.iX = aBox.iBr.iX - aLeftMrg - width; sl@0: else if (aHoriz == ECenter) sl@0: pos.iX = (aBox.iTl.iX + aBox.iBr.iX - width) / 2; sl@0: DrawText(aString, pos); sl@0: } sl@0: else sl@0: iBandedGc->DrawText(KNullDesC, aBox, aBaselineOffset, aHoriz, aLeftMrg); sl@0: } sl@0: else sl@0: { sl@0: if (PdrControl()->IsGraphicsBand()) sl@0: iBandedGc->DrawText(aString, aBox, aBaselineOffset, aHoriz, aLeftMrg); sl@0: } sl@0: }