Ticket #102: dbcs.diff

File dbcs.diff, 8.8 KB (added by KO Myung-Hun, 14 years ago)

Patch for DBCS font issues

  • src/gui/kernel/qapplication_pm.cpp

     
    222222                    case 9: f.setStretch(QFont::UltraExpanded); break;
    223223                    default: f.setStretch(QFont::Unstretched); break;
    224224                }
    225                 f.setFamily(fm.szFamilyname);
     225                f.setFamily(QString::fromLocal8Bit(fm.szFamilyname));
    226226                f.setPointSize(height);
    227227            }
    228228        }
  • src/gui/text/qfontdatabase_pm.cpp

     
    4141**
    4242****************************************************************************/
    4343
     44#ifndef QT_NO_TEXTCODEC
     45#include <qtextcodec.h>
     46#endif
     47
    4448#include "qabstractfileengine.h"
    4549
    4650#include "qfontengine_pm_p.h"
     
    5559#include FT_TYPES_H
    5660#include FT_TRUETYPE_TABLES_H
    5761#include FT_LCD_FILTER_H
     62#include FT_SFNT_NAMES_H
     63#include FT_TRUETYPE_IDS_H
    5864
    5965QT_BEGIN_NAMESPACE
    6066
     
    119125static FontFileHash knownFontFiles;
    120126static bool knownFontFilesInitialized = false;
    121127
     128static bool lookupFamilyName(FT_Face ftface, QString& familyName)
     129{
     130    FT_UInt     nNameCount;
     131    FT_UInt     i;
     132    FT_SfntName sfntName;
     133    FT_UInt     found, best;
     134
     135    nNameCount = FT_Get_Sfnt_Name_Count(ftface);
     136
     137    if (nNameCount == 0)
     138        return false;
     139
     140#ifndef QT_NO_TEXTCODEC
     141    QTextCodec *codec = QTextCodec::codecForName("UTF-16BE");
     142
     143    // find a unicode name at first
     144    if (codec) {
     145        found = (FT_UInt)-1;
     146        best  = (FT_UInt)-1;
     147
     148        // try to find the unicode name matching to the locale
     149        for (i = 0; found == (FT_UInt)-1 && i < nNameCount; i++) {
     150            FT_Get_Sfnt_Name(ftface, i, &sfntName);
     151
     152            if (sfntName.name_id     == TT_NAME_ID_FONT_FAMILY &&
     153                sfntName.platform_id == TT_PLATFORM_MICROSOFT &&
     154                sfntName.encoding_id == TT_MS_ID_UNICODE_CS) {
     155                if (best == (FT_UInt)-1 || sfntName.language_id == TT_MS_LANGID_ENGLISH_UNITED_STATES)
     156                    best = i;
     157
     158                switch (sfntName.language_id) {
     159                    case TT_MS_LANGID_KOREAN_EXTENDED_WANSUNG_KOREA :
     160                        if (QLocale::system().language() == QLocale::Korean)
     161                            found = i;
     162                        break;
     163
     164                    case TT_MS_LANGID_JAPANESE_JAPAN :
     165                        if (QLocale::system().language() == QLocale::Japanese)
     166                            found = i;
     167                        break;
     168
     169                    case TT_MS_LANGID_CHINESE_PRC :
     170                        if (QLocale::system().country() == QLocale::China &&
     171                            QLocale::system().language() == QLocale::Chinese)
     172                            found = i;
     173                        break;
     174
     175                    case TT_MS_LANGID_CHINESE_TAIWAN :
     176                        if (QLocale::system().country() == QLocale::Taiwan &&
     177                            QLocale::system().language() == QLocale::Chinese)
     178                            found = i;
     179                        break;
     180                }
     181            }
     182        }
     183
     184        if (found == (FT_UInt)-1)
     185            found = best;
     186
     187        if (found != (FT_UInt)-1) {
     188            FT_Get_Sfnt_Name(ftface, found, &sfntName);
     189
     190            familyName = codec->toUnicode((const char *)sfntName.string, sfntName.string_len);
     191
     192            return true;
     193        }
     194    }
     195#endif
     196
     197    found = (FT_UInt)-1;
     198    best  = (FT_UInt)-1;
     199
     200    // unicode name is not available, try the NLS encoded name
     201    for (i = 0; found == (FT_UInt)-1 && i < nNameCount; i++) {
     202        FT_Get_Sfnt_Name(ftface, i, &sfntName);
     203
     204        if (sfntName.name_id     == TT_NAME_ID_FONT_FAMILY &&
     205            sfntName.platform_id == TT_PLATFORM_MICROSOFT) {
     206            if (best == (FT_UInt)-1)
     207                best = i;
     208
     209            switch (sfntName.encoding_id) {
     210                case TT_MS_ID_WANSUNG :
     211                    if (QLocale::system().language() == QLocale::Korean)
     212                        found = i;
     213                    break;
     214
     215                case TT_MS_ID_SJIS :
     216                    if (QLocale::system().language() == QLocale::Japanese)
     217                        found = i;
     218                    break;
     219
     220                case TT_MS_ID_BIG_5 :
     221                    if (QLocale::system().country() == QLocale::Taiwan &&
     222                        QLocale::system().language() == QLocale::Chinese)
     223                        found = i;
     224                    break;
     225
     226                case TT_MS_ID_GB2312 :
     227                    if (QLocale::system().country() == QLocale::China &&
     228                        QLocale::system().language() == QLocale::Chinese)
     229                        found = i;
     230                    break;
     231
     232                case TT_MS_ID_SYMBOL_CS :
     233                    found = i;
     234                    break;
     235            }
     236        }
     237    }
     238
     239    if (found == (FT_UInt)-1)
     240        found = best;
     241
     242    if (found != (FT_UInt)-1)
     243    {
     244        char   *name;
     245        FT_UInt name_len = 0;
     246
     247        FT_Get_Sfnt_Name(ftface, found, &sfntName);
     248
     249        name = (char *)alloca(sfntName.string_len);
     250
     251        for (FT_UInt j = 0; j < sfntName.string_len; j++)
     252            if (sfntName.string[j])
     253                name[name_len++] = sfntName.string[j];
     254
     255#ifndef QT_NO_TEXTCODEC
     256        switch (sfntName.encoding_id) {
     257            case TT_MS_ID_WANSUNG :
     258                codec = QTextCodec::codecForName("cp949");
     259                break;
     260
     261            case TT_MS_ID_SJIS :
     262                codec = QTextCodec::codecForName("SJIS");
     263                break;
     264
     265            case TT_MS_ID_BIG_5 :
     266                codec = QTextCodec::codecForName("Big5");
     267                break;
     268
     269            case TT_MS_ID_GB2312 :
     270                codec = QTextCodec::codecForName("GB2312");
     271                break;
     272
     273            case TT_MS_ID_SYMBOL_CS :
     274            default :
     275                codec = NULL;
     276                break;
     277        }
     278
     279        if (codec)
     280            familyName = codec->toUnicode(name, name_len);
     281        else
     282#endif
     283            familyName = QString::fromLocal8Bit(name, name_len);
     284
     285        return true;
     286    }
     287
     288    return false;
     289}
     290
    122291static void populateDatabase(const QString& fam)
    123292{
    124293    QFontDatabasePrivate *db = privateDb();
     
    269438                FaceData cached;
    270439
    271440                cached.index = idx;
    272                 cached.familyName = QString::fromLatin1(face->family_name);
    273441
     442                if (!lookupFamilyName(face, cached.familyName))
     443                    cached.familyName = QString::fromLocal8Bit(face->family_name);
     444
    274445                // familyName may contain extra spaces (at least this is true for
    275446                // TNR.PFB that is reported as "Times New Roman ". Trim them.
    276447                cached.familyName = cached.familyName.trimmed();
  • src/gui/text/qfont_pm.cpp

     
    4141**
    4242****************************************************************************/
    4343
     44#include "qt_os2.h"
    4445#include "qfont.h"
    4546#include "qfont_p.h"
    4647#include "qfontengine_p.h"
     
    6869        family = "WarpSans";
    6970        break;
    7071    case QFont::AnyStyle:
    71         if (request.fixedPitch)
     72    default:
     73        static char szFontName[FACESIZE + 1] = {0,};
     74
     75        // already queried ?
     76        if (szFontName[0] != ';') {
     77            szFontName[0] = ';';
     78            // query the associated font
     79            if (PrfQueryProfileString(HINI_USERPROFILE,
     80                                      "PM_SystemFonts", "PM_AssociateFont", 0,
     81                                      szFontName, sizeof(szFontName))) {
     82                szFontName[FACESIZE] = '\0';
     83
     84                // the format of the associated font is face_name;point_size
     85                // so remove ';' and later
     86                for (PSZ pch = szFontName; *pch; pch++)
     87                    if (*pch == ';') {
     88                        *pch = '\0';
     89                        break;
     90                    }
     91            }
     92        }
     93
     94        // is the associated font available ?
     95        if (szFontName[0] != '\0' && szFontName[0] != ';')
     96            family = szFontName;
     97        else if (request.fixedPitch)
    7298            family = "Courier";
    7399        else
    74100            family = "Helvetica";
     
    102128
    103129QString QFont::defaultFamily() const
    104130{
    105     return QLatin1String(qt_fontFamilyFromStyleHint(d->request));
     131    return QString::fromLocal8Bit(qt_fontFamilyFromStyleHint(d->request));
    106132}
    107133
    108134QString QFont::lastResortFamily() const