1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/printingservices/printerdriversupport/src/PDRPAGE.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,263 @@
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 <pdrstore.h>
1.20 +#include "pdrtext.h"
1.21 +
1.22 +const TInt KPageBufferSegmentSize=2048;
1.23 +
1.24 +EXPORT_C CPageBuffer* CPageBuffer::NewL(CPrinterPort* aPrinterPort)
1.25 + {
1.26 + return NewL(aPrinterPort,KPageBufferSegmentSize);
1.27 + }
1.28 +
1.29 +EXPORT_C CPageBuffer* CPageBuffer::NewL(CPrinterPort* aPrinterPort,TInt aGranularity)
1.30 + {
1.31 + CPageBuffer* pagebuffer=new(ELeave) CPageBuffer(aPrinterPort,aGranularity);
1.32 + CleanupStack::PushL(pagebuffer);
1.33 + pagebuffer->ConstructL();
1.34 + CleanupStack::Pop();
1.35 + return pagebuffer;
1.36 + }
1.37 +
1.38 +EXPORT_C void CPageBuffer::StartFlush(TRequestStatus& aRequestStatus)
1.39 + { //
1.40 + iRequestStatus=&aRequestStatus;
1.41 + aRequestStatus=KRequestPending;
1.42 + iWritePos=0;
1.43 + Queue();
1.44 + }
1.45 +
1.46 +EXPORT_C void CPageBuffer::AddBytesL(const TDesC8& aDes)
1.47 + {
1.48 + iBuffer->InsertL(iBuffer->Size(),aDes);
1.49 + }
1.50 +
1.51 +EXPORT_C RWriteStream& CPageBuffer::CreateWriteStreamL()
1.52 + {
1.53 + if (!iWriteStreamBuffer)
1.54 + {
1.55 + iWriteStreamBuffer=CBufSeg::NewL(iGranularity);
1.56 + iWriteStream.Open(*iWriteStreamBuffer,0);
1.57 + }
1.58 + else
1.59 + {
1.60 + iWriteStream.Truncate(*iWriteStreamBuffer,0);
1.61 + }
1.62 + return iWriteStream;
1.63 + }
1.64 +
1.65 +EXPORT_C void CPageBuffer::CloseWriteStream()
1.66 + {
1.67 + iWriteStream.Close();
1.68 + CBufSeg* buf=iBuffer;
1.69 + iBuffer=iWriteStreamBuffer;
1.70 + iWriteStreamBuffer=buf;
1.71 + }
1.72 +
1.73 +EXPORT_C CPageBuffer::~CPageBuffer()
1.74 + {
1.75 + Cancel();
1.76 + delete iBuffer;
1.77 + if (iWriteStreamBuffer)
1.78 + {
1.79 + iWriteStream.Close();
1.80 + delete iWriteStreamBuffer;
1.81 + }
1.82 + }
1.83 +
1.84 +void CPageBuffer::DoCancel()
1.85 + {
1.86 + iPrinterPort->Cancel(); // clears my request
1.87 + if (iRequestStatus!=NULL)
1.88 + User::RequestComplete(iRequestStatus,KErrCancel); // clears my callers request
1.89 + }
1.90 +
1.91 +void CPageBuffer::RunL() // Shouldn't leave in practice
1.92 + {
1.93 + if ((iWritePos>=iBuffer->Size()) || (iStatus!=KErrNone))
1.94 + {
1.95 + iBuffer->Reset();
1.96 + if (iRequestStatus!=NULL)
1.97 + User::RequestComplete(iRequestStatus,iStatus.Int()); // clears my callers request
1.98 + } // Reports back error if iStatus!=KErrNone
1.99 + else
1.100 + {
1.101 + Queue();
1.102 + }
1.103 + }
1.104 +
1.105 +void CPageBuffer::ConstructL()
1.106 + {
1.107 + iBuffer=CBufSeg::NewL(iGranularity);
1.108 + CActiveScheduler::Add(this);
1.109 + }
1.110 +
1.111 +CPageBuffer::CPageBuffer(CPrinterPort* aPrinterPort,TInt aGranularity):
1.112 + CActive(CActive::EPriorityLow),
1.113 + iRequestStatus(NULL),
1.114 + iWritePos(0),
1.115 + iGranularity(aGranularity),
1.116 + iBuffer(NULL),
1.117 + iPtr(NULL,0),
1.118 + iPrinterPort(aPrinterPort),
1.119 + iWriteStream(),
1.120 + iWriteStreamBuffer(NULL)
1.121 + {
1.122 + __DECLARE_NAME(_S("CPageBuffer"));
1.123 + }
1.124 +
1.125 +void CPageBuffer::Queue()
1.126 + {
1.127 + TPtr8 ptr=iBuffer->Ptr(iWritePos);
1.128 + iPtr.Set(ptr);
1.129 + iPrinterPort->WriteRequest(iPtr,iStatus);
1.130 + iWritePos+=iPtr.Length();
1.131 + SetActive();
1.132 + }
1.133 +
1.134 +/**
1.135 + This function is internal only, and is not intended for use.
1.136 + @internalTechnology
1.137 +*/
1.138 +EXPORT_C TTextFormat::TTextFormat():
1.139 + iUnderlineStyle(EUnderlineOff),
1.140 + iStrikethroughStyle(EStrikethroughOff),
1.141 + iColor(KRgbBlack),
1.142 + iFontString(_L8("")),
1.143 + iFontStyle()
1.144 + {
1.145 + }
1.146 +
1.147 +EXPORT_C TTextFormat::TTextFormat(const TFontUnderline anUnderlineStyle,const TFontStrikethrough aStrikethroughStyle,const TRgb& aColor,const TDesC8& aFontString,const TFontStyle& aFontStyle):
1.148 + iUnderlineStyle(anUnderlineStyle),
1.149 + iStrikethroughStyle(aStrikethroughStyle),
1.150 + iColor(aColor),
1.151 + iFontString(aFontString),
1.152 + iFontStyle(aFontStyle)
1.153 + {
1.154 + }
1.155 +
1.156 +EXPORT_C TBool TTextFormat::operator == (const TTextFormat& aFormat) const
1.157 + {
1.158 + return (iUnderlineStyle==aFormat.iUnderlineStyle) &&
1.159 + (iStrikethroughStyle==aFormat.iStrikethroughStyle) &&
1.160 + (!iFontString.Compare(aFormat.iFontString)) &&
1.161 + (iFontStyle==aFormat.iFontStyle) && (iColor==aFormat.iColor);
1.162 + }
1.163 +
1.164 +EXPORT_C CPageTextEntry::CPageTextEntry(const TPoint& aDrawPos,TInt aHeightInPixels,TInt aTextWidthInPixels,HBufC8* aText,TTextFormat* aTextFormat):
1.165 + iDrawPos(aDrawPos),
1.166 + iHeightInPixels(aHeightInPixels),
1.167 + iTextWidthInPixels(aTextWidthInPixels),
1.168 + iText(aText),
1.169 + iTextFormat(aTextFormat)
1.170 + {
1.171 + __DECLARE_NAME(_S("CPageTextEntry"));
1.172 + }
1.173 +
1.174 +EXPORT_C CPageTextEntry::~CPageTextEntry()
1.175 + {
1.176 + delete iText;
1.177 + }
1.178 +
1.179 +EXPORT_C TPoint CPageTextEntry::TopTextPos()
1.180 + {
1.181 + return iDrawPos-TPoint(0,iHeightInPixels);
1.182 + }
1.183 +
1.184 +CPageText::CPageText()
1.185 + {
1.186 + }
1.187 +
1.188 +void CPageText::ConstructL()
1.189 + {
1.190 + iTextFormatList = new(ELeave) CArrayPtrFlat<TTextFormat>(8);
1.191 + iPageTextEntryList = new(ELeave) CArrayPtrFlat<CPageTextEntry>(8);
1.192 + }
1.193 +
1.194 +EXPORT_C CPageText* CPageText::NewL()
1.195 + {
1.196 + CPageText* pagetext = new(ELeave) CPageText;
1.197 + CleanupStack::PushL(pagetext);
1.198 + pagetext->ConstructL();
1.199 + CleanupStack::Pop();
1.200 + return pagetext;
1.201 + }
1.202 +
1.203 +EXPORT_C CPageText::~CPageText()
1.204 + {
1.205 + Reset();
1.206 + delete iPageTextEntryList;
1.207 + delete iTextFormatList;
1.208 + }
1.209 +
1.210 +EXPORT_C void CPageText::Reset()
1.211 + {
1.212 + if (iPageTextEntryList)
1.213 + iPageTextEntryList->ResetAndDestroy();
1.214 + if (iTextFormatList)
1.215 + iTextFormatList->ResetAndDestroy();
1.216 + }
1.217 +
1.218 +EXPORT_C void CPageText::AddEntryL(const TPoint& aPoint,const TFontUnderline aUnderlineStyle,const TFontStrikethrough aStrikethroughStyle,const TRgb& aColor,const CInfoFont* aFont,const TDesC& aString)
1.219 + {
1.220 + TTextFormat textformat(aUnderlineStyle,aStrikethroughStyle,aColor,aFont->CommandString(),aFont->FontSpecInTwips().iFontStyle);
1.221 + TInt count=iTextFormatList->Count();
1.222 + TTextFormat* tf;
1.223 + TInt i;
1.224 + for (i = 0; ; i++)
1.225 + {
1.226 + if (i==count)
1.227 + {
1.228 + tf=new(ELeave) TTextFormat(textformat);
1.229 + CleanupStack::PushL(tf);
1.230 + iTextFormatList->AppendL(tf);
1.231 + CleanupStack::Pop();
1.232 + break;
1.233 + }
1.234 + tf=(*iTextFormatList)[i];
1.235 + if (textformat==*tf)
1.236 + break;
1.237 + }
1.238 + HBufC8* text=aFont->TranslateStringL(aString);
1.239 + CleanupStack::PushL(text);
1.240 + CPageTextEntry* textentry=new(ELeave) CPageTextEntry(aPoint+TPoint(0,aFont->BaselineOffsetInPixels()),aFont->HeightInPixels(),aFont->MeasureText(aString),text,tf);
1.241 + CleanupStack::Pop();
1.242 +
1.243 + i=0,count=iPageTextEntryList->Count();
1.244 + for (; (i<count) && (textentry->iDrawPos.iY>(*iPageTextEntryList)[i]->iDrawPos.iY); i++ )
1.245 + {
1.246 + }
1.247 + for (; (i<count) && (textentry->iDrawPos.iY==(*iPageTextEntryList)[i]->iDrawPos.iY) &&
1.248 + (textentry->iDrawPos.iX>(*iPageTextEntryList)[i]->iDrawPos.iX); i++)
1.249 + {
1.250 + }
1.251 + CleanupStack::PushL(textentry);
1.252 + iPageTextEntryList->InsertL(i,textentry);
1.253 + CleanupStack::Pop();
1.254 + if (textentry->iHeightInPixels>iMaxFontHeightInPixels)
1.255 + iMaxFontHeightInPixels=textentry->iHeightInPixels;
1.256 + }
1.257 +
1.258 +EXPORT_C TInt CPageText::NumEntries()
1.259 + {
1.260 + return iPageTextEntryList->Count();
1.261 + }
1.262 +
1.263 +EXPORT_C CPageTextEntry* CPageText::operator [] (TInt anIndex)
1.264 + {
1.265 + return (*iPageTextEntryList)[anIndex];
1.266 + }