Changeset 220 for trunk/src


Ignore:
Timestamp:
Oct 12, 2009, 11:37:39 PM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: Added enumeration of installed PM fonts.

Location:
trunk/src/gui/text
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/text/qfontdatabase.cpp

    r124 r220  
    5454#include <locale.h>
    5555#endif
     56#ifdef Q_WS_PM
     57#include "qt_os2.h"
     58#endif
     59
    5660#include <stdlib.h>
    5761#include <limits.h>
     
    7478#  define for if(0){}else for
    7579#endif
     80
     81#define SMOOTH_SCALABLE 0xffff
    7682
    7783QT_BEGIN_NAMESPACE
     
    146152    int fileIndex;
    147153#endif
     154#ifdef Q_WS_PM
     155    unsigned short pointSize; // in deca-points
     156    LONG lMatch;
     157#endif
    148158};
    149159
     
    209219        weightName = setwidthName = 0;
    210220#endif // Q_WS_X11
     221#if defined(Q_WS_PM)
     222        faceName[0] = 0;
     223#endif
    211224    }
    212225
     
    242255    bool antialiased;
    243256#endif
    244 
     257#ifdef Q_WS_PM
     258    CHAR faceName[FACESIZE];
     259#endif
     260
     261#ifdef Q_WS_PM
     262    QtFontSize *pixelSize(unsigned short size, bool = false,
     263                          unsigned short pointSize = 0);
     264#else
    245265    QtFontSize *pixelSize(unsigned short size, bool = false);
     266#endif
    246267};
    247268
     
    259280}
    260281
     282#ifdef Q_WS_PM
     283QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add,
     284                                   unsigned short pointSize)
     285#else
    261286QtFontSize *QtFontStyle::pixelSize(unsigned short size, bool add)
     287#endif
    262288{
    263289    for (int i = 0; i < count; i++) {
     290#ifdef Q_WS_PM
     291        if (pixelSizes[i].pixelSize == size &&
     292        (size == SMOOTH_SCALABLE || !pointSize ||
     293         pixelSizes[i].pointSize == pointSize))
     294        return pixelSizes + i;
     295#else
    264296        if (pixelSizes[i].pixelSize == size)
    265297            return pixelSizes + i;
     298#endif
    266299    }
    267300    if (!add)
     
    280313    new (&pixelSizes[count].fileName) QByteArray;
    281314    pixelSizes[count].fileIndex = 0;
     315#endif
     316#ifdef Q_WS_PM
     317    pixelSizes[count].pointSize = pointSize;
     318    pixelSizes[count].lMatch = 0;
    282319#endif
    283320    return pixelSizes + (count++);
     
    364401    {
    365402        memset(writingSystems, 0, sizeof(writingSystems));
     403#ifdef Q_WS_PM
     404        // the concept of writing systems isn't used, let's support just Any
     405        writingSystems[QFontDatabase::Any] = Supported;
     406#endif
    366407    }
    367408    ~QtFontFamily() {
     
    867908}
    868909
    869 #define SMOOTH_SCALABLE 0xffff
    870 
    871910QT_BEGIN_INCLUDE_NAMESPACE
    872911#if defined(Q_WS_X11)
  • trunk/src/gui/text/qfontdatabase_pm.cpp

    r125 r220  
    4848QT_BEGIN_NAMESPACE
    4949
     50static void populateDatabase(const QString& fam)
     51{
     52    QFontDatabasePrivate *db = privateDb();
     53    if (!db)
     54        return;
     55
     56    QtFontFamily *family = 0;
     57    if(!fam.isEmpty()) {
     58        family = db->family(fam);
     59        if(family)
     60            return;
     61    } else if (db->count) {
     62        return;
     63    }
     64
     65    // we don't recognize foundries on OS/2, use an empty one
     66    const QString foundryName;
     67
     68    int hps = qt_display_ps();
     69
     70    LONG cFonts = 0;
     71    cFonts = GpiQueryFonts(hps, QF_PUBLIC, NULL, &cFonts, 0, NULL);
     72    PFONTMETRICS afm = new FONTMETRICS[cFonts];
     73    GpiQueryFonts(hps, QF_PUBLIC, NULL, &cFonts, sizeof(FONTMETRICS), afm);
     74
     75    LONG info[2];
     76    DevQueryCaps(GpiQueryDevice(hps), CAPS_HORIZONTAL_FONT_RES, 2, info);
     77    LONG xRes = info[0], yRes = info[1];
     78
     79    for (PFONTMETRICS fm = afm ; cFonts ; cFonts--, fm++) {
     80        // ignore the default (lMatch = 0) GPI font, since it is always
     81        // present with non-zero lMatch in the list
     82        if (!fm->lMatch)
     83            continue;
     84
     85        QString familyName = QString::fromLocal8Bit(fm->szFamilyname);
     86        bool italic = fm->fsSelection & FM_SEL_ITALIC;
     87        bool fixed = fm->fsType & FM_TYPE_FIXED;
     88        bool scalable = fm->fsDefn & FM_DEFN_OUTLINE;
     89        USHORT weight = fm->usWeightClass;
     90        USHORT width = fm->usWidthClass;
     91
     92        // ignore bitmap fonts that do not match the current device resolution
     93        if (!scalable && (fm->sXDeviceRes != xRes || fm->sYDeviceRes != yRes))
     94            continue;
     95
     96        // the "@family" fonts are just the same as "family". Ignore them.
     97        if (familyName[0] == '@')
     98            continue;
     99
     100        QtFontStyle::Key styleKey;
     101        styleKey.style = italic ? QFont::StyleItalic : QFont::StyleNormal;
     102
     103        if (weight < 4)
     104            styleKey.weight = QFont::Light;
     105        else if (weight < 6)
     106            styleKey.weight = QFont::Normal;
     107        else if (weight < 7)
     108            styleKey.weight = QFont::DemiBold;
     109        else if (weight < 8)
     110            styleKey.weight = QFont::Bold;
     111        else
     112            styleKey.weight = QFont::Black;
     113
     114        switch (width) {
     115            case 1: styleKey.stretch = QFont::UltraCondensed; break;
     116            case 2: styleKey.stretch = QFont::ExtraCondensed; break;
     117            case 3: styleKey.stretch = QFont::Condensed; break;
     118            case 4: styleKey.stretch = QFont::SemiCondensed; break;
     119            case 5: styleKey.stretch = QFont::Unstretched; break;
     120            case 6: styleKey.stretch = QFont::SemiExpanded; break;
     121            case 7: styleKey.stretch = QFont::Expanded; break;
     122            case 8: styleKey.stretch = QFont::ExtraExpanded; break;
     123            case 9: styleKey.stretch = QFont::UltraExpanded; break;
     124            default: styleKey.stretch = QFont::Unstretched; break;
     125        }
     126
     127        // @todo why?
     128        familyName.replace('-', ' ');
     129
     130        QtFontFamily *family = privateDb()->family(familyName, true);
     131        // @todo is it possible that the same family is both fixed and not?
     132        family->fixedPitch = fixed;
     133
     134        QtFontFoundry *foundry = family->foundry(foundryName, true);
     135        QtFontStyle *style = foundry->style(styleKey, true);
     136
     137        // add new scalable style only if it hasn't been already added --
     138        // the first one of two duplicate (in Qt terms) non-bitmap font
     139        // styles wins.
     140        if (scalable && style->smoothScalable)
     141            continue;
     142
     143        if (style->faceName[0]) {
     144            // if a duplicate (having the same style in Qt terms) bitmap
     145            // font is encountered but it has the different facename, ignore
     146            // it (we have only one facename field per style -- it should be
     147            // the same for all sizes otherwise we will not be able to create
     148            // a font with some sizes later).
     149            if (strcmp(style->faceName, fm->szFacename))
     150                continue;
     151        } else {
     152            strcpy(style->faceName, fm->szFacename);
     153        }
     154
     155        if (scalable) {
     156            style->smoothScalable = TRUE;
     157            QtFontSize *size =
     158                style->pixelSize(SMOOTH_SCALABLE, TRUE, fm->sNominalPointSize);
     159            size->lMatch = fm->lMatch;
     160        } else {
     161            QtFontSize *size =
     162                style->pixelSize(fm->lEmHeight, TRUE, fm->sNominalPointSize);
     163            // the first bitmap style with a given pixel and point size wins
     164            if (size->lMatch)
     165                continue;
     166            size->lMatch = fm->lMatch;
     167        }
     168    }
     169
     170    delete[] afm;
     171}
     172
    50173static void initializeDb()
    51174{
     175    QFontDatabasePrivate *db = privateDb();
     176    if (!db || db->count)
     177        return;
     178
     179    populateDatabase(QString());
     180
     181#ifdef QFONTDATABASE_DEBUG
     182    // print the database
     183    for (int f = 0; f < db->count; f++) {
     184        QtFontFamily *family = db->families[f];
     185        qDebug("    %s: %p", qPrintable(family->name), family);
     186        populateDatabase(family->name);
     187
     188#if 1
     189        qDebug("        scripts supported:");
     190        for (int i = 0; i < QUnicodeTables::ScriptCount; i++)
     191            if(family->writingSystems[i] & QtFontFamily::Supported)
     192                qDebug("            %d", i);
     193        for (int fd = 0; fd < family->count; fd++) {
     194            QtFontFoundry *foundry = family->foundries[fd];
     195            qDebug("        %s", qPrintable(foundry->name));
     196            for (int s = 0; s < foundry->count; s++) {
     197                QtFontStyle *style = foundry->styles[s];
     198                qDebug("            style: style=%d weight=%d smooth=%d",  style->key.style,
     199                       style->key.weight, style->smoothScalable);
     200                if(!style->smoothScalable) {
     201                    for(int i = 0; i < style->count; ++i) {
     202                        qDebug("                %d", style->pixelSizes[i].pixelSize);
     203                    }
     204                }
     205            }
     206        }
     207#endif
     208    }
     209#endif // QFONTDATABASE_DEBUG
     210}
     211
     212static inline void load(const QString &family = QString(), int = -1)
     213{
     214    populateDatabase(family);
     215}
     216
     217static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
     218{
    52219    // @todo implement
    53220}
    54221
    55 static inline void load(const QString &family = QString(), int = -1)
    56 {
    57     // @todo implement
    58 }
    59 
    60 static void registerFont(QFontDatabasePrivate::ApplicationFont *fnt)
    61 {
    62     // @todo implement
     222static QFontEngine *loadPM(const QFontPrivate *d, int script, const QFontDef &req)
     223{
     224    // @todo initializeDb() and stuff, get the engine
     225    QFontDef fd = req;
     226    QFontEngine *fe = new QFontEnginePMFT(fd);
     227    return fe;
    63228}
    64229
     
    95260            fe->fontDef = req;
    96261        } else {
    97             // @todo initializeDb() and stuff, get the engine
    98             QFontDef fd = req;
    99             fe = new QFontEnginePMFT(fd);
     262            QMutexLocker locker(fontDatabaseMutex());
     263            if (!privateDb()->count)
     264                initializeDb();
     265            fe = loadPM(d, script, req);
    100266        }
    101267        if (!fe) {
  • trunk/src/gui/text/text.pri

    r125 r220  
    189189contains(QT_CONFIG, fontconfig) {
    190190    CONFIG += opentype
     191} else {
     192    DEFINES *= QT_NO_FONTCONFIG
    191193}
    192194
Note: See TracChangeset for help on using the changeset viewer.