sl@0: /* sl@0: * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: #include "PictographObserver.h" sl@0: #include "featmgr/featmgr.h" sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "jisbase.h" sl@0: #include "jisx0201.h" sl@0: #include "jisx0208.h" sl@0: #include "jisx0212.h" sl@0: #include sl@0: #include "charactersetconverter.h" sl@0: sl@0: _LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a"); sl@0: _LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42"); sl@0: //_LIT8(KLit8EscapeSequenceForJisC6226_1978, "\x1b\x24\x40"); sl@0: _LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42"); sl@0: _LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44"); sl@0: //_LIT8(KLit8EscapeSequenceForHalfWidthKatakana, "\x1b\x28\x49"); sl@0: _LIT8(KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters, "\x1b\x24\x42\x21\x29"); // fullwidth question mark sl@0: sl@0: sl@0: class CISO2022JP1ConverterImpl : public CCharacterSetConverterPluginInterface sl@0: { sl@0: sl@0: public: sl@0: virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters(); sl@0: sl@0: virtual TInt ConvertFromUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, sl@0: TDes8& aForeign, sl@0: const TDesC16& aUnicode, sl@0: CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters); sl@0: sl@0: virtual TInt ConvertToUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: TDes16& aUnicode, sl@0: const TDesC8& aForeign, sl@0: TInt& aState, sl@0: TInt& aNumberOfUnconvertibleCharacters, sl@0: TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter); sl@0: sl@0: virtual TBool IsInThisCharacterSetL( sl@0: TBool& aSetToTrue, sl@0: TInt& aConfidenceLevel, sl@0: const TDesC8& aSample); sl@0: sl@0: static CISO2022JP1ConverterImpl* NewL(); sl@0: virtual ~CISO2022JP1ConverterImpl(); sl@0: sl@0: private: sl@0: CISO2022JP1ConverterImpl(); sl@0: void ConstructL(); sl@0: sl@0: }; sl@0: sl@0: sl@0: const TDesC8& CISO2022JP1ConverterImpl::ReplacementForUnconvertibleUnicodeCharacters() sl@0: { sl@0: return KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters; sl@0: } sl@0: sl@0: LOCAL_C void ConvertFromJisRomanToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisRoman, 1); sl@0: } sl@0: sl@0: LOCAL_C void ConvertFromAsciiToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForAscii, 1); sl@0: } sl@0: sl@0: LOCAL_C void ConvertFromJisX0208ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0208_1983, 2); sl@0: } sl@0: sl@0: LOCAL_C void ConvertFromJisX0212ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut) sl@0: { sl@0: CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0212_1990, 2); sl@0: } sl@0: sl@0: TInt CISO2022JP1ConverterImpl::ConvertFromUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, sl@0: TDes8& aForeign, sl@0: const TDesC16& aUnicode, sl@0: CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters) sl@0: { sl@0: TInt ret = KErrNone; sl@0: RArray characterSets; sl@0: if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) ) sl@0: { sl@0: CnvUtilities::SCharacterSet characterSet; sl@0: characterSet.iConversionData=&CnvJisRoman::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisRoman; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForAscii; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0208::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0212::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990; sl@0: ret |= characterSets.Append(characterSet); sl@0: sl@0: SetCharacterSetsForPictograph(characterSets); sl@0: } sl@0: else sl@0: { sl@0: CnvUtilities::SCharacterSet characterSet; sl@0: characterSet.iConversionData=&CnvJisRoman::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisRoman; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForAscii; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0208::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983; sl@0: ret |= characterSets.Append(characterSet); sl@0: characterSet.iConversionData=&CnvJisX0212::ConversionData(); sl@0: characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace; sl@0: characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990; sl@0: ret |= characterSets.Append(characterSet); sl@0: } sl@0: __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret)); sl@0: TUint notUsed; sl@0: TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagMustEndInDefaultCharacterSet; sl@0: TInt unconvert = CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, sl@0: characterSets.Array(),notUsed,inputConversionFlags); sl@0: sl@0: characterSets.Close(); sl@0: return unconvert; sl@0: } sl@0: sl@0: TInt CISO2022JP1ConverterImpl::ConvertToUnicode( sl@0: CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, sl@0: TDes16& aUnicode, sl@0: const TDesC8& aForeign, sl@0: TInt& aState, sl@0: TInt& aNumberOfUnconvertibleCharacters, sl@0: TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter) sl@0: { sl@0: return CnvJisBase::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter); sl@0: } sl@0: sl@0: TBool CISO2022JP1ConverterImpl::IsInThisCharacterSetL( sl@0: TBool& aSetToTrue, sl@0: TInt& aConfidenceLevel, sl@0: const TDesC8& aSample) sl@0: { sl@0: aSetToTrue=ETrue; sl@0: CnvJisBase::IsCharacterJISBased(aConfidenceLevel, aSample); sl@0: return ETrue; sl@0: } sl@0: sl@0: CISO2022JP1ConverterImpl* CISO2022JP1ConverterImpl::NewL() sl@0: { sl@0: CISO2022JP1ConverterImpl* self = new(ELeave) CISO2022JP1ConverterImpl(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CISO2022JP1ConverterImpl::~CISO2022JP1ConverterImpl() sl@0: { sl@0: FeatureManager::UnInitializeLib(); sl@0: } sl@0: sl@0: CISO2022JP1ConverterImpl::CISO2022JP1ConverterImpl() sl@0: { sl@0: } sl@0: sl@0: void CISO2022JP1ConverterImpl::ConstructL() sl@0: { sl@0: FeatureManager::InitializeLibL(); sl@0: } sl@0: sl@0: const TImplementationProxy ImplementationTable[] = sl@0: { sl@0: #ifdef S60_TEST sl@0: IMPLEMENTATION_PROXY_ENTRY(0x01000009, CISO2022JP1ConverterImpl::NewL) sl@0: #else sl@0: IMPLEMENTATION_PROXY_ENTRY(0x100066A3, CISO2022JP1ConverterImpl::NewL) sl@0: #endif sl@0: }; sl@0: sl@0: EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) sl@0: { sl@0: aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy); sl@0: sl@0: return ImplementationTable; sl@0: } sl@0: