Changeset 19051 for S60/trunk/WebCore

Show
Ignore:
Timestamp:
01/23/07 12:19:32 (2 years ago)
Author:
brmorris
Message:

w3liu <wei.liu@nokia.com>

Reviewed by Zalan, landed by brad.
DESC: [S60] PYAN-6MUSWV: OSS browser can not display Chinese characters correctly with selected web sites

http://bugs.webkit.org/show_bug.cgi?id=12371

Location:
S60/trunk/WebCore
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • S60/trunk/WebCore/ChangeLog

    r18949 r19051  
     12007-01-22  w3liu  <wei.liu@nokia.com> 
     2 
     3        Reviewed by Zalan Bujtas <zbujtas@gmail.com>, landed by brad. 
     4        DESC: [S60] PYAN-6MUSWV: OSS browser can not display Chinese characters correctly with selected web sites 
     5        http://bugs.webkit.org/show_bug.cgi?id=12371 
     6 
    172007-01-17  w3liu  <wei.liu@nokia.com> 
    28 
  • S60/trunk/WebCore/khtml/misc/decoder.cpp

    r14549 r19051  
    5353    static int ISkanji(int code) 
    5454    { 
    55         if (code >= 0x100) 
    56                     return 0; 
    57         return (kanji_map_sjis[code & 0xff] & 1); 
     55    if (code >= 0x100) 
     56            return 0; 
     57    return (kanji_map_sjis[code & 0xff] & 1); 
    5858    } 
    5959 
    6060    static int ISkana(int code) 
    6161    { 
    62         if (code >= 0x100) 
    63                     return 0; 
    64         return (kanji_map_sjis[code & 0xff] & 2); 
     62    if (code >= 0x100) 
     63            return 0; 
     64    return (kanji_map_sjis[code & 0xff] & 2); 
    6565    } 
    6666 
     
    119119    enum Type code; 
    120120    int i; 
    121     int bfr = FALSE;            /* Kana Moji */ 
    122     int bfk = 0;                /* EUC Kana */ 
     121    int bfr = FALSE;        /* Kana Moji */ 
     122    int bfk = 0;        /* EUC Kana */ 
    123123    int sjis = 0; 
    124124    int euc = 0; 
     
    130130    i = 0; 
    131131    while (i < size) { 
    132         if (ptr[i] == ESC && (size - i >= 3)) { 
    133             if ((ptr[i + 1] == '$' && ptr[i + 2] == 'B') 
    134             || (ptr[i + 1] == '(' && ptr[i + 2] == 'B')) { 
    135                 code = JIS; 
    136                 goto breakBreak; 
    137             } else if ((ptr[i + 1] == '$' && ptr[i + 2] == '@') 
    138                     || (ptr[i + 1] == '(' && ptr[i + 2] == 'J')) { 
    139                 code = JIS; 
    140                 goto breakBreak; 
    141             } else if (ptr[i + 1] == '(' && ptr[i + 2] == 'I') { 
    142                 code = JIS; 
    143                 i += 3; 
    144             } else if (ptr[i + 1] == ')' && ptr[i + 2] == 'I') { 
    145                 code = JIS; 
    146                 i += 3; 
    147             } else { 
    148                 i++; 
    149             } 
    150             bfr = FALSE; 
    151             bfk = 0; 
    152         } else { 
    153             if (ptr[i] < 0x20) { 
    154                 bfr = FALSE; 
    155                 bfk = 0; 
    156                 /* ?? check kudokuten ?? && ?? hiragana ?? */ 
    157                 if ((i >= 2) && (ptr[i - 2] == 0x81) 
    158                         && (0x41 <= ptr[i - 1] && ptr[i - 1] <= 0x49)) { 
    159                     code = SJIS; 
    160                     sjis += 100;        /* kudokuten */ 
    161                 } else if ((i >= 2) && (ptr[i - 2] == 0xa1) 
    162                         && (0xa2 <= ptr[i - 1] && ptr[i - 1] <= 0xaa)) { 
    163                     code = EUC; 
    164                     euc += 100;         /* kudokuten */ 
    165                 } else if ((i >= 2) && (ptr[i - 2] == 0x82) && (0xa0 <= ptr[i - 1])) { 
    166                     sjis += 40;         /* hiragana */ 
    167                 } else if ((i >= 2) && (ptr[i - 2] == 0xa4) && (0xa0 <= ptr[i - 1])) { 
    168                     euc += 40;  /* hiragana */ 
    169                 } 
    170             } else { 
    171                 /* ?? check hiragana or katana ?? */ 
    172                 if ((size - i > 1) && (ptr[i] == 0x82) && (0xa0 <= ptr[i + 1])) { 
    173                     sjis++;     /* hiragana */ 
    174                 } else if ((size - i > 1) && (ptr[i] == 0x83) 
    175                         && (0x40 <= ptr[i + 1] && ptr[i + 1] <= 0x9f)) { 
    176                     sjis++;     /* katakana */ 
    177                 } else if ((size - i > 1) && (ptr[i] == 0xa4) && (0xa0 <= ptr[i + 1])) { 
    178                     euc++;      /* hiragana */ 
    179                 } else if ((size - i > 1) && (ptr[i] == 0xa5) && (0xa0 <= ptr[i + 1])) { 
    180                     euc++;      /* katakana */ 
    181                 } 
    182                 if (bfr) { 
    183                     if ((i >= 1) && (0x40 <= ptr[i] && ptr[i] <= 0xa0) && ISkanji(ptr[i - 1])) { 
    184                         code = SJIS; 
    185                         goto breakBreak; 
    186                     } else if ((i >= 1) && (0x81 <= ptr[i - 1] && ptr[i - 1] <= 0x9f) && ((0x40 <= ptr[i] && ptr[i] < 0x7e) || (0x7e < ptr[i] && ptr[i] <= 0xfc))) { 
    187                         code = SJIS; 
    188                         goto breakBreak; 
    189                     } else if ((i >= 1) && (0xfd <= ptr[i] && ptr[i] <= 0xfe) && (0xa1 <= ptr[i - 1] && ptr[i - 1] <= 0xfe)) { 
    190                         code = EUC; 
    191                         goto breakBreak; 
    192                     } else if ((i >= 1) && (0xfd <= ptr[i - 1] && ptr[i - 1] <= 0xfe) && (0xa1 <= ptr[i] && ptr[i] <= 0xfe)) { 
    193                         code = EUC; 
    194                         goto breakBreak; 
    195                     } else if ((i >= 1) && (ptr[i] < 0xa0 || 0xdf < ptr[i]) && (0x8e == ptr[i - 1])) { 
    196                         code = SJIS; 
    197                         goto breakBreak; 
    198                     } else if (ptr[i] <= 0x7f) { 
    199                         code = SJIS; 
    200                         goto breakBreak; 
    201                     } else { 
    202                         if (0xa1 <= ptr[i] && ptr[i] <= 0xa6) { 
    203                             euc++;      /* sjis hankaku kana kigo */ 
    204                         } else if (0xa1 <= ptr[i] && ptr[i] <= 0xdf) { 
    205                             ;   /* sjis hankaku kana */ 
    206                         } else if (0xa1 <= ptr[i] && ptr[i] <= 0xfe) { 
    207                             euc++; 
    208                         } else if (0x8e == ptr[i]) { 
    209                             euc++; 
    210                         } else if (0x20 <= ptr[i] && ptr[i] <= 0x7f) { 
    211                             sjis++; 
    212                         } 
    213                         bfr = FALSE; 
    214                         bfk = 0; 
    215                     } 
    216                 } else if (0x8e == ptr[i]) { 
    217                     if (size - i <= 1) { 
    218                         ; 
    219                     } else if (0xa1 <= ptr[i + 1] && ptr[i + 1] <= 0xdf) { 
    220                         /* EUC KANA or SJIS KANJI */ 
    221                         if (bfk == 1) { 
    222                             euc += 100; 
    223                         } 
    224                         bfk++; 
    225                         i++; 
    226                     } else { 
    227                         /* SJIS only */ 
    228                         code = SJIS; 
    229                         goto breakBreak; 
    230                     } 
    231                 } else if (0x81 <= ptr[i] && ptr[i] <= 0x9f) { 
    232                     /* SJIS only */ 
    233                     code = SJIS; 
    234                     if ((size - i >= 1) 
    235                             && ((0x40 <= ptr[i + 1] && ptr[i + 1] <= 0x7e) 
    236                             || (0x80 <= ptr[i + 1] && ptr[i + 1] <= 0xfc))) { 
    237                         goto breakBreak; 
    238                     } 
    239                 } else if (0xfd <= ptr[i] && ptr[i] <= 0xfe) { 
    240                     /* EUC only */ 
    241                     code = EUC; 
    242                     if ((size - i >= 1) 
    243                             && (0xa1 <= ptr[i + 1] && ptr[i + 1] <= 0xfe)) { 
    244                         goto breakBreak; 
    245                     } 
    246                 } else if (ptr[i] <= 0x7f) { 
    247                     ; 
    248                 } else { 
    249                     bfr = TRUE; 
    250                     bfk = 0; 
    251                 } 
    252             } 
    253             i++; 
    254         } 
     132    if (ptr[i] == ESC && (size - i >= 3)) { 
     133        if ((ptr[i + 1] == '$' && ptr[i + 2] == 'B') 
     134        || (ptr[i + 1] == '(' && ptr[i + 2] == 'B')) { 
     135        code = JIS; 
     136        goto breakBreak; 
     137        } else if ((ptr[i + 1] == '$' && ptr[i + 2] == '@') 
     138            || (ptr[i + 1] == '(' && ptr[i + 2] == 'J')) { 
     139        code = JIS; 
     140        goto breakBreak; 
     141        } else if (ptr[i + 1] == '(' && ptr[i + 2] == 'I') { 
     142        code = JIS; 
     143        i += 3; 
     144        } else if (ptr[i + 1] == ')' && ptr[i + 2] == 'I') { 
     145        code = JIS; 
     146        i += 3; 
     147        } else { 
     148        i++; 
     149        } 
     150        bfr = FALSE; 
     151        bfk = 0; 
     152    } else { 
     153        if (ptr[i] < 0x20) { 
     154        bfr = FALSE; 
     155        bfk = 0; 
     156        /* ?? check kudokuten ?? && ?? hiragana ?? */ 
     157        if ((i >= 2) && (ptr[i - 2] == 0x81) 
     158            && (0x41 <= ptr[i - 1] && ptr[i - 1] <= 0x49)) { 
     159            code = SJIS; 
     160            sjis += 100;    /* kudokuten */ 
     161        } else if ((i >= 2) && (ptr[i - 2] == 0xa1) 
     162            && (0xa2 <= ptr[i - 1] && ptr[i - 1] <= 0xaa)) { 
     163            code = EUC; 
     164            euc += 100;     /* kudokuten */ 
     165        } else if ((i >= 2) && (ptr[i - 2] == 0x82) && (0xa0 <= ptr[i - 1])) { 
     166            sjis += 40;     /* hiragana */ 
     167        } else if ((i >= 2) && (ptr[i - 2] == 0xa4) && (0xa0 <= ptr[i - 1])) { 
     168            euc += 40;  /* hiragana */ 
     169        } 
     170        } else { 
     171        /* ?? check hiragana or katana ?? */ 
     172        if ((size - i > 1) && (ptr[i] == 0x82) && (0xa0 <= ptr[i + 1])) { 
     173            sjis++; /* hiragana */ 
     174        } else if ((size - i > 1) && (ptr[i] == 0x83) 
     175            && (0x40 <= ptr[i + 1] && ptr[i + 1] <= 0x9f)) { 
     176            sjis++; /* katakana */ 
     177        } else if ((size - i > 1) && (ptr[i] == 0xa4) && (0xa0 <= ptr[i + 1])) { 
     178            euc++;  /* hiragana */ 
     179        } else if ((size - i > 1) && (ptr[i] == 0xa5) && (0xa0 <= ptr[i + 1])) { 
     180            euc++;  /* katakana */ 
     181        } 
     182        if (bfr) { 
     183            if ((i >= 1) && (0x40 <= ptr[i] && ptr[i] <= 0xa0) && ISkanji(ptr[i - 1])) { 
     184            code = SJIS; 
     185            goto breakBreak; 
     186            } else if ((i >= 1) && (0x81 <= ptr[i - 1] && ptr[i - 1] <= 0x9f) && ((0x40 <= ptr[i] && ptr[i] < 0x7e) || (0x7e < ptr[i] && ptr[i] <= 0xfc))) { 
     187            code = SJIS; 
     188            goto breakBreak; 
     189            } else if ((i >= 1) && (0xfd <= ptr[i] && ptr[i] <= 0xfe) && (0xa1 <= ptr[i - 1] && ptr[i - 1] <= 0xfe)) { 
     190            code = EUC; 
     191            goto breakBreak; 
     192            } else if ((i >= 1) && (0xfd <= ptr[i - 1] && ptr[i - 1] <= 0xfe) && (0xa1 <= ptr[i] && ptr[i] <= 0xfe)) { 
     193            code = EUC; 
     194            goto breakBreak; 
     195            } else if ((i >= 1) && (ptr[i] < 0xa0 || 0xdf < ptr[i]) && (0x8e == ptr[i - 1])) { 
     196            code = SJIS; 
     197            goto breakBreak; 
     198            } else if (ptr[i] <= 0x7f) { 
     199            code = SJIS; 
     200            goto breakBreak; 
     201            } else { 
     202            if (0xa1 <= ptr[i] && ptr[i] <= 0xa6) { 
     203                euc++;  /* sjis hankaku kana kigo */ 
     204            } else if (0xa1 <= ptr[i] && ptr[i] <= 0xdf) { 
     205                ;   /* sjis hankaku kana */ 
     206            } else if (0xa1 <= ptr[i] && ptr[i] <= 0xfe) { 
     207                euc++; 
     208            } else if (0x8e == ptr[i]) { 
     209                euc++; 
     210            } else if (0x20 <= ptr[i] && ptr[i] <= 0x7f) { 
     211                sjis++; 
     212            } 
     213            bfr = FALSE; 
     214            bfk = 0; 
     215            } 
     216        } else if (0x8e == ptr[i]) { 
     217            if (size - i <= 1) { 
     218            ; 
     219            } else if (0xa1 <= ptr[i + 1] && ptr[i + 1] <= 0xdf) { 
     220            /* EUC KANA or SJIS KANJI */ 
     221            if (bfk == 1) { 
     222                euc += 100; 
     223            } 
     224            bfk++; 
     225            i++; 
     226            } else { 
     227            /* SJIS only */ 
     228            code = SJIS; 
     229            goto breakBreak; 
     230            } 
     231        } else if (0x81 <= ptr[i] && ptr[i] <= 0x9f) { 
     232            /* SJIS only */ 
     233            code = SJIS; 
     234            if ((size - i >= 1) 
     235                && ((0x40 <= ptr[i + 1] && ptr[i + 1] <= 0x7e) 
     236                || (0x80 <= ptr[i + 1] && ptr[i + 1] <= 0xfc))) { 
     237            goto breakBreak; 
     238            } 
     239        } else if (0xfd <= ptr[i] && ptr[i] <= 0xfe) { 
     240            /* EUC only */ 
     241            code = EUC; 
     242            if ((size - i >= 1) 
     243                && (0xa1 <= ptr[i + 1] && ptr[i + 1] <= 0xfe)) { 
     244            goto breakBreak; 
     245            } 
     246        } else if (ptr[i] <= 0x7f) { 
     247            ; 
     248        } else { 
     249            bfr = TRUE; 
     250            bfk = 0; 
     251        } 
     252        } 
     253        i++; 
     254    } 
    255255    } 
    256256    if (code == ASCII) { 
    257         if (sjis > euc) { 
    258             code = SJIS; 
    259         } else if (sjis < euc) { 
    260             code = EUC; 
    261         } 
     257    if (sjis > euc) { 
     258        code = SJIS; 
     259    } else if (sjis < euc) { 
     260        code = EUC; 
     261    } 
    262262    } 
    263263breakBreak: 
     
    265265} 
    266266 
    267 Decoder::Decoder()  
     267Decoder::Decoder() 
    268268{ 
    269269    _refCount = 1; 
     
    329329        m_decoder = m_codec->makeDecoder(); 
    330330    } 
    331      
     331 
    332332#ifdef DECODE_DEBUG 
    333333    kdDebug(6005) << "Decoder::encoding used is" << m_codec->name() << endl; 
     
    377377        return -1; 
    378378    pos += 8; 
    379      
     379 
    380380    // Skip spaces and stray control characters. 
    381381    while (str[pos] <= ' ' && pos != len) 
     
    404404    if (end == len) 
    405405        return -1; 
    406      
     406 
    407407    encodingLength = end - pos; 
    408408    return pos; 
     
    447447        beginning = false; 
    448448    } 
    449      
     449 
    450450    // this is not completely efficient, since the function might go 
    451451    // through the html head several times... 
    452452 
    453453    bool lookForMetaTag = m_type == DefaultEncoding && !body; 
    454      
     454 
    455455    if (lookForMetaTag) { 
    456456#ifdef DECODE_DEBUG 
     
    497497                        continue; 
    498498                    } 
    499                      
     499 
    500500                    // Handle XML header, which can have encoding in it. 
    501501                    if (ptr[0] == '?' && ptr[1] == 'x' && ptr[2] == 'm' && ptr[3] == 'l') { 
     
    527527                        len++; 
    528528                    } 
    529                     tmp[len] = 0; 
     529            tmp[len] = 0; 
    530530                    int id = khtml::getTagID(tmp, len); 
    531531                    if(end) id += ID_CLOSE_TAG; 
     
    544544                        //if( (pos = str.find("http-equiv", pos)) == -1) break; 
    545545                        //if( (pos = str.find("content-type", pos)) == -1) break; 
    546                         while( pos < ( int ) str.length() ) { 
    547                             if( (pos = str.find("charset", pos, false)) == -1) break; 
    548                             pos += 7; 
     546            while( pos < ( int ) str.length() ) { 
     547                if( (pos = str.find("charset", pos, false)) == -1) break; 
     548                pos += 7; 
    549549                            // skip whitespace.. 
    550                             while(  pos < (int)str.length() && str[pos] <= ' ' ) pos++; 
     550                while(  pos < (int)str.length() && str[pos] <= ' ' ) pos++; 
    551551                            if ( pos == ( int )str.length()) break; 
    552552                            if ( str[pos++] != '=' ) continue; 
    553553                            while ( pos < ( int )str.length() && 
    554554                                    ( str[pos] <= ' ' ) || str[pos] == '=' || str[pos] == '"' || str[pos] == '\'') 
    555                                 pos++; 
     555                pos++; 
    556556 
    557557                            // end ? 
    558558                            if ( pos == ( int )str.length() ) break; 
    559                             uint endpos = pos; 
    560                             while( endpos < str.length() && 
     559                uint endpos = pos; 
     560                while( endpos < str.length() && 
    561561                                   (str[endpos] != ' ' && str[endpos] != '"' && str[endpos] != '\'' 
    562562                                    && str[endpos] != ';' && str[endpos] != '>') ) 
    563                                 endpos++; 
    564 #ifdef DECODE_DEBUG 
    565                             kdDebug( 6005 ) << "Decoder: found charset: " << str.mid(pos, endpos-pos) << endl; 
    566 #endif 
    567                             setEncoding(str.mid(pos, endpos-pos), EncodingFromMetaTag); 
    568                             if( m_type == EncodingFromMetaTag ) goto found; 
     563                endpos++; 
     564#ifdef DECODE_DEBUG 
     565                kdDebug( 6005 ) << "Decoder: found charset: " << str.mid(pos, endpos-pos) << endl; 
     566#endif 
     567                setEncoding(str.mid(pos, endpos-pos), EncodingFromMetaTag); 
     568                if( m_type == EncodingFromMetaTag ) goto found; 
    569569 
    570570                            if ( endpos >= str.length() || str[endpos] == '/' || str[endpos] == '>' ) break; 
    571571 
    572                             pos = endpos + 1; 
    573                         } 
    574                     } 
     572                pos = endpos + 1; 
     573            } 
     574            } 
    575575                    case (ID_META+ID_CLOSE_TAG): 
    576576                    case ID_SCRIPT: 
     
    590590                    case ID_HTML: 
    591591                    case ID_HEAD: 
     592#if NOKIA_CHANGES 
     593                    case ID_IMG: 
     594#endif 
    592595                    case 0: 
    593596                    case (0 + ID_CLOSE_TAG ): 
     
    596599                        body = true; 
    597600#ifdef DECODE_DEBUG 
    598                         kdDebug( 6005 ) << "Decoder: no charset found. Id=" << id << endl; 
     601            kdDebug( 6005 ) << "Decoder: no charset found. Id=" << id << endl; 
    599602#endif 
    600603                        goto found; 
     
    617620    { 
    618621#ifdef DECODE_DEBUG 
    619         kdDebug( 6005 ) << "Decoder: use auto-detect (" << strlen(data) << ")" << endl; 
    620 #endif 
    621         const char *autoDetectedEncoding; 
     622    kdDebug( 6005 ) << "Decoder: use auto-detect (" << strlen(data) << ")" << endl; 
     623#endif 
     624    const char *autoDetectedEncoding; 
    622625        switch ( KanjiCode::judge( data, len ) ) { 
    623         case KanjiCode::JIS: 
     626    case KanjiCode::JIS: 
    624627#if NOKIA_CHANGES 
    625             autoDetectedEncoding = "jis_x0201-1997"; 
    626 #else 
    627             autoDetectedEncoding = "jis7"; 
    628 #endif 
    629             break; 
    630         case KanjiCode::EUC: 
     628        autoDetectedEncoding = "jis_x0201-1997"; 
     629#else 
     630        autoDetectedEncoding = "jis7"; 
     631#endif 
     632        break; 
     633    case KanjiCode::EUC: 
    631634#if NOKIA_CHANGES 
    632             autoDetectedEncoding = "euc-jp" ; 
    633 #else 
    634             autoDetectedEncoding = "eucjp"; 
    635 #endif 
    636             break; 
    637         case KanjiCode::SJIS: 
    638 #if NOKIA_CHANGES            
     635        autoDetectedEncoding = "euc-jp" ; 
     636#else 
     637        autoDetectedEncoding = "eucjp"; 
     638#endif 
     639        break; 
     640    case KanjiCode::SJIS: 
     641#if NOKIA_CHANGES 
    639642        autoDetectedEncoding = "shift_jis"; 
    640643#else 
    641             autoDetectedEncoding = "sjis"; 
    642 #endif 
    643             break; 
    644         default: 
    645             autoDetectedEncoding = NULL; 
    646             break; 
    647         } 
    648 #ifdef DECODE_DEBUG 
    649         kdDebug( 6005 ) << "Decoder: auto detect encoding is " 
     644        autoDetectedEncoding = "sjis"; 
     645#endif 
     646        break; 
     647    default: 
     648        autoDetectedEncoding = NULL; 
     649        break; 
     650    } 
     651#ifdef DECODE_DEBUG 
     652    kdDebug( 6005 ) << "Decoder: auto detect encoding is " 
    650653            << (autoDetectedEncoding ? autoDetectedEncoding : "NULL") << endl; 
    651654#endif 
    652         if (autoDetectedEncoding != 0) { 
    653             setEncoding(autoDetectedEncoding, AutoDetectedEncoding); 
    654         } 
     655    if (autoDetectedEncoding != 0) { 
     656        setEncoding(autoDetectedEncoding, AutoDetectedEncoding); 
     657    } 
    655658    } 
    656659