Changeset 17536 in webkit


Ignore:
Timestamp:
Nov 2, 2006 8:13:35 AM (17 years ago)
Author:
spadma
Message:

2006-11-01 w3liu <wei.liu@nokia.com>

Reviewed by <yongjun.zhang@nokia.com>
DESC: Thai text rendering fails when using HTTPS.
http://bugs.webkit.org/show_bug.cgi?id=11486
WARNING: NO TEST CASES ADDED OR CHANGED

  • ChangeLog:
  • kwq/KWQTextCodec.cpp: (KWQTextDecoder::KWQTextDecoder): (KWQTextDecoder::~KWQTextDecoder): (QTextCodec::~QTextCodec): (QTextCodec::makeDecoder): (QTextCodec::toUnicode): (KWQTextDecoder::toUnicode): (QTextCodec::PrepareForExit):
  • kwq/KWQTextCodec.h:


Merge from r17535 from main branch

Location:
S60/branches/3.1m/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • S60/branches/3.1m/WebCore/ChangeLog

    r17335 r17536  
     12006-11-01  w3liu  <wei.liu@nokia.com>
     2
     3        Reviewed by <yongjun.zhang@nokia.com>
     4        DESC: Thai text rendering fails when using HTTPS.
     5        http://bugs.webkit.org/show_bug.cgi?id=11486
     6        WARNING: NO TEST CASES ADDED OR CHANGED
     7
     8        * ChangeLog:
     9        * kwq/KWQTextCodec.cpp:
     10        (KWQTextDecoder::KWQTextDecoder):
     11        (KWQTextDecoder::~KWQTextDecoder):
     12        (QTextCodec::~QTextCodec):
     13        (QTextCodec::makeDecoder):
     14        (QTextCodec::toUnicode):
     15        (KWQTextDecoder::toUnicode):
     16        (QTextCodec::PrepareForExit):
     17        * kwq/KWQTextCodec.h:
     18       
     19        Merge from r17535 from main branch
     20
     212006-11-01  w3liu  <wei.liu@nokia.com>
     22
     23        Reviewed by <yongjun.zhang@nokia.com>
     24        DESC:
     25        http://bugs.webkit.org/show_bug.cgi?id=11486
     26        Thai text rendering fails when using HTTPS
     27
     28        WARNING: NO TEST CASES ADDED OR CHANGED
     29
     30        * kwq/KWQTextCodec.cpp:
     31        (KWQTextDecoder::KWQTextDecoder):
     32        (QTextCodec::~QTextCodec):
     33        (QTextCodec::makeDecoder):
     34        (QTextCodec::toUnicode):
     35        (KWQTextDecoder::toUnicode):
     36        * kwq/KWQTextCodec.h:
     37
    1382006-10-25  raalexan  <rasvan.alexandrescu@nokia.com>
    239
  • S60/branches/3.1m/WebCore/kwq/KWQTextCodec.cpp

    r17335 r17536  
    3333#include "KWQKDebug.h"
    3434
     35#define _DEBUG1 0
     36#ifdef _DEBUG1
     37#include <flogger.h>
     38#endif
    3539#define BrDefaultEnc KCharacterSetIdentifierIso88591;
    3640#define BrDefaultEncStr "iso-8859-1";
     
    4650friend class QTextCodec;
    4751public:
    48     KWQTextDecoder(TUint aEnc) : iEncoding(aEnc)  {}
    49     ~KWQTextDecoder()                 {}
     52    KWQTextDecoder(TUint aEnc) : iEncoding(aEnc), iRemainderBuf(NULL)   {}
     53    ~KWQTextDecoder()                 { delete iRemainderBuf; }
    5054
    5155    QString toUnicode(const char *chs, int len, bool flush);
    5256    QCString fromUnicode(const QString &);
    5357    bool IsConversionSupportedL();
    54   QString windows125xToUnicode( const char *chs, int len );
     58    QString windows125xToUnicode( const char *chs, int len );
    5559
    5660private:
     
    6064    static CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* iArrayOfCharacterSetsAvailable;
    6165    TUint iEncoding;
     66    HBufC8 * iRemainderBuf;
    6267};
    6368
     
    8893    }
    8994}
     95
     96QTextCodec::~QTextCodec()
     97{ delete iQTextDecoder; }
    9098
    9199bool validateUtf8(const char* chs, int len, int& validMultiByteChars)
     
    221229QTextDecoder *QTextCodec::makeDecoder() const
    222230{
    223     return new KWQTextDecoder( iEncoding );
     231    return iQTextDecoder? iQTextDecoder : new KWQTextDecoder( iEncoding );
    224232}
    225233
     
    231239QString QTextCodec::toUnicode(const char *chs, int len) const
    232240{
    233     return KWQTextDecoder( iEncoding ).toUnicode(chs, len, true);
     241    return makeDecoder()->toUnicode(chs, len, true);
    234242}
    235243
     
    308316    }
    309317
    310     /**
     318 /**
    311319 * Converts the text buffer from one encoding to Unicode
    312320 * If the indicated charset is not supported, or its converter is not available,
     
    315323QString KWQTextDecoder::toUnicode(const char *chs, int len, bool flush)
    316324    {
    317     // make sure the converter is available
    318 
    319   int bomLength = 0;
    320   TUint encoding = iEncoding;
    321   CCnvCharacterSetConverter::TEndianness endianness = CCnvCharacterSetConverter::ELittleEndian;
    322 
    323   if (len > 2 && chs[0] == FF && chs[1] == FE) {
    324         encoding = KCharacterSetIdentifierUnicodeLittle;
     325
     326    bool lastChunk = (len == 0)? true : false;
     327    int bomLength = 0;
     328    HBufC8 * inHBuf = NULL;     // buffer to hold combination of remainder and next chunk
     329    CCnvCharacterSetConverter::TEndianness endianness = CCnvCharacterSetConverter::ELittleEndian;
     330
     331    if (len > 2 && chs[0] == FF && chs[1] == FE)
     332        {
     333        iEncoding = KCharacterSetIdentifierUnicodeLittle;
    325334        bomLength = 2;
    326     } else if (len > 2 && chs[0] == FE && chs[1] == FF) {
    327         encoding = KCharacterSetIdentifierUnicodeBig;
    328     endianness = CCnvCharacterSetConverter::EBigEndian;
     335        }
     336    else if (len > 2 && chs[0] == FE && chs[1] == FF)
     337        {
     338        iEncoding = KCharacterSetIdentifierUnicodeBig;
     339        endianness = CCnvCharacterSetConverter::EBigEndian;
    329340        bomLength = 2;
    330     } else if (len > 3 && chs[0] == EF && chs[1] == BB && chs[2] == BF) {
    331         encoding = KCharacterSetIdentifierUtf8;
     341        }
     342    else if (len > 3 && chs[0] == EF && chs[1] == BB && chs[2] == BF)
     343        {
     344        iEncoding = KCharacterSetIdentifierUtf8;
    332345        bomLength = 3;
    333     }
     346        }
    334347
    335348    if (!IsConversionSupportedL())
    336     {
    337     iEncoding = KCharacterSetIdentifierIso88591;
    338     }
     349        {
     350        iEncoding = KCharacterSetIdentifierIso88591;
     351        }
    339352
    340353    // check if it really looks like valid utf-8
    341     if (iEncoding == KCharacterSetIdentifierUtf8 && bomLength==0) {
     354    if (iEncoding == KCharacterSetIdentifierUtf8 && bomLength==0)
     355        {
    342356        int validMultibyteChars;
    343357        bool validUtf8 = validateUtf8(chs, Min(len,32*1024),validMultibyteChars);
     
    345359        if (!validUtf8 && validMultibyteChars<3)
    346360            iEncoding = KCharacterSetIdentifierIso88591;
    347     }
     361        }
    348362
    349363    if (iEncoding == KCharacterSetIdentifierIso88591)
     364        {
    350365        return convertLatin1(reinterpret_cast<const unsigned char *>(chs), len);
    351   else if(iEncoding == KCharacterSetIdentifierWindow1250 ||
    352       iEncoding == KCharacterSetIdentifierWindow1251 ||
    353       iEncoding == KCharacterSetIdentifierWindow1253 ||
    354       iEncoding == KCharacterSetIdentifierWindow1256 ||
    355       iEncoding == KCharacterSetIdentifierWindow1257
    356       ) // work around for Symbian converter hanging when converting windows-125x charset
    357     {
    358     return windows125xToUnicode( chs, len );
    359     }
     366        }
     367    else if(iEncoding == KCharacterSetIdentifierWindow1250 ||
     368        iEncoding == KCharacterSetIdentifierWindow1251 ||
     369        iEncoding == KCharacterSetIdentifierWindow1253 ||
     370        iEncoding == KCharacterSetIdentifierWindow1256 ||
     371        iEncoding == KCharacterSetIdentifierWindow1257
     372        ) // work around for Symbian converter hanging when converting windows-125x charset
     373        {
     374        return windows125xToUnicode( chs, len );
     375        }
     376
     377#if _DEBUG1
     378    // print out the incoming buffer to a file for debugging purpose
     379    if (len)
     380        RFileLogger::HexDump( _L("Browser"), _L("text_chunks.txt"), EFileLoggingModeAppend,
     381        NULL, NULL, (const TUint8*)chs, len );
     382#endif // _DEBUG1
    360383
    361384    CCnvCharacterSetConverter* charConv = KWQGlobalServices::InstanceL()->CharConv();
     
    363386
    364387    // check if the target charset is supported
    365     charConv->PrepareToConvertToOrFromL( encoding, *iArrayOfCharacterSetsAvailable, fileSession );
     388    charConv->PrepareToConvertToOrFromL( iEncoding, *iArrayOfCharacterSetsAvailable, fileSession );
    366389    charConv->SetDefaultEndiannessOfForeignCharacters( endianness );
    367390    TBuf16<32> tmpBuf;
    368391    TBuf16<32> outBuf;
    369392
    370   len = len - bomLength ;
     393    len = len - bomLength ;
    371394    TPtrC8  inBuf( (const TUint8*)chs + bomLength, len );
    372     TInt state=CCnvCharacterSetConverter::KStateDefault;
     395    TInt state = CCnvCharacterSetConverter::KStateDefault;
    373396
    374397    // guess the output size
     
    381404    // reserve function reserves 3*len of bytes in momery, to achieve 2*len, times factor of 2/3
    382405    result.reserve( len*2/3 + 1 );
     406
     407    if (iRemainderBuf && iRemainderBuf->Length())
     408        {
     409        inHBuf = HBufC8::NewL(iRemainderBuf->Length() + len);
     410        inHBuf->Des().Append(iRemainderBuf->Des());
     411        inHBuf->Des().Append((const unsigned char *)chs, len);
     412        delete iRemainderBuf;
     413        iRemainderBuf = NULL;
     414        inBuf.Set(inHBuf->Des());
     415        }
     416
    383417    for(;;)
    384418        {
     
    387421        TInt ret = charConv->ConvertToUnicode( tmpBuf, inBuf, state, rep, rIndx );
    388422        if (ret==CCnvCharacterSetConverter::EErrorIllFormedInput )
     423            {
     424            // in case the error is caused by incomplete character at end of chunk
     425            if (inBuf.Length() < 3 && !lastChunk)
     426                {
     427                iRemainderBuf = HBufC8::NewL(inBuf.Length());
     428                iRemainderBuf->Des().Append(inBuf);
     429                }
    389430            break;
     431            }
    390432
    391433        // copy result to out buffer
    392 
    393     if(ret == -1 )
    394       {
    395       // if there are no sifficient character to be converted to unicode,
    396       // just append the rest to the characters to the result string.
    397       result.append( (char *)inBuf.Ptr(), inBuf.Length() );
    398       }
    399     else
    400       {
    401       // ### FIXME NOKIA: is it correct to remove the replacement 0xFFFD chars here?
    402       // Maybe we need to replace it with space character
    403 
    404       TPtr outPtr( 0, 0 );
    405 
    406       // there is some illegal/unconvertible chars
    407       // try to create a buffer with all 0xFFFD chars trimmed
    408       if (rep != 0 && rIndx < tmpBuf.Length() )
    409         {
    410         TInt i=rIndx;
    411         // first copy the part of buffer before the first 0xFFFD char
    412         outBuf.Append(tmpBuf.Left(i++));
    413         rep--;
    414         // search for more occurance of 0xFFFD chars
    415         // and append valid chars before the last 0xFFFD char
    416         // if there is only one 0xFFFD char, wouldn't enter the loop
    417         for( ; rep && i<tmpBuf.Length(); i++ )
    418           {
    419           if( tmpBuf[i] != 0xFFFD )
    420             outBuf.Append( tmpBuf[i] );
    421           else
    422             rep--;
    423           }
    424         // append the chars after last 0xFFFD char
    425         outBuf.Append(tmpBuf.Right(tmpBuf.Length() - i));
    426         outPtr.Set( (TUint16*)outBuf.Ptr(), outBuf.Length(), outBuf.Length() );
    427         outBuf.Zero();
    428 
    429         }
    430       else outPtr.Set( (TUint16*)tmpBuf.Ptr(), tmpBuf.Length(), tmpBuf.Length()  );
     434        TPtr outPtr( 0, 0 );
     435
     436        // there is some illegal/unconvertible chars
     437        // try to create a buffer with all 0xFFFD chars trimmed
     438        if (rep != 0)
     439            {
     440            if (inBuf.Length() <= 64 && !lastChunk)
     441                {
     442                iRemainderBuf = HBufC8::NewL(inBuf.Length());
     443                iRemainderBuf->Des().Append(inBuf);
     444                break;
     445                }
     446
     447            TInt i= (rIndx -1 )/2;
     448            // first copy the part of buffer before the first 0xFFFD char
     449            outBuf.Append(tmpBuf.Left(i));
     450            // search for more occurance of 0xFFFD chars
     451            // and append valid chars before the last 0xFFFD char
     452            // if there is only one 0xFFFD char, wouldn't enter the loop
     453            for( ; rep && i<tmpBuf.Length(); i++ )
     454                {
     455                if( tmpBuf[i] != 0xFFFD )
     456                    outBuf.Append( tmpBuf[i] );
     457                else
     458                    rep--;
     459                }
     460            // append the chars after last 0xFFFD char
     461            outBuf.Append(tmpBuf.Right(tmpBuf.Length() - i));
     462            outPtr.Set( (TUint16*)outBuf.Ptr(), outBuf.Length(), outBuf.Length() );
     463            outBuf.Zero();
     464            }
     465        else outPtr.Set( (TUint16*)tmpBuf.Ptr(), tmpBuf.Length(), tmpBuf.Length() );
    431466
    432467        // append the buffers to final result, will reincrease the size in needed
    433468        result.append( (const QChar*)(outPtr.Ptr()), outPtr.Length() );
    434       }
    435469
    436470        if( ret == 0  || ret == -1 ) break;
     
    440474
    441475    OOM_POST_CHECK_FAILED( return result; )
     476
     477    delete inHBuf;
    442478    return result;
    443479    }
     
    530566void QTextCodec::PrepareForExit()
    531567{
    532     CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arr 
     568    CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arr
    533569                = KWQTextDecoder::iArrayOfCharacterSetsAvailable;
    534570
  • S60/branches/3.1m/WebCore/kwq/KWQTextCodec.h

    r14549 r17536  
    4343
    4444    QTextCodec( TUint aEnc, KWQEncodingFlags f = NoEncodingFlags ) : iEncoding( aEnc ), _flags(f)          {}
     45    ~QTextCodec();
    4546    const char *name() const;
    4647    bool usesVisualOrdering() const { return _flags & VisualOrdering; }
     
    6263
    6364private:
    64         TUint           iEncoding;
     65    TUint       iEncoding;
    6566    KWQEncodingFlags _flags;
     67    QTextDecoder * iQTextDecoder;
    6668};
    6769
     
    7274{
    7375public:
    74     virtual ~QTextDecoder()                                                                                     {}
     76    virtual ~QTextDecoder()                                         {}
    7577    virtual QString toUnicode(const char *, int, bool flush = false) = 0;
    7678};
Note: See TracChangeset for help on using the changeset viewer.