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

📄 qfontdatabase_x11.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    if (FcPatternGetInteger(pattern, FC_SPACING, 0, &spacing) == FcResultMatch) {        fontDef.fixedPitch = (spacing >= FC_MONO);        fontDef.ignorePitch = false;    } else {        fontDef.ignorePitch = true;    }    return fontDef;}static const char *specialLanguages[] = {    "en", // Common    "el", // Greek    "ru", // Cyrillic    "hy", // Armenian    "he", // Hebrew    "ar", // Arabic    "syr", // Syriac    "div", // Thaana    "hi", // Devanagari    "bn", // Bengali    "pa", // Gurmukhi    "gu", // Gujarati    "or", // Oriya    "ta", // Tamil    "te", // Telugu    "kn", // Kannada    "ml", // Malayalam    "si", // Sinhala    "th", // Thai    "lo", // Lao    "bo", // Tibetan    "my", // Myanmar    "ka", // Georgian    "ko", // Hangul    "", // Ogham    "", // Runic    "km" // Khmer};enum { SpecialLanguageCount = sizeof(specialLanguages) / sizeof(const char *) };static ushort specialChars[] = {    0, // English    0, // Greek    0, // Cyrillic    0, // Armenian    0, // Hebrew    0, // Arabic    0, // Syriac    0, // Thaana    0, // Devanagari    0, // Bengali    0, // Gurmukhi    0, // Gujarati    0, // Oriya    0, // Tamil    0xc15, // Telugu    0xc95, // Kannada    0xd15, // Malayalam    0xd9a, // Sinhala    0, // Thai    0, // Lao    0, // Tibetan    0x1000, // Myanmar    0, // Georgian    0, // Hangul    0x1681, // Ogham    0x16a0, // Runic    0  // Khmer};enum { SpecialCharCount = sizeof(specialChars) / sizeof(ushort) };// this could become a list of all languages used for each writing// system, instead of using the single most common language.static const char *languageForWritingSystem[] = {    0,     // Any    "en",  // Latin    "el",  // Greek    "ru",  // Cyrillic    "hy",  // Armenian    "he",  // Hebrew    "ar",  // Arabic    "syr", // Syriac    "div", // Thaana    "hi",  // Devanagari    "bn",  // Bengali    "pa",  // Gurmukhi    "gu",  // Gujarati    "or",  // Oriya    "ta",  // Tamil    "te",  // Telugu    "kn",  // Kannada    "ml",  // Malayalam    "si",  // Sinhala    "th",  // Thai    "lo",  // Lao    "bo",  // Tibetan    "my",  // Myanmar    "ka",  // Georgian    "km",  // Khmer    "zh-cn", // SimplifiedChinese    "zh-tw", // TraditionalChinese    "ja",  // Japanese    "ko",  // Korean    "vi",  // Vietnamese    0, // Symbol    0, // Ogham    0 // Runic};enum { LanguageCount = sizeof(languageForWritingSystem) / sizeof(const char *) };// Unfortunately FontConfig doesn't know about some languages. We have to test these through the// charset. The lists below contain the systems where we need to do this.static const ushort sampleCharForWritingSystem[] = {    0,     // Any    0,  // Latin    0,  // Greek    0,  // Cyrillic    0,  // Armenian    0,  // Hebrew    0,  // Arabic    0, // Syriac    0, // Thaana    0,  // Devanagari    0,  // Bengali    0,  // Gurmukhi    0,  // Gujarati    0,  // Oriya    0,  // Tamil    0xc15,  // Telugu    0xc95,  // Kannada    0xd15,  // Malayalam    0xd9a,  // Sinhala    0,  // Thai    0,  // Lao    0,  // Tibetan    0x1000,  // Myanmar    0,  // Georgian    0,  // Khmer    0, // SimplifiedChinese    0, // TraditionalChinese    0,  // Japanese    0,  // Korean    0,  // Vietnamese    0, // Symbol    0x1681, // Ogham    0x16a0 // Runic};enum { SampleCharCount = sizeof(sampleCharForWritingSystem) / sizeof(ushort) };// Newer FontConfig let's us sort out fonts that contain certain glyphs, but no// open type tables for is directly. Do this so we don't pick some strange// pseudo unicode fontstatic const char *openType[] = {    0,     // Any    0,  // Latin    0,  // Greek    0,  // Cyrillic    0,  // Armenian    0,  // Hebrew    0,  // Arabic    "syrc",  // Syriac    "thaa",  // Thaana    "deva",  // Devanagari    "beng",  // Bengali    "guru",  // Gurmukhi    "gurj",  // Gujarati    "orya",  // Oriya    "taml",  // Tamil    "telu",  // Telugu    "knda",  // Kannada    "mlym",  // Malayalam    "sinh",  // Sinhala    0,  // Thai    0,  // Lao    "tibt",  // Tibetan    "mymr",  // Myanmar    0,  // Georgian    "khmr",  // Khmer    0, // SimplifiedChinese    0, // TraditionalChinese    0,  // Japanese    0,  // Korean    0,  // Vietnamese    0, // Symbol    0, // Ogham    0 // Runic};enum { OpenTypeCount = sizeof(openType) / sizeof(const char *) };static void loadFontConfig(){    Q_ASSERT_X(X11, "QFontDatabase",               "A QApplication object needs to be constructed before FontConfig is used.");    if (!X11->has_fontconfig)        return;    Q_ASSERT_X(int(QUnicodeTables::ScriptCount) == SpecialLanguageCount,               "QFontDatabase", "New scripts have been added.");    Q_ASSERT_X(int(QUnicodeTables::ScriptCount) == SpecialCharCount,               "QFontDatabase", "New scripts have been added.");    Q_ASSERT_X(int(QFontDatabase::WritingSystemsCount) == LanguageCount,               "QFontDatabase", "New writing systems have been added.");    Q_ASSERT_X(int(QFontDatabase::WritingSystemsCount) == SampleCharCount,               "QFontDatabase", "New writing systems have been added.");    Q_ASSERT_X(int(QFontDatabase::WritingSystemsCount) == OpenTypeCount,               "QFontDatabase", "New writing systems have been added.");    QFontDatabasePrivate *db = privateDb();    FcFontSet  *fonts;    QString familyName;    QString rawName;    FcChar8 *value = 0;    int weight_value;    int slant_value;    int spacing_value;    FcChar8 *file_value;    int index_value;    FcChar8 *foundry_value;    FcBool scalable;    {        FcObjectSet *os = FcObjectSetCreate();        FcPattern *pattern = FcPatternCreate();        const char *properties [] = {            FC_FAMILY, FC_WEIGHT, FC_SLANT,            FC_SPACING, FC_FILE, FC_INDEX,            FC_LANG, FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, FC_WEIGHT,            FC_WIDTH,#if FC_VERSION >= 20297            FC_CAPABILITY,#endif            (const char *)0        };        const char **p = properties;        while (*p) {            FcObjectSetAdd(os, *p);            ++p;        }        fonts = FcFontList(0, pattern, os);        FcObjectSetDestroy(os);        FcPatternDestroy(pattern);    }    for (int i = 0; i < fonts->nfont; i++) {        if (FcPatternGetString(fonts->fonts[i], FC_FAMILY, 0, &value) != FcResultMatch)            continue;        //         capitalize(value);        rawName = familyName = QString::fromUtf8((const char *)value);        familyName.replace(QLatin1Char('-'), QLatin1Char(' '));        familyName.remove(QLatin1Char('/'));        slant_value = FC_SLANT_ROMAN;        weight_value = FC_WEIGHT_MEDIUM;        spacing_value = FC_PROPORTIONAL;	file_value = 0;	index_value = 0;	scalable = FcTrue;        if (FcPatternGetInteger (fonts->fonts[i], FC_SLANT, 0, &slant_value) != FcResultMatch)	    slant_value = FC_SLANT_ROMAN;        if (FcPatternGetInteger (fonts->fonts[i], FC_WEIGHT, 0, &weight_value) != FcResultMatch)	    weight_value = FC_WEIGHT_MEDIUM;        if (FcPatternGetInteger (fonts->fonts[i], FC_SPACING, 0, &spacing_value) != FcResultMatch)	    spacing_value = FC_PROPORTIONAL;        if (FcPatternGetString (fonts->fonts[i], FC_FILE, 0, &file_value) != FcResultMatch)	    file_value = 0;        if (FcPatternGetInteger (fonts->fonts[i], FC_INDEX, 0, &index_value) != FcResultMatch)	    index_value = 0;        if (FcPatternGetBool(fonts->fonts[i], FC_SCALABLE, 0, &scalable) != FcResultMatch)	    scalable = FcTrue;        if (FcPatternGetString(fonts->fonts[i], FC_FOUNDRY, 0, &foundry_value) != FcResultMatch)	    foundry_value = 0;        QtFontFamily *family = db->family(familyName, true);        family->rawName = rawName;        FcLangSet *langset = 0;        FcResult res = FcPatternGetLangSet(fonts->fonts[i], FC_LANG, 0, &langset);        if (res == FcResultMatch) {            for (int i = 1; i < LanguageCount; ++i) {                const FcChar8 *lang = (const FcChar8*) languageForWritingSystem[i];                if (!lang) {                    family->writingSystems[i] |= QtFontFamily::UnsupportedFT;                } else {                    FcLangResult langRes = FcLangSetHasLang(langset, lang);                    if (langRes != FcLangDifferentLang)                        family->writingSystems[i] = QtFontFamily::Supported;                    else                        family->writingSystems[i] |= QtFontFamily::UnsupportedFT;                }            }            family->writingSystems[QFontDatabase::Other] = QtFontFamily::UnsupportedFT;            family->ftWritingSystemCheck = true;        } else {            // we set Other to supported for symbol fonts. It makes no            // sense to merge these with other ones, as they are            // special in a way.            for (int i = 1; i < LanguageCount; ++i)                family->writingSystems[i] |= QtFontFamily::UnsupportedFT;            family->writingSystems[QFontDatabase::Other] = QtFontFamily::Supported;        }        FcCharSet *cs = 0;        res = FcPatternGetCharSet(fonts->fonts[i], FC_CHARSET, 0, &cs);        if (res == FcResultMatch) {            // some languages are not supported by FontConfig, we rather check the            // charset to detect these            for (int i = 1; i < SampleCharCount; ++i) {                if (!sampleCharForWritingSystem[i])                    continue;                if (FcCharSetHasChar(cs, sampleCharForWritingSystem[i]))                    family->writingSystems[i] = QtFontFamily::Supported;            }        }#if FC_VERSION >= 20297        for (int j = 1; j < LanguageCount; ++j) {            if (family->writingSystems[j] == QtFontFamily::Supported && requiresOpenType(j) && openType[j]) {                FcChar8 *cap;                res = FcPatternGetString (fonts->fonts[i], FC_CAPABILITY, 0, &cap);                if (res != FcResultMatch || !strstr((const char *)cap, openType[j]))                    family->writingSystems[j] = QtFontFamily::UnsupportedFT;            }        }#endif        QByteArray file((const char *)file_value);        family->fontFilename = file;        family->fontFileIndex = index_value;        QtFontStyle::Key styleKey;        styleKey.style = (slant_value == FC_SLANT_ITALIC)                         ? QFont::StyleItalic                         : ((slant_value == FC_SLANT_OBLIQUE)                            ? QFont::StyleOblique                            : QFont::StyleNormal);        styleKey.weight = getFCWeight(weight_value);        if (!scalable) {            int width = 100;            FcPatternGetInteger (fonts->fonts[i], FC_WIDTH, 0, &width);            styleKey.stretch = width;        }        QtFontFoundry *foundry            = family->foundry(foundry_value ? QString::fromUtf8((const char *)foundry_value) : QString(), true);        QtFontStyle *style = foundry->style(styleKey, true);        if (spacing_value < FC_MONO)            family->fixedPitch = false;        QtFontSize *size;        if (scalable) {            style->smoothScalable = true;            size = style->pixelSize(SMOOTH_SCALABLE, true);        } else {            double pixel_size = 0;            FcPatternGetDouble (fonts->fonts[i], FC_PIXEL_SIZE, 0, &pixel_size);            size = style->pixelSize((int)pixel_size, true);        }        QtFontEncoding *enc = size->encodingID(-1, 0, 0, 0, 0, true);        enc->pitch = (spacing_value >= FC_CHARCELL ? 'c' :                      (spacing_value >= FC_MONO ? 'm' : 'p'));    }    FcFontSetDestroy (fonts);    struct FcDefaultFont {        const char *qtname;        const char *rawname;        bool fixed;    };    const FcDefaultFont defaults[] = {        { "Serif", "serif", false },        { "Sans Serif", "sans-serif", false },        { "Monospace", "monospace", true },        { 0, 0, false }    };    const FcDefaultFont *f = defaults;    while (f->qtname) {        QtFontFamily *family = db->family(QLatin1String(f->qtname), true);        family->fixedPitch = f->fixed;        family->rawName = QLatin1String(f->rawname);        family->synthetic = true;        QtFontFoundry *foundry = family->foundry(QString(), true);        // aliases only make sense for 'common', not for any of the specials        for (int i = 1; i < LanguageCount; ++i) {            if (requiresOpenType(i))                family->writingSystems[i] = QtFontFamily::UnsupportedFT;            else                family->writingSystems[i] = QtFontFamily::Supported;        }        family->writingSystems[QFontDatabase::Other] = QtFontFamily::UnsupportedFT;        QtFontStyle::Key styleKey;        for (int i = 0; i < 4; ++i) {

⌨️ 快捷键说明

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