qbasicfontdatabase.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/platformsupport/fontdatabases/basic/qbasicfontdatabase.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
1/****************************************************************************-
2**-
3** Copyright (C) 2016 The Qt Company Ltd.-
4** Contact: https://www.qt.io/licensing/-
5**-
6** This file is part of the plugins of the Qt Toolkit.-
7**-
8** $QT_BEGIN_LICENSE:LGPL$-
9** Commercial License Usage-
10** Licensees holding valid commercial Qt licenses may use this file in-
11** accordance with the commercial license agreement provided with the-
12** Software or, alternatively, in accordance with the terms contained in-
13** a written agreement between you and The Qt Company. For licensing terms-
14** and conditions see https://www.qt.io/terms-conditions. For further-
15** information use the contact form at https://www.qt.io/contact-us.-
16**-
17** GNU Lesser General Public License Usage-
18** Alternatively, this file may be used under the terms of the GNU Lesser-
19** General Public License version 3 as published by the Free Software-
20** Foundation and appearing in the file LICENSE.LGPL3 included in the-
21** packaging of this file. Please review the following information to-
22** ensure the GNU Lesser General Public License version 3 requirements-
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.-
24**-
25** GNU General Public License Usage-
26** Alternatively, this file may be used under the terms of the GNU-
27** General Public License version 2.0 or (at your option) the GNU General-
28** Public license version 3 or any later version approved by the KDE Free-
29** Qt Foundation. The licenses are as published by the Free Software-
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3-
31** included in the packaging of this file. Please review the following-
32** information to ensure the GNU General Public License requirements will-
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and-
34** https://www.gnu.org/licenses/gpl-3.0.html.-
35**-
36** $QT_END_LICENSE$-
37**-
38****************************************************************************/-
39-
40#include "qbasicfontdatabase_p.h"-
41-
42#include <QtGui/private/qguiapplication_p.h>-
43#include <qpa/qplatformscreen.h>-
44-
45#include <QtCore/QFile>-
46#include <QtCore/QLibraryInfo>-
47#include <QtCore/QDir>-
48#include <QtCore/QUuid>-
49#include <QtCore/QtEndian>-
50-
51#undef QT_NO_FREETYPE-
52#include <QtGui/private/qfontengine_ft_p.h>-
53#include <QtGui/private/qfontengine_p.h>-
54-
55#include <ft2build.h>-
56#include FT_TRUETYPE_TABLES_H-
57#include FT_ERRORS_H-
58-
59QT_BEGIN_NAMESPACE-
60-
61void QBasicFontDatabase::populateFontDatabase()-
62{-
63 QString fontpath = fontDir();-
64 QDir dir(fontpath);-
65-
66 if (!dir.exists()) {
!dir.exists()Description
TRUEnever evaluated
FALSEnever evaluated
0
67 qWarning("QFontDatabase: Cannot find font directory %s.\n"-
68 "Note that Qt no longer ships fonts. Deploy some (from http://dejavu-fonts.org for example) or switch to fontconfig.",-
69 qPrintable(fontpath));-
70 return;
never executed: return;
0
71 }-
72-
73 QStringList nameFilters;-
74 nameFilters << QLatin1String("*.ttf")-
75 << QLatin1String("*.ttc")-
76 << QLatin1String("*.pfa")-
77 << QLatin1String("*.pfb")-
78 << QLatin1String("*.otf");-
79-
80 foreach (const QFileInfo &fi, dir.entryInfoList(nameFilters, QDir::Files)) {-
81 const QByteArray file = QFile::encodeName(fi.absoluteFilePath());-
82 QBasicFontDatabase::addTTFile(QByteArray(), file);-
83 }
never executed: end of block
0
84}
never executed: end of block
0
85-
86QFontEngine *QBasicFontDatabase::fontEngine(const QFontDef &fontDef, void *usrPtr)-
87{-
88 FontFile *fontfile = static_cast<FontFile *> (usrPtr);-
89 QFontEngine::FaceId fid;-
90 fid.filename = QFile::encodeName(fontfile->fileName);-
91 fid.index = fontfile->indexValue;-
92-
93 bool antialias = !(fontDef.styleStrategy & QFont::NoAntialias);-
94 QFontEngineFT *engine = new QFontEngineFT(fontDef);-
95 QFontEngineFT::GlyphFormat format = QFontEngineFT::Format_Mono;-
96 if (antialias) {
antialiasDescription
TRUEnever evaluated
FALSEnever evaluated
0
97 QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint();-
98 if (subpixelType == QFontEngine::Subpixel_None || (fontDef.styleStrategy & QFont::NoSubpixelAntialias)) {
subpixelType =...:Subpixel_NoneDescription
TRUEnever evaluated
FALSEnever evaluated
(fontDef.style...ixelAntialias)Description
TRUEnever evaluated
FALSEnever evaluated
0
99 format = QFontEngineFT::Format_A8;-
100 engine->subpixelType = QFontEngine::Subpixel_None;-
101 } else {
never executed: end of block
0
102 format = QFontEngineFT::Format_A32;-
103 engine->subpixelType = subpixelType;-
104 }
never executed: end of block
0
105 }-
106-
107 if (!engine->init(fid, antialias, format) || engine->invalid()) {
!engine->init(...alias, format)Description
TRUEnever evaluated
FALSEnever evaluated
engine->invalid()Description
TRUEnever evaluated
FALSEnever evaluated
0
108 delete engine;-
109 engine = 0;-
110 } else {
never executed: end of block
0
111 engine->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference));-
112 }
never executed: end of block
0
113-
114 return engine;
never executed: return engine;
0
115}-
116-
117namespace {-
118-
119 class QFontEngineFTRawData: public QFontEngineFT-
120 {-
121 public:-
122 QFontEngineFTRawData(const QFontDef &fontDef) : QFontEngineFT(fontDef)-
123 {-
124 }
executed 1250 times by 1 test: end of block
Executed by:
  • tst_QRawFont
1250
125-
126 void updateFamilyNameAndStyle()-
127 {-
128 fontDef.family = QString::fromLatin1(freetype->face->family_name);-
129-
130 if (freetype->face->style_flags & FT_STYLE_FLAG_ITALIC)
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
131 fontDef.style = QFont::StyleItalic;
executed 605 times by 1 test: fontDef.style = QFont::StyleItalic;
Executed by:
  • tst_QRawFont
605
132-
133 if (freetype->face->style_flags & FT_STYLE_FLAG_BOLD)
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
134 fontDef.weight = QFont::Bold;
executed 605 times by 1 test: fontDef.weight = QFont::Bold;
Executed by:
  • tst_QRawFont
605
135 }
executed 1248 times by 1 test: end of block
Executed by:
  • tst_QRawFont
1248
136-
137 bool initFromData(const QByteArray &fontData)-
138 {-
139 FaceId faceId;-
140 faceId.filename = "";-
141 faceId.index = 0;-
142 faceId.uuid = QUuid::createUuid().toByteArray();-
143-
144 return init(faceId, true, Format_None, fontData);
executed 1250 times by 1 test: return init(faceId, true, Format_None, fontData);
Executed by:
  • tst_QRawFont
1250
145 }-
146 };-
147-
148}-
149-
150QFontEngine *QBasicFontDatabase::fontEngine(const QByteArray &fontData, qreal pixelSize,-
151 QFont::HintingPreference hintingPreference)-
152{-
153 QFontDef fontDef;-
154 fontDef.pixelSize = pixelSize;-
155 fontDef.hintingPreference = hintingPreference;-
156-
157 QFontEngineFTRawData *fe = new QFontEngineFTRawData(fontDef);-
158 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
159 delete fe;-
160 return 0;
executed 2 times by 1 test: return 0;
Executed by:
  • tst_QRawFont
2
161 }-
162-
163 fe->updateFamilyNameAndStyle();-
164 fe->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference));-
165-
166 return fe;
executed 1248 times by 1 test: return fe;
Executed by:
  • tst_QRawFont
1248
167}-
168-
169QStringList QBasicFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName)-
170{-
171 return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
never executed: return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit());
0
172}-
173-
174void QBasicFontDatabase::releaseHandle(void *handle)-
175{-
176 FontFile *file = static_cast<FontFile *>(handle);-
177 delete file;-
178}
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
179-
180extern FT_Library qt_getFreetype();-
181-
182QStringList QBasicFontDatabase::addTTFile(const QByteArray &fontData, const QByteArray &file)-
183{-
184 FT_Library library = qt_getFreetype();-
185-
186 int index = 0;-
187 int numFaces = 0;-
188 QStringList families;-
189 do {-
190 FT_Face face;-
191 FT_Error error;-
192 if (!fontData.isEmpty()) {
!fontData.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
193 error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face);-
194 } else {
never executed: end of block
0
195 error = FT_New_Face(library, file.constData(), index, &face);-
196 }
never executed: end of block
0
197 if (error != FT_Err_Ok) {
error != FT_Err_OkDescription
TRUEnever evaluated
FALSEnever evaluated
0
198 qDebug() << "FT_New_Face failed with index" << index << ':' << hex << error;-
199 break;
never executed: break;
0
200 }-
201 numFaces = face->num_faces;-
202-
203 QFont::Weight weight = QFont::Normal;-
204-
205 QFont::Style style = QFont::StyleNormal;-
206 if (face->style_flags & FT_STYLE_FLAG_ITALIC)
face->style_flags & ( 1 << 0 )Description
TRUEnever evaluated
FALSEnever evaluated
0
207 style = QFont::StyleItalic;
never executed: style = QFont::StyleItalic;
0
208-
209 if (face->style_flags & FT_STYLE_FLAG_BOLD)
face->style_flags & ( 1 << 1 )Description
TRUEnever evaluated
FALSEnever evaluated
0
210 weight = QFont::Bold;
never executed: weight = QFont::Bold;
0
211-
212 bool fixedPitch = (face->face_flags & FT_FACE_FLAG_FIXED_WIDTH);-
213-
214 QSupportedWritingSystems writingSystems;-
215 // detect symbol fonts-
216 for (int i = 0; i < face->num_charmaps; ++i) {
i < face->num_charmapsDescription
TRUEnever evaluated
FALSEnever evaluated
0
217 FT_CharMap cm = face->charmaps[i];-
218 if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM
cm->encoding =...G_ADOBE_CUSTOMDescription
TRUEnever evaluated
FALSEnever evaluated
0
219 || cm->encoding == FT_ENCODING_MS_SYMBOL) {
cm->encoding =...DING_MS_SYMBOLDescription
TRUEnever evaluated
FALSEnever evaluated
0
220 writingSystems.setSupported(QFontDatabase::Symbol);-
221 break;
never executed: break;
0
222 }-
223 }
never executed: end of block
0
224-
225 TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2);-
226 if (os2) {
os2Description
TRUEnever evaluated
FALSEnever evaluated
0
227 quint32 unicodeRange[4] = {-
228 quint32(os2->ulUnicodeRange1),-
229 quint32(os2->ulUnicodeRange2),-
230 quint32(os2->ulUnicodeRange3),-
231 quint32(os2->ulUnicodeRange4)-
232 };-
233 quint32 codePageRange[2] = {-
234 quint32(os2->ulCodePageRange1),-
235 quint32(os2->ulCodePageRange2)-
236 };-
237-
238 writingSystems = QPlatformFontDatabase::writingSystemsFromTrueTypeBits(unicodeRange, codePageRange);-
239-
240 if (os2->usWeightClass) {
os2->usWeightClassDescription
TRUEnever evaluated
FALSEnever evaluated
0
241 weight = QPlatformFontDatabase::weightFromInteger(os2->usWeightClass);-
242 } else if (os2->panose[2]) {
never executed: end of block
os2->panose[2]Description
TRUEnever evaluated
FALSEnever evaluated
0
243 int w = os2->panose[2];-
244 if (w <= 1)
w <= 1Description
TRUEnever evaluated
FALSEnever evaluated
0
245 weight = QFont::Thin;
never executed: weight = QFont::Thin;
0
246 else if (w <= 2)
w <= 2Description
TRUEnever evaluated
FALSEnever evaluated
0
247 weight = QFont::ExtraLight;
never executed: weight = QFont::ExtraLight;
0
248 else if (w <= 3)
w <= 3Description
TRUEnever evaluated
FALSEnever evaluated
0
249 weight = QFont::Light;
never executed: weight = QFont::Light;
0
250 else if (w <= 5)
w <= 5Description
TRUEnever evaluated
FALSEnever evaluated
0
251 weight = QFont::Normal;
never executed: weight = QFont::Normal;
0
252 else if (w <= 6)
w <= 6Description
TRUEnever evaluated
FALSEnever evaluated
0
253 weight = QFont::Medium;
never executed: weight = QFont::Medium;
0
254 else if (w <= 7)
w <= 7Description
TRUEnever evaluated
FALSEnever evaluated
0
255 weight = QFont::DemiBold;
never executed: weight = QFont::DemiBold;
0
256 else if (w <= 8)
w <= 8Description
TRUEnever evaluated
FALSEnever evaluated
0
257 weight = QFont::Bold;
never executed: weight = QFont::Bold;
0
258 else if (w <= 9)
w <= 9Description
TRUEnever evaluated
FALSEnever evaluated
0
259 weight = QFont::ExtraBold;
never executed: weight = QFont::ExtraBold;
0
260 else if (w <= 10)
w <= 10Description
TRUEnever evaluated
FALSEnever evaluated
0
261 weight = QFont::Black;
never executed: weight = QFont::Black;
0
262 }
never executed: end of block
0
263 }
never executed: end of block
0
264-
265 QString family = QString::fromLatin1(face->family_name);-
266 FontFile *fontFile = new FontFile;-
267 fontFile->fileName = QFile::decodeName(file);-
268 fontFile->indexValue = index;-
269-
270 QFont::Stretch stretch = QFont::Unstretched;-
271-
272 registerFont(family,QString::fromLatin1(face->style_name),QString(),weight,style,stretch,true,true,0,fixedPitch,writingSystems,fontFile);-
273-
274 families.append(family);-
275-
276 FT_Done_Face(face);-
277 ++index;-
278 } while (index < numFaces);
never executed: end of block
index < numFacesDescription
TRUEnever evaluated
FALSEnever evaluated
0
279 return families;
never executed: return families;
0
280}-
281-
282QT_END_NAMESPACE-
Source codeSwitch to Preprocessed file

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