Changeset 17536 in webkit
- Timestamp:
- Nov 2, 2006 8:13:35 AM (17 years ago)
- Location:
- S60/branches/3.1m/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
S60/branches/3.1m/WebCore/ChangeLog
r17335 r17536 1 2006-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 21 2006-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 1 38 2006-10-25 raalexan <rasvan.alexandrescu@nokia.com> 2 39 -
S60/branches/3.1m/WebCore/kwq/KWQTextCodec.cpp
r17335 r17536 33 33 #include "KWQKDebug.h" 34 34 35 #define _DEBUG1 0 36 #ifdef _DEBUG1 37 #include <flogger.h> 38 #endif 35 39 #define BrDefaultEnc KCharacterSetIdentifierIso88591; 36 40 #define BrDefaultEncStr "iso-8859-1"; … … 46 50 friend class QTextCodec; 47 51 public: 48 KWQTextDecoder(TUint aEnc) : iEncoding(aEnc) {}49 ~KWQTextDecoder() { }52 KWQTextDecoder(TUint aEnc) : iEncoding(aEnc), iRemainderBuf(NULL) {} 53 ~KWQTextDecoder() { delete iRemainderBuf; } 50 54 51 55 QString toUnicode(const char *chs, int len, bool flush); 52 56 QCString fromUnicode(const QString &); 53 57 bool IsConversionSupportedL(); 54 QString windows125xToUnicode( const char *chs, int len );58 QString windows125xToUnicode( const char *chs, int len ); 55 59 56 60 private: … … 60 64 static CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* iArrayOfCharacterSetsAvailable; 61 65 TUint iEncoding; 66 HBufC8 * iRemainderBuf; 62 67 }; 63 68 … … 88 93 } 89 94 } 95 96 QTextCodec::~QTextCodec() 97 { delete iQTextDecoder; } 90 98 91 99 bool validateUtf8(const char* chs, int len, int& validMultiByteChars) … … 221 229 QTextDecoder *QTextCodec::makeDecoder() const 222 230 { 223 return new KWQTextDecoder( iEncoding );231 return iQTextDecoder? iQTextDecoder : new KWQTextDecoder( iEncoding ); 224 232 } 225 233 … … 231 239 QString QTextCodec::toUnicode(const char *chs, int len) const 232 240 { 233 return KWQTextDecoder( iEncoding ).toUnicode(chs, len, true);241 return makeDecoder()->toUnicode(chs, len, true); 234 242 } 235 243 … … 308 316 } 309 317 310 318 /** 311 319 * Converts the text buffer from one encoding to Unicode 312 320 * If the indicated charset is not supported, or its converter is not available, … … 315 323 QString KWQTextDecoder::toUnicode(const char *chs, int len, bool flush) 316 324 { 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; 325 334 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; 329 340 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; 332 345 bomLength = 3; 333 }346 } 334 347 335 348 if (!IsConversionSupportedL()) 336 {337 iEncoding = KCharacterSetIdentifierIso88591;338 }349 { 350 iEncoding = KCharacterSetIdentifierIso88591; 351 } 339 352 340 353 // check if it really looks like valid utf-8 341 if (iEncoding == KCharacterSetIdentifierUtf8 && bomLength==0) { 354 if (iEncoding == KCharacterSetIdentifierUtf8 && bomLength==0) 355 { 342 356 int validMultibyteChars; 343 357 bool validUtf8 = validateUtf8(chs, Min(len,32*1024),validMultibyteChars); … … 345 359 if (!validUtf8 && validMultibyteChars<3) 346 360 iEncoding = KCharacterSetIdentifierIso88591; 347 }361 } 348 362 349 363 if (iEncoding == KCharacterSetIdentifierIso88591) 364 { 350 365 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 360 383 361 384 CCnvCharacterSetConverter* charConv = KWQGlobalServices::InstanceL()->CharConv(); … … 363 386 364 387 // check if the target charset is supported 365 charConv->PrepareToConvertToOrFromL( encoding, *iArrayOfCharacterSetsAvailable, fileSession );388 charConv->PrepareToConvertToOrFromL( iEncoding, *iArrayOfCharacterSetsAvailable, fileSession ); 366 389 charConv->SetDefaultEndiannessOfForeignCharacters( endianness ); 367 390 TBuf16<32> tmpBuf; 368 391 TBuf16<32> outBuf; 369 392 370 len = len - bomLength ;393 len = len - bomLength ; 371 394 TPtrC8 inBuf( (const TUint8*)chs + bomLength, len ); 372 TInt state =CCnvCharacterSetConverter::KStateDefault;395 TInt state = CCnvCharacterSetConverter::KStateDefault; 373 396 374 397 // guess the output size … … 381 404 // reserve function reserves 3*len of bytes in momery, to achieve 2*len, times factor of 2/3 382 405 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 383 417 for(;;) 384 418 { … … 387 421 TInt ret = charConv->ConvertToUnicode( tmpBuf, inBuf, state, rep, rIndx ); 388 422 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 } 389 430 break; 431 } 390 432 391 433 // 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() ); 431 466 432 467 // append the buffers to final result, will reincrease the size in needed 433 468 result.append( (const QChar*)(outPtr.Ptr()), outPtr.Length() ); 434 }435 469 436 470 if( ret == 0 || ret == -1 ) break; … … 440 474 441 475 OOM_POST_CHECK_FAILED( return result; ) 476 477 delete inHBuf; 442 478 return result; 443 479 } … … 530 566 void QTextCodec::PrepareForExit() 531 567 { 532 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arr 568 CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arr 533 569 = KWQTextDecoder::iArrayOfCharacterSetsAvailable; 534 570 -
S60/branches/3.1m/WebCore/kwq/KWQTextCodec.h
r14549 r17536 43 43 44 44 QTextCodec( TUint aEnc, KWQEncodingFlags f = NoEncodingFlags ) : iEncoding( aEnc ), _flags(f) {} 45 ~QTextCodec(); 45 46 const char *name() const; 46 47 bool usesVisualOrdering() const { return _flags & VisualOrdering; } … … 62 63 63 64 private: 64 TUintiEncoding;65 TUint iEncoding; 65 66 KWQEncodingFlags _flags; 67 QTextDecoder * iQTextDecoder; 66 68 }; 67 69 … … 72 74 { 73 75 public: 74 virtual ~QTextDecoder() 76 virtual ~QTextDecoder() {} 75 77 virtual QString toUnicode(const char *, int, bool flush = false) = 0; 76 78 };
Note: See TracChangeset
for help on using the changeset viewer.