Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickfontloader.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | - | |||||||
8 | - | |||||||
9 | - | |||||||
10 | - | |||||||
11 | - | |||||||
12 | - | |||||||
13 | - | |||||||
14 | class QQuickFontObject : public QObject | - | ||||||
15 | { | - | ||||||
16 | public: | - | ||||||
17 | #pragma GCC diagnostic push | - | ||||||
18 | - | |||||||
19 | #pragma GCC diagnostic ignored "-Wsuggest-override" | - | ||||||
20 | static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); virtual int qt_metacall(QMetaObject::Call, int, void **); static inline QString tr(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = nullptr, int n = -1) { return staticMetaObject.tr(s, c, n); } private: | - | ||||||
21 | #pragma GCC diagnostic ignored "-Wattributes" | - | ||||||
22 | __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); | - | ||||||
23 | #pragma GCC diagnostic pop | - | ||||||
24 | struct QPrivateSignal {}; | - | ||||||
25 | - | |||||||
26 | public: | - | ||||||
27 | explicit QQuickFontObject(int _id = -1); | - | ||||||
28 | - | |||||||
29 | - | |||||||
30 | void download(const QUrl &url, QNetworkAccessManager *manager); | - | ||||||
31 | - | |||||||
32 | public : | - | ||||||
33 | void fontDownloaded(const QString&, QQuickFontLoader::Status); | - | ||||||
34 | - | |||||||
35 | private: | - | ||||||
36 | int redirectCount = 0; | - | ||||||
37 | QNetworkReply *reply = nullptr; | - | ||||||
38 | - | |||||||
39 | private : | - | ||||||
40 | void replyFinished(); | - | ||||||
41 | - | |||||||
42 | - | |||||||
43 | public: | - | ||||||
44 | int id; | - | ||||||
45 | - | |||||||
46 | QQuickFontObject(const QQuickFontObject &) = delete; QQuickFontObject &operator=(const QQuickFontObject &) = delete; | - | ||||||
47 | }; | - | ||||||
48 | - | |||||||
49 | QQuickFontObject::QQuickFontObject(int _id) | - | ||||||
50 | : QObject(nullptr), id(_id) | - | ||||||
51 | { | - | ||||||
52 | } executed 22 times by 3 tests: end of block Executed by:
| 22 | ||||||
53 | - | |||||||
54 | - | |||||||
55 | void QQuickFontObject::download(const QUrl &url, QNetworkAccessManager *manager) | - | ||||||
56 | { | - | ||||||
57 | QNetworkRequest req(url); | - | ||||||
58 | req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true); | - | ||||||
59 | reply = manager->get(req); | - | ||||||
60 | QObject::connect(reply, qFlagLocation("2""finished()" "\0" __FILE__ ":" "104"), this, qFlagLocation("1""replyFinished()" "\0" __FILE__ ":" "104")); | - | ||||||
61 | } executed 14 times by 2 tests: end of block Executed by:
| 14 | ||||||
62 | - | |||||||
63 | void QQuickFontObject::replyFinished() | - | ||||||
64 | { | - | ||||||
65 | if (reply
| 0-14 | ||||||
66 | redirectCount++; | - | ||||||
67 | if (redirectCount < 16
| 0-14 | ||||||
68 | QVariant redirect = reply->attribute(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||
69 | if (redirect.isValid()
| 2-12 | ||||||
70 | QUrl url = reply->url().resolved(redirect.toUrl()); | - | ||||||
71 | QNetworkAccessManager *manager = reply->manager(); | - | ||||||
72 | reply->deleteLater(); | - | ||||||
73 | reply = nullptr; | - | ||||||
74 | download(url, manager); | - | ||||||
75 | return; executed 2 times by 1 test: return; Executed by:
| 2 | ||||||
76 | } | - | ||||||
77 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||
78 | redirectCount = 0; | - | ||||||
79 | - | |||||||
80 | if (!reply->error()
| 6 | ||||||
81 | id = QFontDatabase::addApplicationFontFromData(reply->readAll()); | - | ||||||
82 | if (id != -1
| 0-6 | ||||||
83 | fontDownloaded(QFontDatabase::applicationFontFamilies(id).at(0), QQuickFontLoader::Ready); executed 6 times by 1 test: fontDownloaded(QFontDatabase::applicationFontFamilies(id).at(0), QQuickFontLoader::Ready); Executed by:
| 6 | ||||||
84 | else | - | ||||||
85 | fontDownloaded(QString(), QQuickFontLoader::Error); never executed: fontDownloaded(QString(), QQuickFontLoader::Error); | 0 | ||||||
86 | } else { | - | ||||||
87 | QMessageLogger(__FILE__, 131, __PRETTY_FUNCTION__).warning("%s: Unable to load font '%s': %s", __PRETTY_FUNCTION__, | - | ||||||
88 | QtPrivate::asString(reply->url().toString()).toLocal8Bit().constData(), QtPrivate::asString(reply->errorString()).toLocal8Bit().constData()); | - | ||||||
89 | fontDownloaded(QString(), QQuickFontLoader::Error); | - | ||||||
90 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||
91 | reply->deleteLater(); | - | ||||||
92 | reply = nullptr; | - | ||||||
93 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||
94 | } executed 12 times by 2 tests: end of block Executed by:
| 12 | ||||||
95 | - | |||||||
96 | - | |||||||
97 | class QQuickFontLoaderPrivate : public QObjectPrivate | - | ||||||
98 | { | - | ||||||
99 | inline QQuickFontLoader* q_func() { return static_cast<QQuickFontLoader *>(q_ptr); } inline const QQuickFontLoader* q_func() const { return static_cast<const QQuickFontLoader *>(q_ptr); } friend class QQuickFontLoader; | - | ||||||
100 | - | |||||||
101 | public: | - | ||||||
102 | QQuickFontLoaderPrivate() {} | - | ||||||
103 | - | |||||||
104 | QUrl url; | - | ||||||
105 | QString name; | - | ||||||
106 | QQuickFontLoader::Status status = QQuickFontLoader::Null; | - | ||||||
107 | }; | - | ||||||
108 | - | |||||||
109 | static void q_QFontLoaderFontsStaticReset(); | - | ||||||
110 | static void q_QFontLoaderFontsAddReset() | - | ||||||
111 | { | - | ||||||
112 | qAddPostRoutine(q_QFontLoaderFontsStaticReset); | - | ||||||
113 | } executed 10 times by 3 tests: end of block Executed by:
| 10 | ||||||
114 | class QFontLoaderFonts | - | ||||||
115 | { | - | ||||||
116 | public: | - | ||||||
117 | QFontLoaderFonts() | - | ||||||
118 | { | - | ||||||
119 | qAddPostRoutine(q_QFontLoaderFontsStaticReset); | - | ||||||
120 | qAddPreRoutine(q_QFontLoaderFontsAddReset); | - | ||||||
121 | } executed 6 times by 3 tests: end of block Executed by:
| 6 | ||||||
122 | - | |||||||
123 | ~QFontLoaderFonts() | - | ||||||
124 | { | - | ||||||
125 | qRemovePostRoutine(q_QFontLoaderFontsStaticReset); | - | ||||||
126 | reset(); | - | ||||||
127 | } executed 6 times by 3 tests: end of block Executed by:
| 6 | ||||||
128 | - | |||||||
129 | - | |||||||
130 | void reset() | - | ||||||
131 | { | - | ||||||
132 | QVector<QQuickFontObject *> deleted; | - | ||||||
133 | QHash<QUrl, QQuickFontObject*>::iterator it; | - | ||||||
134 | for (it = map.begin(); it != map.end()
| 22 | ||||||
135 | if (!deleted.contains(it.value())
| 0-22 | ||||||
136 | deleted.append(it.value()); | - | ||||||
137 | delete it.value(); | - | ||||||
138 | } executed 22 times by 3 tests: end of block Executed by:
| 22 | ||||||
139 | } executed 22 times by 3 tests: end of block Executed by:
| 22 | ||||||
140 | map.clear(); | - | ||||||
141 | } executed 22 times by 3 tests: end of block Executed by:
| 22 | ||||||
142 | - | |||||||
143 | QHash<QUrl, QQuickFontObject *> map; | - | ||||||
144 | }; | - | ||||||
145 | namespace { namespace Q_QGS_fontLoaderFonts { typedef QFontLoaderFonts Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
executed 6 times by 3 tests: }guard.store(QtGlobalStatic::Destroyed); Executed by:
executed 6 times by 3 tests: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block Executed by:
executed 78 times by 3 tests: &holder.value;return &holder.value; Executed by:
executed 78 times by 3 tests: } } } static QGlobalStatic<QFontLoaderFonts, Q_QGS_fontLoaderFonts::innerFunction, Q_QGS_fontLoaderFonts::guard> fontLoaderFonts;;return &holder.value; Executed by:
| 0-78 | ||||||
146 | - | |||||||
147 | static void q_QFontLoaderFontsStaticReset() | - | ||||||
148 | { | - | ||||||
149 | fontLoaderFonts()->reset(); | - | ||||||
150 | } executed 16 times by 3 tests: end of block Executed by:
| 16 | ||||||
151 | QQuickFontLoader::QQuickFontLoader(QObject *parent) | - | ||||||
152 | : QObject(*(new QQuickFontLoaderPrivate), parent) | - | ||||||
153 | { | - | ||||||
154 | } executed 30 times by 3 tests: end of block Executed by:
| 30 | ||||||
155 | - | |||||||
156 | QQuickFontLoader::~QQuickFontLoader() | - | ||||||
157 | { | - | ||||||
158 | } | - | ||||||
159 | - | |||||||
160 | - | |||||||
161 | - | |||||||
162 | - | |||||||
163 | - | |||||||
164 | QUrl QQuickFontLoader::source() const | - | ||||||
165 | { | - | ||||||
166 | const QQuickFontLoaderPrivate * const d = d_func(); | - | ||||||
167 | return executed 20 times by 1 test: d->url;return d->url; Executed by:
executed 20 times by 1 test: return d->url; Executed by:
| 20 | ||||||
168 | } | - | ||||||
169 | - | |||||||
170 | void QQuickFontLoader::setSource(const QUrl &url) | - | ||||||
171 | { | - | ||||||
172 | QQuickFontLoaderPrivate * const d = d_func(); | - | ||||||
173 | if (url == d->url
| 0-32 | ||||||
174 | return; never executed: return; | 0 | ||||||
175 | d->url = url; | - | ||||||
176 | sourceChanged(); | - | ||||||
177 | - | |||||||
178 | QString localFile = QQmlFile::urlToLocalFileOrQrc(d->url); | - | ||||||
179 | if (!localFile.isEmpty()
| 14-18 | ||||||
180 | if (!fontLoaderFonts()->map.contains(d->url)
| 6-12 | ||||||
181 | int id = QFontDatabase::addApplicationFont(localFile); | - | ||||||
182 | if (id != -1
| 2-10 | ||||||
183 | updateFontInfo(QFontDatabase::applicationFontFamilies(id).at(0), Ready); | - | ||||||
184 | QQuickFontObject *fo = new QQuickFontObject(id); | - | ||||||
185 | fontLoaderFonts()->map[d->url] = fo; | - | ||||||
186 | } executed 10 times by 3 tests: else {end of block Executed by:
| 10 | ||||||
187 | updateFontInfo(QString(), Error); | - | ||||||
188 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||
189 | } else { | - | ||||||
190 | updateFontInfo(QFontDatabase::applicationFontFamilies(fontLoaderFonts()->map.value(d->url)->id).at(0), Ready); | - | ||||||
191 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||
192 | } else { | - | ||||||
193 | if (!fontLoaderFonts()->map.contains(d->url)
| 2-12 | ||||||
194 | - | |||||||
195 | QQuickFontObject *fo = new QQuickFontObject; | - | ||||||
196 | fontLoaderFonts()->map[d->url] = fo; | - | ||||||
197 | fo->download(d->url, qmlEngine(this)->networkAccessManager()); | - | ||||||
198 | d->status = Loading; | - | ||||||
199 | statusChanged(); | - | ||||||
200 | QObject::connect(fo, qFlagLocation("2""fontDownloaded(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "272"), | - | ||||||
201 | this, qFlagLocation("1""updateFontInfo(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "273")); | - | ||||||
202 | - | |||||||
203 | - | |||||||
204 | - | |||||||
205 | } executed 12 times by 2 tests: else {end of block Executed by:
| 12 | ||||||
206 | QQuickFontObject *fo = fontLoaderFonts()->map.value(d->url); | - | ||||||
207 | if (fo->id == -1
| 0-2 | ||||||
208 | - | |||||||
209 | d->status = Loading; | - | ||||||
210 | statusChanged(); | - | ||||||
211 | QObject::connect(fo, qFlagLocation("2""fontDownloaded(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "283"), | - | ||||||
212 | this, qFlagLocation("1""updateFontInfo(QString,QQuickFontLoader::Status)" "\0" __FILE__ ":" "284")); | - | ||||||
213 | - | |||||||
214 | - | |||||||
215 | - | |||||||
216 | } never executed: end of block | 0 | ||||||
217 | else | - | ||||||
218 | updateFontInfo(QFontDatabase::applicationFontFamilies(fo->id).at(0), Ready); executed 2 times by 1 test: updateFontInfo(QFontDatabase::applicationFontFamilies(fo->id).at(0), Ready); Executed by:
| 2 | ||||||
219 | } | - | ||||||
220 | } | - | ||||||
221 | } | - | ||||||
222 | - | |||||||
223 | void QQuickFontLoader::updateFontInfo(const QString& name, QQuickFontLoader::Status status) | - | ||||||
224 | { | - | ||||||
225 | QQuickFontLoaderPrivate * const d = d_func(); | - | ||||||
226 | - | |||||||
227 | if (name != d->name
| 6-26 | ||||||
228 | d->name = name; | - | ||||||
229 | nameChanged(); | - | ||||||
230 | } executed 26 times by 3 tests: end of block Executed by:
| 26 | ||||||
231 | if (status != d->status
| 4-28 | ||||||
232 | if (status == Error
| 8-20 | ||||||
233 | qmlWarning(this) << "Cannot load font: \"" << d->url.toString() << '"'; executed 8 times by 2 tests: qmlWarning(this) << "Cannot load font: \"" << d->url.toString() << '"'; Executed by:
| 8 | ||||||
234 | d->status = status; | - | ||||||
235 | statusChanged(); | - | ||||||
236 | } executed 28 times by 3 tests: end of block Executed by:
| 28 | ||||||
237 | } executed 32 times by 3 tests: end of block Executed by:
| 32 | ||||||
238 | QString QQuickFontLoader::name() const | - | ||||||
239 | { | - | ||||||
240 | const QQuickFontLoaderPrivate * const d = d_func(); | - | ||||||
241 | return executed 112 times by 3 tests: d->name;return d->name; Executed by:
executed 112 times by 3 tests: return d->name; Executed by:
| 112 | ||||||
242 | } | - | ||||||
243 | - | |||||||
244 | void QQuickFontLoader::setName(const QString &name) | - | ||||||
245 | { | - | ||||||
246 | QQuickFontLoaderPrivate * const d = d_func(); | - | ||||||
247 | if (d->name == name
| 0-6 | ||||||
248 | return; never executed: return; | 0 | ||||||
249 | d->name = name; | - | ||||||
250 | nameChanged(); | - | ||||||
251 | d->status = Ready; | - | ||||||
252 | statusChanged(); | - | ||||||
253 | } executed 6 times by 2 tests: end of block Executed by:
| 6 | ||||||
254 | QQuickFontLoader::Status QQuickFontLoader::status() const | - | ||||||
255 | { | - | ||||||
256 | const QQuickFontLoaderPrivate * const d = d_func(); | - | ||||||
257 | return executed 728 times by 2 tests: d->status;return d->status; Executed by:
executed 728 times by 2 tests: return d->status; Executed by:
| 728 | ||||||
258 | } | - | ||||||
259 | - | |||||||
260 | - | |||||||
261 | - | |||||||
262 | - | |||||||
Switch to Source code | Preprocessed file |