printingservices/printerdriversupport/src/PDRPAGE.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 <pdrstore.h>
       
    17 #include "pdrtext.h"
       
    18 
       
    19 const TInt KPageBufferSegmentSize=2048;
       
    20 
       
    21 EXPORT_C CPageBuffer* CPageBuffer::NewL(CPrinterPort* aPrinterPort)
       
    22 	{
       
    23 	return NewL(aPrinterPort,KPageBufferSegmentSize);
       
    24 	}
       
    25 
       
    26 EXPORT_C CPageBuffer* CPageBuffer::NewL(CPrinterPort* aPrinterPort,TInt aGranularity)
       
    27 	{
       
    28 	CPageBuffer* pagebuffer=new(ELeave) CPageBuffer(aPrinterPort,aGranularity);
       
    29 	CleanupStack::PushL(pagebuffer);
       
    30 	pagebuffer->ConstructL();
       
    31 	CleanupStack::Pop();
       
    32 	return pagebuffer;
       
    33 	}
       
    34 
       
    35 EXPORT_C void CPageBuffer::StartFlush(TRequestStatus& aRequestStatus)	
       
    36 	{		//  
       
    37 	iRequestStatus=&aRequestStatus;
       
    38 	aRequestStatus=KRequestPending;
       
    39 	iWritePos=0;
       
    40 	Queue();
       
    41 	}
       
    42 
       
    43 EXPORT_C void CPageBuffer::AddBytesL(const TDesC8& aDes)
       
    44 	{
       
    45 	iBuffer->InsertL(iBuffer->Size(),aDes);
       
    46 	}
       
    47 
       
    48 EXPORT_C RWriteStream& CPageBuffer::CreateWriteStreamL()
       
    49 	{
       
    50 	if (!iWriteStreamBuffer)
       
    51 		{
       
    52 		iWriteStreamBuffer=CBufSeg::NewL(iGranularity);
       
    53 		iWriteStream.Open(*iWriteStreamBuffer,0);
       
    54 		}
       
    55 	else
       
    56 		{
       
    57 		iWriteStream.Truncate(*iWriteStreamBuffer,0);
       
    58 		}
       
    59 	return iWriteStream;
       
    60 	}
       
    61 
       
    62 EXPORT_C void CPageBuffer::CloseWriteStream()
       
    63 	{
       
    64 	iWriteStream.Close();
       
    65 	CBufSeg* buf=iBuffer;
       
    66 	iBuffer=iWriteStreamBuffer;
       
    67 	iWriteStreamBuffer=buf;
       
    68 	}
       
    69 
       
    70 EXPORT_C CPageBuffer::~CPageBuffer()
       
    71 	{
       
    72 	Cancel();
       
    73 	delete iBuffer;
       
    74 	if (iWriteStreamBuffer)
       
    75 		{
       
    76 		iWriteStream.Close();
       
    77 		delete iWriteStreamBuffer;
       
    78 		}
       
    79 	}
       
    80 
       
    81 void CPageBuffer::DoCancel()
       
    82 	{
       
    83 	iPrinterPort->Cancel();	// clears my request
       
    84 	if (iRequestStatus!=NULL)
       
    85 		User::RequestComplete(iRequestStatus,KErrCancel); // clears my callers request
       
    86 	}
       
    87 
       
    88 void CPageBuffer::RunL()  //  Shouldn't leave in practice
       
    89 	{	
       
    90 	if ((iWritePos>=iBuffer->Size()) || (iStatus!=KErrNone))
       
    91 		{
       
    92 		iBuffer->Reset();
       
    93 		if (iRequestStatus!=NULL)
       
    94 			User::RequestComplete(iRequestStatus,iStatus.Int()); // clears my callers request
       
    95 		}	   //  Reports back error if iStatus!=KErrNone
       
    96 	else
       
    97 		{
       
    98 		Queue();
       
    99 		}
       
   100 	}
       
   101 
       
   102 void CPageBuffer::ConstructL()
       
   103 	{
       
   104 	iBuffer=CBufSeg::NewL(iGranularity);
       
   105 	CActiveScheduler::Add(this);
       
   106 	}
       
   107 
       
   108 CPageBuffer::CPageBuffer(CPrinterPort* aPrinterPort,TInt aGranularity):
       
   109 	CActive(CActive::EPriorityLow),
       
   110 	iRequestStatus(NULL),
       
   111 	iWritePos(0),
       
   112 	iGranularity(aGranularity),
       
   113 	iBuffer(NULL),
       
   114 	iPtr(NULL,0),
       
   115 	iPrinterPort(aPrinterPort),
       
   116 	iWriteStream(),
       
   117 	iWriteStreamBuffer(NULL)
       
   118 	{
       
   119 	__DECLARE_NAME(_S("CPageBuffer"));
       
   120 	}
       
   121 
       
   122 void CPageBuffer::Queue()
       
   123 	{
       
   124 	TPtr8 ptr=iBuffer->Ptr(iWritePos);
       
   125 	iPtr.Set(ptr);
       
   126 	iPrinterPort->WriteRequest(iPtr,iStatus);
       
   127 	iWritePos+=iPtr.Length();
       
   128 	SetActive();
       
   129 	}
       
   130 
       
   131 /** 
       
   132   This function is internal only, and is not intended for use. 
       
   133   @internalTechnology
       
   134 */
       
   135 EXPORT_C TTextFormat::TTextFormat():
       
   136 	iUnderlineStyle(EUnderlineOff),
       
   137 	iStrikethroughStyle(EStrikethroughOff),
       
   138 	iColor(KRgbBlack),
       
   139 	iFontString(_L8("")),
       
   140 	iFontStyle()
       
   141 	{
       
   142 	}
       
   143 
       
   144 EXPORT_C TTextFormat::TTextFormat(const TFontUnderline anUnderlineStyle,const TFontStrikethrough aStrikethroughStyle,const TRgb& aColor,const TDesC8& aFontString,const TFontStyle& aFontStyle):
       
   145 	iUnderlineStyle(anUnderlineStyle),
       
   146 	iStrikethroughStyle(aStrikethroughStyle),
       
   147 	iColor(aColor),
       
   148 	iFontString(aFontString),
       
   149 	iFontStyle(aFontStyle)
       
   150 	{
       
   151 	}
       
   152 
       
   153 EXPORT_C TBool TTextFormat::operator == (const TTextFormat& aFormat) const
       
   154 	{
       
   155 	return (iUnderlineStyle==aFormat.iUnderlineStyle) &&
       
   156 	       (iStrikethroughStyle==aFormat.iStrikethroughStyle) &&
       
   157 	       (!iFontString.Compare(aFormat.iFontString)) && 
       
   158 	       (iFontStyle==aFormat.iFontStyle) && (iColor==aFormat.iColor);
       
   159 	}
       
   160 
       
   161 EXPORT_C CPageTextEntry::CPageTextEntry(const TPoint& aDrawPos,TInt aHeightInPixels,TInt aTextWidthInPixels,HBufC8* aText,TTextFormat* aTextFormat):
       
   162 	iDrawPos(aDrawPos),
       
   163 	iHeightInPixels(aHeightInPixels),
       
   164 	iTextWidthInPixels(aTextWidthInPixels),
       
   165 	iText(aText),
       
   166 	iTextFormat(aTextFormat)
       
   167 	{
       
   168 	__DECLARE_NAME(_S("CPageTextEntry"));
       
   169 	}
       
   170 
       
   171 EXPORT_C CPageTextEntry::~CPageTextEntry()
       
   172 	{
       
   173 	delete iText;
       
   174 	}
       
   175 
       
   176 EXPORT_C TPoint CPageTextEntry::TopTextPos()
       
   177 	{
       
   178 	return iDrawPos-TPoint(0,iHeightInPixels);
       
   179 	}
       
   180 
       
   181 CPageText::CPageText()
       
   182 	{
       
   183 	}
       
   184 
       
   185 void CPageText::ConstructL()
       
   186 	{
       
   187 	iTextFormatList = new(ELeave) CArrayPtrFlat<TTextFormat>(8);
       
   188 	iPageTextEntryList = new(ELeave) CArrayPtrFlat<CPageTextEntry>(8);
       
   189 	}
       
   190 
       
   191 EXPORT_C CPageText* CPageText::NewL()
       
   192 	{
       
   193 	CPageText* pagetext = new(ELeave) CPageText;
       
   194 	CleanupStack::PushL(pagetext);
       
   195 	pagetext->ConstructL();
       
   196 	CleanupStack::Pop();
       
   197 	return pagetext;
       
   198 	}
       
   199 
       
   200 EXPORT_C CPageText::~CPageText()
       
   201 	{
       
   202 	Reset();
       
   203 	delete iPageTextEntryList;
       
   204 	delete iTextFormatList;
       
   205 	}
       
   206 
       
   207 EXPORT_C void CPageText::Reset()
       
   208 	{
       
   209 	if (iPageTextEntryList)
       
   210 		iPageTextEntryList->ResetAndDestroy();
       
   211 	if (iTextFormatList)
       
   212 		iTextFormatList->ResetAndDestroy();
       
   213 	}
       
   214 
       
   215 EXPORT_C void CPageText::AddEntryL(const TPoint& aPoint,const TFontUnderline aUnderlineStyle,const TFontStrikethrough aStrikethroughStyle,const TRgb& aColor,const CInfoFont* aFont,const TDesC& aString)
       
   216 	{
       
   217 	TTextFormat textformat(aUnderlineStyle,aStrikethroughStyle,aColor,aFont->CommandString(),aFont->FontSpecInTwips().iFontStyle);
       
   218 	TInt count=iTextFormatList->Count();
       
   219 	TTextFormat* tf;
       
   220 	TInt i;
       
   221 	for (i = 0; ; i++)
       
   222 		{
       
   223 		if (i==count)
       
   224 			{
       
   225 			tf=new(ELeave) TTextFormat(textformat);
       
   226 			CleanupStack::PushL(tf);
       
   227 			iTextFormatList->AppendL(tf);
       
   228 			CleanupStack::Pop();
       
   229 			break;
       
   230 			}
       
   231 		tf=(*iTextFormatList)[i];
       
   232 		if (textformat==*tf)
       
   233 			break;
       
   234 		}
       
   235 	HBufC8* text=aFont->TranslateStringL(aString);
       
   236 	CleanupStack::PushL(text);
       
   237 	CPageTextEntry* textentry=new(ELeave) CPageTextEntry(aPoint+TPoint(0,aFont->BaselineOffsetInPixels()),aFont->HeightInPixels(),aFont->MeasureText(aString),text,tf);
       
   238 	CleanupStack::Pop();
       
   239 
       
   240 	i=0,count=iPageTextEntryList->Count();
       
   241 	for (; (i<count) && (textentry->iDrawPos.iY>(*iPageTextEntryList)[i]->iDrawPos.iY); i++ )
       
   242 		{
       
   243 		}
       
   244 	for (; (i<count) && (textentry->iDrawPos.iY==(*iPageTextEntryList)[i]->iDrawPos.iY) &&
       
   245 	                    (textentry->iDrawPos.iX>(*iPageTextEntryList)[i]->iDrawPos.iX); i++)
       
   246 		{
       
   247 		}
       
   248 	CleanupStack::PushL(textentry);
       
   249 	iPageTextEntryList->InsertL(i,textentry);
       
   250 	CleanupStack::Pop();
       
   251 	if (textentry->iHeightInPixels>iMaxFontHeightInPixels)
       
   252 		iMaxFontHeightInPixels=textentry->iHeightInPixels;
       
   253 	}
       
   254 
       
   255 EXPORT_C TInt CPageText::NumEntries()
       
   256 	{
       
   257 	return iPageTextEntryList->Count();
       
   258 	}
       
   259 
       
   260 EXPORT_C CPageTextEntry* CPageText::operator [] (TInt anIndex)
       
   261 	{
       
   262 	return (*iPageTextEntryList)[anIndex];
       
   263 	}