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