textrendering/texthandling/stext/TXTPLAIN.H
changeset 0 1fb32624e06b
equal deleted inserted replaced
-1:000000000000 0:1fb32624e06b
       
     1 /*
       
     2 * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * Header for the classes that import and export plain text into and out of ETEXT.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef __TXTPLAIN__
       
    21 #define __TXTPLAIN__ 1
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <s32mem.h>
       
    25 #include <txtetext.h>
       
    26 #include "TxtWriter.h"
       
    27 
       
    28 class CCnvCharacterSetConverter;
       
    29 class TPlainTextIOState;
       
    30 
       
    31 NONSHARABLE_CLASS(CPlainTextConverter) : public CBase
       
    32 /**
       
    33 @internalComponent
       
    34 */
       
    35 	{
       
    36 	public:
       
    37 	static CPlainTextConverter* NewLC();
       
    38 	~CPlainTextConverter();
       
    39 	void PrepareToConvertL(TPlainTextIOState& aState,const TDesC8* aSample);
       
    40 
       
    41 	enum
       
    42 		{
       
    43 		EConversionBufferSize = 1024
       
    44 		};
       
    45 
       
    46 	CCnvCharacterSetConverter* iConverter;	// use this converter to translate input or output
       
    47 	TUint8* iConversionBuffer;				// the buffer used by iConverter for non-Unicode text
       
    48 	TInt iConversionBufferLength;			// current number of characters in the conversion buffer
       
    49 	};
       
    50 
       
    51 class TPlainTextIOState
       
    52 /**
       
    53 @internalComponent
       
    54 */
       
    55 	{
       
    56 	public:
       
    57 	TPlainTextIOState(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
       
    58 					  RWriteStream& aOutput,RReadStream& aInput);
       
    59 	TBool Finished() const
       
    60 		{ return iResult.iOutputChars >= iParam.iMaxOutputChars || iResult.iInputChars >= iParam.iMaxInputChars; }
       
    61 	TText ReadRawCharL();
       
    62 	void WriteRawCharL(TText aChar);
       
    63 
       
    64 	const CPlainText::TImportExportParam& iParam;
       
    65 	CPlainText::TImportExportResult& iResult;
       
    66 	RWriteStream& iOutput;
       
    67 	RReadStream& iInput;
       
    68 	CPlainTextConverter* iConverter;// if non-null, use CHARCONV, via this object, to convert a
       
    69 									// foreign encoding to or from Unicode
       
    70 	TBool iSwapInput;				// input needs to be byte-swapped
       
    71 	TBool iCheckByteOrder;			// flip iSwapInput if the next input character is 0xFFFE (byte-swapped byte order mark)
       
    72 	};
       
    73 
       
    74 class TPlainTextWriter: public TPlainTextIOState
       
    75 /**
       
    76 @internalComponent
       
    77 */
       
    78 	{
       
    79 	public:
       
    80 	static void TranslateL(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
       
    81 						   RWriteStream& aOutput,RReadStream& aInput);
       
    82 
       
    83 	private:
       
    84 	TPlainTextWriter(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
       
    85 					 RWriteStream& aOutput,RReadStream& aInput);
       
    86 	void TranslateHelperL();
       
    87 
       
    88 	enum
       
    89 		{
       
    90 		EDefaultLineBufferSize = CPlainTextConverter::EConversionBufferSize * 2
       
    91 		};
       
    92 
       
    93 	void TranslateToEofL();
       
    94 	void FlushL();
       
    95 	void WriteCharL(TText aChar);
       
    96 	void WriteNewLineL();
       
    97 	void WriteAndConvertL(const TText* aText,TInt aLength);
       
    98 
       
    99 	RBufReadStream iBufReadStream;	// a stream over the input buffer
       
   100 	TInt iMaxLineLength;			// wrap lines automatically if they exceed this length
       
   101 	TInt iLineLength;				// length of the current line
       
   102 	TText* iLineBuffer;				// if non-null, this buffer contains the current line, or Unicode text
       
   103 									// to be converted to a foreign encoding
       
   104 	TInt iMaxLineBufferLength;		// maximum number of characters in iLineBuffer
       
   105 	};
       
   106 
       
   107 /**
       
   108 @internalComponent
       
   109 */
       
   110 NONSHARABLE_CLASS(TPlainTextReader) : public TPlainTextIOState, public MOutputChar
       
   111 	{
       
   112 	public:
       
   113 	static void TranslateL(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
       
   114 						   RWriteStream& aOutput,RReadStream& aInput);
       
   115 
       
   116 	private:
       
   117 	TPlainTextReader(const CPlainText::TImportExportParam& aParam,CPlainText::TImportExportResult& aResult,
       
   118 					 RWriteStream& aOutput,RReadStream& aInput);
       
   119 	void TranslateHelperL(TSLBTransaltor& aSLBTranslator);
       
   120 
       
   121 	enum
       
   122 		{
       
   123 		EInputBufferSize = CPlainTextConverter::EConversionBufferSize * 2
       
   124 		};
       
   125 
       
   126 	void TranslateToEofL(TSLBTransaltor& aSLBTranslator);
       
   127 	TText ReadAndConvertL();
       
   128 	virtual void OutputCharL(TText aChar);
       
   129 
       
   130 	TText* iInputBuffer;				// if non-null, this buffer contains Unicode text
       
   131 										// converted from a foreign encoding
       
   132 	TInt iInputLength;					// number of characters currently stored in iInputBuffer
       
   133 	TInt iInputPos;						// current position in iInputBuffer;
       
   134 	TInt iConversionState;				// state used by iConverter when converting to Unicode
       
   135 	};
       
   136 
       
   137 #endif // __TXTPLAIN__