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