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

📄 qfontdatabase_x11.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.**** This file is part of the QtGui module of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://www.trolltech.com/products/qt/opensource.html**** If you are unsure which license is appropriate for your use, please** review the following information:** http://www.trolltech.com/products/qt/licensing.html or contact the** sales department at sales@trolltech.com.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <qplatformdefs.h>#include <qdatetime.h>#include <qdebug.h>#include <qpaintdevice.h>#include <private/qt_x11_p.h>#include "qx11info_x11.h"#include <qdebug.h>#include <ctype.h>#include <stdlib.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/mman.h>#ifndef QT_NO_FONTCONFIG#include <ft2build.h>#include FT_FREETYPE_H#endif// from qfont_x11.cppextern double qt_pointSize(double pixelSize, int dpi);extern double qt_pixelSize(double pointSize, int dpi);static inline void capitalize (char *s){    bool space = true;    while(*s) {        if (space)            *s = toupper(*s);        space = (*s == ' ');        ++s;    }}/*  To regenerate the writingSystems_for_xlfd_encoding table, run  'util/unicode/x11/makeencodings' and paste the generated  'encodings.c' here.*/// ----- begin of generated code -----#define make_tag( c1, c2, c3, c4 )                              \    ((((unsigned int)c1)<<24) | (((unsigned int)c2)<<16) |      \     (((unsigned int)c3)<<8) | ((unsigned int)c4))struct XlfdEncoding {    const char *name;    int id;    int mib;    unsigned int hash1;    unsigned int hash2;};static const XlfdEncoding xlfd_encoding[] = {    { "iso8859-1", 0, 4, make_tag('i','s','o','8'), make_tag('5','9','-','1') },    { "iso8859-2", 1, 5, make_tag('i','s','o','8'), make_tag('5','9','-','2') },    { "iso8859-3", 2, 6, make_tag('i','s','o','8'), make_tag('5','9','-','3') },    { "iso8859-4", 3, 7, make_tag('i','s','o','8'), make_tag('5','9','-','4') },    { "iso8859-9", 4, 12, make_tag('i','s','o','8'), make_tag('5','9','-','9') },    { "iso8859-10", 5, 13, make_tag('i','s','o','8'), make_tag('9','-','1','0') },    { "iso8859-13", 6, 109, make_tag('i','s','o','8'), make_tag('9','-','1','3') },    { "iso8859-14", 7, 110, make_tag('i','s','o','8'), make_tag('9','-','1','4') },    { "iso8859-15", 8, 111, make_tag('i','s','o','8'), make_tag('9','-','1','5') },    { "hp-roman8", 9, 2004, make_tag('h','p','-','r'), make_tag('m','a','n','8') },    { "iso8859-5", 10, 8, make_tag('i','s','o','8'), make_tag('5','9','-','5') },    { "*-cp1251", 11, 2251, 0, make_tag('1','2','5','1') },    { "koi8-ru", 12, 2084, make_tag('k','o','i','8'), make_tag('8','-','r','u') },    { "koi8-u", 13, 2088, make_tag('k','o','i','8'), make_tag('i','8','-','u') },    { "koi8-r", 14, 2084, make_tag('k','o','i','8'), make_tag('i','8','-','r') },    { "iso8859-7", 15, 10, make_tag('i','s','o','8'), make_tag('5','9','-','7') },    { "iso8859-8", 16, 85, make_tag('i','s','o','8'), make_tag('5','9','-','8') },    { "gb18030-0", 17, -114, make_tag('g','b','1','8'), make_tag('3','0','-','0') },    { "gb18030.2000-0", 18, -113, make_tag('g','b','1','8'), make_tag('0','0','-','0') },    { "gbk-0", 19, -113, make_tag('g','b','k','-'), make_tag('b','k','-','0') },    { "gb2312.*-0", 20, 57, make_tag('g','b','2','3'), 0 },    { "jisx0201*-0", 21, 15, make_tag('j','i','s','x'), 0 },    { "jisx0208*-0", 22, 63, make_tag('j','i','s','x'), 0 },    { "ksc5601*-*", 23, 36, make_tag('k','s','c','5'), 0 },    { "big5hkscs-0", 24, -2101, make_tag('b','i','g','5'), make_tag('c','s','-','0') },    { "hkscs-1", 25, -2101, make_tag('h','k','s','c'), make_tag('c','s','-','1') },    { "big5*-*", 26, -2026, make_tag('b','i','g','5'), 0 },    { "tscii-*", 27, 2028, make_tag('t','s','c','i'), 0 },    { "tis620*-*", 28, 2259, make_tag('t','i','s','6'), 0 },    { "iso8859-11", 29, 2259, make_tag('i','s','o','8'), make_tag('9','-','1','1') },    { "mulelao-1", 30, -4242, make_tag('m','u','l','e'), make_tag('a','o','-','1') },    { "ethiopic-unicode", 31, 0, make_tag('e','t','h','i'), make_tag('c','o','d','e') },    { "iso10646-1", 32, 0, make_tag('i','s','o','1'), make_tag('4','6','-','1') },    { "unicode-*", 33, 0, make_tag('u','n','i','c'), 0 },    { "*-symbol", 34, 0, 0, make_tag('m','b','o','l') },    { "*-fontspecific", 35, 0, 0, make_tag('i','f','i','c') },    { "fontspecific-*", 36, 0, make_tag('f','o','n','t'), 0 },    { 0, 0, 0, 0, 0 }};static const char writingSystems_for_xlfd_encoding[37][39] = {    // iso8859-1    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-2    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-3    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-4    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-9    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-10    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-13    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-14    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-15    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // hp-roman8    { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-5    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // *-cp1251    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // koi8-ru    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // koi8-u    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // koi8-r    { 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-7    { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-8    { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // gb18030-0    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 1, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // gb18030.2000-0    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 1, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // gbk-0    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 1, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // gb2312.*-0    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 1, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // jisx0201*-0    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 1, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // jisx0208*-0    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 1, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // ksc5601*-*    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 1, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // big5hkscs-0    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 1, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // hkscs-1    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 1, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // big5*-*    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 1, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // tscii-*    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 1, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // tis620*-*    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 1,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // iso8859-11    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 1,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // mulelao-1    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      1, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // ethiopic-unicode    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 1 },    // iso10646-1    { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 1,      1, 1, 0, 1, 0, 1, 1, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // unicode-*    { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 1,      1, 1, 0, 1, 0, 1, 1, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0 },    // *-symbol    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 1 },    // *-fontspecific    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 1 },    // fontspecific-*    { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 0, 0,      0, 0, 0, 0, 0, 0, 0, 0, 1 }};// ----- end of generated code -----const int numEncodings = sizeof(xlfd_encoding) / sizeof(XlfdEncoding) - 1;int qt_xlfd_encoding_id(const char *encoding){    // qDebug("looking for encoding id for '%s'", encoding);    int len = strlen(encoding);    if (len < 4)        return -1;    unsigned int hash1 = make_tag(encoding[0], encoding[1], encoding[2], encoding[3]);    const char *ch = encoding + len - 4;    unsigned int hash2 = make_tag(ch[0], ch[1], ch[2], ch[3]);    const XlfdEncoding *enc = xlfd_encoding;    for (; enc->name; ++enc) {        if ((enc->hash1 && enc->hash1 != hash1) ||            (enc->hash2 && enc->hash2 != hash2))            continue;        // hashes match, do a compare if strings match        // the enc->name can contain '*'s we have to interpret correctly        const char *n = enc->name;        const char *e = encoding;        while (1) {            // qDebug("bol: *e='%c', *n='%c'", *e, *n);            if (*e == '\0') {                if (*n)                    break;                // qDebug("found encoding id %d", enc->id);                return enc->id;            }            if (*e == *n) {                ++e;                ++n;                continue;            }            if (*n != '*')                break;            ++n;            // qDebug("skip: *e='%c', *n='%c'", *e, *n);            while (*e && *e != *n)                ++e;        }    }    // qDebug("couldn't find encoding %s", encoding);    return -1;}int qt_mib_for_xlfd_encoding(const char *encoding){    int id = qt_xlfd_encoding_id(encoding);    if (id != -1) return xlfd_encoding[id].mib;    return 0;};int qt_encoding_id_for_mib(int mib){    const XlfdEncoding *enc = xlfd_encoding;    for (; enc->name; ++enc) {        if (enc->mib == mib)            return enc->id;    }    return -1;}static const char * xlfd_for_id(int id){    // special case: -1 returns the "*-*" encoding, allowing us to do full    // database population in a single X server round trip.    if (id < 0 || id > numEncodings)        return "*-*";    return xlfd_encoding[id].name;}enum XLFDFieldNames {    Foundry,    Family,    Weight,    Slant,    Width,    AddStyle,    PixelSize,    PointSize,    ResolutionX,    ResolutionY,    Spacing,    AverageWidth,    CharsetRegistry,    CharsetEncoding,    NFontFields};// Splits an X font name into fields separated by '-'static bool parseXFontName(char *fontName, char **tokens){    if (! fontName || fontName[0] == '0' || fontName[0] != '-') {        tokens[0] = 0;        return false;    }    int          i;    ++fontName;    for (i = 0; i < NFontFields && fontName && fontName[0]; ++i) {        tokens[i] = fontName;        for (;; ++fontName) {            if (*fontName == '-')                break;            if (! *fontName) {                fontName = 0;                break;            }        }        if (fontName) *fontName++ = '\0';    }    if (i < NFontFields) {        for (int j = i ; j < NFontFields; ++j)            tokens[j] = 0;        return false;    }    return true;}static inline bool isZero(char *x){    return (x[0] == '0' && x[1] == 0);}static inline bool isScalable(char **tokens){    return (isZero(tokens[PixelSize]) &&

⌨️ 快捷键说明

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