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 "../incp/T_PMLPAR.H" sl@0: sl@0: #define UNUSED_VAR(a) a = a sl@0: sl@0: #define UNUSED_VAR(a) a = a sl@0: sl@0: //////////////////////////////////////////// sl@0: // CParser sl@0: //////////////////////////////////////////// sl@0: sl@0: CParser* CParser::NewL() sl@0: { sl@0: CParser* self=new(ELeave) CParser; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructApplicationL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CParser::CParser() sl@0: { sl@0: // init variables sl@0: iErrorLevel = ENoError; sl@0: iParagraphIsOpen = EFalse; sl@0: iLineNo = 1; sl@0: iReadPos = 0; sl@0: iDocInsertPos = 0; sl@0: iDocParaLength = 0; sl@0: iDocPhraseLength = 0; sl@0: iBorderUsed = EFalse; sl@0: iBulletUsed = EFalse; sl@0: } sl@0: sl@0: sl@0: void CParser::ConstructApplicationL() sl@0: { sl@0: // Construct Rich Text Doc sl@0: // Make the global format layers and associated formats and masks sl@0: iGlobalParaFormatLayer=CParaFormatLayer::NewL(); sl@0: iGlobalCharFormatLayer=CCharFormatLayer::NewL(); sl@0: iGlobalParaFormat=CParaFormat::NewL(); // initialised with factory settings sl@0: iGlobalParaFormatMask.SetAll(); sl@0: iGlobalCharFormatMask.SetAll(); sl@0: sl@0: // Set the global layers sl@0: iGlobalParaFormatLayer->SetL(iGlobalParaFormat,iGlobalParaFormatMask); sl@0: iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask); sl@0: sl@0: // Create the rich text document sl@0: iRichTextDoc=CRichText::NewL(iGlobalParaFormatLayer,iGlobalCharFormatLayer); sl@0: sl@0: // Initialise the paragraph and character layers sl@0: iParaFormatLayer = CParaFormatLayer::NewL(); sl@0: iCharFormatLayer = CCharFormatLayer::NewL(); sl@0: iParaFormat = CParaFormat::NewL(); sl@0: sl@0: // Create temp alias' for compound attributes sl@0: iBorder = new TParaBorder; sl@0: User::LeaveIfNull(iBorder); sl@0: iBullet = new (ELeave) TBullet; sl@0: } sl@0: sl@0: sl@0: CParser::~CParser() sl@0: { sl@0: // destroy Rich Text Document sl@0: // delete iRichTextDoc; sl@0: // delete iGlobalParaFormatLayer; sl@0: // delete iGlobalCharFormatLayer; sl@0: delete iGlobalParaFormat; sl@0: delete iParaFormatLayer; sl@0: delete iCharFormatLayer; sl@0: delete iParaFormat; sl@0: if (!iBorderUsed) sl@0: delete(iBorder); sl@0: if (!iBulletUsed) sl@0: delete(iBullet); sl@0: } sl@0: sl@0: sl@0: CRichText* CParser::ParseL(CConsoleBase* aConsole) sl@0: // version for parsing with console output and interactive file dialog sl@0: // primarily for debugging purposes (you can see what's going on!) sl@0: { sl@0: // set console sl@0: iConsoleExists = ETrue; sl@0: iConsole = aConsole; sl@0: sl@0: // Construct a CFileApp & load a file sl@0: CFileApp* myFileApp=NULL; sl@0: TRAPD(ret, myFileApp = CFileApp::NewL()); sl@0: UNUSED_VAR(ret); sl@0: iTextBuf = myFileApp->LoadFileL(iConsole); sl@0: iFileName = myFileApp->ReturnFileName(); sl@0: sl@0: ParseTextBufL(); // parse the buffer sl@0: delete myFileApp; // destroy file app sl@0: sl@0: // Pause before returning sl@0: WriteNewLine(); sl@0: WriteNewLine(); sl@0: OutputToScreen(_L("Press Space to continue\n")); sl@0: TKeyCode keystroke = EKeyNull; sl@0: while (keystroke != EKeySpace) sl@0: keystroke = iConsole->Getch(); sl@0: return iRichTextDoc; sl@0: } sl@0: sl@0: CRichText* CParser::ParseL(const TFileName &aFileName) sl@0: // silent version of the parser sl@0: { sl@0: iConsoleExists = EFalse; sl@0: // Construct a CFileApp & load a file sl@0: CFileApp* myFileApp=NULL; sl@0: TRAPD(ret, myFileApp = CFileApp::NewL()); sl@0: UNUSED_VAR(ret); sl@0: iTextBuf = myFileApp->LoadFileL(aFileName); sl@0: iFileName = myFileApp->ReturnFileName(); sl@0: sl@0: ParseTextBufL(); // parse the buffer sl@0: delete myFileApp; // destroy file app sl@0: sl@0: return iRichTextDoc; sl@0: } sl@0: sl@0: sl@0: void CParser::EmitErrorMessage() sl@0: { sl@0: TBuf<80> errorMessage; sl@0: switch (iErrorLevel) sl@0: { sl@0: case EUnknownTagType: sl@0: errorMessage.Format(_L(" Unknown tag type: Line %d"),iLineNo); sl@0: break; sl@0: case EUnparagraphedText: sl@0: errorMessage.Format(_L(" Text not contained by paragraph: Line %d"),iLineNo); sl@0: break; sl@0: case EUnknownAttrib: sl@0: errorMessage.Format(_L(" Unknown tag attribute: Line %d"),iLineNo); sl@0: break; sl@0: case ENoAttribValue: sl@0: errorMessage.Format(_L(" Unknown attribute or no attribute value supplied: Line %d"),iLineNo); sl@0: break; sl@0: case EIllegalAttribValue: sl@0: errorMessage.Format(_L(" Illegal attribute value: Line %d"),iLineNo); sl@0: break; sl@0: default: sl@0: errorMessage.Format(_L(" Error: Line %d"),iLineNo); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: OutputToScreen(_L("*** Error!!\n")); sl@0: OutputToScreen(errorMessage); sl@0: } sl@0: sl@0: sl@0: void CParser::OutputToScreen(const TDesC& aMessageBuffer) sl@0: { sl@0: if (iConsoleExists) sl@0: iConsole->Write(aMessageBuffer); // output line to screen sl@0: } sl@0: sl@0: sl@0: TBool CParser::Validate() sl@0: // Check that document starts with tag - serves as file validation sl@0: // - Read in characters sequentially sl@0: // - if the first alphanumeric characters encountered are not "Size(); sl@0: if (Validate()) sl@0: { sl@0: while ((iReadPos < textBufSize)&&(iErrorLevel == ENoError)) sl@0: { sl@0: charToTest = ReadChar(); sl@0: if (charToTest == '<') sl@0: ProcessTagL(); sl@0: else sl@0: ProcessTextL(charToTest); sl@0: iReadPos+=KCharLength; sl@0: } sl@0: if ((iReadPos == textBufSize)&&(iReadPos>0)&&(iErrorLevel == ENoError)) sl@0: { sl@0: // at end of document apply any outstanding formatting (if there is text to apply it to) sl@0: if (iDocParaLength > 0) sl@0: { sl@0: iParaFormatLayer->SetL(iParaFormat, iParaFormatMask); sl@0: iRichTextDoc->ApplyParaFormatL( iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength); sl@0: } sl@0: if (iDocPhraseLength > 0) sl@0: { sl@0: iCharFormatLayer->SetL(iCharFormat, iCharFormatMask); sl@0: iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength); sl@0: } sl@0: } sl@0: if (iErrorLevel != ENoError) sl@0: EmitErrorMessage(); sl@0: } sl@0: } sl@0: sl@0: sl@0: TChar CParser::ReadChar() sl@0: // Reads the next character from the text buffer sl@0: { sl@0: // TChar charToTest; sl@0: TText charToTest; sl@0: iTextBuf->Read(iReadPos,&charToTest,KCharLength); sl@0: if (charToTest == (TText)KLineFeed) sl@0: iLineNo++; // Info used only by error messages sl@0: return charToTest; sl@0: } sl@0: sl@0: sl@0: void CParser::ProcessTextL(TChar aChar) sl@0: // 1) Check text is in a paragraph sl@0: // 2) Check for escape characters sl@0: // 3) Check for tabs sl@0: // 4) Add to paragraph sl@0: { sl@0: if (!iParagraphIsOpen) sl@0: { sl@0: if (!(aChar.IsControl())) sl@0: iErrorLevel = EUnparagraphedText; // Text not contained by a paragraph - error!! sl@0: } sl@0: else sl@0: { sl@0: if (aChar == '/') // Escape character for < sl@0: { sl@0: TChar tempChar; sl@0: iTextBuf->Read(iReadPos+KCharLength,&tempChar,1); // doesn't increment line counter sl@0: if (tempChar == '<') sl@0: { sl@0: AddCharToParaL(tempChar); sl@0: iReadPos+=2*KCharLength; // Skip escape character sl@0: } sl@0: else sl@0: AddCharToParaL(aChar); sl@0: } sl@0: else if (aChar == KTabChar) sl@0: AddCharToParaL(aChar); sl@0: else if (!(aChar.IsControl())) // if it's not a control char add it sl@0: AddCharToParaL(aChar); // (this includes spaces) sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::AddCharToParaL(TChar aChar) sl@0: { sl@0: // Add char to RichText doc... sl@0: iRichTextDoc->InsertL(iDocInsertPos, aChar); sl@0: iDocInsertPos++; sl@0: iDocParaLength++; sl@0: if (iPhraseOpen) sl@0: iDocPhraseLength++; sl@0: // and also write it to screen sl@0: TBuf<4> screenBuf; // Buffer for text to be written to console sl@0: screenBuf.Append(aChar); sl@0: OutputToScreen(screenBuf); sl@0: } sl@0: sl@0: sl@0: void CParser::ProcessTagL() sl@0: { sl@0: TChar tagChar; sl@0: iReadPos+=KCharLength; sl@0: tagChar = ReadTagChar(); // Read in tag type sl@0: ClassifyTagL(tagChar); sl@0: if (iTagType == EError) sl@0: iErrorLevel = EUnknownTagType; sl@0: else sl@0: { sl@0: ClassifyArgumentsL(); sl@0: } sl@0: } sl@0: sl@0: sl@0: TChar CParser::ReadTagChar() sl@0: { // Returns tag character capitalised - therefore case-insensitive sl@0: TChar charToTest; sl@0: charToTest = ReadChar(); sl@0: charToTest.UpperCase(); sl@0: return charToTest; sl@0: } sl@0: sl@0: sl@0: void CParser::ClassifyArgumentsL() sl@0: // reads tag one argument at a time, dealing with each arg as it is read sl@0: // If and argument is followed by a value (ie a=4) it is processed in two passes. sl@0: { sl@0: TChar tagChar(0); sl@0: iArgStored = EFalse; sl@0: iArgValueExpected = EFalse; // Initialise sl@0: iCancelArg = EFalse; sl@0: while ((tagChar != '>')&&(iErrorLevel == ENoError)) // ">" is end of tag sl@0: { sl@0: iReadPos+=KCharLength; sl@0: tagChar = ReadTagChar(); // Read in next bit of tag sl@0: if (iTagType != EComment) // text of comments is ignored sl@0: { sl@0: if (tagChar.IsSpace()) // spaces separate args sl@0: ProcessArgBufL(); sl@0: if (tagChar == '=') sl@0: { sl@0: iArgValueExpected = ETrue; sl@0: ProcessArgBufL(); sl@0: } sl@0: if (tagChar == '!') sl@0: { sl@0: iCancelArg = ETrue; sl@0: OutputToScreen(_L("!")); sl@0: } sl@0: if (tagChar == ',') sl@0: AppendToArgBuf(tagChar); sl@0: if (tagChar.IsAlphaDigit()) sl@0: { sl@0: AppendToArgBuf(tagChar); sl@0: } sl@0: } sl@0: } sl@0: if (tagChar == '>') // Is it end of tag? sl@0: { sl@0: if (iTagType != EComment) sl@0: { sl@0: ProcessArgBufL(); sl@0: if ((iTagType == EControl)||(iTagType == EGlobal)) // Control & global style formatting is applied "on the spot" sl@0: SetFormatLayerL(); // While char & paragraph are applied retrospectively sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::AppendToArgBuf(TChar aTagChar) sl@0: { sl@0: iArgType.Append(aTagChar); // assume it'll fit sl@0: } sl@0: sl@0: sl@0: void CParser::ProcessArgBufL() sl@0: { sl@0: if (iArgValueExpected) sl@0: { sl@0: if (iArgStored) sl@0: { sl@0: TBuf<32> tempArgBuf; // Swap the buffers back as an arg and its value have been stored sl@0: tempArgBuf = iArgType; sl@0: EmptyBuffer(iArgType); sl@0: iArgType = iArgValue; sl@0: EmptyBuffer(iArgValue); sl@0: iArgValue = tempArgBuf; sl@0: TranslateTagArgL(); // Translate the tag argument sl@0: iArgStored = EFalse; // Reset the flags and buffers sl@0: iArgValueExpected = EFalse; sl@0: EmptyBuffer(iArgType); sl@0: EmptyBuffer(iArgValue); sl@0: } sl@0: else sl@0: { sl@0: iArgValue = iArgType; // Swap the buffers ready to store the value of the arg sl@0: EmptyBuffer(iArgType); // Empty buffer sl@0: iArgStored = ETrue; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: TranslateTagArgL(); // match to list sl@0: EmptyBuffer(iArgType); sl@0: EmptyBuffer(iArgValue); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::EmptyBuffer(TDes &aBuf) sl@0: { sl@0: aBuf.SetLength(0); sl@0: } sl@0: sl@0: sl@0: void CParser::ClassifyTagL(TChar aTagChar) sl@0: { sl@0: switch (aTagChar) sl@0: { sl@0: case 'G': sl@0: iTagType = EGlobal; sl@0: break; sl@0: case 'P': sl@0: { sl@0: iTagType = EParagraph; sl@0: if (iParagraphIsOpen) sl@0: { sl@0: iRichTextDoc->InsertL(iDocInsertPos,CEditableText::EParagraphDelimiter); // insert para delimiter sl@0: WriteNewLine(); // Write new line to console sl@0: iDocInsertPos++; // Paragraph delimiters occupy 1 character space sl@0: iDocParaLength++; sl@0: if (iPhraseOpen) sl@0: iDocPhraseLength++; sl@0: SetFormatLayerL(); // apply formatting to old para before starting to fill new one sl@0: } sl@0: else sl@0: iParagraphIsOpen = ETrue; sl@0: break; sl@0: } sl@0: case 'C': sl@0: { sl@0: iTagType = ECharacter; sl@0: if (iPhraseOpen) sl@0: SetFormatLayerL(); // apply formatting to old phrase retrospectively sl@0: else sl@0: iPhraseOpen = ETrue; sl@0: break; sl@0: } sl@0: case 'X': sl@0: iTagType = EControl; sl@0: break; sl@0: case '!': sl@0: iTagType = EComment; sl@0: break; sl@0: default: sl@0: iTagType = EError; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::SetFormatLayerL() sl@0: // Apply format & mask that have been set in the tag to a Layer sl@0: // Apply the layer to the RichText doc sl@0: { sl@0: if (iTagType == EGlobal) sl@0: { sl@0: iGlobalParaFormatLayer->SetL(iGlobalParaFormat, iGlobalParaFormatMask); sl@0: iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask); sl@0: iRichTextDoc->SetGlobalParaFormat(iGlobalParaFormatLayer); sl@0: iRichTextDoc->SetGlobalCharFormat(iGlobalCharFormatLayer); sl@0: WriteNewLine(); sl@0: } sl@0: if (iTagType == EParagraph) sl@0: { sl@0: iParaFormatLayer->SetL(iParaFormat, iParaFormatMask); sl@0: iRichTextDoc->ApplyParaFormatL(iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength); sl@0: iCharFormatLayer->SetL(iCharFormat, iCharFormatMask); sl@0: if (iDocPhraseLength > 0) sl@0: iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength); sl@0: iDocParaLength = 0; // reset ready for new paragraph sl@0: iDocPhraseLength = 0; sl@0: } sl@0: if (iTagType == ECharacter) sl@0: { sl@0: iCharFormatLayer->SetL(iCharFormat, iCharFormatMask); sl@0: if (iDocPhraseLength > 0) sl@0: iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength); sl@0: iDocPhraseLength = 0; sl@0: } sl@0: } sl@0: sl@0: sl@0: TInt CParser::GetArgValue() sl@0: // converts numerals in iArgValue to a TInt, sl@0: // first checking that the buffer is totally numeric in content sl@0: { sl@0: TInt value = 0; sl@0: if (BufIsNumeric(iArgValue)) sl@0: { sl@0: TLex tmpLex(iArgValue); sl@0: tmpLex.Val(value); sl@0: } sl@0: else iErrorLevel = EIllegalAttribValue; sl@0: return value; sl@0: } sl@0: sl@0: sl@0: TInt CParser::GetArgValue(const TDes &aBuf) sl@0: // converts numerals in aBuf to a TInt as above sl@0: { sl@0: TInt value = 0; sl@0: if (BufIsNumeric(aBuf)) sl@0: { sl@0: TLex tmpLex(aBuf); sl@0: tmpLex.Val(value); sl@0: } sl@0: else iErrorLevel = EIllegalAttribValue; sl@0: return value; sl@0: } sl@0: sl@0: sl@0: TBool CParser::BufIsNumeric(const TDes &aBuffer) sl@0: // checks that aBuffer is totally numeric in content. sl@0: // checks all characters sequentially sl@0: { sl@0: TBool isNumeric = ETrue; sl@0: TChar testChar; sl@0: TUint bufLength = aBuffer.Length(); sl@0: for (TUint pos=0; ((pos")); sl@0: } sl@0: sl@0: sl@0: void CParser::TransParaArgLeftMargin() sl@0: { sl@0: TInt32 margin = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iLeftMarginInTwips = margin; sl@0: iParaFormatMask.SetAttrib(EAttLeftMargin); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iLeftMarginInTwips = margin; sl@0: iGlobalParaFormatMask.SetAttrib(EAttLeftMargin); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),margin); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransParaArgRightMargin() sl@0: { sl@0: TInt32 margin = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iRightMarginInTwips = margin; sl@0: iParaFormatMask.SetAttrib(EAttRightMargin); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iRightMarginInTwips = margin; sl@0: iGlobalParaFormatMask.SetAttrib(EAttRightMargin); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),margin); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransParaArgIndent() sl@0: { sl@0: TInt32 indent = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iIndentInTwips = indent; sl@0: iParaFormatMask.SetAttrib(EAttIndent); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iIndentInTwips = indent; sl@0: iGlobalParaFormatMask.SetAttrib(EAttIndent); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),indent); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransParaLineSpacing() sl@0: { sl@0: TInt32 lineSpacing = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iLineSpacingInTwips = lineSpacing; sl@0: iParaFormatMask.SetAttrib(EAttLineSpacing); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iLineSpacingInTwips = lineSpacing; sl@0: iGlobalParaFormatMask.SetAttrib(EAttLineSpacing); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),lineSpacing); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransParaArgLineSpacingControl() sl@0: { sl@0: if (iArgValue == _L("ATLEAST")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips; sl@0: iParaFormatMask.SetAttrib(EAttLineSpacingControl); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips; sl@0: iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else if (iArgValue == _L("EXACTLY")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips; sl@0: iParaFormatMask.SetAttrib(EAttLineSpacingControl); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips; sl@0: iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: sl@0: void CParser::TransParaSpaceBefore() sl@0: { sl@0: TInt32 spaceBefore = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iSpaceBeforeInTwips = spaceBefore; sl@0: iParaFormatMask.SetAttrib(EAttSpaceBefore); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iSpaceBeforeInTwips = spaceBefore; sl@0: iGlobalParaFormatMask.SetAttrib(EAttSpaceBefore); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),spaceBefore); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransParaSpaceAfter() sl@0: { sl@0: TInt32 spaceAfter = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iSpaceAfterInTwips = spaceAfter; sl@0: iParaFormatMask.SetAttrib(EAttSpaceAfter); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iSpaceAfterInTwips = spaceAfter; sl@0: iGlobalParaFormatMask.SetAttrib(EAttSpaceAfter); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),spaceAfter); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransParaBorderMargin() sl@0: { sl@0: TInt32 borderMargin = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iBorderMarginInTwips = borderMargin; sl@0: iParaFormatMask.SetAttrib(EAttBorderMargin); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iBorderMarginInTwips = borderMargin; sl@0: iGlobalParaFormatMask.SetAttrib(EAttBorderMargin); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),borderMargin); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransParaKeepTogether() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: if (iCancelArg) sl@0: iParaFormat->iKeepTogether = EFalse; sl@0: else sl@0: iParaFormat->iKeepTogether = ETrue; sl@0: iParaFormatMask.SetAttrib(EAttKeepTogether); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalParaFormat->iKeepTogether = EFalse; sl@0: else sl@0: iGlobalParaFormat->iKeepTogether = ETrue; sl@0: iGlobalParaFormatMask.SetAttrib(EAttKeepTogether); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: void CParser::TransParaKeepWithNext() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: if (iCancelArg) sl@0: iParaFormat->iKeepWithNext = EFalse; sl@0: else sl@0: iParaFormat->iKeepWithNext = ETrue; sl@0: iParaFormatMask.SetAttrib(EAttKeepWithNext); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalParaFormat->iKeepWithNext = EFalse; sl@0: else sl@0: iGlobalParaFormat->iKeepWithNext = ETrue; sl@0: iGlobalParaFormatMask.SetAttrib(EAttKeepWithNext); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: void CParser::TransParaStartNewPage() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: if (iCancelArg) sl@0: iParaFormat->iStartNewPage = EFalse; sl@0: else sl@0: iParaFormat->iStartNewPage = ETrue; sl@0: iParaFormatMask.SetAttrib(EAttStartNewPage); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalParaFormat->iStartNewPage = EFalse; sl@0: else sl@0: iGlobalParaFormat->iStartNewPage = ETrue; sl@0: iGlobalParaFormatMask.SetAttrib(EAttStartNewPage); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: void CParser::TransParaWidowOrphan() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: if (iCancelArg) sl@0: iParaFormat->iWidowOrphan = EFalse; sl@0: else sl@0: iParaFormat->iWidowOrphan = ETrue; sl@0: iParaFormatMask.SetAttrib(EAttWidowOrphan); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalParaFormat->iWidowOrphan = EFalse; sl@0: else sl@0: iGlobalParaFormat->iWidowOrphan = ETrue; sl@0: iGlobalParaFormatMask.SetAttrib(EAttWidowOrphan); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: void CParser::TransParaArgAlignment() sl@0: { sl@0: // parse argValue sl@0: if (iArgValue == _L("LEFT")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign; sl@0: iParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign; sl@0: iGlobalParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else if (iArgValue == _L("RIGHT")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign; sl@0: iParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign; sl@0: iGlobalParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else if (iArgValue == _L("CENTER")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign; sl@0: iParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign; sl@0: iGlobalParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else if (iArgValue == _L("JUSTIFIED")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign; sl@0: iParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign; sl@0: iGlobalParaFormatMask.SetAttrib(EAttAlignment); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: sl@0: sl@0: void CParser::TransParaBullet() sl@0: { sl@0: TInt characterCode = 0x2022; sl@0: TUint32 heightInTwips=0; sl@0: TUint32 flags=0; sl@0: TBuf name; sl@0: TBuf<128> component; sl@0: sl@0: // set first component (character code) sl@0: TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma sl@0: component = iArgValue.Left(commaPos); sl@0: if (component != _L("")) // only third arg remains sl@0: { sl@0: if (BufIsNumeric(component)) sl@0: { sl@0: TLex tmpLex(component); sl@0: // TUint value; sl@0: tmpLex.Val(characterCode); sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: sl@0: // set second component (bullet height) sl@0: iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma sl@0: commaPos = iArgValue.Locate(KComma); // find pos of first comma sl@0: component = iArgValue.Left(commaPos); sl@0: if (component != _L("")) // only third arg remains sl@0: { sl@0: if (BufIsNumeric(component)) sl@0: { sl@0: TLex tmpLex(component); sl@0: TUint value; sl@0: tmpLex.Val(value); sl@0: heightInTwips = value; sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: sl@0: // set third component (typeface flags) sl@0: iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma sl@0: commaPos = iArgValue.Locate(KComma); // find pos of first comma sl@0: component = iArgValue.Left(commaPos); sl@0: if (component != _L("")) // only third arg remains sl@0: { sl@0: flags = GetArgValue(component); sl@0: if (flags>2) sl@0: iErrorLevel=EIllegalAttribValue; // only values 0,1,2 valid for flag sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: sl@0: // set fourth component (typeface name) sl@0: iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma sl@0: if (iArgValue != _L("")) // only third arg remains sl@0: { sl@0: name.Copy(iArgValue); sl@0: // name = SquashBuf(iArgValue); sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: sl@0: // apply sl@0: if (iErrorLevel == ENoError) sl@0: { sl@0: iBulletUsed = ETrue; sl@0: iBullet->iCharacterCode = (TText)characterCode; sl@0: iBullet->iHeightInTwips = heightInTwips; sl@0: if (flags>=1) sl@0: iBullet->iTypeface.SetIsProportional(ETrue); sl@0: if (flags>=3) sl@0: iBullet->iTypeface.SetIsSerif(ETrue); sl@0: iBullet->iTypeface.iName = name; sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iBullet = iBullet; sl@0: iParaFormatMask.SetAttrib(EAttBullet); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iBullet = iBullet; sl@0: iGlobalParaFormatMask.SetAttrib(EAttBullet); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: } sl@0: sl@0: TBuf8<512> CParser::SquashBuf(TDes aBuffer) sl@0: // sl@0: // Input 8/16 bit buffer to be returned as an 8-bit version sl@0: // Used for unicode compatability sl@0: // sl@0: { sl@0: TText16 textPointer; sl@0: sl@0: TBuf8<512> returnBuf; sl@0: sl@0: for ( TInt pos=0 ; pos component; sl@0: sl@0: // set first component sl@0: TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma sl@0: component = iArgValue.Left(commaPos); sl@0: if (component != _L("")) sl@0: { sl@0: if (component == _L("NULL")) sl@0: lineStyle = TParaBorder::ENullLineStyle; sl@0: else if (component == _L("SOLID")) sl@0: lineStyle = TParaBorder::ESolid; sl@0: else if (component == _L("DOUBLE")) sl@0: lineStyle = TParaBorder::EDouble; sl@0: else if (component == _L("DOTTED")) sl@0: lineStyle = TParaBorder::EDotted; sl@0: else if (component == _L("DASHED")) sl@0: lineStyle = TParaBorder::EDashed; sl@0: else if (component == _L("DOTDASH")) sl@0: lineStyle = TParaBorder::EDotDash; sl@0: else if (component == _L("DOTDOTDASH")) sl@0: lineStyle = TParaBorder::EDotDotDash; sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: sl@0: // set second component sl@0: iArgValue.Delete(0,commaPos+1); // delete first component & trailing comma sl@0: commaPos = iArgValue.Locate(KComma); // find pos of first comma sl@0: component = iArgValue.Left(commaPos); sl@0: if (component != _L("")) sl@0: { sl@0: if (component == _L("ON")) sl@0: autoColor = ETrue; sl@0: else if (component == _L("OFF")) sl@0: autoColor = EFalse; sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: sl@0: // set third component sl@0: iArgValue.Delete(0,commaPos+1); // delete second component & trailing comma sl@0: if (component != _L("")) // only third arg remains sl@0: { sl@0: if (BufIsNumeric(iArgValue)) sl@0: { sl@0: TLex tmpLex(iArgValue); sl@0: TUint value; sl@0: tmpLex.Val(value); sl@0: color=TRgb((TUint32)value); sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: sl@0: // apply sl@0: if (iErrorLevel == ENoError) sl@0: { sl@0: iBorderUsed = ETrue; sl@0: iBorder->iLineStyle = lineStyle; sl@0: iBorder->iAutoColor = autoColor; sl@0: iBorder->iColor = color; sl@0: if (iArgType == _L("TOPBORDER")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder); sl@0: iParaFormatMask.SetAttrib(EAttTopBorder); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder); sl@0: iGlobalParaFormatMask.SetAttrib(EAttTopBorder); sl@0: break; sl@0: } sl@0: } sl@0: if (iArgType == _L("BOTTOMBORDER")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder); sl@0: iParaFormatMask.SetAttrib(EAttBottomBorder); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder); sl@0: iGlobalParaFormatMask.SetAttrib(EAttBottomBorder); sl@0: break; sl@0: } sl@0: } sl@0: if (iArgType == _L("LEFTBORDER")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder); sl@0: iParaFormatMask.SetAttrib(EAttLeftBorder); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder); sl@0: iGlobalParaFormatMask.SetAttrib(EAttLeftBorder); sl@0: break; sl@0: } sl@0: } sl@0: if (iArgType == _L("RIGHTBORDER")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder); sl@0: iParaFormatMask.SetAttrib(EAttRightBorder); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder); sl@0: iGlobalParaFormatMask.SetAttrib(EAttRightBorder); sl@0: break; sl@0: } sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: } sl@0: sl@0: void CParser::TransParaTabWidth() sl@0: { sl@0: TInt32 tabWidth = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->iDefaultTabWidthInTwips = tabWidth; sl@0: iParaFormatMask.SetAttrib(EAttDefaultTabWidth); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->iDefaultTabWidthInTwips = tabWidth; sl@0: iGlobalParaFormatMask.SetAttrib(EAttDefaultTabWidth); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),tabWidth); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CParser::TransParaTabStopL() sl@0: // This arg has a compound value of the form Tabstop=value,type sl@0: // It also accepts !Tabstop=value to delete an existing tabstop sl@0: { sl@0: TTabStop tabStop; sl@0: TBuf<128> component; sl@0: TBuf<6> outputBuf; sl@0: sl@0: // get first component (tab type) sl@0: TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma (returns -1 if no comma) sl@0: if (commaPos > 0) // comma & first component exist sl@0: { sl@0: component = iArgValue.Left(commaPos); // take part to the left of the comma sl@0: if (component != _L("")) sl@0: tabStop.iTwipsPosition = GetArgValue(component); sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: else if ((iCancelArg)&&(commaPos == -1)) // no comma but only one component required (position) sl@0: { sl@0: if (iArgValue != _L("")) sl@0: tabStop.iTwipsPosition = GetArgValue(iArgValue); sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: sl@0: if (iErrorLevel == ENoError) sl@0: { sl@0: if (iCancelArg) sl@0: // insert a null tab sl@0: { sl@0: if ((iParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound) sl@0: ||(iGlobalParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound)) sl@0: { sl@0: tabStop.iType = TTabStop::ENullTab; // null tab "deletes" existing tab sl@0: outputBuf = _L(""); sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: else sl@0: { sl@0: // set second component (tab position in twips) sl@0: iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma sl@0: if (iArgValue != _L("")) sl@0: { sl@0: outputBuf = _L(""); sl@0: if (iArgValue == _L("NULL")) sl@0: tabStop.iType = TTabStop::ENullTab; sl@0: else if (iArgValue == _L("LEFT")) sl@0: tabStop.iType = TTabStop::ELeftTab; sl@0: else if (iArgValue == _L("CENTERED")) sl@0: tabStop.iType = TTabStop::ECenteredTab; sl@0: else if (iArgValue == _L("RIGHT")) sl@0: tabStop.iType = TTabStop::ERightTab; sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: } sl@0: sl@0: // Insert the tab sl@0: if (iErrorLevel == ENoError) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case EParagraph: sl@0: iParaFormat->StoreTabL(tabStop); sl@0: iParaFormatMask.SetAttrib(EAttTabStop); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalParaFormat->StoreTabL(tabStop); sl@0: iGlobalParaFormatMask.SetAttrib(EAttTabStop); sl@0: break; sl@0: } sl@0: // output to screen sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharArg() sl@0: { sl@0: if (iArgType != _L("")) // Is there an argument? sl@0: { sl@0: if (iArgType == _L("DEFAULT")) sl@0: TransCharDefault(); sl@0: else if (iArgType == _L("ITALIC")) sl@0: TransCharPosture(); sl@0: else if (iArgType == _L("BOLD")) sl@0: TransCharStrokeWeight(); sl@0: else if (iArgType == _L("UNDERLINE")) sl@0: TransCharUnderline(); sl@0: else if (iArgType == _L("STRIKETHROUGH")) sl@0: TransCharStrikethrough(); sl@0: else if (!iArgValueExpected) // No argument value supplied when one is required for the sl@0: iErrorLevel = ENoAttribValue; // remaining options or an unknown argument supplied sl@0: else if (iArgType == _L("FONTHEIGHT")) sl@0: TransCharFontHeight(); sl@0: else if (iArgType == _L("PRINTPOS")) sl@0: TransCharPrintPos(); sl@0: else if (iArgType == _L("TYPEFACENAME")) sl@0: TransCharTypefaceName(); sl@0: else if (iArgType == _L("TYPEFACEFLAGS")) sl@0: TransCharTypefaceFlags(); sl@0: else if (iArgType == _L("COLOR")) sl@0: TransCharColor(); sl@0: else if (iArgType == _L("LANGUAGE")) sl@0: TransCharLanguage(); sl@0: else sl@0: iErrorLevel = EUnknownAttrib; sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharDefault() sl@0: // turns off all applied Char formatting - reverts to global sl@0: { sl@0: iCharFormatMask.ClearAll(); sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharPosture() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: if (iCancelArg) sl@0: iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright); sl@0: else sl@0: iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic); sl@0: iCharFormatMask.SetAttrib(EAttFontPosture); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright); sl@0: else sl@0: iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic); sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontPosture); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharStrokeWeight() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: if (iCancelArg) sl@0: iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal); sl@0: else sl@0: iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); sl@0: iCharFormatMask.SetAttrib(EAttFontStrokeWeight); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal); sl@0: else sl@0: iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontStrokeWeight); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharUnderline() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: if (iCancelArg) sl@0: iCharFormat.iFontPresentation.iUnderline = EUnderlineOff; sl@0: else sl@0: iCharFormat.iFontPresentation.iUnderline = EUnderlineOn; sl@0: iCharFormatMask.SetAttrib(EAttFontUnderline); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOff; sl@0: else sl@0: iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOn; sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontUnderline); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharStrikethrough() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: if (iCancelArg) sl@0: iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff; sl@0: else sl@0: iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn; sl@0: iCharFormatMask.SetAttrib(EAttFontStrikethrough); sl@0: break; sl@0: case EGlobal: sl@0: if (iCancelArg) sl@0: iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff; sl@0: else sl@0: iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn; sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontStrikethrough); sl@0: break; sl@0: } sl@0: // screen output sl@0: OutputToScreen(_L("")); sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharFontHeight() sl@0: { sl@0: TInt32 fontHeight = GetArgValue(); sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: iCharFormat.iFontSpec.iHeight = fontHeight; sl@0: iCharFormatMask.SetAttrib(EAttFontHeight); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalCharFormat.iFontSpec.iHeight = fontHeight; sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontHeight); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),fontHeight); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: void CParser::TransCharPrintPos() sl@0: { sl@0: if (iArgValue == _L("NORMAL")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal); sl@0: iCharFormatMask.SetAttrib(EAttFontPrintPos); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal); sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else if (iArgValue == _L("SUPERSCRIPT")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript); sl@0: iCharFormatMask.SetAttrib(EAttFontPrintPos); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript); sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else if (iArgValue == _L("SUBSCRIPT")) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript); sl@0: iCharFormatMask.SetAttrib(EAttFontPrintPos); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript); sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos); sl@0: break; sl@0: } sl@0: OutputToScreen(_L("")); sl@0: } sl@0: else sl@0: iErrorLevel = EIllegalAttribValue; sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharTypefaceFlags() sl@0: { sl@0: TUint flags = GetArgValue(); sl@0: if (flags>2) sl@0: iErrorLevel=EIllegalAttribValue; // only values 0,1,2 valid for flag sl@0: if (iErrorLevel==ENoError) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: if (flags>=1) sl@0: iCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue); sl@0: if (flags>=3) sl@0: iCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue); sl@0: iCharFormatMask.SetAttrib(EAttFontTypeface); sl@0: break; sl@0: case EGlobal: sl@0: if (flags>=1) sl@0: iGlobalCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue); sl@0: if (flags>=3) sl@0: iGlobalCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue); sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontTypeface); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),flags); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharTypefaceName() sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: iCharFormat.iFontSpec.iTypeface.iName=iArgValue; sl@0: iCharFormatMask.SetAttrib(EAttFontTypeface); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalCharFormat.iFontSpec.iTypeface.iName=iArgValue; sl@0: iGlobalCharFormatMask.SetAttrib(EAttFontTypeface); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),&iArgValue); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharColor() sl@0: { sl@0: TUint value = GetArgValue(); sl@0: if (iErrorLevel==ENoError) sl@0: { sl@0: TRgb color; sl@0: color=TRgb((TUint32)value); sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: iCharFormat.iFontPresentation.iTextColor = color; sl@0: iCharFormatMask.SetAttrib(EAttColor); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalCharFormat.iFontPresentation.iTextColor = color; sl@0: iGlobalCharFormatMask.SetAttrib(EAttColor); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),value); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: } sl@0: sl@0: sl@0: void CParser::TransCharLanguage() sl@0: // Assumes languages are integer coded - will have to change in time sl@0: { sl@0: TUint value = GetArgValue(); sl@0: if (iErrorLevel==ENoError) sl@0: { sl@0: switch (iTagType) sl@0: { sl@0: case ECharacter: sl@0: iCharFormat.iLanguage = value; sl@0: iCharFormatMask.SetAttrib(EAttCharLanguage); sl@0: break; sl@0: case EGlobal: sl@0: iGlobalCharFormat.iLanguage = value; sl@0: iGlobalCharFormatMask.SetAttrib(EAttCharLanguage); sl@0: break; sl@0: } sl@0: // screen output sl@0: TBuf<80> outputBuf; sl@0: outputBuf.Format(_L(""),value); sl@0: OutputToScreen(outputBuf); sl@0: } sl@0: } sl@0: sl@0: sl@0: sl@0: //////////////////////////////// sl@0: // CFileApp sl@0: //////////////////////////////// sl@0: sl@0: sl@0: CFileApp* CFileApp::NewL() sl@0: { sl@0: CFileApp* self=new(ELeave) CFileApp; sl@0: CleanupStack::PushL(self); sl@0: self->ConstructApplicationL(); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: sl@0: CFileApp::CFileApp() sl@0: { sl@0: // init variables sl@0: iConsoleExists = EFalse; sl@0: iFilePos = 0; sl@0: } sl@0: sl@0: sl@0: void CFileApp::ConstructApplicationL() sl@0: { sl@0: iTextBuf = CBufSeg::NewL(64); // Granularity of 64 bytes sl@0: } sl@0: sl@0: sl@0: CFileApp::~CFileApp() sl@0: { sl@0: delete iTextBuf; sl@0: } sl@0: sl@0: sl@0: CBufSeg* CFileApp::LoadFileL(CConsoleBase* aConsoleWin) sl@0: // Asks for file name, then loads file into text buffer. sl@0: { sl@0: iConsoleExists = ETrue; sl@0: iConsole = aConsoleWin; // grab console handle sl@0: GetFileName(); sl@0: FileHandlingL(); // load file & store it sl@0: return iTextBuf; sl@0: } sl@0: sl@0: CBufSeg* CFileApp::LoadFileL(const TFileName &aFileName) sl@0: // uses supplied FileName to load file into CBufSeg sl@0: { sl@0: iFileName = aFileName; sl@0: FileHandlingL(); // load file & store it sl@0: return iTextBuf; sl@0: } sl@0: sl@0: sl@0: void CFileApp::OutputToScreen(const TDesC& aMessageBuffer) sl@0: { sl@0: if (iConsoleExists) sl@0: iConsole->Write(aMessageBuffer); // output line to screen sl@0: } sl@0: sl@0: sl@0: TInt CFileApp::SaveFile(CBufSeg* aTextBuf, TFileName aFileName) sl@0: // saves supplied buffer to disc, making the new filename a varient of the PML source filename supplied sl@0: { sl@0: // set filename to be saved as sl@0: TInt length = aFileName.Length(); sl@0: aFileName.Delete(length-1,1); sl@0: aFileName.Append(_L("G")); // generated filenames end in G sl@0: sl@0: // create fileserver client and save. sl@0: RFs fsClient; sl@0: RFile theFile; sl@0: TInt err = fsClient.Connect(); sl@0: if (err == 0) sl@0: err = theFile.Replace(fsClient, aFileName, EFileStream|EFileRead|EFileWrite); sl@0: if (err == 0) sl@0: { sl@0: TInt readWritePos = 0; sl@0: TBuf8<80> insertBuf; sl@0: TInt readLength=0; sl@0: FOREVER sl@0: { sl@0: // read from TextBuf into insertBuf sl@0: readLength=Min(aTextBuf->Size()-readWritePos,insertBuf.MaxLength()); sl@0: insertBuf.SetLength(0); // empty buffer sl@0: aTextBuf->Read(readWritePos,insertBuf,readLength); sl@0: // insert buf into file sl@0: theFile.Write(readWritePos, insertBuf); sl@0: readWritePos += insertBuf.Length(); sl@0: if (readWritePos >= aTextBuf->Size()) sl@0: break; sl@0: } sl@0: theFile.Close(); sl@0: } sl@0: return err; sl@0: } sl@0: sl@0: void CFileApp::GetFileName() sl@0: // read FileName synchronously from console sl@0: { sl@0: TKeyCode keystroke = EKeyNull; sl@0: iFileName.SetLength(0); sl@0: sl@0: //Debuging cheat to hardwire filename sl@0: //iFileName=_L("d:\\etext\\incp\\dunk.pml"); sl@0: //return; sl@0: sl@0: OutputToScreen(_L("Enter file to be parsed: ")); sl@0: keystroke = iConsole->Getch(); sl@0: while (keystroke != EKeyEnter) sl@0: { sl@0: TBuf<1> uniBuf; // used to ease unicode build sl@0: uniBuf.Append(keystroke); sl@0: sl@0: iConsole->Write(uniBuf); sl@0: iFileName.Append(uniBuf); sl@0: keystroke = iConsole->Getch(); sl@0: } sl@0: WriteNewLine(); sl@0: } sl@0: sl@0: void CFileApp::FileHandlingL() sl@0: // Open a file, read contents into buffer, then close file again sl@0: { sl@0: // open file sl@0: RFile textFile; sl@0: RFs fsClient; sl@0: TInt err = 1; sl@0: while (err) sl@0: { sl@0: err = fsClient.Connect(); sl@0: if (!err) sl@0: err = textFile.Open(fsClient,iFileName,EFileStream|EFileRead|EFileShareReadersOnly); sl@0: if (err) sl@0: return; sl@0: /******GA sl@0: { sl@0: OutputToScreen(_L("Error in file open\n\n")); sl@0: GetFileName(); sl@0: } sl@0: ******/ sl@0: } sl@0: sl@0: OutputToScreen(_L("Parsing ")); sl@0: OutputToScreen(iFileName); sl@0: WriteNewLine(); sl@0: WriteNewLine(); sl@0: sl@0: // Read file into segmented buffer sl@0: TUint insertPos = 0; sl@0: sl@0: TInt max = sizeof(TText) * KFileBufSize; sl@0: sl@0: FOREVER sl@0: { sl@0: iFileBuf.SetLength(0); sl@0: ReadChunkOfFileContents(textFile); sl@0: iTextBuf->/*Do*/InsertL(insertPos,iFileBuf.Ptr(),iFileBuf.Size()); sl@0: insertPos += iFileBuf.Size(); // in bytes sl@0: if (iFileBuf.Size() < max) sl@0: break; sl@0: } sl@0: sl@0: // finish up sl@0: textFile.Close(); sl@0: iFilePos = 0; // reset sl@0: } sl@0: sl@0: void CFileApp::ReadChunkOfFileContents(RFile &aFile) sl@0: { sl@0: TBuf8 readBuf; sl@0: aFile.Read(iFilePos,readBuf); sl@0: // read into iFileBuf (8/16 bit); sl@0: TText textPointer; sl@0: for ( TInt pos=0 ; pos buf(_L("\n")); sl@0: OutputToScreen(buf); sl@0: } sl@0: