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()TRUE | never evaluated | FALSE | never evaluated |
) { | 0 |
17 | QMessageLogger(__FILE__, 6167, __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 isfor Qtexample) installedor correctly?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 | | - |
36 | QFontEngine *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) { | - |
47 | QFontEngine::SubpixelAntialiasingType subpixelType = subpixelAntialiasingTypeHint(); | - |
48 | if (subpixelType == QFontEngine::Subpixel_None || (fontDef.styleStrategy & QFont::NoSubpixelAntialias)) { | - |
49 | format = QFontEngineFT::Format_A8; | - |
50 | engine->subpixelType = QFontEngine::Subpixel_None; | - |
51 | } else { | - |
52 | format = QFontEngineFT::Format_A32; | - |
53 | engine->subpixelType = subpixelType; | - |
54 | } | - |
55 | } | - |
56 | | - |
57 | if (!engine->init(fid, antialias, format) || engine->invalid()) { | - |
58 | delete engine; | - |
59 | engine = 0; | - |
60 | } else { | - |
61 | engine->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference)); | - |
62 | } | - |
63 | | - |
64 | return engine; | - |
65 | } | - |
66 | | - |
67 | namespace { | - |
68 | | - |
69 | class QFontEngineFTRawData: public QFontEngineFT | - |
70 | { | - |
71 | public: | - |
72 | QFontEngineFTRawData(const QFontDef &fontDef) : QFontEngineFT(fontDef) | - |
73 | { | - |
74 | } | - |
75 | | - |
76 | void updateFamilyNameAndStyle() | - |
77 | { | - |
78 | fontDef.family = QString::fromLatin1(freetype->face->family_name); | - |
79 | | - |
80 | if (freetype->face->style_flags & ( 1 << 0 )) | - |
81 | fontDef.style = QFont::StyleItalic; | - |
82 | | - |
83 | if (freetype->face->style_flags & ( 1 << 1 )) | - |
84 | fontDef.weight = QFont::Bold; | - |
85 | } | - |
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 init(faceId, true, Format_None, fontData); | - |
95 | } | - |
96 | }; | - |
97 | | - |
98 | } | - |
99 | | - |
100 | QFontEngine *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)) { | - |
109 | delete fe; | - |
110 | return 0; | - |
111 | } | - |
112 | | - |
113 | fe->updateFamilyNameAndStyle(); | - |
114 | fe->setQtDefaultHintStyle(static_cast<QFont::HintingPreference>(fontDef.hintingPreference)); | - |
115 | | - |
116 | return fe; | - |
117 | } | - |
118 | | - |
119 | QStringList QBasicFontDatabase::addApplicationFont(const QByteArray &fontData, const QString &fileName) | - |
120 | { | - |
121 | return QBasicFontDatabase::addTTFile(fontData, fileName.toLocal8Bit()); | - |
122 | } | - |
123 | | - |
124 | void QBasicFontDatabase::releaseHandle(void *handle) | - |
125 | { | - |
126 | FontFile *file = static_cast<FontFile *>(handle); | - |
127 | delete file; | - |
128 | } | - |
129 | | - |
130 | extern FT_Library qt_getFreetype(); | - |
131 | | - |
132 | QStringList 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()) { | - |
143 | error = FT_New_Memory_Face(library, (const FT_Byte *)fontData.constData(), fontData.size(), index, &face); | - |
144 | } else { | - |
145 | error = FT_New_Face(library, file.constData(), index, &face); | - |
146 | } | - |
147 | if (error != FT_Err_Ok) { | - |
148 | QMessageLogger(__FILE__, 191198, __PRETTY_FUNCTION__).debug() << "FT_New_Face failed with index" << index << ':' << hex << error; | - |
149 | break; | - |
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 )) | - |
157 | style = QFont::StyleItalic; | - |
158 | | - |
159 | if (face->style_flags & ( 1 << 1 )) | - |
160 | weight = QFont::Bold; | - |
161 | | - |
162 | bool fixedPitch = (face->face_flags & ( 1L << 2 )); | - |
163 | | - |
164 | QSupportedWritingSystems writingSystems; | - |
165 | | - |
166 | for (int i = 0; i < face->num_charmaps; ++i) { | - |
167 | FT_CharMap cm = face->charmaps[i]; | - |
168 | if (cm->encoding == FT_ENCODING_ADOBE_CUSTOM | - |
169 | || cm->encoding == FT_ENCODING_MS_SYMBOL) { | - |
170 | writingSystems.setSupported(QFontDatabase::Symbol); | - |
171 | break; | - |
172 | } | - |
173 | } | - |
174 | | - |
175 | TT_OS2 *os2 = (TT_OS2 *)FT_Get_Sfnt_Table(face, ft_sfnt_os2); | - |
176 | if (os2) { | - |
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) { | - |
191 | weight = QPlatformFontDatabase::weightFromInteger(os2->usWeightClass); | - |
192 | } else if (os2->panose[2]) { | - |
193 | int w = os2->panose[2]; | - |
194 | if (w <= 1) | - |
195 | weight = QFont::Thin; | - |
196 | else if (w <= 2) | - |
197 | weight = QFont::ExtraLight; | - |
198 | else if (w <= 3) | - |
199 | weight = QFont::Light; | - |
200 | else if (w <= 5) | - |
201 | weight = QFont::Normal; | - |
202 | else if (w <= 6) | - |
203 | weight = QFont::Medium; | - |
204 | else if (w <= 7) | - |
205 | weight = QFont::DemiBold; | - |
206 | else if (w <= 8) | - |
207 | weight = QFont::Bold; | - |
208 | else if (w <= 9) | - |
209 | weight = QFont::ExtraBold; | - |
210 | else if (w <= 10) | - |
211 | weight = QFont::Black; | - |
212 | } | - |
213 | } | - |
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 | } while (index < numFaces); | - |
229 | return families; | - |
230 | } | - |
231 | | - |
232 | | - |
| | |