1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/textandloc/charconvfw/charconvplugins/src/plugins/ISO2022JP1_2.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,221 @@
1.4 +/*
1.5 +* Copyright (c) 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 +#include "PictographObserver.h"
1.22 +#include "featmgr/featmgr.h"
1.23 +
1.24 +#include <e32std.h>
1.25 +#include <charconv.h>
1.26 +#include <convutils.h>
1.27 +#include "jisbase.h"
1.28 +#include "jisx0201.h"
1.29 +#include "jisx0208.h"
1.30 +#include "jisx0212.h"
1.31 +#include <ecom/implementationproxy.h>
1.32 +#include "charactersetconverter.h"
1.33 +
1.34 +_LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
1.35 +_LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");
1.36 +//_LIT8(KLit8EscapeSequenceForJisC6226_1978, "\x1b\x24\x40");
1.37 +_LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
1.38 +_LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44");
1.39 +//_LIT8(KLit8EscapeSequenceForHalfWidthKatakana, "\x1b\x28\x49");
1.40 +_LIT8(KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters, "\x1b\x24\x42\x21\x29"); // fullwidth question mark
1.41 +
1.42 +
1.43 +class CISO2022JP1ConverterImpl : public CCharacterSetConverterPluginInterface
1.44 + {
1.45 +
1.46 +public:
1.47 + virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
1.48 +
1.49 + virtual TInt ConvertFromUnicode(
1.50 + CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
1.51 + const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
1.52 + TDes8& aForeign,
1.53 + const TDesC16& aUnicode,
1.54 + CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters);
1.55 +
1.56 + virtual TInt ConvertToUnicode(
1.57 + CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
1.58 + TDes16& aUnicode,
1.59 + const TDesC8& aForeign,
1.60 + TInt& aState,
1.61 + TInt& aNumberOfUnconvertibleCharacters,
1.62 + TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
1.63 +
1.64 + virtual TBool IsInThisCharacterSetL(
1.65 + TBool& aSetToTrue,
1.66 + TInt& aConfidenceLevel,
1.67 + const TDesC8& aSample);
1.68 +
1.69 + static CISO2022JP1ConverterImpl* NewL();
1.70 + virtual ~CISO2022JP1ConverterImpl();
1.71 +
1.72 +private:
1.73 + CISO2022JP1ConverterImpl();
1.74 + void ConstructL();
1.75 +
1.76 + };
1.77 +
1.78 +
1.79 +const TDesC8& CISO2022JP1ConverterImpl::ReplacementForUnconvertibleUnicodeCharacters()
1.80 + {
1.81 + return KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters;
1.82 + }
1.83 +
1.84 +LOCAL_C void ConvertFromJisRomanToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
1.85 + {
1.86 + CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisRoman, 1);
1.87 + }
1.88 +
1.89 +LOCAL_C void ConvertFromAsciiToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
1.90 + {
1.91 + CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForAscii, 1);
1.92 + }
1.93 +
1.94 +LOCAL_C void ConvertFromJisX0208ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
1.95 + {
1.96 + CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0208_1983, 2);
1.97 + }
1.98 +
1.99 +LOCAL_C void ConvertFromJisX0212ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
1.100 + {
1.101 + CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0212_1990, 2);
1.102 + }
1.103 +
1.104 +TInt CISO2022JP1ConverterImpl::ConvertFromUnicode(
1.105 + CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
1.106 + const TDesC8& aReplacementForUnconvertibleUnicodeCharacters,
1.107 + TDes8& aForeign,
1.108 + const TDesC16& aUnicode,
1.109 + CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
1.110 + {
1.111 + TInt ret = KErrNone;
1.112 + RArray<CnvUtilities::SCharacterSet> characterSets;
1.113 + if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) )
1.114 + {
1.115 + CnvUtilities::SCharacterSet characterSet;
1.116 + characterSet.iConversionData=&CnvJisRoman::ConversionData();
1.117 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
1.118 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
1.119 + ret |= characterSets.Append(characterSet);
1.120 + characterSet.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
1.121 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
1.122 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForAscii;
1.123 + ret |= characterSets.Append(characterSet);
1.124 + characterSet.iConversionData=&CnvJisX0208::ConversionData();
1.125 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
1.126 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
1.127 + ret |= characterSets.Append(characterSet);
1.128 + characterSet.iConversionData=&CnvJisX0212::ConversionData();
1.129 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace;
1.130 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
1.131 + ret |= characterSets.Append(characterSet);
1.132 +
1.133 + SetCharacterSetsForPictograph(characterSets);
1.134 + }
1.135 + else
1.136 + {
1.137 + CnvUtilities::SCharacterSet characterSet;
1.138 + characterSet.iConversionData=&CnvJisRoman::ConversionData();
1.139 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
1.140 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
1.141 + ret |= characterSets.Append(characterSet);
1.142 + characterSet.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
1.143 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
1.144 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForAscii;
1.145 + ret |= characterSets.Append(characterSet);
1.146 + characterSet.iConversionData=&CnvJisX0208::ConversionData();
1.147 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
1.148 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
1.149 + ret |= characterSets.Append(characterSet);
1.150 + characterSet.iConversionData=&CnvJisX0212::ConversionData();
1.151 + characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace;
1.152 + characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
1.153 + ret |= characterSets.Append(characterSet);
1.154 + }
1.155 + __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret));
1.156 + TUint notUsed;
1.157 + TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagMustEndInDefaultCharacterSet;
1.158 + TInt unconvert = CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters,
1.159 + characterSets.Array(),notUsed,inputConversionFlags);
1.160 +
1.161 + characterSets.Close();
1.162 + return unconvert;
1.163 + }
1.164 +
1.165 +TInt CISO2022JP1ConverterImpl::ConvertToUnicode(
1.166 + CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters,
1.167 + TDes16& aUnicode,
1.168 + const TDesC8& aForeign,
1.169 + TInt& aState,
1.170 + TInt& aNumberOfUnconvertibleCharacters,
1.171 + TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
1.172 + {
1.173 + return CnvJisBase::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
1.174 + }
1.175 +
1.176 +TBool CISO2022JP1ConverterImpl::IsInThisCharacterSetL(
1.177 + TBool& aSetToTrue,
1.178 + TInt& aConfidenceLevel,
1.179 + const TDesC8& aSample)
1.180 + {
1.181 + aSetToTrue=ETrue;
1.182 + CnvJisBase::IsCharacterJISBased(aConfidenceLevel, aSample);
1.183 + return ETrue;
1.184 + }
1.185 +
1.186 +CISO2022JP1ConverterImpl* CISO2022JP1ConverterImpl::NewL()
1.187 + {
1.188 + CISO2022JP1ConverterImpl* self = new(ELeave) CISO2022JP1ConverterImpl();
1.189 + CleanupStack::PushL(self);
1.190 + self->ConstructL();
1.191 + CleanupStack::Pop(self);
1.192 + return self;
1.193 + }
1.194 +
1.195 +CISO2022JP1ConverterImpl::~CISO2022JP1ConverterImpl()
1.196 + {
1.197 + FeatureManager::UnInitializeLib();
1.198 + }
1.199 +
1.200 +CISO2022JP1ConverterImpl::CISO2022JP1ConverterImpl()
1.201 + {
1.202 + }
1.203 +
1.204 +void CISO2022JP1ConverterImpl::ConstructL()
1.205 + {
1.206 + FeatureManager::InitializeLibL();
1.207 + }
1.208 +
1.209 +const TImplementationProxy ImplementationTable[] =
1.210 + {
1.211 +#ifdef S60_TEST
1.212 + IMPLEMENTATION_PROXY_ENTRY(0x01000009, CISO2022JP1ConverterImpl::NewL)
1.213 +#else
1.214 + IMPLEMENTATION_PROXY_ENTRY(0x100066A3, CISO2022JP1ConverterImpl::NewL)
1.215 +#endif
1.216 + };
1.217 +
1.218 +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
1.219 + {
1.220 + aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
1.221 +
1.222 + return ImplementationTable;
1.223 + }
1.224 +