⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qfontdatabase.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            PitchMismatch       = 0x4000,            StyleMismatch       = 0x2000,            BitmapScaledPenalty = 0x1000,            EncodingMismatch    = 0x0002,            XLFDPenalty         = 0x0001        };#ifdef Q_WS_X11        if (encoding->encoding != -1) {            this_score += XLFDPenalty;            if (encoding->encoding != QFontPrivate::defaultEncodingID)                this_score += EncodingMismatch;        }        if (pitch != '*') {            if (!(pitch == 'm' && encoding->pitch == 'c') && pitch != encoding->pitch)                this_score += PitchMismatch;        }#else        if (pitch != '*') {#if !defined(QWS) && defined(Q_OS_MAC)            qt_mac_get_fixed_pitch(const_cast<QtFontFamily*>(family));#endif            if ((pitch == 'm' && !family->fixedPitch)                || (pitch == 'p' && family->fixedPitch))                this_score += PitchMismatch;        }#endif        if (styleKey != style->key)            this_score += StyleMismatch;        if (!style->smoothScalable && px != size->pixelSize) // bitmap scaled            this_score += BitmapScaledPenalty;        if (px != pixelSize) // close, but not exact, size match            this_score += qAbs(px - pixelSize);        if (this_score < score) {            FM_DEBUG("          found a match: score %x best score so far %x",                     this_score, score);            score = this_score;            desc->foundry = foundry;            desc->style = style;            desc->size = size;#ifdef Q_WS_X11            desc->encoding = encoding;#endif // Q_WS_X11        } else {            FM_DEBUG("          score %x no better than best %x", this_score, score);        }    }    return score;}/*!    \internal    Tries to find the best match for a given request and family/foundry*/static void match(int script, const QFontDef &request,                  const QString &family_name, const QString &foundry_name, int force_encoding_id,                  QtFontDesc *desc){    Q_UNUSED(force_encoding_id);    QtFontStyle::Key styleKey;    styleKey.style = request.style;    styleKey.weight = request.weight;    styleKey.stretch = request.stretch;    char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p';    FM_DEBUG("QFontDatabase::match\n"             "  request:\n"             "    family: %s [%s], script: %d\n"             "    weight: %d, style: %d\n"             "    stretch: %d\n"             "    pixelSize: %d\n"             "    pitch: %c",             family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(),             foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(),             script, request.weight, request.style, request.stretch, request.pixelSize, pitch);#if defined(FONT_MATCH_DEBUG) && defined(Q_WS_X11)    if (force_encoding_id >= 0) {        FM_DEBUG("    required encoding: %d", force_encoding_id);    }#endif    desc->family = 0;    desc->foundry = 0;    desc->style = 0;    desc->size = 0;    desc->encoding = 0;    unsigned int score = ~0u;    ::load(family_name, script);    QFontDatabasePrivate *db = privateDb();    for (int x = 0; x < db->count; ++x) {        QtFontDesc test;        test.family = db->families[x];        if (!family_name.isEmpty()            && ucstricmp(test.family->name, family_name) != 0#ifdef Q_WS_WIN            && ucstricmp(test.family->english_name, family_name) != 0#endif            )            continue;        if (family_name.isEmpty())            ::load(test.family->name, script);        uint score_adjust = 0;        bool supported = (script == QUnicodeTables::Common);        for (int ws = 1; !supported && ws < QFontDatabase::WritingSystemsCount; ++ws) {            if (scriptForWritingSystem[ws] != script)                continue;            if (test.family->writingSystems[ws] & QtFontFamily::Supported)                supported = true;        }        if (!supported) {            // family not supported in the script we want            continue;        }        // as we know the script is supported, we can be sure        // to find a matching font here.        unsigned int newscore =            bestFoundry(script, score, request.styleStrategy,                        test.family, foundry_name, styleKey, request.pixelSize, pitch,                        &test, force_encoding_id);        if (test.foundry == 0) {            // the specific foundry was not found, so look for            // any foundry matching our requirements            newscore = bestFoundry(script, score, request.styleStrategy, test.family,                                   QString(), styleKey, request.pixelSize,                                   pitch, &test, force_encoding_id);        }        newscore += score_adjust;        if (newscore < score) {            score = newscore;            *desc = test;        }        if (newscore < 10) // xlfd instead of FT... just accept it            break;    }}#if !defined(Q_WS_X11) && !defined(Q_WS_WIN)/*!    \internal*/QFontEngine *QFontDatabase::findFont(int script, const QFontPrivate *fp,                        const QFontDef &request, int#ifdef Q_WS_X11                        force_encoding_id#endif    ){#ifndef Q_WS_X11    const int force_encoding_id = -1;#endif    if (!privateDb()->count)        initializeDb();    QFontEngine *fe = 0;    if (fp) {        if (fp->rawMode) {            fe = loadEngine(script, fp, request, 0, 0, 0#ifdef Q_WS_X11                            , 0, 0, false#endif#ifdef Q_WS_QWS                            , 0#endif                );            // if we fail to load the rawmode font, use a 12pixel box engine instead            if (! fe) fe = new QFontEngineBox(12);            return fe;        }        QFontCache::Key key(request, script#if defined(Q_WS_X11)                            , fp->screen#endif            );        fe = QFontCache::instance->findEngine(key);        if (fe)            return fe;    }    QString family_name, foundry_name;    QtFontStyle::Key styleKey;    styleKey.style = request.style;    styleKey.weight = request.weight;    styleKey.stretch = request.stretch;    char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p';    parseFontName(request.family, foundry_name, family_name);    FM_DEBUG("QFontDatabase::findFont\n"             "  request:\n"             "    family: %s [%s], script: %d\n"             "    weight: %d, style: %d\n"             "    stretch: %d\n"             "    pixelSize: %d\n"             "    pitch: %c",             family_name.isEmpty() ? "-- first in script --" : family_name.toLatin1().constData(),             foundry_name.isEmpty() ? "-- any --" : foundry_name.toLatin1().constData(),             script, request.weight, request.style, request.stretch, request.pixelSize, pitch);#if defined(FONT_MATCH_DEBUG) && defined(Q_WS_X11)    if (force_encoding_id >= 0) {        FM_DEBUG("    required encoding: %d", force_encoding_id);    }#endif    if (qt_enable_test_font && request.family == QLatin1String("__Qt__Box__Engine__")) {        fe = new QTestFontEngine(request.pixelSize);        fe->fontDef = request;    }    if (!fe)    {        QtFontDesc desc;        match(script, request, family_name, foundry_name, force_encoding_id, &desc);        if (desc.family != 0 && desc.foundry != 0 && desc.style != 0#ifdef Q_WS_X11            && desc.size != 0 && desc.encoding != 0#endif            ) {            FM_DEBUG("  BEST:\n"                     "    family: %s [%s]\n"                     "    weight: %d, style: %d\n"                     "    stretch: %d\n"                     "    pixelSize: %d\n"                     "    pitch: %c\n"                     "    encoding: %d\n",                     desc.family->name.toLatin1().constData(),                     desc.foundry->name.isEmpty() ? "-- none --" : desc.foundry->name.toLatin1().constData(),                     desc.style->key.weight, desc.style->key.style,                     desc.style->key.stretch, desc.size ? desc.size->pixelSize : 0xffff,#ifdef Q_WS_X11                     desc.encoding->pitch, desc.encoding->encoding#else                     'p', 0#endif                );            fe = loadEngine(script, fp, request, desc.family, desc.foundry, desc.style#ifdef Q_WS_X11                            , desc.size, desc.encoding, (force_encoding_id >= 0)#endif#ifdef Q_WS_QWS                            , desc.size#endif                );        } else {            FM_DEBUG("  NO MATCH FOUND\n");        }        if (fe)            initFontDef(desc, request, &fe->fontDef);    }    if (fe) {        if (fp) {            QFontDef def = request;            if (def.family.isEmpty()) {                def.family = fp->request.family;                def.family = def.family.left(def.family.indexOf(','));            }            QFontCache::Key key(def, script#if defined(Q_WS_X11)                                , fp->screen#endif                );            QFontCache::instance->insertEngine(key, fe);        }#if defined(Q_WS_X11) && !defined(QT_NO_FONTCONFIG)        if (scriptRequiresOpenType(script)) {            QOpenType *ot = fe->openType();            if (!ot || !ot->supportsScript(script)) {                FM_DEBUG("  OpenType support missing for script");                fe = 0;            }        }#endif    }    if (!fe) {        if (!request.family.isEmpty())            return 0;        FM_DEBUG("returning box engine");        fe = new QFontEngineBox(request.pixelSize);        if (fp) {            QFontCache::Key key(request, script#if defined(Q_WS_X11)                                , fp->screen#endif                );            QFontCache::instance->insertEngine(key, fe);        }    }    if (fp) {#if defined(Q_WS_X11)        fe->fontDef.pointSize = qt_pointSize(fe->fontDef.pixelSize, fp->dpi);#elif defined(Q_WS_WIN)        fe->fontDef.pointSize = qreal(fe->fontDef.pixelSize) * 72.0                                / GetDeviceCaps(shared_dc,LOGPIXELSY);#elif defined(Q_WS_MAC)        fe->fontDef.pointSize = qt_mac_pointsize(fe->fontDef, fp->dpi);#else        fe->fontDef.pointSize = qreal(fe->fontDef.pixelSize); //####int(double(fe->fontDef.pixelSize) * 72.0 / 96.0);#endif    } else {        fe->fontDef.pointSize = request.pointSize;    }    return fe;}#endifstatic QString styleString(int weight, QFont::Style style){    QString result;    if (weight >= QFont::Black)        result = "Black";    else if (weight >= QFont::Bold)        result = "Bold";    else if (weight >= QFont::DemiBold)        result = "Demi Bold";    else if (weight < QFont::Normal)        result = "Light";    if (style == QFont::StyleItalic)        result += " Italic";    else if (style == QFont::StyleOblique)        result += " Oblique";    if (result.isEmpty())        result = "Normal";    return result.simplified();}/*!    Returns a string that describes the style of the \a font. For    example, "Bold Italic", "Bold", "Italic" or "Normal". An empty    string may be returned.*/QString QFontDatabase::styleString(const QFont &font){    return ::styleString(font.weight(), font.style());}/*!    Returns a string that describes the style of the \a fontInfo. For    example, "Bold Italic", "Bold", "Italic" or "Normal". An empty    string may be returned.*/QString QFontDatabase::styleString(const QFontInfo &fontInfo){    return ::styleString(fontInfo.weight(), fontInfo.style());}/*!    \class QFontDatabase qfontdatabase.h    \brief The QFontDatabase class provides information about the fonts available in the underlying window system.    \ingroup environment    \ingroup multimedia    The most common uses of this class are to query the database for    the list of font families() and for the pointSizes() and styles()    that are available for each family. An alternative to pointSizes()    is smoothSizes() which returns the sizes at which a given family    and style will look attractive.    If the font family is available from two or more foundries the    foundry name is included in the family name, e.g. "Helvetica    [Adobe]" and "Helvetica [Cronyx]". When you specify a family you    can either use the old hyphenated Qt 2.x "foundry-family" format,    e.g. "Cronyx-Helvetica", or the new bracketed Qt 3.x "family    [foundry]" format e.g. "Helvetica [Cronyx]". If the family has a    foundry it is always returned, e.g. by families(), using the    bracketed format.    The font() function returns a QFont given a family, style and    point size.    A family and style combination can be checked to see if it is    italic() or bold(), and to retrieve its weight(). Similarly we can    call isBitmapScalable(), isSmoothlyScalable(), isScalable() and    isFixedPitch().    Use the styleString() to obtain a text version of a style.    The QFontDatabase class also supports some static functions, for    example, standardSizes(). You can retrieve the description of a    writing system using writingSystemName(), and a sample of    characters in a writing system with writingSystemSample().    Example:\code#include <qapplication.h>#include <qfontdatabase.h>int main(int argc, char **argv){    QApplication app(argc, argv);    QFontDatabase fdb;    QStringList families = fdb.families();    for (QStringList::Iterator f = families.begin(); f != families.end(); ++f) {        QString family = *f;        qDebug(family);        QStringList styles = fdb.styles(family);        for (QStringList::Iterator s = styles.begin(); s != styles.end(); ++s) {            QString style = *s;            QString dstyle = "\t" + style + " (";            QList<int> smoothies = fdb.smoothSizes(family, style);            for (QList<int>::Iterator points = smoothies.begin();                  points != smoothies.end(); ++points) {                dstyle += QString::number(*points) + " ";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -