sl@0: /* 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: sl@0: sl@0: #include "T_RTPAR.H" sl@0: sl@0: //////////////////////////////////////////// sl@0: // CRichTextReader sl@0: //////////////////////////////////////////// sl@0: sl@0: CRichTextReader* CRichTextReader::NewL() sl@0: { sl@0: CRichTextReader* self=new(ELeave) CRichTextReader; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CRichTextReader::CRichTextReader() sl@0: { sl@0: // init variables sl@0: iParaStart = 0; sl@0: iConsoleExists = EFalse; sl@0: } sl@0: sl@0: sl@0: void CRichTextReader::ConstructL() sl@0: { sl@0: // construct PML writer sl@0: iPMLWriter = CPMLWriter::NewL(); sl@0: sl@0: // construct RichText bits sl@0: iThisParaFormat = CParaFormat::NewL(); sl@0: iPrevParaFormat = CParaFormat::NewL(); sl@0: } sl@0: sl@0: sl@0: void CRichTextReader::Destruct() sl@0: { sl@0: // iConsole.Destroy(); sl@0: Adt::Destroy(iPMLWriter); sl@0: Adt::Destroy(iThisParaFormat); sl@0: Adt::Destroy(iPrevParaFormat); sl@0: if (iBorder) sl@0: delete(iBorder); // only delete if it hasn't been used (if it has RT destroys it automatically) sl@0: } sl@0: sl@0: sl@0: CBufSeg* CRichTextReader::ConvertRichText(CRichText* aRichTextDoc) sl@0: // Quiet version of the RichText->PML parser sl@0: // Takes RT doc passed in, reads its global format, sl@0: // then reads the character and paragraph formats phrase by phrase sl@0: { sl@0: iRichTextDoc = aRichTextDoc; sl@0: iDocLength = iRichTextDoc->DocumentLength(); sl@0: SenseGlobalFormat(); sl@0: sl@0: TInt nextPhrase; sl@0: TInt readPos = 0; sl@0: while (readPos < iDocLength) sl@0: { sl@0: nextPhrase = TranslatePhrase(readPos); sl@0: readPos += nextPhrase; sl@0: } sl@0: iPMLWriter->Delete(1); // remove end-of-document paragraph delimiter sl@0: return iPMLWriter->ReturnPmlDoc(); sl@0: } sl@0: sl@0: sl@0: CBufSeg* CRichTextReader::ConvertRichText(CRichText* aRichTextDoc, RConsole aConsole) sl@0: // Version of the RichText->PML parser with console output (primarily for debugging) sl@0: // Takes RT doc passed in, reads its global format, sl@0: // then reads the character and paragraph formats phrase by phrase sl@0: { sl@0: iConsoleExists = ETrue; sl@0: iRichTextDoc = aRichTextDoc; sl@0: iConsole = aConsole; sl@0: iDocLength = iRichTextDoc->DocumentLength(); sl@0: SenseGlobalFormat(); sl@0: sl@0: TInt nextPhrase; sl@0: TInt readPos = 0; sl@0: while (readPos <= iDocLength) sl@0: { sl@0: nextPhrase = TranslatePhrase(readPos); sl@0: readPos += nextPhrase; sl@0: } sl@0: iPMLWriter->Delete(1); sl@0: iPMLWriter->Output(iConsole); // output PML doc to screen sl@0: return iPMLWriter->ReturnPmlDoc(); sl@0: } sl@0: sl@0: sl@0: void CRichTextReader::SenseGlobalFormat() sl@0: // Senses global format & writes it to PML sl@0: { sl@0: // construct rich text bits sl@0: const CParaFormatLayer* globalParaFormatLayer; // initialised with factory settings sl@0: const CCharFormatLayer* globalCharFormatLayer; sl@0: CParaFormat* globalParaFormat = CParaFormat::NewL(); sl@0: TCharFormat globalCharFormat; sl@0: sl@0: // Sense global format sl@0: globalParaFormatLayer = iRichTextDoc->SenseGlobalParaFormatLayer(); sl@0: globalParaFormatLayer->SenseEffectiveL(globalParaFormat); sl@0: globalCharFormatLayer = iRichTextDoc->SenseGlobalCharFormatLayer(); sl@0: globalCharFormatLayer->SenseEffective(globalCharFormat); sl@0: sl@0: // now set it sl@0: iPMLWriter->SetTag(EGlobal, ETagStart); // output SetTag(EGlobal, ETagEnd); // output >\n sl@0: sl@0: // initialise iPrevXxxxFormat sl@0: globalParaFormatLayer->SenseEffectiveL(iPrevParaFormat); sl@0: globalCharFormatLayer->SenseEffective(iPrevCharFormat); sl@0: sl@0: // destroy rich text bits sl@0: Adt::Destroy(globalParaFormat); sl@0: } sl@0: sl@0: sl@0: TInt CRichTextReader::TranslatePhrase(TInt aReadPos) sl@0: // Output any new formatting being applied to this phrase sl@0: // First check whether this phrase is the start of a new paragraph sl@0: // If so check the paragraph format sl@0: // Next check the character formatting of the phrase sl@0: { sl@0: CPicture* pic; // dummy pointer for senseChars sl@0: TPtrC currentPhrase; sl@0: TUint pmlWritePos; sl@0: sl@0: TInt currentParaStart = aReadPos; sl@0: sl@0: // paragraph formatting sl@0: if (currentParaStart != 0) // doesn't work for position=0 -- Duncan!! sl@0: iRichTextDoc->ParagraphStart(currentParaStart); sl@0: if ((currentParaStart > iParaStart)||(aReadPos == 0)) // is it a new paragraph? sl@0: { sl@0: iParaStart = currentParaStart; sl@0: // delete para delimiter sl@0: if (aReadPos > 0) sl@0: iPMLWriter->Delete(1); // deletes 1 chars previous to the current insert pos sl@0: // add para tag sl@0: iPMLWriter->SetTag(EParagraph, ETagStart); sl@0: iRichTextDoc->SenseParagraphFormatL(aReadPos,iThisParaFormat); // get para format sl@0: CompareParaFormats(); // compare to previous paragraph to get changes sl@0: iRichTextDoc->SenseParagraphFormatL(aReadPos,iPrevParaFormat); // set prevParaFormat to current & copy compound attributes sl@0: iPrevParaFormat->iTopBorder=CopyBorderL(iThisParaFormat->iTopBorder,iPrevParaFormat->iTopBorder); sl@0: iPrevParaFormat->iBottomBorder=CopyBorderL(iThisParaFormat->iBottomBorder,iPrevParaFormat->iBottomBorder); sl@0: iPrevParaFormat->iLeftBorder=CopyBorderL(iThisParaFormat->iLeftBorder,iPrevParaFormat->iLeftBorder); sl@0: iPrevParaFormat->iRightBorder=CopyBorderL(iThisParaFormat->iRightBorder,iPrevParaFormat->iRightBorder); sl@0: iPrevParaFormat->iBullet=CopyBulletL(iThisParaFormat->iBullet,iPrevParaFormat->iBullet); sl@0: iPMLWriter->SetTag(EParagraph, ETagEnd); sl@0: sl@0: } sl@0: sl@0: // character formatting sl@0: iPMLWriter->SetTag(ECharacter, ETagStart); sl@0: pmlWritePos = iPMLWriter->WritePos(); sl@0: iRichTextDoc->SenseChars(aReadPos,currentPhrase,iThisCharFormat,pic); // get char format sl@0: CompareCharFormats(); // compare to previous sl@0: iRichTextDoc->SenseChars(aReadPos,currentPhrase,iPrevCharFormat,pic); // get char format sl@0: if (pmlWritePos == iPMLWriter->WritePos()) sl@0: iPMLWriter->Delete(3); // delete tag start if tag is empty sl@0: else sl@0: iPMLWriter->SetTag(ECharacter, ETagEnd); // else close tag sl@0: sl@0: iPMLWriter->Insert(currentPhrase); // output text of phrase to PML sl@0: return currentPhrase.Length(); // return relative pos of start of next phrase sl@0: } sl@0: sl@0: sl@0: TParaBorder* CRichTextReader::CopyBorderL(const TParaBorder* aFrom,TParaBorder* aTo) sl@0: // copies one paragraph border to another, creating or destroying where necessary sl@0: { sl@0: if (!aFrom) sl@0: { sl@0: if (aTo) sl@0: delete(aTo); sl@0: return NULL; // No border cell in the original sl@0: } sl@0: else sl@0: { sl@0: if (!aTo) sl@0: aTo = new(ELeave) TParaBorder; sl@0: *aTo = *aFrom; sl@0: return aTo; sl@0: } sl@0: } sl@0: sl@0: sl@0: TBullet* CRichTextReader::CopyBulletL(const TBullet* aFrom,TBullet* aTo) sl@0: // copies one bullet to another, creating or destroying where necessary sl@0: { sl@0: if (!aFrom) sl@0: { sl@0: if (aTo) sl@0: delete(aTo); sl@0: return NULL; // No bullet cell in the original sl@0: } sl@0: else sl@0: { sl@0: if (!aTo) sl@0: aTo = new(ELeave) TBullet; sl@0: *aTo = *aFrom; sl@0: return aTo; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CRichTextReader::CompareParaToFactory(CParaFormat* aSensedParaFormat) sl@0: // Compares the supplied paragraph format to the factory defaults and acts on any differences sl@0: { sl@0: // create a new reference format with factory settings sl@0: CParaFormat* refParaFormat = CParaFormat::NewL(); sl@0: // step through, comparing aSensedParaFormat to the reference sl@0: // if any attributes differ, set the differences in the PML doc sl@0: if (aSensedParaFormat->iLanguage != refParaFormat->iLanguage) sl@0: iPMLWriter->SetFormat(EAttParaLanguage, aSensedParaFormat->iLanguage); sl@0: if (aSensedParaFormat->iLeftMargin != refParaFormat->iLeftMargin) sl@0: iPMLWriter->SetFormat(EAttLeftMargin, aSensedParaFormat->iLeftMargin); sl@0: if (aSensedParaFormat->iRightMargin != refParaFormat->iRightMargin) sl@0: iPMLWriter->SetFormat(EAttRightMargin, aSensedParaFormat->iRightMargin); sl@0: if (aSensedParaFormat->iIndent != refParaFormat->iIndent) sl@0: iPMLWriter->SetFormat(EAttIndent, aSensedParaFormat->iIndent); sl@0: if (aSensedParaFormat->iAlignment != refParaFormat->iAlignment) sl@0: iPMLWriter->SetFormat(EAttAlignment, aSensedParaFormat->iAlignment); sl@0: if (aSensedParaFormat->iLineSpacing != refParaFormat->iLineSpacing) sl@0: iPMLWriter->SetFormat(EAttLineSpacing, aSensedParaFormat->iLineSpacing); sl@0: if (aSensedParaFormat->iLineSpacingControl != refParaFormat->iLineSpacingControl) sl@0: iPMLWriter->SetFormat(EAttLineSpacingControl, aSensedParaFormat->iLineSpacingControl); sl@0: if (aSensedParaFormat->iSpaceBefore != refParaFormat->iSpaceBefore) sl@0: iPMLWriter->SetFormat(EAttSpaceBefore, aSensedParaFormat->iSpaceBefore); sl@0: if (aSensedParaFormat->iSpaceAfter != refParaFormat->iSpaceAfter) sl@0: iPMLWriter->SetFormat(EAttSpaceAfter, aSensedParaFormat->iSpaceAfter); sl@0: if (aSensedParaFormat->iKeepTogether != refParaFormat->iKeepTogether) sl@0: iPMLWriter->SetFormat(EAttKeepTogether, aSensedParaFormat->iKeepTogether); sl@0: if (aSensedParaFormat->iKeepWithNext != refParaFormat->iKeepWithNext) sl@0: iPMLWriter->SetFormat(EAttKeepWithNext, aSensedParaFormat->iKeepWithNext); sl@0: if (aSensedParaFormat->iStartNewPage != refParaFormat->iStartNewPage) sl@0: iPMLWriter->SetFormat(EAttStartNewPage, aSensedParaFormat->iStartNewPage); sl@0: if (aSensedParaFormat->iWidowOrphan != refParaFormat->iWidowOrphan) sl@0: iPMLWriter->SetFormat(EAttWidowOrphan, aSensedParaFormat->iWidowOrphan); sl@0: if (aSensedParaFormat->iBorderMargin != refParaFormat->iBorderMargin) sl@0: iPMLWriter->SetFormat(EAttBorderMargin, aSensedParaFormat->iBorderMargin); sl@0: if (aSensedParaFormat->iTopBorder) sl@0: { sl@0: if (refParaFormat->iTopBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttTopBorder, aSensedParaFormat->iTopBorder); sl@0: else if ((aSensedParaFormat->iTopBorder->iLineStyle != refParaFormat->iTopBorder->iLineStyle) sl@0: ||(aSensedParaFormat->iTopBorder->iAutoColor != refParaFormat->iTopBorder->iAutoColor) sl@0: ||(aSensedParaFormat->iTopBorder->iColor != refParaFormat->iTopBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttTopBorder, aSensedParaFormat->iTopBorder); sl@0: } sl@0: } sl@0: if (aSensedParaFormat->iBottomBorder) sl@0: { sl@0: if (refParaFormat->iTopBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttBottomBorder, aSensedParaFormat->iBottomBorder); sl@0: else if ((aSensedParaFormat->iBottomBorder->iLineStyle != refParaFormat->iBottomBorder->iLineStyle) sl@0: ||(aSensedParaFormat->iBottomBorder->iAutoColor != refParaFormat->iBottomBorder->iAutoColor) sl@0: ||(aSensedParaFormat->iBottomBorder->iColor != refParaFormat->iBottomBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttBottomBorder, aSensedParaFormat->iBottomBorder); sl@0: } sl@0: } sl@0: if (aSensedParaFormat->iLeftBorder) sl@0: { sl@0: if (refParaFormat->iTopBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttLeftBorder, aSensedParaFormat->iLeftBorder); sl@0: else if ((aSensedParaFormat->iLeftBorder->iLineStyle != refParaFormat->iLeftBorder->iLineStyle) sl@0: ||(aSensedParaFormat->iLeftBorder->iAutoColor != refParaFormat->iLeftBorder->iAutoColor) sl@0: ||(aSensedParaFormat->iLeftBorder->iColor != refParaFormat->iLeftBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttLeftBorder, aSensedParaFormat->iLeftBorder); sl@0: } sl@0: } sl@0: if (aSensedParaFormat->iRightBorder) sl@0: { sl@0: if (refParaFormat->iTopBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttRightBorder, aSensedParaFormat->iRightBorder); sl@0: else if ((aSensedParaFormat->iRightBorder->iLineStyle != refParaFormat->iRightBorder->iLineStyle) sl@0: ||(aSensedParaFormat->iRightBorder->iAutoColor != refParaFormat->iRightBorder->iAutoColor) sl@0: ||(aSensedParaFormat->iRightBorder->iColor != refParaFormat->iRightBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttRightBorder, aSensedParaFormat->iRightBorder); sl@0: } sl@0: } sl@0: if (aSensedParaFormat->iBullet) sl@0: { sl@0: if (refParaFormat->iBullet == NULL) sl@0: iPMLWriter->SetFormat(EAttBullet, aSensedParaFormat->iBullet); sl@0: if ((aSensedParaFormat->iBullet->iCharacterCode != refParaFormat->iBullet->iCharacterCode) sl@0: ||(aSensedParaFormat->iBullet->iHeight != refParaFormat->iBullet->iHeight) sl@0: ||(aSensedParaFormat->iBullet->iTypeface.iName != refParaFormat->iBullet->iTypeface.iName) sl@0: ||(aSensedParaFormat->iBullet->iTypeface.iFlags != refParaFormat->iBullet->iTypeface.iFlags)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttBullet, aSensedParaFormat->iBullet); sl@0: } sl@0: } sl@0: if (aSensedParaFormat->iDefaultTabWidth != refParaFormat->iDefaultTabWidth) sl@0: iPMLWriter->SetFormat(EAttDefaultTabWidth, aSensedParaFormat->iDefaultTabWidth); sl@0: CheckTabList(aSensedParaFormat, refParaFormat); // tabs are sensed separately sl@0: sl@0: // Destroy ref format sl@0: Adt::Destroy(refParaFormat); sl@0: } sl@0: sl@0: void CRichTextReader::CompareCharToFactory(TCharFormat aSensedCharFormat) sl@0: // Compares the supplied character format to the factory defaults and acts on any differences sl@0: { sl@0: // create a new reference format with factory settings sl@0: TCharFormat refCharFormat; sl@0: // step through, comparing aSensedCharFormat to the reference sl@0: // if any attributes differ, set the differences in the PML doc sl@0: if (aSensedCharFormat.iLanguage != refCharFormat.iLanguage) sl@0: iPMLWriter->SetFormat(EAttCharLanguage, aSensedCharFormat.iLanguage); sl@0: if (aSensedCharFormat.iColor != refCharFormat.iColor) sl@0: iPMLWriter->SetFormat(EAttColor, aSensedCharFormat.iColor.RgbToUint()); sl@0: if (aSensedCharFormat.iFontSpec.iTypeface.iName != refCharFormat.iFontSpec.iTypeface.iName) sl@0: iPMLWriter->SetFormat(EAttFontTypefaceName, aSensedCharFormat.iFontSpec.iTypeface); sl@0: if (aSensedCharFormat.iFontSpec.iTypeface.iFlags != refCharFormat.iFontSpec.iTypeface.iFlags) sl@0: iPMLWriter->SetFormat(EAttFontTypefaceFlags, aSensedCharFormat.iFontSpec.iTypeface); sl@0: if (aSensedCharFormat.iFontSpec.iHeight != refCharFormat.iFontSpec.iHeight) sl@0: iPMLWriter->SetFormat(EAttFontHeight, aSensedCharFormat.iFontSpec.iHeight); sl@0: if (aSensedCharFormat.iFontSpec.iPosture != refCharFormat.iFontSpec.iPosture) sl@0: iPMLWriter->SetFormat(EAttFontPosture, aSensedCharFormat.iFontSpec.iPosture); sl@0: if (aSensedCharFormat.iFontSpec.iStrokeWeight != refCharFormat.iFontSpec.iStrokeWeight) sl@0: iPMLWriter->SetFormat(EAttFontStrokeWeight, aSensedCharFormat.iFontSpec.iStrokeWeight); sl@0: if (aSensedCharFormat.iFontSpec.iPos != refCharFormat.iFontSpec.iPos) sl@0: iPMLWriter->SetFormat(EAttFontPrintPos, aSensedCharFormat.iFontSpec.iPos); sl@0: if (aSensedCharFormat.iFontSpec.iUnderline != refCharFormat.iFontSpec.iUnderline) sl@0: iPMLWriter->SetFormat((TTextFormatAttribute)EAttFontUnderline, aSensedCharFormat.iFontSpec.iUnderline); sl@0: if (aSensedCharFormat.iFontSpec.iStrikethrough != refCharFormat.iFontSpec.iStrikethrough) sl@0: iPMLWriter->SetFormat(EAttFontStrikethrough, aSensedCharFormat.iFontSpec.iStrikethrough); sl@0: } sl@0: sl@0: sl@0: void CRichTextReader::CompareParaFormats() sl@0: // compares the current para format with the format of the previous para sl@0: // any differences are output to PML sl@0: { sl@0: if (iThisParaFormat->iLanguage != iPrevParaFormat->iLanguage) sl@0: iPMLWriter->SetFormat(EAttParaLanguage, iThisParaFormat->iLanguage); sl@0: if (iThisParaFormat->iLeftMargin != iPrevParaFormat->iLeftMargin) sl@0: iPMLWriter->SetFormat(EAttLeftMargin, iThisParaFormat->iLeftMargin); sl@0: if (iThisParaFormat->iRightMargin != iPrevParaFormat->iRightMargin) sl@0: iPMLWriter->SetFormat(EAttRightMargin, iThisParaFormat->iRightMargin); sl@0: if (iThisParaFormat->iIndent != iPrevParaFormat->iIndent) sl@0: iPMLWriter->SetFormat(EAttIndent, iThisParaFormat->iIndent); sl@0: if (iThisParaFormat->iAlignment != iPrevParaFormat->iAlignment) sl@0: iPMLWriter->SetFormat(EAttAlignment, iThisParaFormat->iAlignment); sl@0: if (iThisParaFormat->iLineSpacing != iPrevParaFormat->iLineSpacing) sl@0: iPMLWriter->SetFormat(EAttLineSpacing, iThisParaFormat->iLineSpacing); sl@0: if (iThisParaFormat->iLineSpacingControl != iPrevParaFormat->iLineSpacingControl) sl@0: iPMLWriter->SetFormat(EAttLineSpacingControl, iThisParaFormat->iLineSpacingControl); sl@0: if (iThisParaFormat->iSpaceBefore != iPrevParaFormat->iSpaceBefore) sl@0: iPMLWriter->SetFormat(EAttSpaceBefore, iThisParaFormat->iSpaceBefore); sl@0: if (iThisParaFormat->iSpaceAfter != iPrevParaFormat->iSpaceAfter) sl@0: iPMLWriter->SetFormat(EAttSpaceAfter, iThisParaFormat->iSpaceAfter); sl@0: if (iThisParaFormat->iKeepTogether != iPrevParaFormat->iKeepTogether) sl@0: iPMLWriter->SetFormat(EAttKeepTogether, iThisParaFormat->iKeepTogether); sl@0: if (iThisParaFormat->iKeepWithNext != iPrevParaFormat->iKeepWithNext) sl@0: iPMLWriter->SetFormat(EAttKeepWithNext, iThisParaFormat->iKeepWithNext); sl@0: if (iThisParaFormat->iStartNewPage != iPrevParaFormat->iStartNewPage) sl@0: iPMLWriter->SetFormat(EAttStartNewPage, iThisParaFormat->iStartNewPage); sl@0: if (iThisParaFormat->iWidowOrphan != iPrevParaFormat->iWidowOrphan) sl@0: iPMLWriter->SetFormat(EAttWidowOrphan, iThisParaFormat->iWidowOrphan); sl@0: if (iThisParaFormat->iBorderMargin != iPrevParaFormat->iBorderMargin) sl@0: iPMLWriter->SetFormat(EAttBorderMargin, iThisParaFormat->iBorderMargin); sl@0: if (iThisParaFormat->iTopBorder) sl@0: { sl@0: if (iPrevParaFormat->iTopBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttTopBorder, iThisParaFormat->iTopBorder); sl@0: else if ((iThisParaFormat->iTopBorder->iLineStyle != iPrevParaFormat->iTopBorder->iLineStyle) sl@0: ||(iThisParaFormat->iTopBorder->iAutoColor != iPrevParaFormat->iTopBorder->iAutoColor) sl@0: ||(iThisParaFormat->iTopBorder->iColor != iPrevParaFormat->iTopBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttTopBorder, iThisParaFormat->iTopBorder); sl@0: } sl@0: } sl@0: if (iThisParaFormat->iBottomBorder) sl@0: { sl@0: if (iPrevParaFormat->iBottomBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttBottomBorder, iThisParaFormat->iBottomBorder); sl@0: else if ((iThisParaFormat->iBottomBorder->iLineStyle != iPrevParaFormat->iBottomBorder->iLineStyle) sl@0: ||(iThisParaFormat->iBottomBorder->iAutoColor != iPrevParaFormat->iBottomBorder->iAutoColor) sl@0: ||(iThisParaFormat->iBottomBorder->iColor != iPrevParaFormat->iBottomBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttBottomBorder, iThisParaFormat->iBottomBorder); sl@0: } sl@0: } sl@0: if (iThisParaFormat->iLeftBorder) sl@0: { sl@0: if (iPrevParaFormat->iLeftBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttLeftBorder, iThisParaFormat->iLeftBorder); sl@0: if ((iThisParaFormat->iLeftBorder->iLineStyle != iPrevParaFormat->iLeftBorder->iLineStyle) sl@0: ||(iThisParaFormat->iLeftBorder->iAutoColor != iPrevParaFormat->iLeftBorder->iAutoColor) sl@0: ||(iThisParaFormat->iLeftBorder->iColor != iPrevParaFormat->iLeftBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttLeftBorder, iThisParaFormat->iLeftBorder); sl@0: } sl@0: } sl@0: if (iThisParaFormat->iRightBorder) sl@0: { sl@0: if (iPrevParaFormat->iRightBorder == NULL) sl@0: iPMLWriter->SetFormat(EAttRightBorder, iThisParaFormat->iRightBorder); sl@0: if ((iThisParaFormat->iRightBorder->iLineStyle != iPrevParaFormat->iRightBorder->iLineStyle) sl@0: ||(iThisParaFormat->iRightBorder->iAutoColor != iPrevParaFormat->iRightBorder->iAutoColor) sl@0: ||(iThisParaFormat->iRightBorder->iColor != iPrevParaFormat->iRightBorder->iColor)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttRightBorder, iThisParaFormat->iRightBorder); sl@0: } sl@0: } sl@0: if (iThisParaFormat->iBullet) sl@0: { sl@0: if (iPrevParaFormat->iBullet == NULL) sl@0: iPMLWriter->SetFormat(EAttBullet, iThisParaFormat->iBullet); sl@0: else if ((iThisParaFormat->iBullet->iCharacterCode != iPrevParaFormat->iBullet->iCharacterCode) sl@0: ||(iThisParaFormat->iBullet->iHeight != iPrevParaFormat->iBullet->iHeight) sl@0: ||(iThisParaFormat->iBullet->iTypeface.iName != iPrevParaFormat->iBullet->iTypeface.iName) sl@0: ||(iThisParaFormat->iBullet->iTypeface.iFlags != iPrevParaFormat->iBullet->iTypeface.iFlags)) sl@0: { sl@0: iPMLWriter->SetFormat(EAttBullet, iThisParaFormat->iBullet); sl@0: } sl@0: } sl@0: if (iThisParaFormat->iDefaultTabWidth != iPrevParaFormat->iDefaultTabWidth) sl@0: iPMLWriter->SetFormat(EAttDefaultTabWidth, iThisParaFormat->iDefaultTabWidth); sl@0: CheckTabList(iThisParaFormat, iPrevParaFormat); // tabs are sensed separately sl@0: } sl@0: sl@0: sl@0: void CRichTextReader::CheckTabList(CParaFormat* aFormatOne, CParaFormat* aFormatTwo) sl@0: // Check whether the first (current) and second formats' tablists differ sl@0: // If they do, output whole of first list to PML sl@0: { sl@0: TBool output = EFalse; sl@0: if (aFormatOne->TabCount() != aFormatTwo->TabCount()) sl@0: output = ETrue; // output to PML sl@0: else sl@0: { sl@0: // lists are same length: check that all members are the same sl@0: TInt index = 0; sl@0: TBool dif = EFalse; sl@0: while ((index < aFormatOne->TabCount())&&(!dif)) sl@0: { sl@0: if (aFormatOne->TabStop(index) != aFormatTwo->TabStop(index)) sl@0: output = ETrue; // output to PML sl@0: index++; sl@0: } sl@0: } sl@0: if (output) sl@0: { sl@0: for (TInt i=0; i < aFormatOne->TabCount(); i++) sl@0: iPMLWriter->SetFormat(EAttTabStop, aFormatOne->TabStop(i)); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CRichTextReader::CompareCharFormats() sl@0: { sl@0: if (iThisCharFormat.iLanguage != iPrevCharFormat.iLanguage) sl@0: iPMLWriter->SetFormat(EAttCharLanguage, iThisCharFormat.iLanguage); sl@0: if (iThisCharFormat.iColor != iPrevCharFormat.iColor) sl@0: iPMLWriter->SetFormat(EAttColor, iThisCharFormat.iColor.RgbToUint()); sl@0: if (iThisCharFormat.iFontSpec.iTypeface.iName != iPrevCharFormat.iFontSpec.iTypeface.iName) sl@0: iPMLWriter->SetFormat(EAttFontTypefaceName, iThisCharFormat.iFontSpec.iTypeface); sl@0: if (iThisCharFormat.iFontSpec.iTypeface.iFlags != iPrevCharFormat.iFontSpec.iTypeface.iFlags) sl@0: iPMLWriter->SetFormat(EAttFontTypefaceFlags, iThisCharFormat.iFontSpec.iTypeface); sl@0: if (iThisCharFormat.iFontSpec.iHeight != iPrevCharFormat.iFontSpec.iHeight) sl@0: iPMLWriter->SetFormat(EAttFontHeight, iThisCharFormat.iFontSpec.iHeight); sl@0: if (iThisCharFormat.iFontSpec.iPosture != iPrevCharFormat.iFontSpec.iPosture) sl@0: iPMLWriter->SetFormat(EAttFontPosture, iThisCharFormat.iFontSpec.iPosture); sl@0: if (iThisCharFormat.iFontSpec.iStrokeWeight != iPrevCharFormat.iFontSpec.iStrokeWeight) sl@0: iPMLWriter->SetFormat(EAttFontStrokeWeight, iThisCharFormat.iFontSpec.iStrokeWeight); sl@0: if (iThisCharFormat.iFontSpec.iPos != iPrevCharFormat.iFontSpec.iPos) sl@0: iPMLWriter->SetFormat(EAttFontPrintPos, iThisCharFormat.iFontSpec.iPos); sl@0: if (iThisCharFormat.iFontSpec.iUnderline != iPrevCharFormat.iFontSpec.iUnderline) sl@0: iPMLWriter->SetFormat(EAttFontUnderline, iThisCharFormat.iFontSpec.iUnderline); sl@0: if (iThisCharFormat.iFontSpec.iStrikethrough != iPrevCharFormat.iFontSpec.iStrikethrough) sl@0: iPMLWriter->SetFormat(EAttFontStrikethrough, iThisCharFormat.iFontSpec.iStrikethrough); sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: ////////////////////////////////////////////////////// sl@0: // CPMLWriter sl@0: ////////////////////////////////////////////////////// sl@0: sl@0: CPMLWriter* CPMLWriter::NewL() sl@0: { sl@0: CPMLWriter* self=new(ELeave) CPMLWriter; sl@0: self->Construct(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CPMLWriter::CPMLWriter() sl@0: { sl@0: // init variables sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::Construct() sl@0: { sl@0: iTextBuf = CBufSeg::New(64); // create buffer with granularity 64 sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::Destruct() sl@0: { sl@0: Adt::Destroy(iTextBuf); sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::ExpandBuf(const TDes8& aBuffer, TDes& aTarget) sl@0: // sl@0: // Input 8 bit buffer to be returned by ref. as an 8/16-bit version sl@0: // Used for unicode compatability sl@0: // sl@0: { sl@0: TText textPointer; sl@0: for (TInt pos=0 ; pos temp; sl@0: SquashBuf(aBuf,temp); sl@0: iTextBuf->InsertL(iInsertPos, temp, bufLength); sl@0: iInsertPos += bufLength; sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::Delete(TUint aLength) sl@0: // delete back from current insert pos aLength (characters) sl@0: { sl@0: iTextBuf->Delete(iInsertPos-aLength, aLength); sl@0: iInsertPos -= aLength; sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::Output(RConsole aConsole) sl@0: // output buffer to screen sl@0: { sl@0: TBuf8<1> tempBuf; sl@0: TInt readPos = 0; sl@0: while (readPos < iTextBuf->Size()) sl@0: { sl@0: iTextBuf->Read(readPos, tempBuf, 1); sl@0: TBuf<1> wideTemp; sl@0: ExpandBuf(tempBuf,wideTemp); sl@0: aConsole.Write(wideTemp); sl@0: readPos++; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::SetTag(TTagType aTagType, TTagStatus aStatus) sl@0: // insert a tag-open or tag-close into the PML doc sl@0: { sl@0: if (aStatus == ETagStart) sl@0: { sl@0: switch (aTagType) sl@0: { sl@0: case EGlobal: sl@0: Insert(_L("\n\n")); sl@0: break; sl@0: case EParagraph: sl@0: Insert(_L(">\n")); sl@0: break; sl@0: case ECharacter: sl@0: Insert(_L(">")); sl@0: break; sl@0: case EControl: sl@0: Insert(_L(">")); sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::SetTab(TTabStop aTabStop) sl@0: // insert a tab into the PML doc sl@0: { sl@0: TBuf<80> tagBuf; sl@0: tagBuf.Format(_L("Tab=,%d"),aTabStop.iPosition); // put 2nd paramater in first sl@0: switch (aTabStop.iType) // insert 1st paramater after "=" sl@0: { sl@0: case ENullTab: sl@0: tagBuf.Insert(4,_L("Null")); sl@0: break; sl@0: case ELeftTab: sl@0: tagBuf.Insert(4,_L("Left")); sl@0: break; sl@0: case ECenteredTab: sl@0: tagBuf.Insert(4,_L("Centered")); sl@0: break; sl@0: case ERightTab: sl@0: tagBuf.Insert(4,_L("Right")); sl@0: break; sl@0: } sl@0: Insert(tagBuf); sl@0: } sl@0: sl@0: /* The setFormat functions add the stipulated formatting to the PML doc */ sl@0: sl@0: void CPMLWriter::SetFormat(TTextFormatAttribute aAttribute, TInt aValue) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: switch (aAttribute) sl@0: { sl@0: // Para Formats sl@0: case EAttParaLanguage: sl@0: outputBuf.Format(_L("ParaLanguage=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttLeftMargin: sl@0: outputBuf.Format(_L("LeftMargin=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttRightMargin: sl@0: outputBuf.Format(_L("RightMargin=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttIndent: sl@0: outputBuf.Format(_L("Indent=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttAlignment: sl@0: ProcessAlignment(aValue); sl@0: break; sl@0: case EAttLineSpacing: sl@0: outputBuf.Format(_L("LineSpacing=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttLineSpacingControl: sl@0: ProcessLineSpacingControl(aValue); sl@0: break; sl@0: case EAttSpaceBefore: sl@0: outputBuf.Format(_L("SpaceBefore=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttSpaceAfter: sl@0: outputBuf.Format(_L("SpaceAfter=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttKeepTogether: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttKeepWithNext: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttStartNewPage: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttWidowOrphan: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttBorderMargin: sl@0: outputBuf.Format(_L("BorderMargin=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttDefaultTabWidth: sl@0: outputBuf.Format(_L("DefaultTabWidth=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: sl@0: // Char formats sl@0: case EAttCharLanguage: sl@0: outputBuf.Format(_L("Language=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttColor: sl@0: outputBuf.Format(_L("Color=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttFontHeight: sl@0: outputBuf.Format(_L("FontHeight=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: case EAttFontPosture: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttFontStrokeWeight: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttFontPrintPos: sl@0: ProcessFontPrintPos(aValue); sl@0: break; sl@0: case EAttFontUnderline: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttFontStrikethrough: sl@0: ProcessBooleanAtt(aAttribute, aValue); sl@0: break; sl@0: case EAttFontTypefaceFlags: sl@0: outputBuf.Format(_L("TypefaceFlags=%d "),aValue); sl@0: Insert(outputBuf); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::SetFormat(TTextFormatAttribute aAttribute, const TTypeface &aTypeface) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: switch (aAttribute) sl@0: { sl@0: case EAttFontTypefaceName: sl@0: outputBuf.Format(_L("TypefaceName=%S "),&aTypeface.iName); sl@0: break; sl@0: case EAttFontTypefaceFlags: sl@0: outputBuf.Format(_L("TypefaceFlags=%u "),aTypeface.iFlags); sl@0: break; sl@0: } sl@0: Insert(outputBuf); sl@0: } sl@0: sl@0: void CPMLWriter::SetFormat(TTextFormatAttribute aAttribute, TParaBorder* aParaBorder) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: TBuf<80> values; sl@0: values.Format(_L("%d,%d,%d"),aParaBorder->iLineStyle,aParaBorder->iAutoColor,aParaBorder->iColor.RgbToUint()); sl@0: outputBuf.Insert(0,values); sl@0: switch (aAttribute) sl@0: { sl@0: case EAttTopBorder: sl@0: outputBuf.Insert(0,_L("TopBorder=")); sl@0: break; sl@0: case EAttBottomBorder: sl@0: outputBuf.Insert(0,_L("BottomBorder=")); sl@0: break; sl@0: case EAttLeftBorder: sl@0: outputBuf.Insert(0,_L("LeftBorder=")); sl@0: break; sl@0: case EAttRightBorder: sl@0: outputBuf.Insert(0,_L("RightBorder=")); sl@0: break; sl@0: } sl@0: Insert(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::SetFormat(TTextFormatAttribute /*aAttribute*/, TBullet* aBullet) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L("%d,%u,%u,"),aBullet->iCharacterCode,aBullet->iHeight, sl@0: aBullet->iTypeface.iFlags); sl@0: TBuf<128> wideTemp; // long enough?? sl@0: ExpandBuf(aBullet->iTypeface.iName,wideTemp); sl@0: outputBuf.Append(wideTemp); sl@0: outputBuf.Append(_L(" ")); sl@0: outputBuf.Insert(0,_L("Bullet=")); sl@0: Insert(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::SetFormat(TTextFormatAttribute /*aAttribute*/, TTabStop aTabStop) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L("Tabstop=%u,"),aTabStop.iPosition); sl@0: switch (aTabStop.iType) sl@0: { sl@0: case ENullTab: sl@0: outputBuf.Append(_L("Null ")); sl@0: break; sl@0: case ELeftTab: sl@0: outputBuf.Append(_L("Left ")); sl@0: break; sl@0: case ERightTab: sl@0: outputBuf.Append(_L("Right ")); sl@0: break; sl@0: case ECenteredTab: sl@0: outputBuf.Append(_L("Centered ")); sl@0: break; sl@0: } sl@0: Insert(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::ProcessAlignment(TInt aValue) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: switch (aValue) sl@0: { sl@0: case 0: sl@0: outputBuf.Insert(0,_L("Alignment=Left ")); sl@0: break; sl@0: case 1: sl@0: outputBuf.Insert(0,_L("Alignment=Center ")); sl@0: break; sl@0: case 2: sl@0: outputBuf.Insert(0,_L("Alignment=Right ")); sl@0: break; sl@0: case 3: sl@0: outputBuf.Insert(0,_L("Alignment=Justified ")); sl@0: break; sl@0: } sl@0: Insert(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::ProcessLineSpacingControl(TInt aValue) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: switch (aValue) sl@0: { sl@0: case 0: sl@0: outputBuf.Insert(0,_L("LineSpacingControl=Atleast ")); sl@0: break; sl@0: case 1: sl@0: outputBuf.Insert(0,_L("LineSpacingControl=Exactly ")); sl@0: break; sl@0: } sl@0: Insert(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::ProcessFontPrintPos(TInt aValue) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: switch (aValue) sl@0: { sl@0: case 0: sl@0: outputBuf.Insert(0,_L("PrintPos=Normal ")); sl@0: break; sl@0: case 1: sl@0: outputBuf.Insert(0,_L("PrintPos=SuperScript ")); sl@0: break; sl@0: case 2: sl@0: outputBuf.Insert(0,_L("PrintPos=SubScript ")); sl@0: break; sl@0: } sl@0: Insert(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CPMLWriter::ProcessBooleanAtt(TTextFormatAttribute aAttribute, TInt aValue) sl@0: { sl@0: TBuf<80> outputBuf; sl@0: switch (aAttribute) sl@0: { sl@0: case EAttKeepTogether: sl@0: outputBuf.Insert(0,_L("KeepTogether ")); sl@0: break; sl@0: case EAttKeepWithNext: sl@0: outputBuf.Insert(0,_L("KeepWithNext ")); sl@0: break; sl@0: case EAttStartNewPage: sl@0: outputBuf.Insert(0,_L("StartNewPage ")); sl@0: break; sl@0: case EAttWidowOrphan: sl@0: outputBuf.Insert(0,_L("WidowOrphan ")); sl@0: break; sl@0: case EAttFontPosture: sl@0: outputBuf.Insert(0,_L("Italic ")); sl@0: break; sl@0: case EAttFontStrokeWeight: sl@0: outputBuf.Insert(0,_L("Bold ")); sl@0: break; sl@0: case EAttFontUnderline: sl@0: outputBuf.Insert(0,_L("Underline ")); sl@0: break; sl@0: case EAttFontStrikethrough: sl@0: outputBuf.Insert(0,_L("Strikethrough ")); sl@0: break; sl@0: } sl@0: if (aValue == 0) // Boolean NOT sl@0: outputBuf.Insert(0,_L("!")); sl@0: Insert(outputBuf); sl@0: }