Update contrib.
2 * Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
21 ////////////////////////////////////////////
23 ////////////////////////////////////////////
25 CRichTextReader* CRichTextReader::NewL()
27 CRichTextReader* self=new(ELeave) CRichTextReader;
28 CleanupStack::PushL(self);
35 CRichTextReader::CRichTextReader()
39 iConsoleExists = EFalse;
43 void CRichTextReader::ConstructL()
45 // construct PML writer
46 iPMLWriter = CPMLWriter::NewL();
48 // construct RichText bits
49 iThisParaFormat = CParaFormat::NewL();
50 iPrevParaFormat = CParaFormat::NewL();
54 void CRichTextReader::Destruct()
56 // iConsole.Destroy();
57 Adt::Destroy(iPMLWriter);
58 Adt::Destroy(iThisParaFormat);
59 Adt::Destroy(iPrevParaFormat);
61 delete(iBorder); // only delete if it hasn't been used (if it has RT destroys it automatically)
65 CBufSeg* CRichTextReader::ConvertRichText(CRichText* aRichTextDoc)
66 // Quiet version of the RichText->PML parser
67 // Takes RT doc passed in, reads its global format,
68 // then reads the character and paragraph formats phrase by phrase
70 iRichTextDoc = aRichTextDoc;
71 iDocLength = iRichTextDoc->DocumentLength();
76 while (readPos < iDocLength)
78 nextPhrase = TranslatePhrase(readPos);
79 readPos += nextPhrase;
81 iPMLWriter->Delete(1); // remove end-of-document paragraph delimiter
82 return iPMLWriter->ReturnPmlDoc();
86 CBufSeg* CRichTextReader::ConvertRichText(CRichText* aRichTextDoc, RConsole aConsole)
87 // Version of the RichText->PML parser with console output (primarily for debugging)
88 // Takes RT doc passed in, reads its global format,
89 // then reads the character and paragraph formats phrase by phrase
91 iConsoleExists = ETrue;
92 iRichTextDoc = aRichTextDoc;
94 iDocLength = iRichTextDoc->DocumentLength();
99 while (readPos <= iDocLength)
101 nextPhrase = TranslatePhrase(readPos);
102 readPos += nextPhrase;
104 iPMLWriter->Delete(1);
105 iPMLWriter->Output(iConsole); // output PML doc to screen
106 return iPMLWriter->ReturnPmlDoc();
110 void CRichTextReader::SenseGlobalFormat()
111 // Senses global format & writes it to PML
113 // construct rich text bits
114 const CParaFormatLayer* globalParaFormatLayer; // initialised with factory settings
115 const CCharFormatLayer* globalCharFormatLayer;
116 CParaFormat* globalParaFormat = CParaFormat::NewL();
117 TCharFormat globalCharFormat;
119 // Sense global format
120 globalParaFormatLayer = iRichTextDoc->SenseGlobalParaFormatLayer();
121 globalParaFormatLayer->SenseEffectiveL(globalParaFormat);
122 globalCharFormatLayer = iRichTextDoc->SenseGlobalCharFormatLayer();
123 globalCharFormatLayer->SenseEffective(globalCharFormat);
126 iPMLWriter->SetTag(EGlobal, ETagStart); // output <G
127 CompareParaToFactory(globalParaFormat); // step through format, adding all != factory settings
128 CompareCharToFactory(globalCharFormat); // ...
129 iPMLWriter->SetTag(EGlobal, ETagEnd); // output >\n
131 // initialise iPrevXxxxFormat
132 globalParaFormatLayer->SenseEffectiveL(iPrevParaFormat);
133 globalCharFormatLayer->SenseEffective(iPrevCharFormat);
135 // destroy rich text bits
136 Adt::Destroy(globalParaFormat);
140 TInt CRichTextReader::TranslatePhrase(TInt aReadPos)
141 // Output any new formatting being applied to this phrase
142 // First check whether this phrase is the start of a new paragraph
143 // If so check the paragraph format
144 // Next check the character formatting of the phrase
146 CPicture* pic; // dummy pointer for senseChars
150 TInt currentParaStart = aReadPos;
152 // paragraph formatting
153 if (currentParaStart != 0) // doesn't work for position=0 -- Duncan!!
154 iRichTextDoc->ParagraphStart(currentParaStart);
155 if ((currentParaStart > iParaStart)||(aReadPos == 0)) // is it a new paragraph?
157 iParaStart = currentParaStart;
158 // delete para delimiter
160 iPMLWriter->Delete(1); // deletes 1 chars previous to the current insert pos
162 iPMLWriter->SetTag(EParagraph, ETagStart);
163 iRichTextDoc->SenseParagraphFormatL(aReadPos,iThisParaFormat); // get para format
164 CompareParaFormats(); // compare to previous paragraph to get changes
165 iRichTextDoc->SenseParagraphFormatL(aReadPos,iPrevParaFormat); // set prevParaFormat to current & copy compound attributes
166 iPrevParaFormat->iTopBorder=CopyBorderL(iThisParaFormat->iTopBorder,iPrevParaFormat->iTopBorder);
167 iPrevParaFormat->iBottomBorder=CopyBorderL(iThisParaFormat->iBottomBorder,iPrevParaFormat->iBottomBorder);
168 iPrevParaFormat->iLeftBorder=CopyBorderL(iThisParaFormat->iLeftBorder,iPrevParaFormat->iLeftBorder);
169 iPrevParaFormat->iRightBorder=CopyBorderL(iThisParaFormat->iRightBorder,iPrevParaFormat->iRightBorder);
170 iPrevParaFormat->iBullet=CopyBulletL(iThisParaFormat->iBullet,iPrevParaFormat->iBullet);
171 iPMLWriter->SetTag(EParagraph, ETagEnd);
175 // character formatting
176 iPMLWriter->SetTag(ECharacter, ETagStart);
177 pmlWritePos = iPMLWriter->WritePos();
178 iRichTextDoc->SenseChars(aReadPos,currentPhrase,iThisCharFormat,pic); // get char format
179 CompareCharFormats(); // compare to previous
180 iRichTextDoc->SenseChars(aReadPos,currentPhrase,iPrevCharFormat,pic); // get char format
181 if (pmlWritePos == iPMLWriter->WritePos())
182 iPMLWriter->Delete(3); // delete tag start if tag is empty
184 iPMLWriter->SetTag(ECharacter, ETagEnd); // else close tag
186 iPMLWriter->Insert(currentPhrase); // output text of phrase to PML
187 return currentPhrase.Length(); // return relative pos of start of next phrase
191 TParaBorder* CRichTextReader::CopyBorderL(const TParaBorder* aFrom,TParaBorder* aTo)
192 // copies one paragraph border to another, creating or destroying where necessary
198 return NULL; // No border cell in the original
203 aTo = new(ELeave) TParaBorder;
210 TBullet* CRichTextReader::CopyBulletL(const TBullet* aFrom,TBullet* aTo)
211 // copies one bullet to another, creating or destroying where necessary
217 return NULL; // No bullet cell in the original
222 aTo = new(ELeave) TBullet;
229 void CRichTextReader::CompareParaToFactory(CParaFormat* aSensedParaFormat)
230 // Compares the supplied paragraph format to the factory defaults and acts on any differences
232 // create a new reference format with factory settings
233 CParaFormat* refParaFormat = CParaFormat::NewL();
234 // step through, comparing aSensedParaFormat to the reference
235 // if any attributes differ, set the differences in the PML doc
236 if (aSensedParaFormat->iLanguage != refParaFormat->iLanguage)
237 iPMLWriter->SetFormat(EAttParaLanguage, aSensedParaFormat->iLanguage);
238 if (aSensedParaFormat->iLeftMargin != refParaFormat->iLeftMargin)
239 iPMLWriter->SetFormat(EAttLeftMargin, aSensedParaFormat->iLeftMargin);
240 if (aSensedParaFormat->iRightMargin != refParaFormat->iRightMargin)
241 iPMLWriter->SetFormat(EAttRightMargin, aSensedParaFormat->iRightMargin);
242 if (aSensedParaFormat->iIndent != refParaFormat->iIndent)
243 iPMLWriter->SetFormat(EAttIndent, aSensedParaFormat->iIndent);
244 if (aSensedParaFormat->iAlignment != refParaFormat->iAlignment)
245 iPMLWriter->SetFormat(EAttAlignment, aSensedParaFormat->iAlignment);
246 if (aSensedParaFormat->iLineSpacing != refParaFormat->iLineSpacing)
247 iPMLWriter->SetFormat(EAttLineSpacing, aSensedParaFormat->iLineSpacing);
248 if (aSensedParaFormat->iLineSpacingControl != refParaFormat->iLineSpacingControl)
249 iPMLWriter->SetFormat(EAttLineSpacingControl, aSensedParaFormat->iLineSpacingControl);
250 if (aSensedParaFormat->iSpaceBefore != refParaFormat->iSpaceBefore)
251 iPMLWriter->SetFormat(EAttSpaceBefore, aSensedParaFormat->iSpaceBefore);
252 if (aSensedParaFormat->iSpaceAfter != refParaFormat->iSpaceAfter)
253 iPMLWriter->SetFormat(EAttSpaceAfter, aSensedParaFormat->iSpaceAfter);
254 if (aSensedParaFormat->iKeepTogether != refParaFormat->iKeepTogether)
255 iPMLWriter->SetFormat(EAttKeepTogether, aSensedParaFormat->iKeepTogether);
256 if (aSensedParaFormat->iKeepWithNext != refParaFormat->iKeepWithNext)
257 iPMLWriter->SetFormat(EAttKeepWithNext, aSensedParaFormat->iKeepWithNext);
258 if (aSensedParaFormat->iStartNewPage != refParaFormat->iStartNewPage)
259 iPMLWriter->SetFormat(EAttStartNewPage, aSensedParaFormat->iStartNewPage);
260 if (aSensedParaFormat->iWidowOrphan != refParaFormat->iWidowOrphan)
261 iPMLWriter->SetFormat(EAttWidowOrphan, aSensedParaFormat->iWidowOrphan);
262 if (aSensedParaFormat->iBorderMargin != refParaFormat->iBorderMargin)
263 iPMLWriter->SetFormat(EAttBorderMargin, aSensedParaFormat->iBorderMargin);
264 if (aSensedParaFormat->iTopBorder)
266 if (refParaFormat->iTopBorder == NULL)
267 iPMLWriter->SetFormat(EAttTopBorder, aSensedParaFormat->iTopBorder);
268 else if ((aSensedParaFormat->iTopBorder->iLineStyle != refParaFormat->iTopBorder->iLineStyle)
269 ||(aSensedParaFormat->iTopBorder->iAutoColor != refParaFormat->iTopBorder->iAutoColor)
270 ||(aSensedParaFormat->iTopBorder->iColor != refParaFormat->iTopBorder->iColor))
272 iPMLWriter->SetFormat(EAttTopBorder, aSensedParaFormat->iTopBorder);
275 if (aSensedParaFormat->iBottomBorder)
277 if (refParaFormat->iTopBorder == NULL)
278 iPMLWriter->SetFormat(EAttBottomBorder, aSensedParaFormat->iBottomBorder);
279 else if ((aSensedParaFormat->iBottomBorder->iLineStyle != refParaFormat->iBottomBorder->iLineStyle)
280 ||(aSensedParaFormat->iBottomBorder->iAutoColor != refParaFormat->iBottomBorder->iAutoColor)
281 ||(aSensedParaFormat->iBottomBorder->iColor != refParaFormat->iBottomBorder->iColor))
283 iPMLWriter->SetFormat(EAttBottomBorder, aSensedParaFormat->iBottomBorder);
286 if (aSensedParaFormat->iLeftBorder)
288 if (refParaFormat->iTopBorder == NULL)
289 iPMLWriter->SetFormat(EAttLeftBorder, aSensedParaFormat->iLeftBorder);
290 else if ((aSensedParaFormat->iLeftBorder->iLineStyle != refParaFormat->iLeftBorder->iLineStyle)
291 ||(aSensedParaFormat->iLeftBorder->iAutoColor != refParaFormat->iLeftBorder->iAutoColor)
292 ||(aSensedParaFormat->iLeftBorder->iColor != refParaFormat->iLeftBorder->iColor))
294 iPMLWriter->SetFormat(EAttLeftBorder, aSensedParaFormat->iLeftBorder);
297 if (aSensedParaFormat->iRightBorder)
299 if (refParaFormat->iTopBorder == NULL)
300 iPMLWriter->SetFormat(EAttRightBorder, aSensedParaFormat->iRightBorder);
301 else if ((aSensedParaFormat->iRightBorder->iLineStyle != refParaFormat->iRightBorder->iLineStyle)
302 ||(aSensedParaFormat->iRightBorder->iAutoColor != refParaFormat->iRightBorder->iAutoColor)
303 ||(aSensedParaFormat->iRightBorder->iColor != refParaFormat->iRightBorder->iColor))
305 iPMLWriter->SetFormat(EAttRightBorder, aSensedParaFormat->iRightBorder);
308 if (aSensedParaFormat->iBullet)
310 if (refParaFormat->iBullet == NULL)
311 iPMLWriter->SetFormat(EAttBullet, aSensedParaFormat->iBullet);
312 if ((aSensedParaFormat->iBullet->iCharacterCode != refParaFormat->iBullet->iCharacterCode)
313 ||(aSensedParaFormat->iBullet->iHeight != refParaFormat->iBullet->iHeight)
314 ||(aSensedParaFormat->iBullet->iTypeface.iName != refParaFormat->iBullet->iTypeface.iName)
315 ||(aSensedParaFormat->iBullet->iTypeface.iFlags != refParaFormat->iBullet->iTypeface.iFlags))
317 iPMLWriter->SetFormat(EAttBullet, aSensedParaFormat->iBullet);
320 if (aSensedParaFormat->iDefaultTabWidth != refParaFormat->iDefaultTabWidth)
321 iPMLWriter->SetFormat(EAttDefaultTabWidth, aSensedParaFormat->iDefaultTabWidth);
322 CheckTabList(aSensedParaFormat, refParaFormat); // tabs are sensed separately
324 // Destroy ref format
325 Adt::Destroy(refParaFormat);
328 void CRichTextReader::CompareCharToFactory(TCharFormat aSensedCharFormat)
329 // Compares the supplied character format to the factory defaults and acts on any differences
331 // create a new reference format with factory settings
332 TCharFormat refCharFormat;
333 // step through, comparing aSensedCharFormat to the reference
334 // if any attributes differ, set the differences in the PML doc
335 if (aSensedCharFormat.iLanguage != refCharFormat.iLanguage)
336 iPMLWriter->SetFormat(EAttCharLanguage, aSensedCharFormat.iLanguage);
337 if (aSensedCharFormat.iColor != refCharFormat.iColor)
338 iPMLWriter->SetFormat(EAttColor, aSensedCharFormat.iColor.RgbToUint());
339 if (aSensedCharFormat.iFontSpec.iTypeface.iName != refCharFormat.iFontSpec.iTypeface.iName)
340 iPMLWriter->SetFormat(EAttFontTypefaceName, aSensedCharFormat.iFontSpec.iTypeface);
341 if (aSensedCharFormat.iFontSpec.iTypeface.iFlags != refCharFormat.iFontSpec.iTypeface.iFlags)
342 iPMLWriter->SetFormat(EAttFontTypefaceFlags, aSensedCharFormat.iFontSpec.iTypeface);
343 if (aSensedCharFormat.iFontSpec.iHeight != refCharFormat.iFontSpec.iHeight)
344 iPMLWriter->SetFormat(EAttFontHeight, aSensedCharFormat.iFontSpec.iHeight);
345 if (aSensedCharFormat.iFontSpec.iPosture != refCharFormat.iFontSpec.iPosture)
346 iPMLWriter->SetFormat(EAttFontPosture, aSensedCharFormat.iFontSpec.iPosture);
347 if (aSensedCharFormat.iFontSpec.iStrokeWeight != refCharFormat.iFontSpec.iStrokeWeight)
348 iPMLWriter->SetFormat(EAttFontStrokeWeight, aSensedCharFormat.iFontSpec.iStrokeWeight);
349 if (aSensedCharFormat.iFontSpec.iPos != refCharFormat.iFontSpec.iPos)
350 iPMLWriter->SetFormat(EAttFontPrintPos, aSensedCharFormat.iFontSpec.iPos);
351 if (aSensedCharFormat.iFontSpec.iUnderline != refCharFormat.iFontSpec.iUnderline)
352 iPMLWriter->SetFormat((TTextFormatAttribute)EAttFontUnderline, aSensedCharFormat.iFontSpec.iUnderline);
353 if (aSensedCharFormat.iFontSpec.iStrikethrough != refCharFormat.iFontSpec.iStrikethrough)
354 iPMLWriter->SetFormat(EAttFontStrikethrough, aSensedCharFormat.iFontSpec.iStrikethrough);
358 void CRichTextReader::CompareParaFormats()
359 // compares the current para format with the format of the previous para
360 // any differences are output to PML
362 if (iThisParaFormat->iLanguage != iPrevParaFormat->iLanguage)
363 iPMLWriter->SetFormat(EAttParaLanguage, iThisParaFormat->iLanguage);
364 if (iThisParaFormat->iLeftMargin != iPrevParaFormat->iLeftMargin)
365 iPMLWriter->SetFormat(EAttLeftMargin, iThisParaFormat->iLeftMargin);
366 if (iThisParaFormat->iRightMargin != iPrevParaFormat->iRightMargin)
367 iPMLWriter->SetFormat(EAttRightMargin, iThisParaFormat->iRightMargin);
368 if (iThisParaFormat->iIndent != iPrevParaFormat->iIndent)
369 iPMLWriter->SetFormat(EAttIndent, iThisParaFormat->iIndent);
370 if (iThisParaFormat->iAlignment != iPrevParaFormat->iAlignment)
371 iPMLWriter->SetFormat(EAttAlignment, iThisParaFormat->iAlignment);
372 if (iThisParaFormat->iLineSpacing != iPrevParaFormat->iLineSpacing)
373 iPMLWriter->SetFormat(EAttLineSpacing, iThisParaFormat->iLineSpacing);
374 if (iThisParaFormat->iLineSpacingControl != iPrevParaFormat->iLineSpacingControl)
375 iPMLWriter->SetFormat(EAttLineSpacingControl, iThisParaFormat->iLineSpacingControl);
376 if (iThisParaFormat->iSpaceBefore != iPrevParaFormat->iSpaceBefore)
377 iPMLWriter->SetFormat(EAttSpaceBefore, iThisParaFormat->iSpaceBefore);
378 if (iThisParaFormat->iSpaceAfter != iPrevParaFormat->iSpaceAfter)
379 iPMLWriter->SetFormat(EAttSpaceAfter, iThisParaFormat->iSpaceAfter);
380 if (iThisParaFormat->iKeepTogether != iPrevParaFormat->iKeepTogether)
381 iPMLWriter->SetFormat(EAttKeepTogether, iThisParaFormat->iKeepTogether);
382 if (iThisParaFormat->iKeepWithNext != iPrevParaFormat->iKeepWithNext)
383 iPMLWriter->SetFormat(EAttKeepWithNext, iThisParaFormat->iKeepWithNext);
384 if (iThisParaFormat->iStartNewPage != iPrevParaFormat->iStartNewPage)
385 iPMLWriter->SetFormat(EAttStartNewPage, iThisParaFormat->iStartNewPage);
386 if (iThisParaFormat->iWidowOrphan != iPrevParaFormat->iWidowOrphan)
387 iPMLWriter->SetFormat(EAttWidowOrphan, iThisParaFormat->iWidowOrphan);
388 if (iThisParaFormat->iBorderMargin != iPrevParaFormat->iBorderMargin)
389 iPMLWriter->SetFormat(EAttBorderMargin, iThisParaFormat->iBorderMargin);
390 if (iThisParaFormat->iTopBorder)
392 if (iPrevParaFormat->iTopBorder == NULL)
393 iPMLWriter->SetFormat(EAttTopBorder, iThisParaFormat->iTopBorder);
394 else if ((iThisParaFormat->iTopBorder->iLineStyle != iPrevParaFormat->iTopBorder->iLineStyle)
395 ||(iThisParaFormat->iTopBorder->iAutoColor != iPrevParaFormat->iTopBorder->iAutoColor)
396 ||(iThisParaFormat->iTopBorder->iColor != iPrevParaFormat->iTopBorder->iColor))
398 iPMLWriter->SetFormat(EAttTopBorder, iThisParaFormat->iTopBorder);
401 if (iThisParaFormat->iBottomBorder)
403 if (iPrevParaFormat->iBottomBorder == NULL)
404 iPMLWriter->SetFormat(EAttBottomBorder, iThisParaFormat->iBottomBorder);
405 else if ((iThisParaFormat->iBottomBorder->iLineStyle != iPrevParaFormat->iBottomBorder->iLineStyle)
406 ||(iThisParaFormat->iBottomBorder->iAutoColor != iPrevParaFormat->iBottomBorder->iAutoColor)
407 ||(iThisParaFormat->iBottomBorder->iColor != iPrevParaFormat->iBottomBorder->iColor))
409 iPMLWriter->SetFormat(EAttBottomBorder, iThisParaFormat->iBottomBorder);
412 if (iThisParaFormat->iLeftBorder)
414 if (iPrevParaFormat->iLeftBorder == NULL)
415 iPMLWriter->SetFormat(EAttLeftBorder, iThisParaFormat->iLeftBorder);
416 if ((iThisParaFormat->iLeftBorder->iLineStyle != iPrevParaFormat->iLeftBorder->iLineStyle)
417 ||(iThisParaFormat->iLeftBorder->iAutoColor != iPrevParaFormat->iLeftBorder->iAutoColor)
418 ||(iThisParaFormat->iLeftBorder->iColor != iPrevParaFormat->iLeftBorder->iColor))
420 iPMLWriter->SetFormat(EAttLeftBorder, iThisParaFormat->iLeftBorder);
423 if (iThisParaFormat->iRightBorder)
425 if (iPrevParaFormat->iRightBorder == NULL)
426 iPMLWriter->SetFormat(EAttRightBorder, iThisParaFormat->iRightBorder);
427 if ((iThisParaFormat->iRightBorder->iLineStyle != iPrevParaFormat->iRightBorder->iLineStyle)
428 ||(iThisParaFormat->iRightBorder->iAutoColor != iPrevParaFormat->iRightBorder->iAutoColor)
429 ||(iThisParaFormat->iRightBorder->iColor != iPrevParaFormat->iRightBorder->iColor))
431 iPMLWriter->SetFormat(EAttRightBorder, iThisParaFormat->iRightBorder);
434 if (iThisParaFormat->iBullet)
436 if (iPrevParaFormat->iBullet == NULL)
437 iPMLWriter->SetFormat(EAttBullet, iThisParaFormat->iBullet);
438 else if ((iThisParaFormat->iBullet->iCharacterCode != iPrevParaFormat->iBullet->iCharacterCode)
439 ||(iThisParaFormat->iBullet->iHeight != iPrevParaFormat->iBullet->iHeight)
440 ||(iThisParaFormat->iBullet->iTypeface.iName != iPrevParaFormat->iBullet->iTypeface.iName)
441 ||(iThisParaFormat->iBullet->iTypeface.iFlags != iPrevParaFormat->iBullet->iTypeface.iFlags))
443 iPMLWriter->SetFormat(EAttBullet, iThisParaFormat->iBullet);
446 if (iThisParaFormat->iDefaultTabWidth != iPrevParaFormat->iDefaultTabWidth)
447 iPMLWriter->SetFormat(EAttDefaultTabWidth, iThisParaFormat->iDefaultTabWidth);
448 CheckTabList(iThisParaFormat, iPrevParaFormat); // tabs are sensed separately
452 void CRichTextReader::CheckTabList(CParaFormat* aFormatOne, CParaFormat* aFormatTwo)
453 // Check whether the first (current) and second formats' tablists differ
454 // If they do, output whole of first list to PML
456 TBool output = EFalse;
457 if (aFormatOne->TabCount() != aFormatTwo->TabCount())
458 output = ETrue; // output to PML
461 // lists are same length: check that all members are the same
464 while ((index < aFormatOne->TabCount())&&(!dif))
466 if (aFormatOne->TabStop(index) != aFormatTwo->TabStop(index))
467 output = ETrue; // output to PML
473 for (TInt i=0; i < aFormatOne->TabCount(); i++)
474 iPMLWriter->SetFormat(EAttTabStop, aFormatOne->TabStop(i));
479 void CRichTextReader::CompareCharFormats()
481 if (iThisCharFormat.iLanguage != iPrevCharFormat.iLanguage)
482 iPMLWriter->SetFormat(EAttCharLanguage, iThisCharFormat.iLanguage);
483 if (iThisCharFormat.iColor != iPrevCharFormat.iColor)
484 iPMLWriter->SetFormat(EAttColor, iThisCharFormat.iColor.RgbToUint());
485 if (iThisCharFormat.iFontSpec.iTypeface.iName != iPrevCharFormat.iFontSpec.iTypeface.iName)
486 iPMLWriter->SetFormat(EAttFontTypefaceName, iThisCharFormat.iFontSpec.iTypeface);
487 if (iThisCharFormat.iFontSpec.iTypeface.iFlags != iPrevCharFormat.iFontSpec.iTypeface.iFlags)
488 iPMLWriter->SetFormat(EAttFontTypefaceFlags, iThisCharFormat.iFontSpec.iTypeface);
489 if (iThisCharFormat.iFontSpec.iHeight != iPrevCharFormat.iFontSpec.iHeight)
490 iPMLWriter->SetFormat(EAttFontHeight, iThisCharFormat.iFontSpec.iHeight);
491 if (iThisCharFormat.iFontSpec.iPosture != iPrevCharFormat.iFontSpec.iPosture)
492 iPMLWriter->SetFormat(EAttFontPosture, iThisCharFormat.iFontSpec.iPosture);
493 if (iThisCharFormat.iFontSpec.iStrokeWeight != iPrevCharFormat.iFontSpec.iStrokeWeight)
494 iPMLWriter->SetFormat(EAttFontStrokeWeight, iThisCharFormat.iFontSpec.iStrokeWeight);
495 if (iThisCharFormat.iFontSpec.iPos != iPrevCharFormat.iFontSpec.iPos)
496 iPMLWriter->SetFormat(EAttFontPrintPos, iThisCharFormat.iFontSpec.iPos);
497 if (iThisCharFormat.iFontSpec.iUnderline != iPrevCharFormat.iFontSpec.iUnderline)
498 iPMLWriter->SetFormat(EAttFontUnderline, iThisCharFormat.iFontSpec.iUnderline);
499 if (iThisCharFormat.iFontSpec.iStrikethrough != iPrevCharFormat.iFontSpec.iStrikethrough)
500 iPMLWriter->SetFormat(EAttFontStrikethrough, iThisCharFormat.iFontSpec.iStrikethrough);
506 //////////////////////////////////////////////////////
508 //////////////////////////////////////////////////////
510 CPMLWriter* CPMLWriter::NewL()
512 CPMLWriter* self=new(ELeave) CPMLWriter;
518 CPMLWriter::CPMLWriter()
524 void CPMLWriter::Construct()
526 iTextBuf = CBufSeg::New(64); // create buffer with granularity 64
530 void CPMLWriter::Destruct()
532 Adt::Destroy(iTextBuf);
536 void CPMLWriter::ExpandBuf(const TDes8& aBuffer, TDes& aTarget)
538 // Input 8 bit buffer to be returned by ref. as an 8/16-bit version
539 // Used for unicode compatability
543 for (TInt pos=0 ; pos<aBuffer.Length() ; pos++ )
545 textPointer = aBuffer[pos];
546 aTarget.Append(textPointer);
551 void CPMLWriter::SquashBuf(const TDesC& aBuffer, TDes8& aTarget)
553 // Input 8/16 bit buffer and an 8-bit target to be copied into.
554 // Used for unicode compatability
558 for (TInt pos=0; pos<aBuffer.Length(); pos++)
560 textPointer = aBuffer[pos];
561 aTarget.Append(textPointer);
566 void CPMLWriter::Insert(const TDesC& aBuf)
567 // insert aBuf into PML doc
569 TUint bufLength = aBuf.Length();
571 SquashBuf(aBuf,temp);
572 iTextBuf->InsertL(iInsertPos, temp, bufLength);
573 iInsertPos += bufLength;
577 void CPMLWriter::Delete(TUint aLength)
578 // delete back from current insert pos aLength (characters)
580 iTextBuf->Delete(iInsertPos-aLength, aLength);
581 iInsertPos -= aLength;
585 void CPMLWriter::Output(RConsole aConsole)
586 // output buffer to screen
590 while (readPos < iTextBuf->Size())
592 iTextBuf->Read(readPos, tempBuf, 1);
594 ExpandBuf(tempBuf,wideTemp);
595 aConsole.Write(wideTemp);
601 void CPMLWriter::SetTag(TTagType aTagType, TTagStatus aStatus)
602 // insert a tag-open or tag-close into the PML doc
604 if (aStatus == ETagStart)
622 if (aStatus == ETagEnd)
643 void CPMLWriter::SetTab(TTabStop aTabStop)
644 // insert a tab into the PML doc
647 tagBuf.Format(_L("Tab=,%d"),aTabStop.iPosition); // put 2nd paramater in first
648 switch (aTabStop.iType) // insert 1st paramater after "="
651 tagBuf.Insert(4,_L("Null"));
654 tagBuf.Insert(4,_L("Left"));
657 tagBuf.Insert(4,_L("Centered"));
660 tagBuf.Insert(4,_L("Right"));
666 /* The setFormat functions add the stipulated formatting to the PML doc */
668 void CPMLWriter::SetFormat(TTextFormatAttribute aAttribute, TInt aValue)
674 case EAttParaLanguage:
675 outputBuf.Format(_L("ParaLanguage=%d "),aValue);
679 outputBuf.Format(_L("LeftMargin=%d "),aValue);
682 case EAttRightMargin:
683 outputBuf.Format(_L("RightMargin=%d "),aValue);
687 outputBuf.Format(_L("Indent=%d "),aValue);
691 ProcessAlignment(aValue);
693 case EAttLineSpacing:
694 outputBuf.Format(_L("LineSpacing=%d "),aValue);
697 case EAttLineSpacingControl:
698 ProcessLineSpacingControl(aValue);
700 case EAttSpaceBefore:
701 outputBuf.Format(_L("SpaceBefore=%d "),aValue);
705 outputBuf.Format(_L("SpaceAfter=%d "),aValue);
708 case EAttKeepTogether:
709 ProcessBooleanAtt(aAttribute, aValue);
711 case EAttKeepWithNext:
712 ProcessBooleanAtt(aAttribute, aValue);
714 case EAttStartNewPage:
715 ProcessBooleanAtt(aAttribute, aValue);
717 case EAttWidowOrphan:
718 ProcessBooleanAtt(aAttribute, aValue);
720 case EAttBorderMargin:
721 outputBuf.Format(_L("BorderMargin=%d "),aValue);
724 case EAttDefaultTabWidth:
725 outputBuf.Format(_L("DefaultTabWidth=%d "),aValue);
730 case EAttCharLanguage:
731 outputBuf.Format(_L("Language=%d "),aValue);
735 outputBuf.Format(_L("Color=%d "),aValue);
739 outputBuf.Format(_L("FontHeight=%d "),aValue);
742 case EAttFontPosture:
743 ProcessBooleanAtt(aAttribute, aValue);
745 case EAttFontStrokeWeight:
746 ProcessBooleanAtt(aAttribute, aValue);
748 case EAttFontPrintPos:
749 ProcessFontPrintPos(aValue);
751 case EAttFontUnderline:
752 ProcessBooleanAtt(aAttribute, aValue);
754 case EAttFontStrikethrough:
755 ProcessBooleanAtt(aAttribute, aValue);
757 case EAttFontTypefaceFlags:
758 outputBuf.Format(_L("TypefaceFlags=%d "),aValue);
765 void CPMLWriter::SetFormat(TTextFormatAttribute aAttribute, const TTypeface &aTypeface)
770 case EAttFontTypefaceName:
771 outputBuf.Format(_L("TypefaceName=%S "),&aTypeface.iName);
773 case EAttFontTypefaceFlags:
774 outputBuf.Format(_L("TypefaceFlags=%u "),aTypeface.iFlags);
780 void CPMLWriter::SetFormat(TTextFormatAttribute aAttribute, TParaBorder* aParaBorder)
784 values.Format(_L("%d,%d,%d"),aParaBorder->iLineStyle,aParaBorder->iAutoColor,aParaBorder->iColor.RgbToUint());
785 outputBuf.Insert(0,values);
789 outputBuf.Insert(0,_L("TopBorder="));
791 case EAttBottomBorder:
792 outputBuf.Insert(0,_L("BottomBorder="));
795 outputBuf.Insert(0,_L("LeftBorder="));
797 case EAttRightBorder:
798 outputBuf.Insert(0,_L("RightBorder="));
805 void CPMLWriter::SetFormat(TTextFormatAttribute /*aAttribute*/, TBullet* aBullet)
808 outputBuf.Format(_L("%d,%u,%u,"),aBullet->iCharacterCode,aBullet->iHeight,
809 aBullet->iTypeface.iFlags);
810 TBuf<128> wideTemp; // long enough??
811 ExpandBuf(aBullet->iTypeface.iName,wideTemp);
812 outputBuf.Append(wideTemp);
813 outputBuf.Append(_L(" "));
814 outputBuf.Insert(0,_L("Bullet="));
819 void CPMLWriter::SetFormat(TTextFormatAttribute /*aAttribute*/, TTabStop aTabStop)
822 outputBuf.Format(_L("Tabstop=%u,"),aTabStop.iPosition);
823 switch (aTabStop.iType)
826 outputBuf.Append(_L("Null "));
829 outputBuf.Append(_L("Left "));
832 outputBuf.Append(_L("Right "));
835 outputBuf.Append(_L("Centered "));
842 void CPMLWriter::ProcessAlignment(TInt aValue)
848 outputBuf.Insert(0,_L("Alignment=Left "));
851 outputBuf.Insert(0,_L("Alignment=Center "));
854 outputBuf.Insert(0,_L("Alignment=Right "));
857 outputBuf.Insert(0,_L("Alignment=Justified "));
864 void CPMLWriter::ProcessLineSpacingControl(TInt aValue)
870 outputBuf.Insert(0,_L("LineSpacingControl=Atleast "));
873 outputBuf.Insert(0,_L("LineSpacingControl=Exactly "));
880 void CPMLWriter::ProcessFontPrintPos(TInt aValue)
886 outputBuf.Insert(0,_L("PrintPos=Normal "));
889 outputBuf.Insert(0,_L("PrintPos=SuperScript "));
892 outputBuf.Insert(0,_L("PrintPos=SubScript "));
899 void CPMLWriter::ProcessBooleanAtt(TTextFormatAttribute aAttribute, TInt aValue)
904 case EAttKeepTogether:
905 outputBuf.Insert(0,_L("KeepTogether "));
907 case EAttKeepWithNext:
908 outputBuf.Insert(0,_L("KeepWithNext "));
910 case EAttStartNewPage:
911 outputBuf.Insert(0,_L("StartNewPage "));
913 case EAttWidowOrphan:
914 outputBuf.Insert(0,_L("WidowOrphan "));
916 case EAttFontPosture:
917 outputBuf.Insert(0,_L("Italic "));
919 case EAttFontStrokeWeight:
920 outputBuf.Insert(0,_L("Bold "));
922 case EAttFontUnderline:
923 outputBuf.Insert(0,_L("Underline "));
925 case EAttFontStrikethrough:
926 outputBuf.Insert(0,_L("Strikethrough "));
929 if (aValue == 0) // Boolean NOT
930 outputBuf.Insert(0,_L("!"));