1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/textrendering/texthandling/stext/TXTPLAIN.H Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,137 @@
1.4 +/*
1.5 +* Copyright (c) 1998-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 +* Header for the classes that import and export plain text into and out of ETEXT.
1.19 +*
1.20 +*/
1.21 +
1.22 +
1.23 +#ifndef __TXTPLAIN__
1.24 +#define __TXTPLAIN__ 1
1.25 +
1.26 +#include <e32std.h>
1.27 +#include <s32mem.h>
1.28 +#include <txtetext.h>
1.29 +#include "TxtWriter.h"
1.30 +
1.31 +class CCnvCharacterSetConverter;
1.32 +class TPlainTextIOState;
1.33 +
1.34 +NONSHARABLE_CLASS(CPlainTextConverter) : public CBase
1.35 +/**
1.36 +@internalComponent
1.37 +*/
1.38 + {
1.39 + public:
1.40 + static CPlainTextConverter* NewLC();
1.41 + ~CPlainTextConverter();
1.42 + void PrepareToConvertL(TPlainTextIOState& aState,const TDesC8* aSample);
1.43 +
1.44 + enum
1.45 + {
1.46 + EConversionBufferSize = 1024
1.47 + };
1.48 +
1.49 + CCnvCharacterSetConverter* iConverter; // use this converter to translate input or output
1.50 + TUint8* iConversionBuffer; // the buffer used by iConverter for non-Unicode text
1.51 + TInt iConversionBufferLength; // current number of characters in the conversion buffer
1.52 + };
1.53 +
1.54 +class TPlainTextIOState
1.55 +/**
1.56 +@internalComponent
1.57 +*/
1.58 + {
1.59 + public:
1.60 + TPlainTextIOState(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
1.61 + RWriteStream& aOutput,RReadStream& aInput);
1.62 + TBool Finished() const
1.63 + { return iResult.iOutputChars >= iParam.iMaxOutputChars || iResult.iInputChars >= iParam.iMaxInputChars; }
1.64 + TText ReadRawCharL();
1.65 + void WriteRawCharL(TText aChar);
1.66 +
1.67 + const CPlainText::TImportExportParam& iParam;
1.68 + CPlainText::TImportExportResult& iResult;
1.69 + RWriteStream& iOutput;
1.70 + RReadStream& iInput;
1.71 + CPlainTextConverter* iConverter;// if non-null, use CHARCONV, via this object, to convert a
1.72 + // foreign encoding to or from Unicode
1.73 + TBool iSwapInput; // input needs to be byte-swapped
1.74 + TBool iCheckByteOrder; // flip iSwapInput if the next input character is 0xFFFE (byte-swapped byte order mark)
1.75 + };
1.76 +
1.77 +class TPlainTextWriter: public TPlainTextIOState
1.78 +/**
1.79 +@internalComponent
1.80 +*/
1.81 + {
1.82 + public:
1.83 + static void TranslateL(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
1.84 + RWriteStream& aOutput,RReadStream& aInput);
1.85 +
1.86 + private:
1.87 + TPlainTextWriter(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
1.88 + RWriteStream& aOutput,RReadStream& aInput);
1.89 + void TranslateHelperL();
1.90 +
1.91 + enum
1.92 + {
1.93 + EDefaultLineBufferSize = CPlainTextConverter::EConversionBufferSize * 2
1.94 + };
1.95 +
1.96 + void TranslateToEofL();
1.97 + void FlushL();
1.98 + void WriteCharL(TText aChar);
1.99 + void WriteNewLineL();
1.100 + void WriteAndConvertL(const TText* aText,TInt aLength);
1.101 +
1.102 + RBufReadStream iBufReadStream; // a stream over the input buffer
1.103 + TInt iMaxLineLength; // wrap lines automatically if they exceed this length
1.104 + TInt iLineLength; // length of the current line
1.105 + TText* iLineBuffer; // if non-null, this buffer contains the current line, or Unicode text
1.106 + // to be converted to a foreign encoding
1.107 + TInt iMaxLineBufferLength; // maximum number of characters in iLineBuffer
1.108 + };
1.109 +
1.110 +/**
1.111 +@internalComponent
1.112 +*/
1.113 +NONSHARABLE_CLASS(TPlainTextReader) : public TPlainTextIOState, public MOutputChar
1.114 + {
1.115 + public:
1.116 + static void TranslateL(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
1.117 + RWriteStream& aOutput,RReadStream& aInput);
1.118 +
1.119 + private:
1.120 + TPlainTextReader(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
1.121 + RWriteStream& aOutput,RReadStream& aInput);
1.122 + void TranslateHelperL(TSLBTransaltor& aSLBTranslator);
1.123 +
1.124 + enum
1.125 + {
1.126 + EInputBufferSize = CPlainTextConverter::EConversionBufferSize * 2
1.127 + };
1.128 +
1.129 + void TranslateToEofL(TSLBTransaltor& aSLBTranslator);
1.130 + TText ReadAndConvertL();
1.131 + virtual void OutputCharL(TText aChar);
1.132 +
1.133 + TText* iInputBuffer; // if non-null, this buffer contains Unicode text
1.134 + // converted from a foreign encoding
1.135 + TInt iInputLength; // number of characters currently stored in iInputBuffer
1.136 + TInt iInputPos; // current position in iInputBuffer;
1.137 + TInt iConversionState; // state used by iConverter when converting to Unicode
1.138 + };
1.139 +
1.140 +#endif // __TXTPLAIN__