qbasicfontdatabase.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8-
9-
10-
11void QBasicFontDatabase::populateFontDatabase()-
12{-
13 QString fontpath = fontDir();-
14 QDir dir(fontpath);-
15-
16 if (!dir.exists()
!dir.exists()Description
TRUEnever evaluated
FALSEnever evaluated
) {
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-
35QFontEngine *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
antialiasDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
46 QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint();-
47 if (subpixelType == QFontEngine::Subpixel_None
subpixelType =...:Subpixel_NoneDescription
TRUEnever evaluated
FALSEnever evaluated
|| (
(fontDef.style...ixelAntialias)Description
TRUEnever evaluated
FALSEnever evaluated
fontDef.styleStrategy & QFont::NoSubpixelAntialias)
(fontDef.style...ixelAntialias)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
48 format = QFontEngineFT::Format_A8;-
49 engine->subpixelType = QFontEngine::Subpixel_None;-
50 }
never executed: end of block
else {
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)
!engine->init(...alias, format)Description
TRUEnever evaluated
FALSEnever evaluated
|| engine->invalid()
engine->invalid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
57 delete engine;-
58 engine = 0;-
59 }
never executed: end of block
else {
0
60 engine->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference));-
61 }
never executed: end of block
0
62-
63 return
never executed: return engine;
engine;
never executed: return engine;
0
64}-
65-
66namespace {-
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:
  • tst_QRawFont
1249
74-
75 void updateFamilyNameAndStyle()-
76 {-
77 fontDef.family = QString::fromLatin1(freetype->face->family_name);-
78-
79 if (freetype->face->style_flags & ( 1 << 0 )
freetype->face...s & ( 1 << 0 )Description
TRUEevaluated 605 times by 1 test
Evaluated by:
  • tst_QRawFont
FALSEevaluated 642 times by 1 test
Evaluated by:
  • tst_QRawFont
)
605-642
80 fontDef.style = QFont::StyleItalic;
executed 605 times by 1 test: fontDef.style = QFont::StyleItalic;
Executed by:
  • tst_QRawFont
605
81-
82 if (freetype->face->style_flags & ( 1 << 1 )
freetype->face...s & ( 1 << 1 )Description
TRUEevaluated 605 times by 1 test
Evaluated by:
  • tst_QRawFont
FALSEevaluated 642 times by 1 test
Evaluated by:
  • tst_QRawFont
)
605-642
83 fontDef.weight = QFont::Bold;
executed 605 times by 1 test: fontDef.weight = QFont::Bold;
Executed by:
  • tst_QRawFont
605
84 }
executed 1247 times by 1 test: end of block
Executed by:
  • tst_QRawFont
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: return init(faceId, true, Format_None, fontData);
Executed by:
  • tst_QRawFont
init(faceId, true, Format_None, fontData);
executed 1249 times by 1 test: return init(faceId, true, Format_None, fontData);
Executed by:
  • tst_QRawFont
1249
94 }-
95 };-
96-
97}-
98-
99QFontEngine *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)
!fe->initFromData(fontData)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QRawFont
FALSEevaluated 1247 times by 1 test
Evaluated by:
  • tst_QRawFont
) {
2-1247
108 delete fe;-
109 return
executed 2 times by 1 test: return 0;
Executed by:
  • tst_QRawFont
0;
executed 2 times by 1 test: return 0;
Executed by:
  • tst_QRawFont
2
110 }-
111-
112 fe->updateFamilyNameAndStyle();-
113 fe->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference));-
114-
115 return
executed 1247 times by 1 test: return fe;
Executed by:
  • tst_QRawFont
fe;
executed 1247 times by 1 test: return fe;
Executed by:
  • tst_QRawFont
1247
116}-
117-
118QStringList QBasicFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName)-
119{-
120 return
never executed: return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
never executed: return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
0
121}-
122-
123void 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:
  • tst_QApplication
  • tst_QFontDatabase
  • tst_QFontDialog
  • tst_QFontMetrics
  • tst_QGlyphRun
  • tst_QRawFont
  • tst_languagechange - unknown status
  • tst_qabstractbutton - unknown status
  • tst_qabstractitemview - unknown status
  • tst_qabstractspinbox - unknown status
  • tst_qabstracttextdocumentlayout - unknown status
  • tst_qaccessibility - unknown status
  • tst_qapplication - unknown status
  • tst_qboxlayout - unknown status
  • tst_qbuttongroup - unknown status
  • tst_qcalendarwidget - unknown status
  • tst_qcheckbox - unknown status
  • tst_qcolordialog - unknown status
  • tst_qcolumnview - unknown status
  • tst_qcombobox - unknown status
  • tst_qcommandlinkbutton - unknown status
  • tst_qcompleter - unknown status
  • tst_qcomplextext - unknown status
  • tst_qcssparser - unknown status
  • tst_qdatawidgetmapper - unknown status
  • ...
21921
128-
129extern FT_Library qt_getFreetype();-
130-
131QStringList 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()
!fontData.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
142 error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face);-
143 }
never executed: end of block
else {
0
144 error = FT_New_Face(library, file.constData(), index, &face);-
145 }
never executed: end of block
0
146 if (error != FT_Err_Ok
error != FT_Err_OkDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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 )
face->style_flags & ( 1 << 0 )Description
TRUEnever evaluated
FALSEnever evaluated
)
0
156 style = QFont::StyleItalic;
never executed: style = QFont::StyleItalic;
0
157-
158 if (face->style_flags & ( 1 << 1 )
face->style_flags & ( 1 << 1 )Description
TRUEnever evaluated
FALSEnever evaluated
)
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
i < face->num_charmapsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
166 FT_CharMap cm = face->charmaps[i];-
167 if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM
cm->encoding =...G_ADOBE_CUSTOMDescription
TRUEnever evaluated
FALSEnever evaluated
0
168 || cm->encoding == FT_ENCODING_MS_SYMBOL
cm->encoding =...DING_MS_SYMBOLDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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
os2Description
TRUEnever evaluated
FALSEnever evaluated
) {
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
os2->usWeightClassDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
190 weight = QPlatformFontDatabase::weightFromInteger(os2->usWeightClass);-
191 }
never executed: end of block
else if (os2->panose[2]
os2->panose[2]Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
192 int w = os2->panose[2];-
193 if (w <= 1
w <= 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
194 weight = QFont::Thin;
never executed: weight = QFont::Thin;
0
195 else if (w <= 2
w <= 2Description
TRUEnever evaluated
FALSEnever evaluated
)
0
196 weight = QFont::ExtraLight;
never executed: weight = QFont::ExtraLight;
0
197 else if (w <= 3
w <= 3Description
TRUEnever evaluated
FALSEnever evaluated
)
0
198 weight = QFont::Light;
never executed: weight = QFont::Light;
0
199 else if (w <= 5
w <= 5Description
TRUEnever evaluated
FALSEnever evaluated
)
0
200 weight = QFont::Normal;
never executed: weight = QFont::Normal;
0
201 else if (w <= 6
w <= 6Description
TRUEnever evaluated
FALSEnever evaluated
)
0
202 weight = QFont::Medium;
never executed: weight = QFont::Medium;
0
203 else if (w <= 7
w <= 7Description
TRUEnever evaluated
FALSEnever evaluated
)
0
204 weight = QFont::DemiBold;
never executed: weight = QFont::DemiBold;
0
205 else if (w <= 8
w <= 8Description
TRUEnever evaluated
FALSEnever evaluated
)
0
206 weight = QFont::Bold;
never executed: weight = QFont::Bold;
0
207 else if (w <= 9
w <= 9Description
TRUEnever evaluated
FALSEnever evaluated
)
0
208 weight = QFont::ExtraBold;
never executed: weight = QFont::ExtraBold;
0
209 else if (w <= 10
w <= 10Description
TRUEnever evaluated
FALSEnever evaluated
)
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: end of block
while (index < numFaces
index < numFacesDescription
TRUEnever evaluated
FALSEnever evaluated
);
0
228 return
never executed: return families;
families;
never executed: return families;
0
229}-
230-
231-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9