os/textandloc/charconvfw/charconvplugins/src/shared/CnvPictographShared.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:         This class is a utitlity class for conversion of Vodafone
sl@0
    15
*                pictograph.
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
sl@0
    21
sl@0
    22
sl@0
    23
sl@0
    24
sl@0
    25
sl@0
    26
// PICTOGRAPH_SHARED.CPP
sl@0
    27
//
sl@0
    28
//
sl@0
    29
sl@0
    30
#include "CnvPictographShared.h"
sl@0
    31
// #include "CnvPictograph1.h"
sl@0
    32
#include "CnvShiftJisDirectmap.h"
sl@0
    33
#include <convgeneratedcpp.h>
sl@0
    34
sl@0
    35
sl@0
    36
// CONSTANTS
sl@0
    37
// Escape sequence for Vodafone pictograph
sl@0
    38
_LIT8(KLit8EscapeSequenceForPictograph, "\x1b\x24");
sl@0
    39
// _LIT8(KLit8EscapeSequenceForPictograph1, "\x1b\x24\x47");
sl@0
    40
sl@0
    41
const TInt KEscape = 0x1B;
sl@0
    42
const TInt KShiftIn = 0x0F;
sl@0
    43
sl@0
    44
// Intermidiate buffers for pictograph
sl@0
    45
const TInt KIntermediateBuffer1 = 'G';
sl@0
    46
sl@0
    47
const TUint KSingleByteRangeFirstBlockStart = 0xF0;
sl@0
    48
const TUint KSingleByteRangeFirstBlockEnd = 0xF9;
sl@0
    49
const TUint KSingleByteRangeSecondBlockStart = 0x40;
sl@0
    50
const TUint KSingleByteRangeSecondBlockEnd = 0xFC;
sl@0
    51
sl@0
    52
const TUint KFirstByteRangeFirstBlockStart = 0xF5;
sl@0
    53
const TUint KFirstByteRangeFirstBlockEnd = 0xFE;
sl@0
    54
const TUint KSecondByteRangeSecondBlockStart = 0xA1;
sl@0
    55
const TUint KSecondByteRangeSecondBlockEnd = 0xFE;
sl@0
    56
sl@0
    57
const TUint KEUCJPSecondBlockStart = 0xF5;
sl@0
    58
const TUint KEUCJPBlockSize = 0x5D;
sl@0
    59
const TUint KSingleShift3=0x8f;
sl@0
    60
// used for EucJp
sl@0
    61
const TUint KPictographStartFirstByte = 0xF0;
sl@0
    62
const TUint KPictographStartSecondByte = 0x40;
sl@0
    63
const TUint KShiftJisTrailByteIllegal = 0x7F;
sl@0
    64
sl@0
    65
// ============================ LOCAL FUNCTIONS ===============================
sl@0
    66
sl@0
    67
sl@0
    68
// -----------------------------------------------------------------------------
sl@0
    69
// DummyConvertToIntermediateBufferInPlace ?description.
sl@0
    70
//
sl@0
    71
// -----------------------------------------------------------------------------
sl@0
    72
//
sl@0
    73
LOCAL_C void DummyConvertToIntermediateBufferInPlace(TDes8&)
sl@0
    74
    {
sl@0
    75
    }
sl@0
    76
sl@0
    77
// -----------------------------------------------------------------------------
sl@0
    78
// DummyConvertFromIntermediateBufferInPlace
sl@0
    79
//
sl@0
    80
// -----------------------------------------------------------------------------
sl@0
    81
//
sl@0
    82
LOCAL_C void DummyConvertFromIntermediateBufferInPlace(TInt, TDes8&,
sl@0
    83
                                TInt& aNumberOfCharactersThatDroppedOut)
sl@0
    84
    {
sl@0
    85
    aNumberOfCharactersThatDroppedOut=0;
sl@0
    86
    }
sl@0
    87
sl@0
    88
// -----------------------------------------------------------------------------
sl@0
    89
// ConvertFromPictogaphToEucJpDirectmapInPlace
sl@0
    90
// Converts from EucJp packed Pictograph to Unicode
sl@0
    91
// -----------------------------------------------------------------------------
sl@0
    92
//
sl@0
    93
LOCAL_C void ConvertFromPictogaphToEucJpDirectmapInPlace(
sl@0
    94
        TInt aStartPositionInDescriptor, TDes8& aDescriptor,
sl@0
    95
        TInt& aNumberOfCharactersThatDroppedOut)
sl@0
    96
    {
sl@0
    97
    TInt descriptorLength=aDescriptor.Length();
sl@0
    98
    TInt bytesPerCharacter = 2;
sl@0
    99
    if (aDescriptor[0] >= KEUCJPSecondBlockStart)
sl@0
   100
        {
sl@0
   101
        bytesPerCharacter = 3;
sl@0
   102
        }
sl@0
   103
sl@0
   104
    aNumberOfCharactersThatDroppedOut =
sl@0
   105
        Max(0, ((descriptorLength - aStartPositionInDescriptor) / 2) -
sl@0
   106
        ((aDescriptor.MaxLength() - aStartPositionInDescriptor) /
sl@0
   107
        bytesPerCharacter));
sl@0
   108
    descriptorLength -= aNumberOfCharactersThatDroppedOut * 2;
sl@0
   109
    if (descriptorLength <= aStartPositionInDescriptor)
sl@0
   110
        {
sl@0
   111
        aDescriptor.SetLength(descriptorLength);
sl@0
   112
        }
sl@0
   113
    else
sl@0
   114
        {
sl@0
   115
        // pointerToTargetByte is initialized properly when descriptorLength
sl@0
   116
        // has been offset to the actual final length of aDescriptor
sl@0
   117
        TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   118
        const TUint8* const pointerToFirstByte =
sl@0
   119
            pointerToTargetByte + aStartPositionInDescriptor;
sl@0
   120
        const TUint8* pointerToSourceByte =
sl@0
   121
            pointerToTargetByte + (descriptorLength - 1);
sl@0
   122
        descriptorLength = (((descriptorLength - aStartPositionInDescriptor)
sl@0
   123
            * bytesPerCharacter) / 2) + aStartPositionInDescriptor;
sl@0
   124
        aDescriptor.SetLength(descriptorLength);
sl@0
   125
        // pointerToTargetByte is is initialized properly here
sl@0
   126
        pointerToTargetByte += descriptorLength - 1;
sl@0
   127
        for (;pointerToTargetByte > pointerToFirstByte; )
sl@0
   128
            {
sl@0
   129
            TInt secondByte = *pointerToSourceByte;
sl@0
   130
            TInt firstByte = *(pointerToSourceByte - 1);
sl@0
   131
sl@0
   132
            if (bytesPerCharacter == 3)
sl@0
   133
                {
sl@0
   134
                firstByte = (firstByte - KEUCJPSecondBlockStart) * 2 +
sl@0
   135
                    KFirstByteRangeFirstBlockStart;
sl@0
   136
                }
sl@0
   137
            else
sl@0
   138
                {
sl@0
   139
                firstByte = (firstByte - KPictographStartFirstByte) * 2 +
sl@0
   140
                    KFirstByteRangeFirstBlockStart;
sl@0
   141
                }
sl@0
   142
            if (static_cast<TInt>(KEUCJPBlockSize + KPictographStartSecondByte + 1)
sl@0
   143
                 < secondByte)
sl@0
   144
                {
sl@0
   145
                if (secondByte > KShiftJisTrailByteIllegal)
sl@0
   146
                    secondByte -= 1;
sl@0
   147
                secondByte = secondByte -(KPictographStartSecondByte +
sl@0
   148
                    KEUCJPBlockSize + 1) + KSecondByteRangeSecondBlockStart;
sl@0
   149
                firstByte++;
sl@0
   150
                }
sl@0
   151
            else
sl@0
   152
                {
sl@0
   153
                if (secondByte > KShiftJisTrailByteIllegal)
sl@0
   154
                    secondByte -= 1;
sl@0
   155
                secondByte += KSecondByteRangeSecondBlockStart - KPictographStartSecondByte;
sl@0
   156
                }
sl@0
   157
            *pointerToTargetByte = static_cast<TUint8>(secondByte);
sl@0
   158
            --pointerToTargetByte;
sl@0
   159
            *pointerToTargetByte = static_cast<TUint8>(firstByte);
sl@0
   160
            if (bytesPerCharacter == 3)
sl@0
   161
                {
sl@0
   162
                --pointerToTargetByte;
sl@0
   163
                *pointerToTargetByte = KSingleShift3;
sl@0
   164
                }
sl@0
   165
            --pointerToTargetByte;
sl@0
   166
            pointerToSourceByte -= 2;
sl@0
   167
            }
sl@0
   168
        }
sl@0
   169
    }
sl@0
   170
sl@0
   171
// ============================ MEMBER FUNCTIONS ===============================
sl@0
   172
sl@0
   173
// -----------------------------------------------------------------------------
sl@0
   174
// CnvPictographShared::SetCharacterSetsForPictograph
sl@0
   175
// It sets parameters to SCharacterSet array. It called in ConvertFromUnicode().
sl@0
   176
// It makes possible that pictograph conversion is called from other conversion
sl@0
   177
// plug-ins.
sl@0
   178
// (other items were commented in a header).
sl@0
   179
// -----------------------------------------------------------------------------
sl@0
   180
//
sl@0
   181
void CnvPictographShared::SetCharacterSetsForPictograph(
sl@0
   182
        RArray<CnvUtilities::SCharacterSet>& /*aArrayOfCharacterSets*/)
sl@0
   183
    {
sl@0
   184
    // SAMPLE CODE
sl@0
   185
    // If this module needs to support escape sequence pictograph,
sl@0
   186
    // Remove the comment from the following code.
sl@0
   187
sl@0
   188
    // CnvUtilities::SCharacterSet characterSet;
sl@0
   189
    // characterSet.iConversionData = &CnvPictograph1::ConversionData();
sl@0
   190
    // characterSet.iConvertFromIntermediateBufferInPlace =
sl@0
   191
    //     CnvPictographShared::ConvertToPictograph1InPlace;
sl@0
   192
    // characterSet.iEscapeSequence = &KLit8EscapeSequenceForPictograph1;
sl@0
   193
    // aArrayOfCharacterSets.Append(characterSet);
sl@0
   194
sl@0
   195
    }
sl@0
   196
sl@0
   197
// -----------------------------------------------------------------------------
sl@0
   198
// CnvPictographShared::SetMethodsForPictograph
sl@0
   199
// It sets parameters to SMethod array. It called in ConvertToUnicode().
sl@0
   200
// It makes possible that pictograph conversion is called from other conversion
sl@0
   201
// plug-ins.
sl@0
   202
// (other items were commented in a header).
sl@0
   203
// -----------------------------------------------------------------------------
sl@0
   204
//
sl@0
   205
void CnvPictographShared::SetMethodsForPictograph(
sl@0
   206
        RArray<CnvUtilities::SMethod>& aArrayOfMethods, TOriginalCharset aOriginalCharset)
sl@0
   207
    {
sl@0
   208
    TInt ret = KErrNone;
sl@0
   209
    CnvUtilities::SMethod method;
sl@0
   210
    switch (aOriginalCharset)
sl@0
   211
        {
sl@0
   212
        case ECharsetShiftJis:
sl@0
   213
            method.iNumberOfBytesAbleToConvert =
sl@0
   214
                CnvPictographShared::NumberOfBytesAbleToConvertSJisDirectMap;
sl@0
   215
            method.iConvertToIntermediateBufferInPlace =
sl@0
   216
                DummyConvertToIntermediateBufferInPlace;
sl@0
   217
            method.iConversionData =
sl@0
   218
                &CnvShiftJisDirectmap::ConversionData();
sl@0
   219
            method.iNumberOfBytesPerCharacter = 2;
sl@0
   220
            method.iNumberOfCoreBytesPerCharacter = 2;
sl@0
   221
            ret |= aArrayOfMethods.Append(method);
sl@0
   222
            break;
sl@0
   223
        case ECharsetEucJp:
sl@0
   224
            method.iNumberOfBytesAbleToConvert =
sl@0
   225
                CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap1;
sl@0
   226
            method.iConvertToIntermediateBufferInPlace =
sl@0
   227
                CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace;
sl@0
   228
            method.iConversionData =
sl@0
   229
                &CnvShiftJisDirectmap::ConversionData();
sl@0
   230
            method.iNumberOfBytesPerCharacter = 2;
sl@0
   231
            method.iNumberOfCoreBytesPerCharacter = 2;
sl@0
   232
            ret |= aArrayOfMethods.Append(method);
sl@0
   233
            method.iNumberOfBytesAbleToConvert =
sl@0
   234
                CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap2;
sl@0
   235
            method.iConvertToIntermediateBufferInPlace =
sl@0
   236
                CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace;
sl@0
   237
            method.iConversionData =
sl@0
   238
                &CnvShiftJisDirectmap::ConversionData();
sl@0
   239
            method.iNumberOfBytesPerCharacter = 3;
sl@0
   240
            method.iNumberOfCoreBytesPerCharacter = 2;
sl@0
   241
            ret |= aArrayOfMethods.Append(method);
sl@0
   242
            break;
sl@0
   243
        default:
sl@0
   244
            break;
sl@0
   245
        }
sl@0
   246
    __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret));
sl@0
   247
    // SAMPLE CODE
sl@0
   248
    // If this module needs to support escape sequence pictograph,
sl@0
   249
    // Remove the comment from the following code.
sl@0
   250
sl@0
   251
    // method.iNumberOfBytesAbleToConvert =
sl@0
   252
    //     CnvPictographShared::NumberOfBytesAbleToConvertToPicto1;
sl@0
   253
    // method.iConvertToIntermediateBufferInPlace =
sl@0
   254
    //     CnvPictographShared::ConvertToPictographFromUnicode;
sl@0
   255
    // method.iConversionData = &CnvPictograph1::ConversionData();
sl@0
   256
    // method.iNumberOfBytesPerCharacter = 1;
sl@0
   257
    // method.iNumberOfCoreBytesPerCharacter = 1;
sl@0
   258
    // aArrayOfMethods.Append(method);
sl@0
   259
    }
sl@0
   260
sl@0
   261
// -----------------------------------------------------------------------------
sl@0
   262
// CnvPictographShared::SetCharacterSetsForPictograph
sl@0
   263
// It sets parameters to SState array. It called in ConvertToUnicode().
sl@0
   264
// It makes possible that pictograph conversion is called from other
sl@0
   265
// conversion plug-ins.
sl@0
   266
// (other items were commented in a header).
sl@0
   267
// -----------------------------------------------------------------------------
sl@0
   268
//
sl@0
   269
void CnvPictographShared::SetCharacterSetsForPictograph(
sl@0
   270
        RArray<CnvUtilities::SCharacterSet>& aArrayOfStates,
sl@0
   271
        TOriginalCharset aOriginalCharset)
sl@0
   272
    {
sl@0
   273
    TInt ret = KErrNone;
sl@0
   274
    CnvUtilities::SCharacterSet characterSet;
sl@0
   275
    switch (aOriginalCharset)
sl@0
   276
        {
sl@0
   277
        case ECharsetShiftJis:
sl@0
   278
            // Append the character set for pictograph
sl@0
   279
            characterSet.iConversionData =
sl@0
   280
                &CnvShiftJisDirectmap::ConversionData();
sl@0
   281
            characterSet.iConvertFromIntermediateBufferInPlace =
sl@0
   282
                DummyConvertFromIntermediateBufferInPlace;
sl@0
   283
            characterSet.iEscapeSequence = &KNullDesC8;
sl@0
   284
            ret |= aArrayOfStates.Append(characterSet);
sl@0
   285
            break;
sl@0
   286
        case ECharsetEucJp:
sl@0
   287
            // Append the character set for pictograph1
sl@0
   288
            characterSet.iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
   289
            characterSet.iConvertFromIntermediateBufferInPlace =
sl@0
   290
                ConvertFromPictogaphToEucJpDirectmapInPlace;
sl@0
   291
            characterSet.iEscapeSequence = &KNullDesC8;
sl@0
   292
            ret |= aArrayOfStates.Append(characterSet);
sl@0
   293
sl@0
   294
            // Append the character set for pictograph2
sl@0
   295
            characterSet.iConversionData = &CnvShiftJisDirectmap::ConversionData();
sl@0
   296
            characterSet.iConvertFromIntermediateBufferInPlace =
sl@0
   297
                ConvertFromPictogaphToEucJpDirectmapInPlace;
sl@0
   298
            characterSet.iEscapeSequence = &KNullDesC8;
sl@0
   299
            ret |= aArrayOfStates.Append(characterSet);
sl@0
   300
            break;
sl@0
   301
        default:
sl@0
   302
            break;
sl@0
   303
        }
sl@0
   304
    __ASSERT_DEBUG(!ret, User::Panic(_L("RArray append failure"), ret));
sl@0
   305
    }
sl@0
   306
sl@0
   307
// -----------------------------------------------------------------------------
sl@0
   308
// CnvPictographShared::SetStatesForPictograph
sl@0
   309
// It sets parameters to SState array. It called in ConvertToUnicode().
sl@0
   310
// It makes possible that pictograph conversion is called from other
sl@0
   311
// conversion plug-ins.
sl@0
   312
// (other items were commented in a header).
sl@0
   313
// -----------------------------------------------------------------------------
sl@0
   314
//
sl@0
   315
void CnvPictographShared::SetStatesForPictograph(
sl@0
   316
        RArray<CnvUtilities::SState>& /*aArrayOfStates*/)
sl@0
   317
    {
sl@0
   318
    // SAMPLE CODE
sl@0
   319
    // If this module needs to support escape sequence pictograph,
sl@0
   320
    // Remove the comment from the following code.
sl@0
   321
sl@0
   322
    // CnvUtilities::SState state;
sl@0
   323
    // state.iEscapeSequence = &KLit8EscapeSequenceForPictograph1;
sl@0
   324
    // state.iConversionData = &CnvPictograph1::ConversionData();
sl@0
   325
    // aArrayOfStates.Append(state);
sl@0
   326
    }
sl@0
   327
sl@0
   328
// -----------------------------------------------------------------------------
sl@0
   329
// CnvPictographShared::ConvertToPictograph1InPlace
sl@0
   330
// It converts from an intermediate buffer to a pictograph code.
sl@0
   331
// After that, it adds shift-in code(0x0F).
sl@0
   332
// (other items were commented in a header).
sl@0
   333
// -----------------------------------------------------------------------------
sl@0
   334
//
sl@0
   335
// void CnvPictographShared::ConvertToPictograph1InPlace(
sl@0
   336
//         TInt aStartPositionInDescriptor,
sl@0
   337
//         TDes8& aDescriptor, TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   338
//     {
sl@0
   339
//     CnvUtilities::ConvertFromIntermediateBufferInPlace(
sl@0
   340
//         aStartPositionInDescriptor, aDescriptor,
sl@0
   341
//         aNumberOfCharactersThatDroppedOut,
sl@0
   342
//         KLit8EscapeSequenceForPictograph1, 1);
sl@0
   343
//     AppendShiftIn(aDescriptor, aNumberOfCharactersThatDroppedOut);
sl@0
   344
//     }
sl@0
   345
sl@0
   346
sl@0
   347
// -----------------------------------------------------------------------------
sl@0
   348
// CnvPictographShared::NumberOfBytesAbleToConvertToPicto1
sl@0
   349
// It returns a number of bytes that the conversion to pictograph is
sl@0
   350
// possible in the descriptor.
sl@0
   351
// (other items were commented in a header).
sl@0
   352
// -----------------------------------------------------------------------------
sl@0
   353
//
sl@0
   354
TInt CnvPictographShared::NumberOfBytesAbleToConvertSJisDirectMap(
sl@0
   355
        const TDesC8& aDescriptor)
sl@0
   356
    {
sl@0
   357
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr()-1;
sl@0
   358
    const TUint8* const pointerToLastByte =
sl@0
   359
            pointerToPreviousByte + aDescriptor.Length();
sl@0
   360
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
   361
        {
sl@0
   362
        return 0;
sl@0
   363
        }
sl@0
   364
    for (; pointerToPreviousByte < pointerToLastByte; )
sl@0
   365
        {
sl@0
   366
        const TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   367
        const TUint nextByte = *(pointerToPreviousByte + 2);
sl@0
   368
        if (((currentByte < KSingleByteRangeFirstBlockStart) ||
sl@0
   369
             (currentByte > KSingleByteRangeFirstBlockEnd)) ||
sl@0
   370
            ((nextByte < KSingleByteRangeSecondBlockStart) ||
sl@0
   371
             (nextByte > KSingleByteRangeSecondBlockEnd)))
sl@0
   372
            {
sl@0
   373
            break;
sl@0
   374
            }
sl@0
   375
        pointerToPreviousByte += 2;
sl@0
   376
        }
sl@0
   377
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
   378
    }
sl@0
   379
sl@0
   380
// -----------------------------------------------------------------------------
sl@0
   381
// NumberOfBytesAbleToConvertToEucJpDirectMap1
sl@0
   382
//
sl@0
   383
// -----------------------------------------------------------------------------
sl@0
   384
//
sl@0
   385
TInt CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap1(
sl@0
   386
        const TDesC8& aDescriptor)
sl@0
   387
    {
sl@0
   388
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
   389
    const TUint8* const pointerToLastByte =
sl@0
   390
        pointerToPreviousByte + aDescriptor.Length();
sl@0
   391
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
   392
        {
sl@0
   393
        return 0;
sl@0
   394
        }
sl@0
   395
    for (;pointerToPreviousByte < pointerToLastByte;)
sl@0
   396
        {
sl@0
   397
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   398
        const TUint nextByte = *(pointerToPreviousByte + 2);
sl@0
   399
        if (((currentByte < KFirstByteRangeFirstBlockStart) ||
sl@0
   400
             (currentByte > KFirstByteRangeFirstBlockEnd)) ||
sl@0
   401
            ((nextByte < KSecondByteRangeSecondBlockStart) ||
sl@0
   402
             (nextByte > KSecondByteRangeSecondBlockEnd)))
sl@0
   403
            {
sl@0
   404
            break;
sl@0
   405
            }
sl@0
   406
        pointerToPreviousByte += 2;
sl@0
   407
        }
sl@0
   408
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
   409
    }
sl@0
   410
sl@0
   411
// -----------------------------------------------------------------------------
sl@0
   412
// NumberOfBytesAbleToConvertToPictograph
sl@0
   413
//
sl@0
   414
// -----------------------------------------------------------------------------
sl@0
   415
//
sl@0
   416
TInt CnvPictographShared::NumberOfBytesAbleToConvertToEucJpDirectMap2(
sl@0
   417
        const TDesC8& aDescriptor)
sl@0
   418
    {
sl@0
   419
    const TUint8* pointerToPreviousByte = aDescriptor.Ptr() - 1;
sl@0
   420
    const TUint8* const pointerToLastByte =
sl@0
   421
        pointerToPreviousByte + aDescriptor.Length();
sl@0
   422
    if (pointerToPreviousByte == pointerToLastByte)
sl@0
   423
        {
sl@0
   424
        return 0;
sl@0
   425
        }
sl@0
   426
    for (;pointerToPreviousByte < pointerToLastByte;)
sl@0
   427
        {
sl@0
   428
        TUint currentByte = *(pointerToPreviousByte + 1);
sl@0
   429
        if (currentByte == KSingleShift3)
sl@0
   430
            {
sl@0
   431
            pointerToPreviousByte++;
sl@0
   432
            currentByte = *(pointerToPreviousByte + 1);
sl@0
   433
            }
sl@0
   434
        else
sl@0
   435
            {
sl@0
   436
            break;
sl@0
   437
            }
sl@0
   438
        if (currentByte < 0xa0)
sl@0
   439
            {
sl@0
   440
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
   441
            }
sl@0
   442
        const TUint nextByte = *(pointerToPreviousByte + 2);
sl@0
   443
        if (nextByte < 0xa0)
sl@0
   444
            {
sl@0
   445
            return CCnvCharacterSetConverter::EErrorIllFormedInput;
sl@0
   446
            }
sl@0
   447
        if (((currentByte < KFirstByteRangeFirstBlockStart) ||
sl@0
   448
             (currentByte > KFirstByteRangeFirstBlockEnd)) ||
sl@0
   449
            ((nextByte < KSecondByteRangeSecondBlockStart) ||
sl@0
   450
             (nextByte > KSecondByteRangeSecondBlockEnd)))
sl@0
   451
            {
sl@0
   452
            // return the previous byte to the beginning of loop.
sl@0
   453
            pointerToPreviousByte--;
sl@0
   454
            break;
sl@0
   455
            }
sl@0
   456
        pointerToPreviousByte += 2;
sl@0
   457
        }
sl@0
   458
    return (pointerToPreviousByte + 1) - aDescriptor.Ptr();
sl@0
   459
    }
sl@0
   460
sl@0
   461
// -----------------------------------------------------------------------------
sl@0
   462
// CnvPictographShared::NumberOfBytesAbleToConvertToPicto1
sl@0
   463
// It returns a number of bytes that the conversion to pictograph is
sl@0
   464
// possible in the descriptor.
sl@0
   465
// (other items were commented in a header).
sl@0
   466
// -----------------------------------------------------------------------------
sl@0
   467
//
sl@0
   468
TInt CnvPictographShared::NumberOfBytesAbleToConvertToPicto1(
sl@0
   469
        const TDesC8& aDescriptor)
sl@0
   470
    {
sl@0
   471
    return NumberOfBytesAbleToConvertToPictograph(aDescriptor,
sl@0
   472
        KIntermediateBuffer1);
sl@0
   473
    }
sl@0
   474
sl@0
   475
// -----------------------------------------------------------------------------
sl@0
   476
// CnvPictographShared::NumberOfBytesAbleToConvertToPictograph
sl@0
   477
// It's a common function for checking the number of bytes that the conversion
sl@0
   478
// to pictograph
sl@0
   479
// (other items were commented in a header).
sl@0
   480
// -----------------------------------------------------------------------------
sl@0
   481
//
sl@0
   482
TInt CnvPictographShared::NumberOfBytesAbleToConvertToPictograph(
sl@0
   483
        const TDesC8& aDescriptor, TInt aIntermidiateCode)
sl@0
   484
    {
sl@0
   485
    TInt compLen(KLit8EscapeSequenceForPictograph().Length());
sl@0
   486
    TInt ret(0);
sl@0
   487
    if (aDescriptor.Left(compLen) == KLit8EscapeSequenceForPictograph)
sl@0
   488
        {
sl@0
   489
        const TInt intermidiateBuff = aDescriptor[compLen];
sl@0
   490
        if (intermidiateBuff == aIntermidiateCode)
sl@0
   491
            {
sl@0
   492
            ret = compLen + 2;
sl@0
   493
sl@0
   494
            const TInt descriptorLength = aDescriptor.Length();
sl@0
   495
            const TUint8* pointerToCurrentByte = aDescriptor.Ptr();
sl@0
   496
            const TUint8* pointerToLastByte = pointerToCurrentByte +
sl@0
   497
                (descriptorLength - 1);
sl@0
   498
            pointerToCurrentByte += compLen + 2;
sl@0
   499
            for (; pointerToCurrentByte <= pointerToLastByte;
sl@0
   500
                 pointerToCurrentByte++)
sl@0
   501
                {
sl@0
   502
                if (*pointerToCurrentByte == KShiftIn)
sl@0
   503
                    {
sl@0
   504
                    ret++;
sl@0
   505
                    break;
sl@0
   506
                    }
sl@0
   507
                if (*pointerToCurrentByte == KEscape)
sl@0
   508
                    break;
sl@0
   509
                ret++;
sl@0
   510
                }
sl@0
   511
            }
sl@0
   512
        }
sl@0
   513
    return ret;
sl@0
   514
    }
sl@0
   515
sl@0
   516
// -----------------------------------------------------------------------------
sl@0
   517
// CnvPictographShared::ConvertToPictographFromUnicode
sl@0
   518
// It converts the string which includes a pictograph's escape sequence
sl@0
   519
// to unicode.
sl@0
   520
// (other items were commented in a header).
sl@0
   521
// -----------------------------------------------------------------------------
sl@0
   522
//
sl@0
   523
void CnvPictographShared::ConvertToPictographFromUnicode(TDes8& aDescriptor)
sl@0
   524
    {
sl@0
   525
    const TInt descriptorLength = aDescriptor.Length();
sl@0
   526
    TUint8* pointerToCurrentByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   527
    TUint8* pointerToDataByte = pointerToCurrentByte +
sl@0
   528
        KLit8EscapeSequenceForPictograph().Length();
sl@0
   529
    const TUint8* const pointerToLastByte = pointerToCurrentByte +
sl@0
   530
        (descriptorLength - 1);
sl@0
   531
    const TUint8* const pointerToFirstByte = pointerToCurrentByte;
sl@0
   532
    pointerToDataByte++;
sl@0
   533
sl@0
   534
    for (; pointerToDataByte <= pointerToLastByte; pointerToDataByte++)
sl@0
   535
        {
sl@0
   536
        if (*pointerToDataByte != KShiftIn)
sl@0
   537
            {
sl@0
   538
            *pointerToCurrentByte = *pointerToDataByte;
sl@0
   539
            pointerToCurrentByte++;
sl@0
   540
            }
sl@0
   541
        }
sl@0
   542
    aDescriptor.SetLength(pointerToCurrentByte - pointerToFirstByte);
sl@0
   543
    }
sl@0
   544
sl@0
   545
// -----------------------------------------------------------------------------
sl@0
   546
// CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace
sl@0
   547
// Converts from EucJp packed Pictograph to Unicode
sl@0
   548
// -----------------------------------------------------------------------------
sl@0
   549
//
sl@0
   550
void CnvPictographShared::ConvertToPictographFromEucJpPackedInPlace(TDes8& aDescriptor)
sl@0
   551
    {
sl@0
   552
    const TInt descriptorLength = aDescriptor.Length();
sl@0
   553
    TUint8* pointerToTargetByte = CONST_CAST(TUint8*, aDescriptor.Ptr());
sl@0
   554
    const TUint8* pointerToSourceByte = pointerToTargetByte;
sl@0
   555
    const TUint8* const pointerToLastByte =
sl@0
   556
        pointerToSourceByte + (descriptorLength - 1);
sl@0
   557
    TInt bytesPerCharacter = 2;
sl@0
   558
    TInt sjisStartbyte = KSingleByteRangeFirstBlockStart;
sl@0
   559
    if (*pointerToSourceByte == KSingleShift3)
sl@0
   560
        {
sl@0
   561
        ++pointerToSourceByte;
sl@0
   562
        bytesPerCharacter = 3;
sl@0
   563
        sjisStartbyte = KEUCJPSecondBlockStart;
sl@0
   564
        }
sl@0
   565
    for (;pointerToSourceByte < pointerToLastByte; )
sl@0
   566
        {
sl@0
   567
        TUint firstByte = (*pointerToSourceByte
sl@0
   568
            - KFirstByteRangeFirstBlockStart) / 2 + sjisStartbyte;
sl@0
   569
        TUint secondByte = *(pointerToSourceByte + 1);
sl@0
   570
        if ((*pointerToSourceByte % 2) == 0)
sl@0
   571
            {
sl@0
   572
            secondByte += KSingleByteRangeSecondBlockStart - KSecondByteRangeSecondBlockStart
sl@0
   573
                + KEUCJPBlockSize + 1;
sl@0
   574
            if (secondByte >= KShiftJisTrailByteIllegal)
sl@0
   575
                secondByte++;
sl@0
   576
            }
sl@0
   577
        else
sl@0
   578
            {
sl@0
   579
            secondByte += KSingleByteRangeSecondBlockStart - KSecondByteRangeSecondBlockStart;
sl@0
   580
            if (secondByte >= KShiftJisTrailByteIllegal)
sl@0
   581
                secondByte++;
sl@0
   582
            }
sl@0
   583
        *pointerToTargetByte = static_cast<TUint8>(firstByte);
sl@0
   584
sl@0
   585
        ++pointerToTargetByte;
sl@0
   586
        *pointerToTargetByte = static_cast<TUint8>(secondByte);
sl@0
   587
        pointerToSourceByte += 2;
sl@0
   588
        ++pointerToTargetByte;
sl@0
   589
        }
sl@0
   590
    aDescriptor.SetLength((descriptorLength / bytesPerCharacter) * 2);
sl@0
   591
    }
sl@0
   592
sl@0
   593
// -----------------------------------------------------------------------------
sl@0
   594
// CnvPictographShared::AppendShiftIn
sl@0
   595
// It appends a shift-in code to the descriptor.
sl@0
   596
// (other items were commented in a header).
sl@0
   597
// -----------------------------------------------------------------------------
sl@0
   598
//
sl@0
   599
void CnvPictographShared::AppendShiftIn(TDes8& aDescriptor,
sl@0
   600
        TInt& aNumberOfCharactersThatDroppedOut)
sl@0
   601
    {
sl@0
   602
    if (aDescriptor.MaxLength() > aDescriptor.Length())
sl@0
   603
        {
sl@0
   604
        aDescriptor.Append(KShiftIn);
sl@0
   605
        }
sl@0
   606
    else
sl@0
   607
        {
sl@0
   608
        aNumberOfCharactersThatDroppedOut++;
sl@0
   609
        }
sl@0
   610
    }
sl@0
   611
sl@0
   612
// ========================== OTHER EXPORTED FUNCTIONS =========================
sl@0
   613
sl@0
   614
// -----------------------------------------------------------------------------
sl@0
   615
// SetCharacterSetsForPictograph()
sl@0
   616
// It sets parameters to SCharacterSet array.
sl@0
   617
// It called in ConvertFromUnicode().
sl@0
   618
// It makes possible that pictograph conversion is called from other
sl@0
   619
// conversion plug-ins.
sl@0
   620
// @since 2.6
sl@0
   621
// @param aArrayOfCharacterSets The conversion table array
sl@0
   622
// -----------------------------------------------------------------------------
sl@0
   623
//
sl@0
   624
EXPORT_C void SetCharacterSetsForPictograph(
sl@0
   625
            RArray<CnvUtilities::SCharacterSet>& aArrayOfCharacterSets)
sl@0
   626
    {
sl@0
   627
    CnvPictographShared::SetCharacterSetsForPictograph(aArrayOfCharacterSets);
sl@0
   628
    }
sl@0
   629
sl@0
   630
// -----------------------------------------------------------------------------
sl@0
   631
// SetCharacterSetsForPictograph()
sl@0
   632
// It sets parameters to SCharacterSet array.
sl@0
   633
// It called in ConvertFromUnicode().
sl@0
   634
// It makes possible that pictograph conversion is called from other
sl@0
   635
// conversion plug-ins.
sl@0
   636
// @since 2.6
sl@0
   637
// @param aArrayOfCharacterSets The conversion table array
sl@0
   638
// @param aOriginalCharset The character set
sl@0
   639
// -----------------------------------------------------------------------------
sl@0
   640
//
sl@0
   641
EXPORT_C void SetCharacterSetsForPictograph(
sl@0
   642
            RArray<CnvUtilities::SCharacterSet>& aArrayOfCharacterSets,
sl@0
   643
            TOriginalCharset aOriginalCharset)
sl@0
   644
    {
sl@0
   645
    CnvPictographShared::SetCharacterSetsForPictograph(aArrayOfCharacterSets,
sl@0
   646
                                                       aOriginalCharset);
sl@0
   647
    }
sl@0
   648
sl@0
   649
// -----------------------------------------------------------------------------
sl@0
   650
// SetMethodsForPictograph()
sl@0
   651
// It sets parameters to SMethod array.
sl@0
   652
// It called in ConvertToUnicode().
sl@0
   653
// It makes possible that pictograph conversion is called from other
sl@0
   654
// conversion plug-ins.
sl@0
   655
// @since 2.6
sl@0
   656
// @param aArrayOfMethods The conversion table array
sl@0
   657
// @param aOriginalCharset The character set
sl@0
   658
// -----------------------------------------------------------------------------
sl@0
   659
//
sl@0
   660
EXPORT_C void SetMethodsForPictograph(
sl@0
   661
            RArray<CnvUtilities::SMethod>& aArrayOfMethods,
sl@0
   662
            TOriginalCharset aOriginalCharset)
sl@0
   663
    {
sl@0
   664
    CnvPictographShared::SetMethodsForPictograph(aArrayOfMethods,
sl@0
   665
        aOriginalCharset);
sl@0
   666
    }
sl@0
   667
sl@0
   668
// -----------------------------------------------------------------------------
sl@0
   669
// SetStatesForPictograph()
sl@0
   670
// It sets parameters to SState array.
sl@0
   671
// It called in ConvertToUnicode().
sl@0
   672
// It makes possible that pictograph conversion is called from other
sl@0
   673
// conversion plug-ins.
sl@0
   674
// @since 2.6
sl@0
   675
// @param aArrayOfMethods The conversion table array
sl@0
   676
// -----------------------------------------------------------------------------
sl@0
   677
//
sl@0
   678
EXPORT_C void SetStatesForPictograph(
sl@0
   679
            RArray<CnvUtilities::SState>& aArrayOfStates)
sl@0
   680
    {
sl@0
   681
    CnvPictographShared::SetStatesForPictograph(aArrayOfStates);
sl@0
   682
    }
sl@0
   683
sl@0
   684
// -----------------------------------------------------------------------------
sl@0
   685
// CountOfPictographPagesFromUnicode()
sl@0
   686
// It returns count of pictograph pages.
sl@0
   687
// This method is used for the conversion from Unicode to foreign character
sl@0
   688
// set.
sl@0
   689
// @since 2.6
sl@0
   690
// @return count of pictograph pages.
sl@0
   691
// -----------------------------------------------------------------------------
sl@0
   692
//
sl@0
   693
EXPORT_C TInt CountOfPictographPagesFromUnicode()
sl@0
   694
    {
sl@0
   695
    return KCountOfPictoPages;
sl@0
   696
    }
sl@0
   697
sl@0
   698
// -----------------------------------------------------------------------------
sl@0
   699
// CountOfPictographPagesToUnicode()
sl@0
   700
// It returns count of pictograph pages.
sl@0
   701
// This method is used for the conversion from foreign character set to
sl@0
   702
// Unicode.
sl@0
   703
// @since 2.6
sl@0
   704
// @return count of pictograph pages.
sl@0
   705
// -----------------------------------------------------------------------------
sl@0
   706
//
sl@0
   707
EXPORT_C TInt CountOfPictographPagesToUnicode()
sl@0
   708
    {
sl@0
   709
    return KCountOfPictoPages + 1;
sl@0
   710
    }
sl@0
   711
sl@0
   712
//  End of File