1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textrendering/texthandling/spml/T_PMLPAR.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,1933 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "../incp/T_PMLPAR.H"
1.23 +
1.24 +#define UNUSED_VAR(a) a = a
1.25 +
1.26 +#define UNUSED_VAR(a) a = a
1.27 +
1.28 +////////////////////////////////////////////
1.29 +// CParser
1.30 +////////////////////////////////////////////
1.31 +
1.32 +CParser* CParser::NewL()
1.33 + {
1.34 + CParser* self=new(ELeave) CParser;
1.35 + CleanupStack::PushL(self);
1.36 + self->ConstructApplicationL();
1.37 + CleanupStack::Pop();
1.38 + return self;
1.39 + }
1.40 +
1.41 +
1.42 +CParser::CParser()
1.43 + {
1.44 + // init variables
1.45 + iErrorLevel = ENoError;
1.46 + iParagraphIsOpen = EFalse;
1.47 + iLineNo = 1;
1.48 + iReadPos = 0;
1.49 + iDocInsertPos = 0;
1.50 + iDocParaLength = 0;
1.51 + iDocPhraseLength = 0;
1.52 + iBorderUsed = EFalse;
1.53 + iBulletUsed = EFalse;
1.54 + }
1.55 +
1.56 +
1.57 +void CParser::ConstructApplicationL()
1.58 + {
1.59 + // Construct Rich Text Doc
1.60 + // Make the global format layers and associated formats and masks
1.61 + iGlobalParaFormatLayer=CParaFormatLayer::NewL();
1.62 + iGlobalCharFormatLayer=CCharFormatLayer::NewL();
1.63 + iGlobalParaFormat=CParaFormat::NewL(); // initialised with factory settings
1.64 + iGlobalParaFormatMask.SetAll();
1.65 + iGlobalCharFormatMask.SetAll();
1.66 +
1.67 + // Set the global layers
1.68 + iGlobalParaFormatLayer->SetL(iGlobalParaFormat,iGlobalParaFormatMask);
1.69 + iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask);
1.70 +
1.71 + // Create the rich text document
1.72 + iRichTextDoc=CRichText::NewL(iGlobalParaFormatLayer,iGlobalCharFormatLayer);
1.73 +
1.74 + // Initialise the paragraph and character layers
1.75 + iParaFormatLayer = CParaFormatLayer::NewL();
1.76 + iCharFormatLayer = CCharFormatLayer::NewL();
1.77 + iParaFormat = CParaFormat::NewL();
1.78 +
1.79 + // Create temp alias' for compound attributes
1.80 + iBorder = new TParaBorder;
1.81 + User::LeaveIfNull(iBorder);
1.82 + iBullet = new (ELeave) TBullet;
1.83 + }
1.84 +
1.85 +
1.86 +CParser::~CParser()
1.87 + {
1.88 + // destroy Rich Text Document
1.89 +// delete iRichTextDoc;
1.90 +// delete iGlobalParaFormatLayer;
1.91 +// delete iGlobalCharFormatLayer;
1.92 + delete iGlobalParaFormat;
1.93 + delete iParaFormatLayer;
1.94 + delete iCharFormatLayer;
1.95 + delete iParaFormat;
1.96 + if (!iBorderUsed)
1.97 + delete(iBorder);
1.98 + if (!iBulletUsed)
1.99 + delete(iBullet);
1.100 + }
1.101 +
1.102 +
1.103 +CRichText* CParser::ParseL(CConsoleBase* aConsole)
1.104 +// version for parsing with console output and interactive file dialog
1.105 +// primarily for debugging purposes (you can see what's going on!)
1.106 + {
1.107 + // set console
1.108 + iConsoleExists = ETrue;
1.109 + iConsole = aConsole;
1.110 +
1.111 + // Construct a CFileApp & load a file
1.112 + CFileApp* myFileApp=NULL;
1.113 + TRAPD(ret, myFileApp = CFileApp::NewL());
1.114 + UNUSED_VAR(ret);
1.115 + iTextBuf = myFileApp->LoadFileL(iConsole);
1.116 + iFileName = myFileApp->ReturnFileName();
1.117 +
1.118 + ParseTextBufL(); // parse the buffer
1.119 + delete myFileApp; // destroy file app
1.120 +
1.121 + // Pause before returning
1.122 + WriteNewLine();
1.123 + WriteNewLine();
1.124 + OutputToScreen(_L("Press Space to continue\n"));
1.125 + TKeyCode keystroke = EKeyNull;
1.126 + while (keystroke != EKeySpace)
1.127 + keystroke = iConsole->Getch();
1.128 + return iRichTextDoc;
1.129 + }
1.130 +
1.131 +CRichText* CParser::ParseL(const TFileName &aFileName)
1.132 +// silent version of the parser
1.133 + {
1.134 + iConsoleExists = EFalse;
1.135 + // Construct a CFileApp & load a file
1.136 + CFileApp* myFileApp=NULL;
1.137 + TRAPD(ret, myFileApp = CFileApp::NewL());
1.138 + UNUSED_VAR(ret);
1.139 + iTextBuf = myFileApp->LoadFileL(aFileName);
1.140 + iFileName = myFileApp->ReturnFileName();
1.141 +
1.142 + ParseTextBufL(); // parse the buffer
1.143 + delete myFileApp; // destroy file app
1.144 +
1.145 + return iRichTextDoc;
1.146 + }
1.147 +
1.148 +
1.149 +void CParser::EmitErrorMessage()
1.150 + {
1.151 + TBuf<80> errorMessage;
1.152 + switch (iErrorLevel)
1.153 + {
1.154 + case EUnknownTagType:
1.155 + errorMessage.Format(_L(" Unknown tag type: Line %d"),iLineNo);
1.156 + break;
1.157 + case EUnparagraphedText:
1.158 + errorMessage.Format(_L(" Text not contained by paragraph: Line %d"),iLineNo);
1.159 + break;
1.160 + case EUnknownAttrib:
1.161 + errorMessage.Format(_L(" Unknown tag attribute: Line %d"),iLineNo);
1.162 + break;
1.163 + case ENoAttribValue:
1.164 + errorMessage.Format(_L(" Unknown attribute or no attribute value supplied: Line %d"),iLineNo);
1.165 + break;
1.166 + case EIllegalAttribValue:
1.167 + errorMessage.Format(_L(" Illegal attribute value: Line %d"),iLineNo);
1.168 + break;
1.169 + default:
1.170 + errorMessage.Format(_L(" Error: Line %d"),iLineNo);
1.171 + break;
1.172 + }
1.173 + OutputToScreen(_L(""));
1.174 + OutputToScreen(_L("*** Error!!\n"));
1.175 + OutputToScreen(errorMessage);
1.176 + }
1.177 +
1.178 +
1.179 +void CParser::OutputToScreen(const TDesC& aMessageBuffer)
1.180 + {
1.181 + if (iConsoleExists)
1.182 + iConsole->Write(aMessageBuffer); // output line to screen
1.183 + }
1.184 +
1.185 +
1.186 +TBool CParser::Validate()
1.187 +// Check that document starts with <G> tag - serves as file validation
1.188 +// - Read in characters sequentially
1.189 +// - if the first alphanumeric characters encountered are not "<G" then error
1.190 + {
1.191 + TBool fileFormatError = EFalse;
1.192 + TBool fileValidated = EFalse;
1.193 + TChar charToTest;
1.194 + while ((!fileFormatError)&&(!fileValidated))
1.195 + {
1.196 + charToTest = ReadChar();
1.197 + if (charToTest == '<')
1.198 + {
1.199 + iReadPos+=KCharLength;
1.200 + charToTest = ReadTagChar();
1.201 + if (charToTest != 'G') // Not a style tag - error
1.202 + fileFormatError = ETrue;
1.203 + else
1.204 + fileValidated = ETrue;
1.205 + }
1.206 + else
1.207 + {
1.208 + if (charToTest.IsAlphaDigit()) // Char is alphanumeric - error
1.209 + fileFormatError = ETrue; // (File must start with style tag)
1.210 + else
1.211 + iReadPos+=KCharLength;
1.212 + }
1.213 + }
1.214 + if (fileFormatError)
1.215 + {
1.216 + OutputToScreen(_L("File format error\n"));
1.217 + }
1.218 + iReadPos = 0; // reset after validation
1.219 + iLineNo = 1; // ...
1.220 + return fileValidated;
1.221 + }
1.222 +
1.223 +
1.224 +void CParser::ParseTextBufL()
1.225 +// Parses contents of iTextBuf
1.226 +// Reads in chars sequentially.
1.227 +// - If a char is a tag open ("<") process the following tag
1.228 +// - otherwise add the char to the text of the rich text document
1.229 +// Tidy up at the end of the document
1.230 + {
1.231 + TChar charToTest;
1.232 + TUint textBufSize = iTextBuf->Size();
1.233 + if (Validate())
1.234 + {
1.235 + while ((iReadPos < textBufSize)&&(iErrorLevel == ENoError))
1.236 + {
1.237 + charToTest = ReadChar();
1.238 + if (charToTest == '<')
1.239 + ProcessTagL();
1.240 + else
1.241 + ProcessTextL(charToTest);
1.242 + iReadPos+=KCharLength;
1.243 + }
1.244 + if ((iReadPos == textBufSize)&&(iReadPos>0)&&(iErrorLevel == ENoError))
1.245 + {
1.246 + // at end of document apply any outstanding formatting (if there is text to apply it to)
1.247 + if (iDocParaLength > 0)
1.248 + {
1.249 + iParaFormatLayer->SetL(iParaFormat, iParaFormatMask);
1.250 + iRichTextDoc->ApplyParaFormatL( iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength);
1.251 + }
1.252 + if (iDocPhraseLength > 0)
1.253 + {
1.254 + iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
1.255 + iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
1.256 + }
1.257 + }
1.258 + if (iErrorLevel != ENoError)
1.259 + EmitErrorMessage();
1.260 + }
1.261 + }
1.262 +
1.263 +
1.264 +TChar CParser::ReadChar()
1.265 +// Reads the next character from the text buffer
1.266 + {
1.267 +// TChar charToTest;
1.268 + TText charToTest;
1.269 + iTextBuf->Read(iReadPos,&charToTest,KCharLength);
1.270 + if (charToTest == (TText)KLineFeed)
1.271 + iLineNo++; // Info used only by error messages
1.272 + return charToTest;
1.273 + }
1.274 +
1.275 +
1.276 +void CParser::ProcessTextL(TChar aChar)
1.277 +// 1) Check text is in a paragraph
1.278 +// 2) Check for escape characters
1.279 +// 3) Check for tabs
1.280 +// 4) Add to paragraph
1.281 + {
1.282 + if (!iParagraphIsOpen)
1.283 + {
1.284 + if (!(aChar.IsControl()))
1.285 + iErrorLevel = EUnparagraphedText; // Text not contained by a paragraph - error!!
1.286 + }
1.287 + else
1.288 + {
1.289 + if (aChar == '/') // Escape character for <
1.290 + {
1.291 + TChar tempChar;
1.292 + iTextBuf->Read(iReadPos+KCharLength,&tempChar,1); // doesn't increment line counter
1.293 + if (tempChar == '<')
1.294 + {
1.295 + AddCharToParaL(tempChar);
1.296 + iReadPos+=2*KCharLength; // Skip escape character
1.297 + }
1.298 + else
1.299 + AddCharToParaL(aChar);
1.300 + }
1.301 + else if (aChar == KTabChar)
1.302 + AddCharToParaL(aChar);
1.303 + else if (!(aChar.IsControl())) // if it's not a control char add it
1.304 + AddCharToParaL(aChar); // (this includes spaces)
1.305 + }
1.306 + }
1.307 +
1.308 +
1.309 +void CParser::AddCharToParaL(TChar aChar)
1.310 + {
1.311 + // Add char to RichText doc...
1.312 + iRichTextDoc->InsertL(iDocInsertPos, aChar);
1.313 + iDocInsertPos++;
1.314 + iDocParaLength++;
1.315 + if (iPhraseOpen)
1.316 + iDocPhraseLength++;
1.317 + // and also write it to screen
1.318 + TBuf<4> screenBuf; // Buffer for text to be written to console
1.319 + screenBuf.Append(aChar);
1.320 + OutputToScreen(screenBuf);
1.321 + }
1.322 +
1.323 +
1.324 +void CParser::ProcessTagL()
1.325 + {
1.326 + TChar tagChar;
1.327 + iReadPos+=KCharLength;
1.328 + tagChar = ReadTagChar(); // Read in tag type
1.329 + ClassifyTagL(tagChar);
1.330 + if (iTagType == EError)
1.331 + iErrorLevel = EUnknownTagType;
1.332 + else
1.333 + {
1.334 + ClassifyArgumentsL();
1.335 + }
1.336 + }
1.337 +
1.338 +
1.339 +TChar CParser::ReadTagChar()
1.340 + { // Returns tag character capitalised - therefore case-insensitive
1.341 + TChar charToTest;
1.342 + charToTest = ReadChar();
1.343 + charToTest.UpperCase();
1.344 + return charToTest;
1.345 + }
1.346 +
1.347 +
1.348 +void CParser::ClassifyArgumentsL()
1.349 +// reads tag one argument at a time, dealing with each arg as it is read
1.350 +// If and argument is followed by a value (ie a=4) it is processed in two passes.
1.351 + {
1.352 + TChar tagChar(0);
1.353 + iArgStored = EFalse;
1.354 + iArgValueExpected = EFalse; // Initialise
1.355 + iCancelArg = EFalse;
1.356 + while ((tagChar != '>')&&(iErrorLevel == ENoError)) // ">" is end of tag
1.357 + {
1.358 + iReadPos+=KCharLength;
1.359 + tagChar = ReadTagChar(); // Read in next bit of tag
1.360 + if (iTagType != EComment) // text of comments is ignored
1.361 + {
1.362 + if (tagChar.IsSpace()) // spaces separate args
1.363 + ProcessArgBufL();
1.364 + if (tagChar == '=')
1.365 + {
1.366 + iArgValueExpected = ETrue;
1.367 + ProcessArgBufL();
1.368 + }
1.369 + if (tagChar == '!')
1.370 + {
1.371 + iCancelArg = ETrue;
1.372 + OutputToScreen(_L("!"));
1.373 + }
1.374 + if (tagChar == ',')
1.375 + AppendToArgBuf(tagChar);
1.376 + if (tagChar.IsAlphaDigit())
1.377 + {
1.378 + AppendToArgBuf(tagChar);
1.379 + }
1.380 + }
1.381 + }
1.382 + if (tagChar == '>') // Is it end of tag?
1.383 + {
1.384 + if (iTagType != EComment)
1.385 + {
1.386 + ProcessArgBufL();
1.387 + if ((iTagType == EControl)||(iTagType == EGlobal)) // Control & global style formatting is applied "on the spot"
1.388 + SetFormatLayerL(); // While char & paragraph are applied retrospectively
1.389 + }
1.390 + }
1.391 + }
1.392 +
1.393 +
1.394 +void CParser::AppendToArgBuf(TChar aTagChar)
1.395 + {
1.396 + iArgType.Append(aTagChar); // assume it'll fit
1.397 + }
1.398 +
1.399 +
1.400 +void CParser::ProcessArgBufL()
1.401 + {
1.402 + if (iArgValueExpected)
1.403 + {
1.404 + if (iArgStored)
1.405 + {
1.406 + TBuf<32> tempArgBuf; // Swap the buffers back as an arg and its value have been stored
1.407 + tempArgBuf = iArgType;
1.408 + EmptyBuffer(iArgType);
1.409 + iArgType = iArgValue;
1.410 + EmptyBuffer(iArgValue);
1.411 + iArgValue = tempArgBuf;
1.412 + TranslateTagArgL(); // Translate the tag argument
1.413 + iArgStored = EFalse; // Reset the flags and buffers
1.414 + iArgValueExpected = EFalse;
1.415 + EmptyBuffer(iArgType);
1.416 + EmptyBuffer(iArgValue);
1.417 + }
1.418 + else
1.419 + {
1.420 + iArgValue = iArgType; // Swap the buffers ready to store the value of the arg
1.421 + EmptyBuffer(iArgType); // Empty buffer
1.422 + iArgStored = ETrue;
1.423 + }
1.424 + }
1.425 + else
1.426 + {
1.427 + TranslateTagArgL(); // match to list
1.428 + EmptyBuffer(iArgType);
1.429 + EmptyBuffer(iArgValue);
1.430 + }
1.431 + }
1.432 +
1.433 +
1.434 +void CParser::EmptyBuffer(TDes &aBuf)
1.435 + {
1.436 + aBuf.SetLength(0);
1.437 + }
1.438 +
1.439 +
1.440 +void CParser::ClassifyTagL(TChar aTagChar)
1.441 + {
1.442 + switch (aTagChar)
1.443 + {
1.444 + case 'G':
1.445 + iTagType = EGlobal;
1.446 + break;
1.447 + case 'P':
1.448 + {
1.449 + iTagType = EParagraph;
1.450 + if (iParagraphIsOpen)
1.451 + {
1.452 + iRichTextDoc->InsertL(iDocInsertPos,CEditableText::EParagraphDelimiter); // insert para delimiter
1.453 + WriteNewLine(); // Write new line to console
1.454 + iDocInsertPos++; // Paragraph delimiters occupy 1 character space
1.455 + iDocParaLength++;
1.456 + if (iPhraseOpen)
1.457 + iDocPhraseLength++;
1.458 + SetFormatLayerL(); // apply formatting to old para before starting to fill new one
1.459 + }
1.460 + else
1.461 + iParagraphIsOpen = ETrue;
1.462 + break;
1.463 + }
1.464 + case 'C':
1.465 + {
1.466 + iTagType = ECharacter;
1.467 + if (iPhraseOpen)
1.468 + SetFormatLayerL(); // apply formatting to old phrase retrospectively
1.469 + else
1.470 + iPhraseOpen = ETrue;
1.471 + break;
1.472 + }
1.473 + case 'X':
1.474 + iTagType = EControl;
1.475 + break;
1.476 + case '!':
1.477 + iTagType = EComment;
1.478 + break;
1.479 + default:
1.480 + iTagType = EError;
1.481 + break;
1.482 + }
1.483 + }
1.484 +
1.485 +
1.486 +void CParser::SetFormatLayerL()
1.487 +// Apply format & mask that have been set in the tag to a Layer
1.488 +// Apply the layer to the RichText doc
1.489 + {
1.490 + if (iTagType == EGlobal)
1.491 + {
1.492 + iGlobalParaFormatLayer->SetL(iGlobalParaFormat, iGlobalParaFormatMask);
1.493 + iGlobalCharFormatLayer->SetL(iGlobalCharFormat, iGlobalCharFormatMask);
1.494 + iRichTextDoc->SetGlobalParaFormat(iGlobalParaFormatLayer);
1.495 + iRichTextDoc->SetGlobalCharFormat(iGlobalCharFormatLayer);
1.496 + WriteNewLine();
1.497 + }
1.498 + if (iTagType == EParagraph)
1.499 + {
1.500 + iParaFormatLayer->SetL(iParaFormat, iParaFormatMask);
1.501 + iRichTextDoc->ApplyParaFormatL(iParaFormat,iParaFormatMask,iDocInsertPos-iDocParaLength,iDocParaLength);
1.502 + iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
1.503 + if (iDocPhraseLength > 0)
1.504 + iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
1.505 + iDocParaLength = 0; // reset ready for new paragraph
1.506 + iDocPhraseLength = 0;
1.507 + }
1.508 + if (iTagType == ECharacter)
1.509 + {
1.510 + iCharFormatLayer->SetL(iCharFormat, iCharFormatMask);
1.511 + if (iDocPhraseLength > 0)
1.512 + iRichTextDoc->ApplyCharFormatL(iCharFormat,iCharFormatMask,iDocInsertPos-iDocPhraseLength,iDocPhraseLength);
1.513 + iDocPhraseLength = 0;
1.514 + }
1.515 + }
1.516 +
1.517 +
1.518 +TInt CParser::GetArgValue()
1.519 +// converts numerals in iArgValue to a TInt,
1.520 +// first checking that the buffer is totally numeric in content
1.521 + {
1.522 + TInt value = 0;
1.523 + if (BufIsNumeric(iArgValue))
1.524 + {
1.525 + TLex tmpLex(iArgValue);
1.526 + tmpLex.Val(value);
1.527 + }
1.528 + else iErrorLevel = EIllegalAttribValue;
1.529 + return value;
1.530 + }
1.531 +
1.532 +
1.533 +TInt CParser::GetArgValue(const TDes &aBuf)
1.534 +// converts numerals in aBuf to a TInt as above
1.535 + {
1.536 + TInt value = 0;
1.537 + if (BufIsNumeric(aBuf))
1.538 + {
1.539 + TLex tmpLex(aBuf);
1.540 + tmpLex.Val(value);
1.541 + }
1.542 + else iErrorLevel = EIllegalAttribValue;
1.543 + return value;
1.544 + }
1.545 +
1.546 +
1.547 +TBool CParser::BufIsNumeric(const TDes &aBuffer)
1.548 +// checks that aBuffer is totally numeric in content.
1.549 +// checks all characters sequentially
1.550 + {
1.551 + TBool isNumeric = ETrue;
1.552 + TChar testChar;
1.553 + TUint bufLength = aBuffer.Length();
1.554 + for (TUint pos=0; ((pos<bufLength)&&(isNumeric)); pos++)
1.555 + {
1.556 + testChar = (aBuffer[pos]);
1.557 + if (!(testChar.IsDigit()&&isNumeric))
1.558 + isNumeric = EFalse;
1.559 + }
1.560 + return isNumeric;
1.561 + }
1.562 +
1.563 +/* All the TransXxx.. functions translate arguments and their values and apply these
1.564 + to RichText Formats and Masks */
1.565 +
1.566 +
1.567 +void CParser::TranslateTagArgL()
1.568 + {
1.569 + switch (iTagType)
1.570 + {
1.571 + case EGlobal:
1.572 + TransGlobalArgL();
1.573 + break;
1.574 + case EParagraph:
1.575 + TransParagraphArgL();
1.576 + break;
1.577 + case ECharacter:
1.578 + TransCharArg();
1.579 + break;
1.580 + case EControl:
1.581 + TransControlArgL();
1.582 + break;
1.583 + case EError:
1.584 + break;
1.585 + }
1.586 + iCancelArg = EFalse; // reset
1.587 + }
1.588 +
1.589 +
1.590 +void CParser::TransControlArgL()
1.591 + {
1.592 + if (iArgType != _L(""))
1.593 + {
1.594 + if (iArgType == _L("TAB"))
1.595 + AddCharToParaL(KTabChar); // TransTab();
1.596 + else
1.597 + iErrorLevel = EUnknownAttrib;
1.598 + }
1.599 + }
1.600 +
1.601 +
1.602 +void CParser::TransGlobalArgL()
1.603 +// Test for each possible arg in turn
1.604 +// (a switch statement cannot be used)
1.605 + {
1.606 + if (iArgType != _L("")) // Is there an argument?
1.607 + {
1.608 + if (iArgType == _L("KEEPTOGETHER"))
1.609 + TransParaKeepTogether();
1.610 + else if (iArgType == _L("KEEPWITHNEXT"))
1.611 + TransParaKeepWithNext();
1.612 + else if (iArgType == _L("STARTNEWPAGE"))
1.613 + TransParaStartNewPage();
1.614 + else if (iArgType == _L("WIDOWORPHAN"))
1.615 + TransParaWidowOrphan();
1.616 +
1.617 + if (iArgType == _L("ITALIC"))
1.618 + TransCharPosture();
1.619 + else if (iArgType == _L("BOLD"))
1.620 + TransCharStrokeWeight();
1.621 + else if (iArgType == _L("UNDERLINE"))
1.622 + TransCharUnderline();
1.623 + else if (iArgType == _L("STRIKETHROUGH"))
1.624 + TransCharStrikethrough();
1.625 +
1.626 + else if (!iArgValueExpected) // No argument value supplied when one is required for the
1.627 + iErrorLevel = ENoAttribValue; // remaining options or an unknown argument supplied
1.628 +
1.629 + else if (iArgType == _L("PARALANGUAGE"))
1.630 + OutputToScreen(_L("PARA LANGUAGE "));
1.631 + else if (iArgType == _L("LEFTMARGIN"))
1.632 + TransParaArgLeftMargin();
1.633 + else if (iArgType == _L("RIGHTMARGIN"))
1.634 + TransParaArgRightMargin();
1.635 + else if (iArgType == _L("INDENT"))
1.636 + TransParaArgIndent();
1.637 + else if (iArgType == _L("ALIGNMENT"))
1.638 + TransParaArgAlignment();
1.639 + else if (iArgType == _L("LINESPACING"))
1.640 + TransParaLineSpacing();
1.641 + else if (iArgType == _L("LINESPACINGCONTROL"))
1.642 + TransParaArgLineSpacingControl();
1.643 + else if (iArgType == _L("SPACEBEFORE"))
1.644 + TransParaSpaceBefore();
1.645 + else if (iArgType == _L("SPACEAFTER"))
1.646 + TransParaSpaceAfter();
1.647 + else if (iArgType == _L("BORDERMARGIN"))
1.648 + TransParaBorderMargin();
1.649 + else if (iArgType == _L("TOPBORDER"))
1.650 + TransParaBorderL();
1.651 + else if (iArgType == _L("BOTTOMBORDER"))
1.652 + TransParaBorderL();
1.653 + else if (iArgType == _L("LEFT BORDER"))
1.654 + TransParaBorderL();
1.655 + else if (iArgType == _L("RIGHTBORDER"))
1.656 + TransParaBorderL();
1.657 + else if (iArgType == _L("BULLET"))
1.658 + TransParaBullet();
1.659 + else if (iArgType == _L("DEFAULTTABWIDTH"))
1.660 + TransParaTabWidth();
1.661 + else if (iArgType == _L("TABSTOP"))
1.662 + TransParaTabStopL();
1.663 +
1.664 + else if (iArgType == _L("FONTHEIGHT"))
1.665 + TransCharFontHeight();
1.666 + else if (iArgType == _L("PRINTPOS"))
1.667 + TransCharPrintPos();
1.668 + else if (iArgType == _L("TYPEFACENAME"))
1.669 + TransCharTypefaceName();
1.670 + else if (iArgType == _L("TYPEFACEFLAGS"))
1.671 + TransCharTypefaceFlags();
1.672 + else if (iArgType == _L("COLOR"))
1.673 + TransCharColor();
1.674 + else if (iArgType == _L("LANGUAGE"))
1.675 + TransCharLanguage();
1.676 + else
1.677 + iErrorLevel = EUnknownAttrib;
1.678 + }
1.679 + }
1.680 +
1.681 +
1.682 +void CParser::TransParagraphArgL()
1.683 +// Test for each possible arg in turn
1.684 +// (a switch statement cannot be used)
1.685 + {
1.686 + if (iArgType != _L("")) // Is there an argument?
1.687 + {
1.688 + if (iArgType == _L("DEFAULT"))
1.689 + TransParaDefault();
1.690 + else if (iArgType == _L("KEEPTOGETHER"))
1.691 + TransParaKeepTogether();
1.692 + else if (iArgType == _L("KEEPWITHNEXT"))
1.693 + TransParaKeepWithNext();
1.694 + else if (iArgType == _L("STARTNEWPAGE"))
1.695 + TransParaStartNewPage();
1.696 + else if (iArgType == _L("WIDOWORPHAN"))
1.697 + TransParaWidowOrphan();
1.698 + else if (!iArgValueExpected) // No argument value supplied when one is required for the
1.699 + iErrorLevel = ENoAttribValue; // remaining options or an unknown argument supplied
1.700 + else if (iArgType == _L("PARALANGUAGE"))
1.701 + OutputToScreen(_L("PARA LANGUAGE "));
1.702 + else if (iArgType == _L("LEFTMARGIN"))
1.703 + TransParaArgLeftMargin();
1.704 + else if (iArgType == _L("RIGHTMARGIN"))
1.705 + TransParaArgRightMargin();
1.706 + else if (iArgType == _L("INDENT"))
1.707 + TransParaArgIndent();
1.708 + else if (iArgType == _L("ALIGNMENT"))
1.709 + TransParaArgAlignment();
1.710 + else if (iArgType == _L("LINESPACING"))
1.711 + TransParaLineSpacing();
1.712 + else if (iArgType == _L("LINESPACINGCONTROL"))
1.713 + TransParaArgLineSpacingControl();
1.714 + else if (iArgType == _L("SPACEBEFORE"))
1.715 + TransParaSpaceBefore();
1.716 + else if (iArgType == _L("SPACEAFTER"))
1.717 + TransParaSpaceAfter();
1.718 + else if (iArgType == _L("BORDERMARGIN"))
1.719 + TransParaBorderMargin();
1.720 + else if (iArgType == _L("TOPBORDER"))
1.721 + TransParaBorderL();
1.722 + else if (iArgType == _L("BOTTOMBORDER"))
1.723 + TransParaBorderL();
1.724 + else if (iArgType == _L("LEFT BORDER"))
1.725 + TransParaBorderL();
1.726 + else if (iArgType == _L("RIGHTBORDER"))
1.727 + TransParaBorderL();
1.728 + else if (iArgType == _L("BULLET"))
1.729 + TransParaBullet();
1.730 + else if (iArgType == _L("DEFAULTTABWIDTH"))
1.731 + TransParaTabWidth();
1.732 + else if (iArgType == _L("TABSTOP"))
1.733 + TransParaTabStopL();
1.734 + else
1.735 + iErrorLevel = EUnknownAttrib;
1.736 + }
1.737 + }
1.738 +
1.739 +
1.740 +void CParser::TransParaDefault()
1.741 +// turns off all applied para formatting - reverts to global
1.742 + {
1.743 + iParaFormatMask.ClearAll();
1.744 + OutputToScreen(_L("<PARA-DEFAULT>"));
1.745 + }
1.746 +
1.747 +
1.748 +void CParser::TransParaArgLeftMargin()
1.749 + {
1.750 + TInt32 margin = GetArgValue();
1.751 + switch (iTagType)
1.752 + {
1.753 + case EParagraph:
1.754 + iParaFormat->iLeftMarginInTwips = margin;
1.755 + iParaFormatMask.SetAttrib(EAttLeftMargin);
1.756 + break;
1.757 + case EGlobal:
1.758 + iGlobalParaFormat->iLeftMarginInTwips = margin;
1.759 + iGlobalParaFormatMask.SetAttrib(EAttLeftMargin);
1.760 + break;
1.761 + }
1.762 + // screen output
1.763 + TBuf<80> outputBuf;
1.764 + outputBuf.Format(_L("<LEFT MARGIN = %d>"),margin);
1.765 + OutputToScreen(outputBuf);
1.766 + }
1.767 +
1.768 +void CParser::TransParaArgRightMargin()
1.769 + {
1.770 + TInt32 margin = GetArgValue();
1.771 + switch (iTagType)
1.772 + {
1.773 + case EParagraph:
1.774 + iParaFormat->iRightMarginInTwips = margin;
1.775 + iParaFormatMask.SetAttrib(EAttRightMargin);
1.776 + break;
1.777 + case EGlobal:
1.778 + iGlobalParaFormat->iRightMarginInTwips = margin;
1.779 + iGlobalParaFormatMask.SetAttrib(EAttRightMargin);
1.780 + break;
1.781 + }
1.782 + // screen output
1.783 + TBuf<80> outputBuf;
1.784 + outputBuf.Format(_L("<RIGHT MARGIN = %d>"),margin);
1.785 + OutputToScreen(outputBuf);
1.786 + }
1.787 +
1.788 +void CParser::TransParaArgIndent()
1.789 + {
1.790 + TInt32 indent = GetArgValue();
1.791 + switch (iTagType)
1.792 + {
1.793 + case EParagraph:
1.794 + iParaFormat->iIndentInTwips = indent;
1.795 + iParaFormatMask.SetAttrib(EAttIndent);
1.796 + break;
1.797 + case EGlobal:
1.798 + iGlobalParaFormat->iIndentInTwips = indent;
1.799 + iGlobalParaFormatMask.SetAttrib(EAttIndent);
1.800 + break;
1.801 + }
1.802 + // screen output
1.803 + TBuf<80> outputBuf;
1.804 + outputBuf.Format(_L("<INDENT = %d>"),indent);
1.805 + OutputToScreen(outputBuf);
1.806 + }
1.807 +
1.808 +void CParser::TransParaLineSpacing()
1.809 + {
1.810 + TInt32 lineSpacing = GetArgValue();
1.811 + switch (iTagType)
1.812 + {
1.813 + case EParagraph:
1.814 + iParaFormat->iLineSpacingInTwips = lineSpacing;
1.815 + iParaFormatMask.SetAttrib(EAttLineSpacing);
1.816 + break;
1.817 + case EGlobal:
1.818 + iGlobalParaFormat->iLineSpacingInTwips = lineSpacing;
1.819 + iGlobalParaFormatMask.SetAttrib(EAttLineSpacing);
1.820 + break;
1.821 + }
1.822 + // screen output
1.823 + TBuf<80> outputBuf;
1.824 + outputBuf.Format(_L("<LINESPACING = %d>"),lineSpacing);
1.825 + OutputToScreen(outputBuf);
1.826 + }
1.827 +
1.828 +void CParser::TransParaArgLineSpacingControl()
1.829 + {
1.830 + if (iArgValue == _L("ATLEAST"))
1.831 + {
1.832 + switch (iTagType)
1.833 + {
1.834 + case EParagraph:
1.835 + iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips;
1.836 + iParaFormatMask.SetAttrib(EAttLineSpacingControl);
1.837 + break;
1.838 + case EGlobal:
1.839 + iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingAtLeastInTwips;
1.840 + iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl);
1.841 + break;
1.842 + }
1.843 + OutputToScreen(_L("<Line spacing control Atleast>"));
1.844 + }
1.845 + else if (iArgValue == _L("EXACTLY"))
1.846 + {
1.847 + switch (iTagType)
1.848 + {
1.849 + case EParagraph:
1.850 + iParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
1.851 + iParaFormatMask.SetAttrib(EAttLineSpacingControl);
1.852 + break;
1.853 + case EGlobal:
1.854 + iGlobalParaFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
1.855 + iGlobalParaFormatMask.SetAttrib(EAttLineSpacingControl);
1.856 + break;
1.857 + }
1.858 + OutputToScreen(_L("<Line spacing control Exactly>"));
1.859 + }
1.860 + else
1.861 + iErrorLevel = EIllegalAttribValue;
1.862 + }
1.863 +
1.864 +void CParser::TransParaSpaceBefore()
1.865 + {
1.866 + TInt32 spaceBefore = GetArgValue();
1.867 + switch (iTagType)
1.868 + {
1.869 + case EParagraph:
1.870 + iParaFormat->iSpaceBeforeInTwips = spaceBefore;
1.871 + iParaFormatMask.SetAttrib(EAttSpaceBefore);
1.872 + break;
1.873 + case EGlobal:
1.874 + iGlobalParaFormat->iSpaceBeforeInTwips = spaceBefore;
1.875 + iGlobalParaFormatMask.SetAttrib(EAttSpaceBefore);
1.876 + break;
1.877 + }
1.878 + // screen output
1.879 + TBuf<80> outputBuf;
1.880 + outputBuf.Format(_L("<SPACE BEFORE = %d>"),spaceBefore);
1.881 + OutputToScreen(outputBuf);
1.882 + }
1.883 +
1.884 +void CParser::TransParaSpaceAfter()
1.885 + {
1.886 + TInt32 spaceAfter = GetArgValue();
1.887 + switch (iTagType)
1.888 + {
1.889 + case EParagraph:
1.890 + iParaFormat->iSpaceAfterInTwips = spaceAfter;
1.891 + iParaFormatMask.SetAttrib(EAttSpaceAfter);
1.892 + break;
1.893 + case EGlobal:
1.894 + iGlobalParaFormat->iSpaceAfterInTwips = spaceAfter;
1.895 + iGlobalParaFormatMask.SetAttrib(EAttSpaceAfter);
1.896 + break;
1.897 + }
1.898 + // screen output
1.899 + TBuf<80> outputBuf;
1.900 + outputBuf.Format(_L("<SPACE AFTER = %d>"),spaceAfter);
1.901 + OutputToScreen(outputBuf);
1.902 + }
1.903 +
1.904 +void CParser::TransParaBorderMargin()
1.905 + {
1.906 + TInt32 borderMargin = GetArgValue();
1.907 + switch (iTagType)
1.908 + {
1.909 + case EParagraph:
1.910 + iParaFormat->iBorderMarginInTwips = borderMargin;
1.911 + iParaFormatMask.SetAttrib(EAttBorderMargin);
1.912 + break;
1.913 + case EGlobal:
1.914 + iGlobalParaFormat->iBorderMarginInTwips = borderMargin;
1.915 + iGlobalParaFormatMask.SetAttrib(EAttBorderMargin);
1.916 + break;
1.917 + }
1.918 + // screen output
1.919 + TBuf<80> outputBuf;
1.920 + outputBuf.Format(_L("<BORDER MARGIN = %d>"),borderMargin);
1.921 + OutputToScreen(outputBuf);
1.922 + }
1.923 +
1.924 +void CParser::TransParaKeepTogether()
1.925 + {
1.926 + switch (iTagType)
1.927 + {
1.928 + case EParagraph:
1.929 + if (iCancelArg)
1.930 + iParaFormat->iKeepTogether = EFalse;
1.931 + else
1.932 + iParaFormat->iKeepTogether = ETrue;
1.933 + iParaFormatMask.SetAttrib(EAttKeepTogether);
1.934 + break;
1.935 + case EGlobal:
1.936 + if (iCancelArg)
1.937 + iGlobalParaFormat->iKeepTogether = EFalse;
1.938 + else
1.939 + iGlobalParaFormat->iKeepTogether = ETrue;
1.940 + iGlobalParaFormatMask.SetAttrib(EAttKeepTogether);
1.941 + break;
1.942 + }
1.943 + // screen output
1.944 + OutputToScreen(_L("<KEEP TOGETHER>"));
1.945 + }
1.946 +
1.947 +void CParser::TransParaKeepWithNext()
1.948 + {
1.949 + switch (iTagType)
1.950 + {
1.951 + case EParagraph:
1.952 + if (iCancelArg)
1.953 + iParaFormat->iKeepWithNext = EFalse;
1.954 + else
1.955 + iParaFormat->iKeepWithNext = ETrue;
1.956 + iParaFormatMask.SetAttrib(EAttKeepWithNext);
1.957 + break;
1.958 + case EGlobal:
1.959 + if (iCancelArg)
1.960 + iGlobalParaFormat->iKeepWithNext = EFalse;
1.961 + else
1.962 + iGlobalParaFormat->iKeepWithNext = ETrue;
1.963 + iGlobalParaFormatMask.SetAttrib(EAttKeepWithNext);
1.964 + break;
1.965 + }
1.966 + // screen output
1.967 + OutputToScreen(_L("<KEEP WITH NEXT>"));
1.968 + }
1.969 +
1.970 +void CParser::TransParaStartNewPage()
1.971 + {
1.972 + switch (iTagType)
1.973 + {
1.974 + case EParagraph:
1.975 + if (iCancelArg)
1.976 + iParaFormat->iStartNewPage = EFalse;
1.977 + else
1.978 + iParaFormat->iStartNewPage = ETrue;
1.979 + iParaFormatMask.SetAttrib(EAttStartNewPage);
1.980 + break;
1.981 + case EGlobal:
1.982 + if (iCancelArg)
1.983 + iGlobalParaFormat->iStartNewPage = EFalse;
1.984 + else
1.985 + iGlobalParaFormat->iStartNewPage = ETrue;
1.986 + iGlobalParaFormatMask.SetAttrib(EAttStartNewPage);
1.987 + break;
1.988 + }
1.989 + // screen output
1.990 + OutputToScreen(_L("<START NEW PAGE>"));
1.991 + }
1.992 +
1.993 +void CParser::TransParaWidowOrphan()
1.994 + {
1.995 + switch (iTagType)
1.996 + {
1.997 + case EParagraph:
1.998 + if (iCancelArg)
1.999 + iParaFormat->iWidowOrphan = EFalse;
1.1000 + else
1.1001 + iParaFormat->iWidowOrphan = ETrue;
1.1002 + iParaFormatMask.SetAttrib(EAttWidowOrphan);
1.1003 + break;
1.1004 + case EGlobal:
1.1005 + if (iCancelArg)
1.1006 + iGlobalParaFormat->iWidowOrphan = EFalse;
1.1007 + else
1.1008 + iGlobalParaFormat->iWidowOrphan = ETrue;
1.1009 + iGlobalParaFormatMask.SetAttrib(EAttWidowOrphan);
1.1010 + break;
1.1011 + }
1.1012 + // screen output
1.1013 + OutputToScreen(_L("<WIDOWS & ORPHANS>"));
1.1014 + }
1.1015 +
1.1016 +void CParser::TransParaArgAlignment()
1.1017 + {
1.1018 + // parse argValue
1.1019 + if (iArgValue == _L("LEFT"))
1.1020 + {
1.1021 + switch (iTagType)
1.1022 + {
1.1023 + case EParagraph:
1.1024 + iParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
1.1025 + iParaFormatMask.SetAttrib(EAttAlignment);
1.1026 + break;
1.1027 + case EGlobal:
1.1028 + iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ELeftAlign;
1.1029 + iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1.1030 + break;
1.1031 + }
1.1032 + OutputToScreen(_L("<ALIGNMENT LEFT>"));
1.1033 + }
1.1034 + else if (iArgValue == _L("RIGHT"))
1.1035 + {
1.1036 + switch (iTagType)
1.1037 + {
1.1038 + case EParagraph:
1.1039 + iParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign;
1.1040 + iParaFormatMask.SetAttrib(EAttAlignment);
1.1041 + break;
1.1042 + case EGlobal:
1.1043 + iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ERightAlign;
1.1044 + iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1.1045 + break;
1.1046 + }
1.1047 + OutputToScreen(_L("<ALIGNMENT RIGHT>"));
1.1048 + }
1.1049 + else if (iArgValue == _L("CENTER"))
1.1050 + {
1.1051 + switch (iTagType)
1.1052 + {
1.1053 + case EParagraph:
1.1054 + iParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
1.1055 + iParaFormatMask.SetAttrib(EAttAlignment);
1.1056 + break;
1.1057 + case EGlobal:
1.1058 + iGlobalParaFormat->iHorizontalAlignment = CParaFormat::ECenterAlign;
1.1059 + iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1.1060 + break;
1.1061 + }
1.1062 + OutputToScreen(_L("<ALIGNMENT CENTER>"));
1.1063 + }
1.1064 + else if (iArgValue == _L("JUSTIFIED"))
1.1065 + {
1.1066 + switch (iTagType)
1.1067 + {
1.1068 + case EParagraph:
1.1069 + iParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign;
1.1070 + iParaFormatMask.SetAttrib(EAttAlignment);
1.1071 + break;
1.1072 + case EGlobal:
1.1073 + iGlobalParaFormat->iHorizontalAlignment = CParaFormat::EJustifiedAlign;
1.1074 + iGlobalParaFormatMask.SetAttrib(EAttAlignment);
1.1075 + break;
1.1076 + }
1.1077 + OutputToScreen(_L("<ALIGNMENT JUSTIFIED>"));
1.1078 + }
1.1079 + else
1.1080 + iErrorLevel = EIllegalAttribValue;
1.1081 + }
1.1082 +
1.1083 +
1.1084 +void CParser::TransParaBullet()
1.1085 + {
1.1086 + TInt characterCode = 0x2022;
1.1087 + TUint32 heightInTwips=0;
1.1088 + TUint32 flags=0;
1.1089 + TBuf<KMaxTypefaceNameLength> name;
1.1090 + TBuf<128> component;
1.1091 +
1.1092 + // set first component (character code)
1.1093 + TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma
1.1094 + component = iArgValue.Left(commaPos);
1.1095 + if (component != _L("")) // only third arg remains
1.1096 + {
1.1097 + if (BufIsNumeric(component))
1.1098 + {
1.1099 + TLex tmpLex(component);
1.1100 + // TUint value;
1.1101 + tmpLex.Val(characterCode);
1.1102 + }
1.1103 + else
1.1104 + iErrorLevel = EIllegalAttribValue;
1.1105 + }
1.1106 + else
1.1107 + iErrorLevel = EIllegalAttribValue;
1.1108 +
1.1109 + // set second component (bullet height)
1.1110 + iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1.1111 + commaPos = iArgValue.Locate(KComma); // find pos of first comma
1.1112 + component = iArgValue.Left(commaPos);
1.1113 + if (component != _L("")) // only third arg remains
1.1114 + {
1.1115 + if (BufIsNumeric(component))
1.1116 + {
1.1117 + TLex tmpLex(component);
1.1118 + TUint value;
1.1119 + tmpLex.Val(value);
1.1120 + heightInTwips = value;
1.1121 + }
1.1122 + else
1.1123 + iErrorLevel = EIllegalAttribValue;
1.1124 + }
1.1125 + else
1.1126 + iErrorLevel = EIllegalAttribValue;
1.1127 +
1.1128 + // set third component (typeface flags)
1.1129 + iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1.1130 + commaPos = iArgValue.Locate(KComma); // find pos of first comma
1.1131 + component = iArgValue.Left(commaPos);
1.1132 + if (component != _L("")) // only third arg remains
1.1133 + {
1.1134 + flags = GetArgValue(component);
1.1135 + if (flags>2)
1.1136 + iErrorLevel=EIllegalAttribValue; // only values 0,1,2 valid for flag
1.1137 + }
1.1138 + else
1.1139 + iErrorLevel = EIllegalAttribValue;
1.1140 +
1.1141 + // set fourth component (typeface name)
1.1142 + iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1.1143 + if (iArgValue != _L("")) // only third arg remains
1.1144 + {
1.1145 + name.Copy(iArgValue);
1.1146 +// name = SquashBuf(iArgValue);
1.1147 + }
1.1148 + else
1.1149 + iErrorLevel = EIllegalAttribValue;
1.1150 +
1.1151 + // apply
1.1152 + if (iErrorLevel == ENoError)
1.1153 + {
1.1154 + iBulletUsed = ETrue;
1.1155 + iBullet->iCharacterCode = (TText)characterCode;
1.1156 + iBullet->iHeightInTwips = heightInTwips;
1.1157 + if (flags>=1)
1.1158 + iBullet->iTypeface.SetIsProportional(ETrue);
1.1159 + if (flags>=3)
1.1160 + iBullet->iTypeface.SetIsSerif(ETrue);
1.1161 + iBullet->iTypeface.iName = name;
1.1162 + switch (iTagType)
1.1163 + {
1.1164 + case EParagraph:
1.1165 + iParaFormat->iBullet = iBullet;
1.1166 + iParaFormatMask.SetAttrib(EAttBullet);
1.1167 + break;
1.1168 + case EGlobal:
1.1169 + iGlobalParaFormat->iBullet = iBullet;
1.1170 + iGlobalParaFormatMask.SetAttrib(EAttBullet);
1.1171 + break;
1.1172 + }
1.1173 + OutputToScreen(_L("<BULLET>"));
1.1174 + }
1.1175 + }
1.1176 +
1.1177 +TBuf8<512> CParser::SquashBuf(TDes aBuffer)
1.1178 + //
1.1179 + // Input 8/16 bit buffer to be returned as an 8-bit version
1.1180 + // Used for unicode compatability
1.1181 + //
1.1182 + {
1.1183 + TText16 textPointer;
1.1184 +
1.1185 + TBuf8<512> returnBuf;
1.1186 +
1.1187 + for ( TInt pos=0 ; pos<aBuffer.Length() ; pos++ )
1.1188 + {
1.1189 + textPointer = aBuffer[pos];
1.1190 +#pragma warning ( disable : 4244 )
1.1191 + returnBuf[pos] = textPointer; // conversion from unsigned short to unsigned char (16 bit to 8 bit) in unicode
1.1192 +#pragma warning ( default : 4244 )
1.1193 + }
1.1194 + return returnBuf;
1.1195 + }
1.1196 +
1.1197 +
1.1198 +
1.1199 +void CParser::TransParaBorderL()
1.1200 + {
1.1201 + TParaBorder::TLineStyle lineStyle=TParaBorder::ENullLineStyle;
1.1202 + TBool autoColor=EFalse;
1.1203 + TRgb color;
1.1204 + TBuf<128> component;
1.1205 +
1.1206 + // set first component
1.1207 + TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma
1.1208 + component = iArgValue.Left(commaPos);
1.1209 + if (component != _L(""))
1.1210 + {
1.1211 + if (component == _L("NULL"))
1.1212 + lineStyle = TParaBorder::ENullLineStyle;
1.1213 + else if (component == _L("SOLID"))
1.1214 + lineStyle = TParaBorder::ESolid;
1.1215 + else if (component == _L("DOUBLE"))
1.1216 + lineStyle = TParaBorder::EDouble;
1.1217 + else if (component == _L("DOTTED"))
1.1218 + lineStyle = TParaBorder::EDotted;
1.1219 + else if (component == _L("DASHED"))
1.1220 + lineStyle = TParaBorder::EDashed;
1.1221 + else if (component == _L("DOTDASH"))
1.1222 + lineStyle = TParaBorder::EDotDash;
1.1223 + else if (component == _L("DOTDOTDASH"))
1.1224 + lineStyle = TParaBorder::EDotDotDash;
1.1225 + else
1.1226 + iErrorLevel = EIllegalAttribValue;
1.1227 + }
1.1228 + else
1.1229 + iErrorLevel = EIllegalAttribValue;
1.1230 +
1.1231 + // set second component
1.1232 + iArgValue.Delete(0,commaPos+1); // delete first component & trailing comma
1.1233 + commaPos = iArgValue.Locate(KComma); // find pos of first comma
1.1234 + component = iArgValue.Left(commaPos);
1.1235 + if (component != _L(""))
1.1236 + {
1.1237 + if (component == _L("ON"))
1.1238 + autoColor = ETrue;
1.1239 + else if (component == _L("OFF"))
1.1240 + autoColor = EFalse;
1.1241 + else
1.1242 + iErrorLevel = EIllegalAttribValue;
1.1243 + }
1.1244 + else
1.1245 + iErrorLevel = EIllegalAttribValue;
1.1246 +
1.1247 + // set third component
1.1248 + iArgValue.Delete(0,commaPos+1); // delete second component & trailing comma
1.1249 + if (component != _L("")) // only third arg remains
1.1250 + {
1.1251 + if (BufIsNumeric(iArgValue))
1.1252 + {
1.1253 + TLex tmpLex(iArgValue);
1.1254 + TUint value;
1.1255 + tmpLex.Val(value);
1.1256 + color=TRgb((TUint32)value);
1.1257 + }
1.1258 + else
1.1259 + iErrorLevel = EIllegalAttribValue;
1.1260 + }
1.1261 +
1.1262 + // apply
1.1263 + if (iErrorLevel == ENoError)
1.1264 + {
1.1265 + iBorderUsed = ETrue;
1.1266 + iBorder->iLineStyle = lineStyle;
1.1267 + iBorder->iAutoColor = autoColor;
1.1268 + iBorder->iColor = color;
1.1269 + if (iArgType == _L("TOPBORDER"))
1.1270 + {
1.1271 + switch (iTagType)
1.1272 + {
1.1273 + case EParagraph:
1.1274 + iParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder);
1.1275 + iParaFormatMask.SetAttrib(EAttTopBorder);
1.1276 + break;
1.1277 + case EGlobal:
1.1278 + iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderTop,*iBorder);
1.1279 + iGlobalParaFormatMask.SetAttrib(EAttTopBorder);
1.1280 + break;
1.1281 + }
1.1282 + }
1.1283 + if (iArgType == _L("BOTTOMBORDER"))
1.1284 + {
1.1285 + switch (iTagType)
1.1286 + {
1.1287 + case EParagraph:
1.1288 + iParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder);
1.1289 + iParaFormatMask.SetAttrib(EAttBottomBorder);
1.1290 + break;
1.1291 + case EGlobal:
1.1292 + iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderBottom,*iBorder);
1.1293 + iGlobalParaFormatMask.SetAttrib(EAttBottomBorder);
1.1294 + break;
1.1295 + }
1.1296 + }
1.1297 + if (iArgType == _L("LEFTBORDER"))
1.1298 + {
1.1299 + switch (iTagType)
1.1300 + {
1.1301 + case EParagraph:
1.1302 + iParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder);
1.1303 + iParaFormatMask.SetAttrib(EAttLeftBorder);
1.1304 + break;
1.1305 + case EGlobal:
1.1306 + iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderLeft,*iBorder);
1.1307 + iGlobalParaFormatMask.SetAttrib(EAttLeftBorder);
1.1308 + break;
1.1309 + }
1.1310 + }
1.1311 + if (iArgType == _L("RIGHTBORDER"))
1.1312 + {
1.1313 + switch (iTagType)
1.1314 + {
1.1315 + case EParagraph:
1.1316 + iParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder);
1.1317 + iParaFormatMask.SetAttrib(EAttRightBorder);
1.1318 + break;
1.1319 + case EGlobal:
1.1320 + iGlobalParaFormat->SetParaBorderL(CParaFormat::EParaBorderRight,*iBorder);
1.1321 + iGlobalParaFormatMask.SetAttrib(EAttRightBorder);
1.1322 + break;
1.1323 + }
1.1324 + }
1.1325 + OutputToScreen(_L("<PARA BORDER>"));
1.1326 + }
1.1327 + }
1.1328 +
1.1329 +void CParser::TransParaTabWidth()
1.1330 + {
1.1331 + TInt32 tabWidth = GetArgValue();
1.1332 + switch (iTagType)
1.1333 + {
1.1334 + case EParagraph:
1.1335 + iParaFormat->iDefaultTabWidthInTwips = tabWidth;
1.1336 + iParaFormatMask.SetAttrib(EAttDefaultTabWidth);
1.1337 + break;
1.1338 + case EGlobal:
1.1339 + iGlobalParaFormat->iDefaultTabWidthInTwips = tabWidth;
1.1340 + iGlobalParaFormatMask.SetAttrib(EAttDefaultTabWidth);
1.1341 + break;
1.1342 + }
1.1343 + // screen output
1.1344 + TBuf<80> outputBuf;
1.1345 + outputBuf.Format(_L("<DEFAULT TAB WIDTH = %d>"),tabWidth);
1.1346 + OutputToScreen(outputBuf);
1.1347 + }
1.1348 +
1.1349 +
1.1350 +void CParser::TransParaTabStopL()
1.1351 +// This arg has a compound value of the form Tabstop=value,type
1.1352 +// It also accepts !Tabstop=value to delete an existing tabstop
1.1353 + {
1.1354 + TTabStop tabStop;
1.1355 + TBuf<128> component;
1.1356 + TBuf<6> outputBuf;
1.1357 +
1.1358 + // get first component (tab type)
1.1359 + TInt commaPos = iArgValue.Locate(KComma); // find pos of first comma (returns -1 if no comma)
1.1360 + if (commaPos > 0) // comma & first component exist
1.1361 + {
1.1362 + component = iArgValue.Left(commaPos); // take part to the left of the comma
1.1363 + if (component != _L(""))
1.1364 + tabStop.iTwipsPosition = GetArgValue(component);
1.1365 + else
1.1366 + iErrorLevel = EIllegalAttribValue;
1.1367 + }
1.1368 + else if ((iCancelArg)&&(commaPos == -1)) // no comma but only one component required (position)
1.1369 + {
1.1370 + if (iArgValue != _L(""))
1.1371 + tabStop.iTwipsPosition = GetArgValue(iArgValue);
1.1372 + else
1.1373 + iErrorLevel = EIllegalAttribValue;
1.1374 + }
1.1375 +
1.1376 + if (iErrorLevel == ENoError)
1.1377 + {
1.1378 + if (iCancelArg)
1.1379 + // insert a null tab
1.1380 + {
1.1381 + if ((iParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound)
1.1382 + ||(iGlobalParaFormat->LocateTab(tabStop.iTwipsPosition) != KTabNotFound))
1.1383 + {
1.1384 + tabStop.iType = TTabStop::ENullTab; // null tab "deletes" existing tab
1.1385 + outputBuf = _L("<!TAB>");
1.1386 + }
1.1387 + else
1.1388 + iErrorLevel = EIllegalAttribValue;
1.1389 + }
1.1390 + else
1.1391 + {
1.1392 + // set second component (tab position in twips)
1.1393 + iArgValue.Delete(0,commaPos+1); // delete previous component & trailing comma
1.1394 + if (iArgValue != _L(""))
1.1395 + {
1.1396 + outputBuf = _L("<TAB>");
1.1397 + if (iArgValue == _L("NULL"))
1.1398 + tabStop.iType = TTabStop::ENullTab;
1.1399 + else if (iArgValue == _L("LEFT"))
1.1400 + tabStop.iType = TTabStop::ELeftTab;
1.1401 + else if (iArgValue == _L("CENTERED"))
1.1402 + tabStop.iType = TTabStop::ECenteredTab;
1.1403 + else if (iArgValue == _L("RIGHT"))
1.1404 + tabStop.iType = TTabStop::ERightTab;
1.1405 + else
1.1406 + iErrorLevel = EIllegalAttribValue;
1.1407 + }
1.1408 + else
1.1409 + iErrorLevel = EIllegalAttribValue;
1.1410 + }
1.1411 + }
1.1412 +
1.1413 + // Insert the tab
1.1414 + if (iErrorLevel == ENoError)
1.1415 + {
1.1416 + switch (iTagType)
1.1417 + {
1.1418 + case EParagraph:
1.1419 + iParaFormat->StoreTabL(tabStop);
1.1420 + iParaFormatMask.SetAttrib(EAttTabStop);
1.1421 + break;
1.1422 + case EGlobal:
1.1423 + iGlobalParaFormat->StoreTabL(tabStop);
1.1424 + iGlobalParaFormatMask.SetAttrib(EAttTabStop);
1.1425 + break;
1.1426 + }
1.1427 + // output to screen
1.1428 + OutputToScreen(outputBuf);
1.1429 + }
1.1430 + }
1.1431 +
1.1432 +
1.1433 +void CParser::TransCharArg()
1.1434 + {
1.1435 + if (iArgType != _L("")) // Is there an argument?
1.1436 + {
1.1437 + if (iArgType == _L("DEFAULT"))
1.1438 + TransCharDefault();
1.1439 + else if (iArgType == _L("ITALIC"))
1.1440 + TransCharPosture();
1.1441 + else if (iArgType == _L("BOLD"))
1.1442 + TransCharStrokeWeight();
1.1443 + else if (iArgType == _L("UNDERLINE"))
1.1444 + TransCharUnderline();
1.1445 + else if (iArgType == _L("STRIKETHROUGH"))
1.1446 + TransCharStrikethrough();
1.1447 + else if (!iArgValueExpected) // No argument value supplied when one is required for the
1.1448 + iErrorLevel = ENoAttribValue; // remaining options or an unknown argument supplied
1.1449 + else if (iArgType == _L("FONTHEIGHT"))
1.1450 + TransCharFontHeight();
1.1451 + else if (iArgType == _L("PRINTPOS"))
1.1452 + TransCharPrintPos();
1.1453 + else if (iArgType == _L("TYPEFACENAME"))
1.1454 + TransCharTypefaceName();
1.1455 + else if (iArgType == _L("TYPEFACEFLAGS"))
1.1456 + TransCharTypefaceFlags();
1.1457 + else if (iArgType == _L("COLOR"))
1.1458 + TransCharColor();
1.1459 + else if (iArgType == _L("LANGUAGE"))
1.1460 + TransCharLanguage();
1.1461 + else
1.1462 + iErrorLevel = EUnknownAttrib;
1.1463 + }
1.1464 + }
1.1465 +
1.1466 +
1.1467 +void CParser::TransCharDefault()
1.1468 +// turns off all applied Char formatting - reverts to global
1.1469 + {
1.1470 + iCharFormatMask.ClearAll();
1.1471 + OutputToScreen(_L("<CHAR-DEFAULT>"));
1.1472 + }
1.1473 +
1.1474 +
1.1475 +void CParser::TransCharPosture()
1.1476 + {
1.1477 + switch (iTagType)
1.1478 + {
1.1479 + case ECharacter:
1.1480 + if (iCancelArg)
1.1481 + iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright);
1.1482 + else
1.1483 + iCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
1.1484 + iCharFormatMask.SetAttrib(EAttFontPosture);
1.1485 + break;
1.1486 + case EGlobal:
1.1487 + if (iCancelArg)
1.1488 + iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureUpright);
1.1489 + else
1.1490 + iGlobalCharFormat.iFontSpec.iFontStyle.SetPosture(EPostureItalic);
1.1491 + iGlobalCharFormatMask.SetAttrib(EAttFontPosture);
1.1492 + break;
1.1493 + }
1.1494 + // screen output
1.1495 + OutputToScreen(_L("<ITALIC>"));
1.1496 + }
1.1497 +
1.1498 +
1.1499 +void CParser::TransCharStrokeWeight()
1.1500 + {
1.1501 + switch (iTagType)
1.1502 + {
1.1503 + case ECharacter:
1.1504 + if (iCancelArg)
1.1505 + iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
1.1506 + else
1.1507 + iCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
1.1508 + iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
1.1509 + break;
1.1510 + case EGlobal:
1.1511 + if (iCancelArg)
1.1512 + iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightNormal);
1.1513 + else
1.1514 + iGlobalCharFormat.iFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
1.1515 + iGlobalCharFormatMask.SetAttrib(EAttFontStrokeWeight);
1.1516 + break;
1.1517 + }
1.1518 + // screen output
1.1519 + OutputToScreen(_L("<BOLD>"));
1.1520 + }
1.1521 +
1.1522 +
1.1523 +void CParser::TransCharUnderline()
1.1524 + {
1.1525 + switch (iTagType)
1.1526 + {
1.1527 + case ECharacter:
1.1528 + if (iCancelArg)
1.1529 + iCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
1.1530 + else
1.1531 + iCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
1.1532 + iCharFormatMask.SetAttrib(EAttFontUnderline);
1.1533 + break;
1.1534 + case EGlobal:
1.1535 + if (iCancelArg)
1.1536 + iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOff;
1.1537 + else
1.1538 + iGlobalCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
1.1539 + iGlobalCharFormatMask.SetAttrib(EAttFontUnderline);
1.1540 + break;
1.1541 + }
1.1542 + // screen output
1.1543 + OutputToScreen(_L("<UNDERLINE>"));
1.1544 + }
1.1545 +
1.1546 +
1.1547 +void CParser::TransCharStrikethrough()
1.1548 + {
1.1549 + switch (iTagType)
1.1550 + {
1.1551 + case ECharacter:
1.1552 + if (iCancelArg)
1.1553 + iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff;
1.1554 + else
1.1555 + iCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;
1.1556 + iCharFormatMask.SetAttrib(EAttFontStrikethrough);
1.1557 + break;
1.1558 + case EGlobal:
1.1559 + if (iCancelArg)
1.1560 + iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOff;
1.1561 + else
1.1562 + iGlobalCharFormat.iFontPresentation.iStrikethrough = EStrikethroughOn;
1.1563 + iGlobalCharFormatMask.SetAttrib(EAttFontStrikethrough);
1.1564 + break;
1.1565 + }
1.1566 + // screen output
1.1567 + OutputToScreen(_L("<STRIKETHROUGH>"));
1.1568 + }
1.1569 +
1.1570 +
1.1571 +void CParser::TransCharFontHeight()
1.1572 + {
1.1573 + TInt32 fontHeight = GetArgValue();
1.1574 + switch (iTagType)
1.1575 + {
1.1576 + case ECharacter:
1.1577 + iCharFormat.iFontSpec.iHeight = fontHeight;
1.1578 + iCharFormatMask.SetAttrib(EAttFontHeight);
1.1579 + break;
1.1580 + case EGlobal:
1.1581 + iGlobalCharFormat.iFontSpec.iHeight = fontHeight;
1.1582 + iGlobalCharFormatMask.SetAttrib(EAttFontHeight);
1.1583 + break;
1.1584 + }
1.1585 + // screen output
1.1586 + TBuf<80> outputBuf;
1.1587 + outputBuf.Format(_L("<FONTHEIGHT = %d>"),fontHeight);
1.1588 + OutputToScreen(outputBuf);
1.1589 + }
1.1590 +
1.1591 +void CParser::TransCharPrintPos()
1.1592 + {
1.1593 + if (iArgValue == _L("NORMAL"))
1.1594 + {
1.1595 + switch (iTagType)
1.1596 + {
1.1597 + case ECharacter:
1.1598 + iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal);
1.1599 + iCharFormatMask.SetAttrib(EAttFontPrintPos);
1.1600 + break;
1.1601 + case EGlobal:
1.1602 + iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosNormal);
1.1603 + iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
1.1604 + break;
1.1605 + }
1.1606 + OutputToScreen(_L("<PRINT POSITION NORMAL>"));
1.1607 + }
1.1608 + else if (iArgValue == _L("SUPERSCRIPT"))
1.1609 + {
1.1610 + switch (iTagType)
1.1611 + {
1.1612 + case ECharacter:
1.1613 + iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
1.1614 + iCharFormatMask.SetAttrib(EAttFontPrintPos);
1.1615 + break;
1.1616 + case EGlobal:
1.1617 + iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSuperscript);
1.1618 + iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
1.1619 + break;
1.1620 + }
1.1621 + OutputToScreen(_L("<SUPERSCRIPT>"));
1.1622 + }
1.1623 + else if (iArgValue == _L("SUBSCRIPT"))
1.1624 + {
1.1625 + switch (iTagType)
1.1626 + {
1.1627 + case ECharacter:
1.1628 + iCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
1.1629 + iCharFormatMask.SetAttrib(EAttFontPrintPos);
1.1630 + break;
1.1631 + case EGlobal:
1.1632 + iGlobalCharFormat.iFontSpec.iFontStyle.SetPrintPosition(EPrintPosSubscript);
1.1633 + iGlobalCharFormatMask.SetAttrib(EAttFontPrintPos);
1.1634 + break;
1.1635 + }
1.1636 + OutputToScreen(_L("<SUBSCRIPT>"));
1.1637 + }
1.1638 + else
1.1639 + iErrorLevel = EIllegalAttribValue;
1.1640 + }
1.1641 +
1.1642 +
1.1643 +void CParser::TransCharTypefaceFlags()
1.1644 + {
1.1645 + TUint flags = GetArgValue();
1.1646 + if (flags>2)
1.1647 + iErrorLevel=EIllegalAttribValue; // only values 0,1,2 valid for flag
1.1648 + if (iErrorLevel==ENoError)
1.1649 + {
1.1650 + switch (iTagType)
1.1651 + {
1.1652 + case ECharacter:
1.1653 + if (flags>=1)
1.1654 + iCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue);
1.1655 + if (flags>=3)
1.1656 + iCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue);
1.1657 + iCharFormatMask.SetAttrib(EAttFontTypeface);
1.1658 + break;
1.1659 + case EGlobal:
1.1660 + if (flags>=1)
1.1661 + iGlobalCharFormat.iFontSpec.iTypeface.SetIsProportional(ETrue);
1.1662 + if (flags>=3)
1.1663 + iGlobalCharFormat.iFontSpec.iTypeface.SetIsSerif(ETrue);
1.1664 + iGlobalCharFormatMask.SetAttrib(EAttFontTypeface);
1.1665 + break;
1.1666 + }
1.1667 + // screen output
1.1668 + TBuf<80> outputBuf;
1.1669 + outputBuf.Format(_L("<TYPEFACE FLAGS = %d>"),flags);
1.1670 + OutputToScreen(outputBuf);
1.1671 + }
1.1672 + }
1.1673 +
1.1674 +
1.1675 +void CParser::TransCharTypefaceName()
1.1676 + {
1.1677 + switch (iTagType)
1.1678 + {
1.1679 + case ECharacter:
1.1680 + iCharFormat.iFontSpec.iTypeface.iName=iArgValue;
1.1681 + iCharFormatMask.SetAttrib(EAttFontTypeface);
1.1682 + break;
1.1683 + case EGlobal:
1.1684 + iGlobalCharFormat.iFontSpec.iTypeface.iName=iArgValue;
1.1685 + iGlobalCharFormatMask.SetAttrib(EAttFontTypeface);
1.1686 + break;
1.1687 + }
1.1688 + // screen output
1.1689 + TBuf<80> outputBuf;
1.1690 + outputBuf.Format(_L("<TYPEFACE NAME = %S>"),&iArgValue);
1.1691 + OutputToScreen(outputBuf);
1.1692 + }
1.1693 +
1.1694 +
1.1695 +void CParser::TransCharColor()
1.1696 + {
1.1697 + TUint value = GetArgValue();
1.1698 + if (iErrorLevel==ENoError)
1.1699 + {
1.1700 + TRgb color;
1.1701 + color=TRgb((TUint32)value);
1.1702 + switch (iTagType)
1.1703 + {
1.1704 + case ECharacter:
1.1705 + iCharFormat.iFontPresentation.iTextColor = color;
1.1706 + iCharFormatMask.SetAttrib(EAttColor);
1.1707 + break;
1.1708 + case EGlobal:
1.1709 + iGlobalCharFormat.iFontPresentation.iTextColor = color;
1.1710 + iGlobalCharFormatMask.SetAttrib(EAttColor);
1.1711 + break;
1.1712 + }
1.1713 + // screen output
1.1714 + TBuf<80> outputBuf;
1.1715 + outputBuf.Format(_L("<COLOR = %d>"),value);
1.1716 + OutputToScreen(outputBuf);
1.1717 + }
1.1718 + }
1.1719 +
1.1720 +
1.1721 +void CParser::TransCharLanguage()
1.1722 +// Assumes languages are integer coded - will have to change in time
1.1723 + {
1.1724 + TUint value = GetArgValue();
1.1725 + if (iErrorLevel==ENoError)
1.1726 + {
1.1727 + switch (iTagType)
1.1728 + {
1.1729 + case ECharacter:
1.1730 + iCharFormat.iLanguage = value;
1.1731 + iCharFormatMask.SetAttrib(EAttCharLanguage);
1.1732 + break;
1.1733 + case EGlobal:
1.1734 + iGlobalCharFormat.iLanguage = value;
1.1735 + iGlobalCharFormatMask.SetAttrib(EAttCharLanguage);
1.1736 + break;
1.1737 + }
1.1738 + // screen output
1.1739 + TBuf<80> outputBuf;
1.1740 + outputBuf.Format(_L("<LANGUAGE = %d>"),value);
1.1741 + OutputToScreen(outputBuf);
1.1742 + }
1.1743 + }
1.1744 +
1.1745 +
1.1746 +
1.1747 +////////////////////////////////
1.1748 +// CFileApp
1.1749 +////////////////////////////////
1.1750 +
1.1751 +
1.1752 +CFileApp* CFileApp::NewL()
1.1753 + {
1.1754 + CFileApp* self=new(ELeave) CFileApp;
1.1755 + CleanupStack::PushL(self);
1.1756 + self->ConstructApplicationL();
1.1757 + CleanupStack::Pop();
1.1758 + return self;
1.1759 + }
1.1760 +
1.1761 +
1.1762 +CFileApp::CFileApp()
1.1763 + {
1.1764 + // init variables
1.1765 + iConsoleExists = EFalse;
1.1766 + iFilePos = 0;
1.1767 + }
1.1768 +
1.1769 +
1.1770 +void CFileApp::ConstructApplicationL()
1.1771 + {
1.1772 + iTextBuf = CBufSeg::NewL(64); // Granularity of 64 bytes
1.1773 + }
1.1774 +
1.1775 +
1.1776 +CFileApp::~CFileApp()
1.1777 + {
1.1778 + delete iTextBuf;
1.1779 + }
1.1780 +
1.1781 +
1.1782 +CBufSeg* CFileApp::LoadFileL(CConsoleBase* aConsoleWin)
1.1783 +// Asks for file name, then loads file into text buffer.
1.1784 + {
1.1785 + iConsoleExists = ETrue;
1.1786 + iConsole = aConsoleWin; // grab console handle
1.1787 + GetFileName();
1.1788 + FileHandlingL(); // load file & store it
1.1789 + return iTextBuf;
1.1790 + }
1.1791 +
1.1792 +CBufSeg* CFileApp::LoadFileL(const TFileName &aFileName)
1.1793 +// uses supplied FileName to load file into CBufSeg
1.1794 + {
1.1795 + iFileName = aFileName;
1.1796 + FileHandlingL(); // load file & store it
1.1797 + return iTextBuf;
1.1798 + }
1.1799 +
1.1800 +
1.1801 +void CFileApp::OutputToScreen(const TDesC& aMessageBuffer)
1.1802 + {
1.1803 + if (iConsoleExists)
1.1804 + iConsole->Write(aMessageBuffer); // output line to screen
1.1805 + }
1.1806 +
1.1807 +
1.1808 +TInt CFileApp::SaveFile(CBufSeg* aTextBuf, TFileName aFileName)
1.1809 +// saves supplied buffer to disc, making the new filename a varient of the PML source filename supplied
1.1810 + {
1.1811 + // set filename to be saved as
1.1812 + TInt length = aFileName.Length();
1.1813 + aFileName.Delete(length-1,1);
1.1814 + aFileName.Append(_L("G")); // generated filenames end in G
1.1815 +
1.1816 + // create fileserver client and save.
1.1817 + RFs fsClient;
1.1818 + RFile theFile;
1.1819 + TInt err = fsClient.Connect();
1.1820 + if (err == 0)
1.1821 + err = theFile.Replace(fsClient, aFileName, EFileStream|EFileRead|EFileWrite);
1.1822 + if (err == 0)
1.1823 + {
1.1824 + TInt readWritePos = 0;
1.1825 + TBuf8<80> insertBuf;
1.1826 + TInt readLength=0;
1.1827 + FOREVER
1.1828 + {
1.1829 + // read from TextBuf into insertBuf
1.1830 + readLength=Min(aTextBuf->Size()-readWritePos,insertBuf.MaxLength());
1.1831 + insertBuf.SetLength(0); // empty buffer
1.1832 + aTextBuf->Read(readWritePos,insertBuf,readLength);
1.1833 + // insert buf into file
1.1834 + theFile.Write(readWritePos, insertBuf);
1.1835 + readWritePos += insertBuf.Length();
1.1836 + if (readWritePos >= aTextBuf->Size())
1.1837 + break;
1.1838 + }
1.1839 + theFile.Close();
1.1840 + }
1.1841 + return err;
1.1842 + }
1.1843 +
1.1844 +void CFileApp::GetFileName()
1.1845 +// read FileName synchronously from console
1.1846 + {
1.1847 + TKeyCode keystroke = EKeyNull;
1.1848 + iFileName.SetLength(0);
1.1849 +
1.1850 + //Debuging cheat to hardwire filename
1.1851 + //iFileName=_L("d:\\etext\\incp\\dunk.pml");
1.1852 + //return;
1.1853 +
1.1854 + OutputToScreen(_L("Enter file to be parsed: "));
1.1855 + keystroke = iConsole->Getch();
1.1856 + while (keystroke != EKeyEnter)
1.1857 + {
1.1858 + TBuf<1> uniBuf; // used to ease unicode build
1.1859 + uniBuf.Append(keystroke);
1.1860 +
1.1861 + iConsole->Write(uniBuf);
1.1862 + iFileName.Append(uniBuf);
1.1863 + keystroke = iConsole->Getch();
1.1864 + }
1.1865 + WriteNewLine();
1.1866 + }
1.1867 +
1.1868 +void CFileApp::FileHandlingL()
1.1869 +// Open a file, read contents into buffer, then close file again
1.1870 + {
1.1871 + // open file
1.1872 + RFile textFile;
1.1873 + RFs fsClient;
1.1874 + TInt err = 1;
1.1875 + while (err)
1.1876 + {
1.1877 + err = fsClient.Connect();
1.1878 + if (!err)
1.1879 + err = textFile.Open(fsClient,iFileName,EFileStream|EFileRead|EFileShareReadersOnly);
1.1880 + if (err)
1.1881 + return;
1.1882 +/******GA
1.1883 + {
1.1884 + OutputToScreen(_L("Error in file open\n\n"));
1.1885 + GetFileName();
1.1886 + }
1.1887 +******/
1.1888 + }
1.1889 +
1.1890 + OutputToScreen(_L("Parsing "));
1.1891 + OutputToScreen(iFileName);
1.1892 + WriteNewLine();
1.1893 + WriteNewLine();
1.1894 +
1.1895 + // Read file into segmented buffer
1.1896 + TUint insertPos = 0;
1.1897 +
1.1898 + TInt max = sizeof(TText) * KFileBufSize;
1.1899 +
1.1900 + FOREVER
1.1901 + {
1.1902 + iFileBuf.SetLength(0);
1.1903 + ReadChunkOfFileContents(textFile);
1.1904 + iTextBuf->/*Do*/InsertL(insertPos,iFileBuf.Ptr(),iFileBuf.Size());
1.1905 + insertPos += iFileBuf.Size(); // in bytes
1.1906 + if (iFileBuf.Size() < max)
1.1907 + break;
1.1908 + }
1.1909 +
1.1910 + // finish up
1.1911 + textFile.Close();
1.1912 + iFilePos = 0; // reset
1.1913 + }
1.1914 +
1.1915 +void CFileApp::ReadChunkOfFileContents(RFile &aFile)
1.1916 + {
1.1917 + TBuf8<KFileBufSize> readBuf;
1.1918 + aFile.Read(iFilePos,readBuf);
1.1919 + // read into iFileBuf (8/16 bit);
1.1920 + TText textPointer;
1.1921 + for ( TInt pos=0 ; pos<readBuf.Length() ; pos++ )
1.1922 + {
1.1923 + textPointer = readBuf[pos];
1.1924 + iFileBuf.Append(textPointer);
1.1925 + }
1.1926 + //TInt ret=aFile.Read(iFilePos,iFileBuf);
1.1927 + iFilePos += KFileBufSize;
1.1928 + }
1.1929 +
1.1930 +void CFileApp::WriteNewLine()
1.1931 +//
1.1932 + {
1.1933 + TBuf<1> buf(_L("\n"));
1.1934 + OutputToScreen(buf);
1.1935 + }
1.1936 +