os/textandloc/charconvfw/charconvplugins/src/plugins/jis.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/textandloc/charconvfw/charconvplugins/src/plugins/jis.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,185 @@
     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 <e32std.h>
    1.23 +#include <charconv.h>
    1.24 +#include <convutils.h>
    1.25 +#include "jisbase.h"
    1.26 +#include "jisx0201.h"
    1.27 +#include "jisx0208.h"
    1.28 +#include "jisx0212.h"
    1.29 +#include <ecom/implementationproxy.h>
    1.30 +#include <charactersetconverter.h>
    1.31 +#include "featmgr/featmgr.h" 
    1.32 +
    1.33 +_LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
    1.34 +_LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");
    1.35 +_LIT8(KLit8EscapeSequenceForHalfWidthKatakana, "\x1b\x28\x49");
    1.36 +_LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
    1.37 +_LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44");
    1.38 +_LIT8(KLit8JisReplacementForUnconvertibleUnicodeCharacters, "\x1b\x24\x42\x21\x29"); // fullwidth question mark
    1.39 +
    1.40 +class CJISConverterImpl : public CCharacterSetConverterPluginInterface
    1.41 +	{
    1.42 +
    1.43 +public:
    1.44 +	virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
    1.45 +
    1.46 +	virtual TInt ConvertFromUnicode(
    1.47 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    1.48 +		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
    1.49 +		TDes8& aForeign, 
    1.50 +		const TDesC16& aUnicode, 
    1.51 +		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters);
    1.52 +
    1.53 +	virtual TInt ConvertToUnicode(
    1.54 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    1.55 +		TDes16& aUnicode, 
    1.56 +		const TDesC8& aForeign, 
    1.57 +		TInt& aState, 
    1.58 +		TInt& aNumberOfUnconvertibleCharacters, 
    1.59 +		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
    1.60 +
    1.61 +	virtual TBool IsInThisCharacterSetL(
    1.62 +		TBool& aSetToTrue, 
    1.63 +		TInt& aConfidenceLevel, 
    1.64 +		const TDesC8& aSample);
    1.65 +
    1.66 +	static CJISConverterImpl* NewL();
    1.67 +	virtual ~CJISConverterImpl();
    1.68 +
    1.69 +private:
    1.70 +	CJISConverterImpl();
    1.71 +	void ConstructL();
    1.72 +
    1.73 +	};
    1.74 +
    1.75 +
    1.76 +
    1.77 +const TDesC8& CJISConverterImpl::ReplacementForUnconvertibleUnicodeCharacters()
    1.78 +	{
    1.79 +	return KLit8JisReplacementForUnconvertibleUnicodeCharacters;
    1.80 +	}
    1.81 +
    1.82 +LOCAL_C void ConvertFromJisRomanToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.83 +	{
    1.84 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisRoman, 1);
    1.85 +	}
    1.86 +
    1.87 +LOCAL_C void ConvertFromAsciiToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.88 +	{
    1.89 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForAscii, 1);
    1.90 +	}
    1.91 +
    1.92 +LOCAL_C void ConvertFromHalfWidthKatakanaToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.93 +	{
    1.94 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForHalfWidthKatakana, 1);
    1.95 +	}
    1.96 +
    1.97 +LOCAL_C void ConvertFromJisX0208ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    1.98 +	{
    1.99 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0208_1983, 2);
   1.100 +	}
   1.101 +
   1.102 +LOCAL_C void ConvertFromJisX0212ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
   1.103 +	{
   1.104 +	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0212_1990, 2);
   1.105 +	}
   1.106 +
   1.107 +TInt CJISConverterImpl::ConvertFromUnicode(
   1.108 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   1.109 +		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
   1.110 +		TDes8& aForeign, 
   1.111 +		const TDesC16& aUnicode, 
   1.112 +		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
   1.113 +	{
   1.114 +	TFixedArray<CnvUtilities::SCharacterSet, 5> characterSets;
   1.115 +	characterSets[0].iConversionData=&CnvJisRoman::ConversionData();
   1.116 +	characterSets[0].iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
   1.117 +	characterSets[0].iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
   1.118 +	characterSets[1].iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
   1.119 +	characterSets[1].iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
   1.120 +	characterSets[1].iEscapeSequence=&KLit8EscapeSequenceForAscii;
   1.121 +	characterSets[2].iConversionData=&CnvJisBase::HalfWidthKatakana7ConversionData();
   1.122 +	characterSets[2].iConvertFromIntermediateBufferInPlace=ConvertFromHalfWidthKatakanaToJisInPlace;
   1.123 +	characterSets[2].iEscapeSequence=&KLit8EscapeSequenceForHalfWidthKatakana;
   1.124 +	characterSets[3].iConversionData=&CnvJisX0208::ConversionData();
   1.125 +	characterSets[3].iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
   1.126 +	characterSets[3].iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   1.127 +	characterSets[4].iConversionData=&CnvJisX0212::ConversionData();
   1.128 +	characterSets[4].iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace;
   1.129 +	characterSets[4].iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
   1.130 +	return CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, characterSets.Array());
   1.131 +	}
   1.132 +
   1.133 +TInt CJISConverterImpl::ConvertToUnicode(
   1.134 +		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   1.135 +		TDes16& aUnicode, 
   1.136 +		const TDesC8& aForeign, 
   1.137 +		TInt& aState, 
   1.138 +		TInt& aNumberOfUnconvertibleCharacters, 
   1.139 +		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
   1.140 +	{
   1.141 +	return CnvJisBase::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
   1.142 +	}
   1.143 +
   1.144 +TBool CJISConverterImpl::IsInThisCharacterSetL(
   1.145 +		TBool& aSetToTrue, 
   1.146 +		TInt& aConfidenceLevel, 
   1.147 +		const TDesC8& aSample)
   1.148 +	{
   1.149 +	aSetToTrue=ETrue;
   1.150 +	CnvJisBase::IsCharacterJISBased(aConfidenceLevel, aSample);
   1.151 +	return ETrue;
   1.152 +	}
   1.153 +
   1.154 +CJISConverterImpl* CJISConverterImpl::NewL()
   1.155 +	{
   1.156 +	CJISConverterImpl* self = new(ELeave) CJISConverterImpl();
   1.157 +    CleanupStack::PushL(self);
   1.158 +    self->ConstructL();
   1.159 +    CleanupStack::Pop(self);
   1.160 +	return self;
   1.161 +	}
   1.162 +
   1.163 +CJISConverterImpl::~CJISConverterImpl()
   1.164 +	{
   1.165 +	FeatureManager::UnInitializeLib();
   1.166 +	}
   1.167 +
   1.168 +CJISConverterImpl::CJISConverterImpl()
   1.169 +	{
   1.170 +	}
   1.171 +
   1.172 +void CJISConverterImpl::ConstructL()
   1.173 +    {
   1.174 +    FeatureManager::InitializeLibL();
   1.175 +    }
   1.176 +
   1.177 +const TImplementationProxy ImplementationTable[] = 
   1.178 +	{
   1.179 +		IMPLEMENTATION_PROXY_ENTRY(0x10006066,	CJISConverterImpl::NewL)
   1.180 +	};
   1.181 +
   1.182 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   1.183 +	{
   1.184 +	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   1.185 +
   1.186 +	return ImplementationTable;
   1.187 +	}
   1.188 +