| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | - | |||||||||||||||||||
| 7 | - | |||||||||||||||||||
| 8 | - | |||||||||||||||||||
| 9 | - | |||||||||||||||||||
| 10 | - | |||||||||||||||||||
| 11 | void QBasicFontDatabase::populateFontDatabase() | - | ||||||||||||||||||
| 12 | { | - | ||||||||||||||||||
| 13 | QString fontpath = fontDir(); | - | ||||||||||||||||||
| 14 | QDir dir(fontpath); | - | ||||||||||||||||||
| 15 | - | |||||||||||||||||||
| 16 | if (!dir.exists()
| 0 | ||||||||||||||||||
| 17 | QMessageLogger(__FILE__, 67, __PRETTY_FUNCTION__).warning("QFontDatabase: Cannot find font directory %s.\n" | - | ||||||||||||||||||
| 18 | "Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.", | - | ||||||||||||||||||
| 19 | QString(fontpath).toLocal8Bit().constData()); | - | ||||||||||||||||||
| 20 | return; never executed: return; | 0 | ||||||||||||||||||
| 21 | } | - | ||||||||||||||||||
| 22 | - | |||||||||||||||||||
| 23 | QStringList nameFilters; | - | ||||||||||||||||||
| 24 | nameFilters << QLatin1String("*.ttf") | - | ||||||||||||||||||
| 25 | << QLatin1String("*.ttc") | - | ||||||||||||||||||
| 26 | << QLatin1String("*.pfa") | - | ||||||||||||||||||
| 27 | << QLatin1String("*.pfb") | - | ||||||||||||||||||
| 28 | << QLatin1String("*.otf"); | - | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | for (QForeachContainer<typename QtPrivate::remove_reference<decltype(dir.entryInfoList(nameFilters, QDir::Files))>::type> _container_((dir.entryInfoList(nameFilters, QDir::Files))); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (const QFileInfo &fi = *_container_.i; _container_.control; _container_.control = 0) { | - | ||||||||||||||||||
| 31 | const QByteArray file = QFile::encodeName(fi.absoluteFilePath()); | - | ||||||||||||||||||
| 32 | QBasicFontDatabase::addTTFile(QByteArray(), file); | - | ||||||||||||||||||
| 33 | } never executed: end of block | 0 | ||||||||||||||||||
| 34 | } never executed: end of block | 0 | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | QFontEngine *QBasicFontDatabase::fontEngine(const QFontDef &fontDef, void *usrPtr) | - | ||||||||||||||||||
| 37 | { | - | ||||||||||||||||||
| 38 | FontFile *fontfile = static_cast<FontFile *> (usrPtr); | - | ||||||||||||||||||
| 39 | QFontEngine::FaceId fid; | - | ||||||||||||||||||
| 40 | fid.filename = QFile::encodeName(fontfile->fileName); | - | ||||||||||||||||||
| 41 | fid.index = fontfile->indexValue; | - | ||||||||||||||||||
| 42 | - | |||||||||||||||||||
| 43 | bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias); | - | ||||||||||||||||||
| 44 | QFontEngineFT *engine = new QFontEngineFT(fontDef); | - | ||||||||||||||||||
| 45 | QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_Mono; | - | ||||||||||||||||||
| 46 | if (antialias
| 0 | ||||||||||||||||||
| 47 | QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint(); | - | ||||||||||||||||||
| 48 | if (subpixelType == QFontEngine::Subpixel_None
| 0 | ||||||||||||||||||
| 49 | format = QFontEngineFT::Format_A8; | - | ||||||||||||||||||
| 50 | engine->subpixelType = QFontEngine::Subpixel_None; | - | ||||||||||||||||||
| 51 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 52 | format = QFontEngineFT::Format_A32; | - | ||||||||||||||||||
| 53 | engine->subpixelType = subpixelType; | - | ||||||||||||||||||
| 54 | } never executed: end of block | 0 | ||||||||||||||||||
| 55 | } | - | ||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | if (!engine->init(fid, antialias, format)
| 0 | ||||||||||||||||||
| 58 | delete engine; | - | ||||||||||||||||||
| 59 | engine = 0; | - | ||||||||||||||||||
| 60 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 61 | engine->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference)); | - | ||||||||||||||||||
| 62 | } never executed: end of block | 0 | ||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 | return never executed: engine;return engine;never executed: return engine; | 0 | ||||||||||||||||||
| 65 | } | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | namespace { | - | ||||||||||||||||||
| 68 | - | |||||||||||||||||||
| 69 | class QFontEngineFTRawData: public QFontEngineFT | - | ||||||||||||||||||
| 70 | { | - | ||||||||||||||||||
| 71 | public: | - | ||||||||||||||||||
| 72 | QFontEngineFTRawData(const QFontDef &fontDef) : QFontEngineFT(fontDef) | - | ||||||||||||||||||
| 73 | { | - | ||||||||||||||||||
| 74 | } executed 1250 times by 1 test: end of blockExecuted by:
| 1250 | ||||||||||||||||||
| 75 | - | |||||||||||||||||||
| 76 | void updateFamilyNameAndStyle() | - | ||||||||||||||||||
| 77 | { | - | ||||||||||||||||||
| 78 | fontDef.family = QString::fromLatin1(freetype->face->family_name); | - | ||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | if (freetype->face->style_flags & ( 1 << 0 )
| 605-643 | ||||||||||||||||||
| 81 | fontDef.style = QFont::StyleItalic; executed 605 times by 1 test: fontDef.style = QFont::StyleItalic;Executed by:
| 605 | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | if (freetype->face->style_flags & ( 1 << 1 )
| 605-643 | ||||||||||||||||||
| 84 | fontDef.weight = QFont::Bold; executed 605 times by 1 test: fontDef.weight = QFont::Bold;Executed by:
| 605 | ||||||||||||||||||
| 85 | } executed 1248 times by 1 test: end of blockExecuted by:
| 1248 | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | bool initFromData(const QByteArray &fontData) | - | ||||||||||||||||||
| 88 | { | - | ||||||||||||||||||
| 89 | FaceId faceId; | - | ||||||||||||||||||
| 90 | faceId.filename = ""; | - | ||||||||||||||||||
| 91 | faceId.index = 0; | - | ||||||||||||||||||
| 92 | faceId.uuid = QUuid::createUuid().toByteArray(); | - | ||||||||||||||||||
| 93 | - | |||||||||||||||||||
| 94 | return executed 1250 times by 1 test: init(faceId, true, Format_None, fontData);return init(faceId, true, Format_None, fontData);Executed by:
executed 1250 times by 1 test: return init(faceId, true, Format_None, fontData);Executed by:
| 1250 | ||||||||||||||||||
| 95 | } | - | ||||||||||||||||||
| 96 | }; | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | } | - | ||||||||||||||||||
| 99 | - | |||||||||||||||||||
| 100 | QFontEngine *QBasicFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize, | - | ||||||||||||||||||
| 101 | QFont::HintingPreference hintingPreference) | - | ||||||||||||||||||
| 102 | { | - | ||||||||||||||||||
| 103 | QFontDef fontDef; | - | ||||||||||||||||||
| 104 | fontDef.pixelSize = pixelSize; | - | ||||||||||||||||||
| 105 | fontDef.hintingPreference = hintingPreference; | - | ||||||||||||||||||
| 106 | - | |||||||||||||||||||
| 107 | QFontEngineFTRawData *fe = new QFontEngineFTRawData(fontDef); | - | ||||||||||||||||||
| 108 | if (!fe->initFromData(fontData)
| 2-1248 | ||||||||||||||||||
| 109 | delete fe; | - | ||||||||||||||||||
| 110 | return executed 2 times by 1 test: 0;return 0;Executed by:
executed 2 times by 1 test: return 0;Executed by:
| 2 | ||||||||||||||||||
| 111 | } | - | ||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | fe->updateFamilyNameAndStyle(); | - | ||||||||||||||||||
| 114 | fe->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference)); | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | return executed 1248 times by 1 test: fe;return fe;Executed by:
executed 1248 times by 1 test: return fe;Executed by:
| 1248 | ||||||||||||||||||
| 117 | } | - | ||||||||||||||||||
| 118 | - | |||||||||||||||||||
| 119 | QStringList QBasicFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) | - | ||||||||||||||||||
| 120 | { | - | ||||||||||||||||||
| 121 | return never executed: QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());never executed: return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit()); | 0 | ||||||||||||||||||
| 122 | } | - | ||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | void QBasicFontDatabase::releaseHandle(void *handle) | - | ||||||||||||||||||
| 125 | { | - | ||||||||||||||||||
| 126 | FontFile *file = static_cast<FontFile *>(handle); | - | ||||||||||||||||||
| 127 | delete file; | - | ||||||||||||||||||
| 128 | } executed 23587 times by 127 tests: end of blockExecuted by:
| 23587 | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | extern FT_Library qt_getFreetype(); | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByteArray &file) | - | ||||||||||||||||||
| 133 | { | - | ||||||||||||||||||
| 134 | FT_Library library = qt_getFreetype(); | - | ||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | int index = 0; | - | ||||||||||||||||||
| 137 | int numFaces = 0; | - | ||||||||||||||||||
| 138 | QStringList families; | - | ||||||||||||||||||
| 139 | do { | - | ||||||||||||||||||
| 140 | FT_Face face; | - | ||||||||||||||||||
| 141 | FT_Error error; | - | ||||||||||||||||||
| 142 | if (!fontData.isEmpty()
| 0 | ||||||||||||||||||
| 143 | error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face); | - | ||||||||||||||||||
| 144 | } never executed: else {end of block | 0 | ||||||||||||||||||
| 145 | error = FT_New_Face(library, file.constData(), index, &face); | - | ||||||||||||||||||
| 146 | } never executed: end of block | 0 | ||||||||||||||||||
| 147 | if (error != FT_Err_Ok
| 0 | ||||||||||||||||||
| 148 | QMessageLogger(__FILE__, 198, __PRETTY_FUNCTION__).debug() << "FT_New_Face failed with index" << index << ':' << hex << error; | - | ||||||||||||||||||
| 149 | break; never executed: break; | 0 | ||||||||||||||||||
| 150 | } | - | ||||||||||||||||||
| 151 | numFaces = face->num_faces; | - | ||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | QFont::Weight weight = QFont::Normal; | - | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | QFont::Style style = QFont::StyleNormal; | - | ||||||||||||||||||
| 156 | if (face->style_flags & ( 1 << 0 )
| 0 | ||||||||||||||||||
| 157 | style = QFont::StyleItalic; never executed: style = QFont::StyleItalic; | 0 | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | if (face->style_flags & ( 1 << 1 )
| 0 | ||||||||||||||||||
| 160 | weight = QFont::Bold; never executed: weight = QFont::Bold; | 0 | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | bool fixedPitch = (face->face_flags & ( 1L << 2 )); | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | QSupportedWritingSystems writingSystems; | - | ||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | for (int i = 0; i < face->num_charmaps
| 0 | ||||||||||||||||||
| 167 | FT_CharMap cm = face->charmaps[i]; | - | ||||||||||||||||||
| 168 | if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM
| 0 | ||||||||||||||||||
| 169 | || cm->encoding == FT_ENCODING_MS_SYMBOL
| 0 | ||||||||||||||||||
| 170 | writingSystems.setSupported(QFontDatabase::Symbol); | - | ||||||||||||||||||
| 171 | break; never executed: break; | 0 | ||||||||||||||||||
| 172 | } | - | ||||||||||||||||||
| 173 | } never executed: end of block | 0 | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); | - | ||||||||||||||||||
| 176 | if (os2
| 0 | ||||||||||||||||||
| 177 | quint32 unicodeRange[4] = { | - | ||||||||||||||||||
| 178 | quint32(os2->ulUnicodeRange1), | - | ||||||||||||||||||
| 179 | quint32(os2->ulUnicodeRange2), | - | ||||||||||||||||||
| 180 | quint32(os2->ulUnicodeRange3), | - | ||||||||||||||||||
| 181 | quint32(os2->ulUnicodeRange4) | - | ||||||||||||||||||
| 182 | }; | - | ||||||||||||||||||
| 183 | quint32 codePageRange[2] = { | - | ||||||||||||||||||
| 184 | quint32(os2->ulCodePageRange1), | - | ||||||||||||||||||
| 185 | quint32(os2->ulCodePageRange2) | - | ||||||||||||||||||
| 186 | }; | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange); | - | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | if (os2->usWeightClass
| 0 | ||||||||||||||||||
| 191 | weight = QPlatformFontDatabase::weightFromInteger(os2->usWeightClass); | - | ||||||||||||||||||
| 192 | } never executed: else if (os2->panose[2]end of block
| 0 | ||||||||||||||||||
| 193 | int w = os2->panose[2]; | - | ||||||||||||||||||
| 194 | if (w <= 1
| 0 | ||||||||||||||||||
| 195 | weight = QFont::Thin; never executed: weight = QFont::Thin; | 0 | ||||||||||||||||||
| 196 | else if (w <= 2
| 0 | ||||||||||||||||||
| 197 | weight = QFont::ExtraLight; never executed: weight = QFont::ExtraLight; | 0 | ||||||||||||||||||
| 198 | else if (w <= 3
| 0 | ||||||||||||||||||
| 199 | weight = QFont::Light; never executed: weight = QFont::Light; | 0 | ||||||||||||||||||
| 200 | else if (w <= 5
| 0 | ||||||||||||||||||
| 201 | weight = QFont::Normal; never executed: weight = QFont::Normal; | 0 | ||||||||||||||||||
| 202 | else if (w <= 6
| 0 | ||||||||||||||||||
| 203 | weight = QFont::Medium; never executed: weight = QFont::Medium; | 0 | ||||||||||||||||||
| 204 | else if (w <= 7
| 0 | ||||||||||||||||||
| 205 | weight = QFont::DemiBold; never executed: weight = QFont::DemiBold; | 0 | ||||||||||||||||||
| 206 | else if (w <= 8
| 0 | ||||||||||||||||||
| 207 | weight = QFont::Bold; never executed: weight = QFont::Bold; | 0 | ||||||||||||||||||
| 208 | else if (w <= 9
| 0 | ||||||||||||||||||
| 209 | weight = QFont::ExtraBold; never executed: weight = QFont::ExtraBold; | 0 | ||||||||||||||||||
| 210 | else if (w <= 10
| 0 | ||||||||||||||||||
| 211 | weight = QFont::Black; never executed: weight = QFont::Black; | 0 | ||||||||||||||||||
| 212 | } never executed: end of block | 0 | ||||||||||||||||||
| 213 | } never executed: end of block | 0 | ||||||||||||||||||
| 214 | - | |||||||||||||||||||
| 215 | QString family = QString::fromLatin1(face->family_name); | - | ||||||||||||||||||
| 216 | FontFile *fontFile = new FontFile; | - | ||||||||||||||||||
| 217 | fontFile->fileName = QFile::decodeName(file); | - | ||||||||||||||||||
| 218 | fontFile->indexValue = index; | - | ||||||||||||||||||
| 219 | - | |||||||||||||||||||
| 220 | QFont::Stretch stretch = QFont::Unstretched; | - | ||||||||||||||||||
| 221 | - | |||||||||||||||||||
| 222 | registerFont(family,QString::fromLatin1(face->style_name),QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile); | - | ||||||||||||||||||
| 223 | - | |||||||||||||||||||
| 224 | families.append(family); | - | ||||||||||||||||||
| 225 | - | |||||||||||||||||||
| 226 | FT_Done_Face(face); | - | ||||||||||||||||||
| 227 | ++index; | - | ||||||||||||||||||
| 228 | } never executed: while (index < numFacesend of block
| 0 | ||||||||||||||||||
| 229 | return never executed: families;return families;never executed: return families; | 0 | ||||||||||||||||||
| 230 | } | - | ||||||||||||||||||
| 231 | - | |||||||||||||||||||
| 232 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |