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

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