OpenCoverage

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__, 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-
36QFontEngine *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
antialiasDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
47 QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint();-
48 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
49 format = QFontEngineFT::Format_A8;-
50 engine->subpixelType = QFontEngine::Subpixel_None;-
51 }
never executed: end of block
else {
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)
!engine->init(...alias, format)Description
TRUEnever evaluated
FALSEnever evaluated
|| engine->invalid()
engine->invalid()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
58 delete engine;-
59 engine = 0;-
60 }
never executed: end of block
else {
0
61 engine->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference));-
62 }
never executed: end of block
0
63-
64 return
never executed: return engine;
engine;
never executed: return engine;
0
65}-
66-
67namespace {-
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 block
Executed by:
  • tst_QRawFont
1250
75-
76 void updateFamilyNameAndStyle()-
77 {-
78 fontDef.family = QString::fromLatin1(freetype->face->family_name);-
79-
80 if (freetype->face->style_flags & ( 1 << 0 )
freetype->face...s & ( 1 << 0 )Description
TRUEevaluated 605 times by 1 test
Evaluated by:
  • tst_QRawFont
FALSEevaluated 643 times by 1 test
Evaluated by:
  • tst_QRawFont
)
605-643
81 fontDef.style = QFont::StyleItalic;
executed 605 times by 1 test: fontDef.style = QFont::StyleItalic;
Executed by:
  • tst_QRawFont
605
82-
83 if (freetype->face->style_flags & ( 1 << 1 )
freetype->face...s & ( 1 << 1 )Description
TRUEevaluated 605 times by 1 test
Evaluated by:
  • tst_QRawFont
FALSEevaluated 643 times by 1 test
Evaluated by:
  • tst_QRawFont
)
605-643
84 fontDef.weight = QFont::Bold;
executed 605 times by 1 test: fontDef.weight = QFont::Bold;
Executed by:
  • tst_QRawFont
605
85 }
executed 1248 times by 1 test: end of block
Executed by:
  • tst_QRawFont
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: return init(faceId, true, Format_None, fontData);
Executed by:
  • tst_QRawFont
init(faceId, true, Format_None, fontData);
executed 1250 times by 1 test: return init(faceId, true, Format_None, fontData);
Executed by:
  • tst_QRawFont
1250
95 }-
96 };-
97-
98}-
99-
100QFontEngine *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)
!fe->initFromData(fontData)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QRawFont
FALSEevaluated 1248 times by 1 test
Evaluated by:
  • tst_QRawFont
) {
2-1248
109 delete fe;-
110 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
111 }-
112-
113 fe->updateFamilyNameAndStyle();-
114 fe->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference));-
115-
116 return
executed 1248 times by 1 test: return fe;
Executed by:
  • tst_QRawFont
fe;
executed 1248 times by 1 test: return fe;
Executed by:
  • tst_QRawFont
1248
117}-
118-
119QStringList QBasicFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName)-
120{-
121 return
never executed: return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
never executed: return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
0
122}-
123-
124void QBasicFontDatabase::releaseHandle(void *handle)-
125{-
126 FontFile *file = static_cast<FontFile *>(handle);-
127 delete file;-
128}
executed 23587 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
  • ...
23587
129-
130extern FT_Library qt_getFreetype();-
131-
132QStringList 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()
!fontData.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
143 error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face);-
144 }
never executed: end of block
else {
0
145 error = FT_New_Face(library, file.constData(), index, &face);-
146 }
never executed: end of block
0
147 if (error != FT_Err_Ok
error != FT_Err_OkDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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 )
face->style_flags & ( 1 << 0 )Description
TRUEnever evaluated
FALSEnever evaluated
)
0
157 style = QFont::StyleItalic;
never executed: style = QFont::StyleItalic;
0
158-
159 if (face->style_flags & ( 1 << 1 )
face->style_flags & ( 1 << 1 )Description
TRUEnever evaluated
FALSEnever evaluated
)
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
i < face->num_charmapsDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
167 FT_CharMap cm = face->charmaps[i];-
168 if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM
cm->encoding =...G_ADOBE_CUSTOMDescription
TRUEnever evaluated
FALSEnever evaluated
0
169 || cm->encoding == FT_ENCODING_MS_SYMBOL
cm->encoding =...DING_MS_SYMBOLDescription
TRUEnever evaluated
FALSEnever evaluated
) {
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
os2Description
TRUEnever evaluated
FALSEnever evaluated
) {
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
os2->usWeightClassDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
191 weight = QPlatformFontDatabase::weightFromInteger(os2->usWeightClass);-
192 }
never executed: end of block
else if (os2->panose[2]
os2->panose[2]Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
193 int w = os2->panose[2];-
194 if (w <= 1
w <= 1Description
TRUEnever evaluated
FALSEnever evaluated
)
0
195 weight = QFont::Thin;
never executed: weight = QFont::Thin;
0
196 else if (w <= 2
w <= 2Description
TRUEnever evaluated
FALSEnever evaluated
)
0
197 weight = QFont::ExtraLight;
never executed: weight = QFont::ExtraLight;
0
198 else if (w <= 3
w <= 3Description
TRUEnever evaluated
FALSEnever evaluated
)
0
199 weight = QFont::Light;
never executed: weight = QFont::Light;
0
200 else if (w <= 5
w <= 5Description
TRUEnever evaluated
FALSEnever evaluated
)
0
201 weight = QFont::Normal;
never executed: weight = QFont::Normal;
0
202 else if (w <= 6
w <= 6Description
TRUEnever evaluated
FALSEnever evaluated
)
0
203 weight = QFont::Medium;
never executed: weight = QFont::Medium;
0
204 else if (w <= 7
w <= 7Description
TRUEnever evaluated
FALSEnever evaluated
)
0
205 weight = QFont::DemiBold;
never executed: weight = QFont::DemiBold;
0
206 else if (w <= 8
w <= 8Description
TRUEnever evaluated
FALSEnever evaluated
)
0
207 weight = QFont::Bold;
never executed: weight = QFont::Bold;
0
208 else if (w <= 9
w <= 9Description
TRUEnever evaluated
FALSEnever evaluated
)
0
209 weight = QFont::ExtraBold;
never executed: weight = QFont::ExtraBold;
0
210 else if (w <= 10
w <= 10Description
TRUEnever evaluated
FALSEnever evaluated
)
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: end of block
while (index < numFaces
index < numFacesDescription
TRUEnever evaluated
FALSEnever evaluated
);
0
229 return
never executed: return families;
families;
never executed: return families;
0
230}-
231-
232-
Switch to Source codePreprocessed file

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