os/textandloc/charconvfw/charconvplugins/src/plugins/ISO2022JP1_2.CPP
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 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 *
    16 */
    17 
    18 #include "PictographObserver.h"
    19 #include "featmgr/featmgr.h"
    20 
    21 #include <e32std.h>
    22 #include <charconv.h>
    23 #include <convutils.h>
    24 #include "jisbase.h"
    25 #include "jisx0201.h"
    26 #include "jisx0208.h"
    27 #include "jisx0212.h"
    28 #include <ecom/implementationproxy.h>
    29 #include "charactersetconverter.h"
    30 
    31 _LIT8(KLit8EscapeSequenceForJisRoman, "\x1b\x28\x4a");
    32 _LIT8(KLit8EscapeSequenceForAscii, "\x1b\x28\x42");
    33 //_LIT8(KLit8EscapeSequenceForJisC6226_1978, "\x1b\x24\x40");
    34 _LIT8(KLit8EscapeSequenceForJisX0208_1983, "\x1b\x24\x42");
    35 _LIT8(KLit8EscapeSequenceForJisX0212_1990, "\x1b\x24\x28\x44");
    36 //_LIT8(KLit8EscapeSequenceForHalfWidthKatakana, "\x1b\x28\x49");
    37 _LIT8(KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters, "\x1b\x24\x42\x21\x29"); // fullwidth question mark
    38 
    39 
    40 class CISO2022JP1ConverterImpl : public CCharacterSetConverterPluginInterface
    41 	{
    42 
    43 public:
    44 	virtual const TDesC8& ReplacementForUnconvertibleUnicodeCharacters();
    45 
    46 	virtual TInt ConvertFromUnicode(
    47 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    48 		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
    49 		TDes8& aForeign, 
    50 		const TDesC16& aUnicode, 
    51 		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters);
    52 
    53 	virtual TInt ConvertToUnicode(
    54 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
    55 		TDes16& aUnicode, 
    56 		const TDesC8& aForeign, 
    57 		TInt& aState, 
    58 		TInt& aNumberOfUnconvertibleCharacters, 
    59 		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter);
    60 
    61 	virtual TBool IsInThisCharacterSetL(
    62 		TBool& aSetToTrue, 
    63 		TInt& aConfidenceLevel, 
    64 		const TDesC8& aSample);
    65 
    66 	static CISO2022JP1ConverterImpl* NewL();
    67 	virtual ~CISO2022JP1ConverterImpl();
    68 
    69 private:
    70 	CISO2022JP1ConverterImpl();
    71 	void ConstructL();
    72 
    73 	};
    74 
    75 
    76 const TDesC8& CISO2022JP1ConverterImpl::ReplacementForUnconvertibleUnicodeCharacters()
    77 	{
    78 	return KLit8Iso2022Jp1ReplacementForUnconvertibleUnicodeCharacters;
    79 	}
    80 
    81 LOCAL_C void ConvertFromJisRomanToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    82 	{
    83 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisRoman, 1);
    84 	}
    85 
    86 LOCAL_C void ConvertFromAsciiToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    87 	{
    88 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForAscii, 1);
    89 	}
    90 
    91 LOCAL_C void ConvertFromJisX0208ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    92 	{
    93 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0208_1983, 2);
    94 	}
    95 
    96 LOCAL_C void ConvertFromJisX0212ToJisInPlace(TInt aStartPositionInDescriptor, TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
    97 	{
    98 	CnvUtilities::ConvertFromIntermediateBufferInPlace(aStartPositionInDescriptor, aDescriptor, aNumberOfCharactersThatDroppedOut, KLit8EscapeSequenceForJisX0212_1990, 2);
    99 	}
   100 
   101 TInt CISO2022JP1ConverterImpl::ConvertFromUnicode(
   102 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   103 		const TDesC8& aReplacementForUnconvertibleUnicodeCharacters, 
   104 		TDes8& aForeign, 
   105 		const TDesC16& aUnicode, 
   106 		CCnvCharacterSetConverter::TArrayOfAscendingIndices& aIndicesOfUnconvertibleCharacters)
   107 	{
   108     TInt ret = KErrNone;
   109     RArray<CnvUtilities::SCharacterSet> characterSets;
   110     if ( FeatureManager::FeatureSupported(KFeatureIdJapanesePicto) )
   111         {        
   112         CnvUtilities::SCharacterSet characterSet;
   113         characterSet.iConversionData=&CnvJisRoman::ConversionData();
   114         characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
   115         characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
   116         ret |= characterSets.Append(characterSet);
   117         characterSet.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
   118         characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
   119         characterSet.iEscapeSequence=&KLit8EscapeSequenceForAscii;
   120         ret |= characterSets.Append(characterSet);
   121         characterSet.iConversionData=&CnvJisX0208::ConversionData();
   122         characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
   123         characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   124         ret |= characterSets.Append(characterSet);
   125         characterSet.iConversionData=&CnvJisX0212::ConversionData();
   126         characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace;
   127         characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
   128         ret |= characterSets.Append(characterSet);
   129 
   130         SetCharacterSetsForPictograph(characterSets);
   131         }
   132     else
   133         {        
   134         CnvUtilities::SCharacterSet characterSet;
   135 	    characterSet.iConversionData=&CnvJisRoman::ConversionData();
   136 	    characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisRomanToJisInPlace;
   137 	    characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisRoman;
   138 	    ret |= characterSets.Append(characterSet);
   139     	characterSet.iConversionData=&CCnvCharacterSetConverter::AsciiConversionData();
   140     	characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromAsciiToJisInPlace;
   141     	characterSet.iEscapeSequence=&KLit8EscapeSequenceForAscii;
   142     	ret |= characterSets.Append(characterSet);
   143     	characterSet.iConversionData=&CnvJisX0208::ConversionData();
   144     	characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0208ToJisInPlace;
   145     	characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0208_1983;
   146     	ret |= characterSets.Append(characterSet);
   147     	characterSet.iConversionData=&CnvJisX0212::ConversionData();
   148     	characterSet.iConvertFromIntermediateBufferInPlace=ConvertFromJisX0212ToJisInPlace;
   149     	characterSet.iEscapeSequence=&KLit8EscapeSequenceForJisX0212_1990;
   150     	ret |= characterSets.Append(characterSet);
   151         }
   152     __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret));
   153 	TUint notUsed;
   154 	TUint inputConversionFlags=CCnvCharacterSetConverter::EInputConversionFlagMustEndInDefaultCharacterSet;
   155     TInt unconvert = CnvUtilities::ConvertFromUnicode(aDefaultEndiannessOfForeignCharacters, aReplacementForUnconvertibleUnicodeCharacters, aForeign, aUnicode, aIndicesOfUnconvertibleCharacters, 
   156         characterSets.Array(),notUsed,inputConversionFlags);
   157 
   158     characterSets.Close();
   159     return unconvert;
   160 	}
   161 
   162 TInt CISO2022JP1ConverterImpl::ConvertToUnicode(
   163 		CCnvCharacterSetConverter::TEndianness aDefaultEndiannessOfForeignCharacters, 
   164 		TDes16& aUnicode, 
   165 		const TDesC8& aForeign, 
   166 		TInt& aState, 
   167 		TInt& aNumberOfUnconvertibleCharacters, 
   168 		TInt& aIndexOfFirstByteOfFirstUnconvertibleCharacter)
   169 	{
   170 	return CnvJisBase::ConvertToUnicode(aDefaultEndiannessOfForeignCharacters, aUnicode, aForeign, aState, aNumberOfUnconvertibleCharacters, aIndexOfFirstByteOfFirstUnconvertibleCharacter);
   171 	}
   172 
   173 TBool CISO2022JP1ConverterImpl::IsInThisCharacterSetL(
   174 		TBool& aSetToTrue, 
   175 		TInt& aConfidenceLevel, 
   176 		const TDesC8& aSample)
   177 	{
   178 	aSetToTrue=ETrue;
   179 	CnvJisBase::IsCharacterJISBased(aConfidenceLevel, aSample);
   180 	return ETrue;
   181 	}
   182 
   183 CISO2022JP1ConverterImpl* CISO2022JP1ConverterImpl::NewL()
   184 	{
   185 	CISO2022JP1ConverterImpl* self = new(ELeave) CISO2022JP1ConverterImpl();
   186 	CleanupStack::PushL(self);
   187 	self->ConstructL();
   188 	CleanupStack::Pop(self);
   189 	return self;
   190 	}
   191 
   192 CISO2022JP1ConverterImpl::~CISO2022JP1ConverterImpl()
   193 	{
   194 	FeatureManager::UnInitializeLib();
   195 	}
   196 
   197 CISO2022JP1ConverterImpl::CISO2022JP1ConverterImpl()
   198 	{
   199 	}
   200 
   201 void CISO2022JP1ConverterImpl::ConstructL()
   202 	{
   203 	FeatureManager::InitializeLibL();
   204 	}
   205 
   206 const TImplementationProxy ImplementationTable[] = 
   207 	{
   208 #ifdef S60_TEST
   209     IMPLEMENTATION_PROXY_ENTRY(0x01000009,  CISO2022JP1ConverterImpl::NewL)
   210 #else
   211 	IMPLEMENTATION_PROXY_ENTRY(0x100066A3,	CISO2022JP1ConverterImpl::NewL)
   212 #endif	
   213 	};
   214 
   215 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
   216 	{
   217 	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
   218 
   219 	return ImplementationTable;
   220 	}
   221