author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 08 Apr 2010 14:19:33 +0300 | |
branch | RCL_3 |
changeset 7 | 3f74d0d4af4c |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
#include <QtTest/QtTest> |
|
44 |
||
45 |
||
46 |
#include <qfont.h> |
|
47 |
#include <qfontdatabase.h> |
|
48 |
#include <qfontinfo.h> |
|
49 |
#include <qstringlist.h> |
|
50 |
#include <qapplication.h> |
|
51 |
#include <qwidget.h> |
|
52 |
#include <qlist.h> |
|
53 |
||
54 |
//TESTED_CLASS= |
|
55 |
//TESTED_FILES= |
|
56 |
||
57 |
class tst_QFont : public QObject |
|
58 |
{ |
|
59 |
Q_OBJECT |
|
60 |
||
61 |
public: |
|
62 |
tst_QFont(); |
|
63 |
virtual ~tst_QFont(); |
|
64 |
||
65 |
public slots: |
|
66 |
void init(); |
|
67 |
void cleanup(); |
|
68 |
private slots: |
|
69 |
void getSetCheck(); |
|
70 |
void exactMatch(); |
|
71 |
void compare(); |
|
72 |
void resolve(); |
|
73 |
void resetFont(); |
|
74 |
void isCopyOf(); |
|
75 |
void setFontRaw(); |
|
76 |
void italicOblique(); |
|
77 |
void insertAndRemoveSubstitutions(); |
|
78 |
void serializeSpacing(); |
|
79 |
}; |
|
80 |
||
81 |
// Testing get/set functions |
|
82 |
void tst_QFont::getSetCheck() |
|
83 |
{ |
|
84 |
QFont obj1; |
|
85 |
// Style QFont::style() |
|
86 |
// void QFont::setStyle(Style) |
|
87 |
obj1.setStyle(QFont::Style(QFont::StyleNormal)); |
|
88 |
QCOMPARE(QFont::Style(QFont::StyleNormal), obj1.style()); |
|
89 |
obj1.setStyle(QFont::Style(QFont::StyleItalic)); |
|
90 |
QCOMPARE(QFont::Style(QFont::StyleItalic), obj1.style()); |
|
91 |
obj1.setStyle(QFont::Style(QFont::StyleOblique)); |
|
92 |
QCOMPARE(QFont::Style(QFont::StyleOblique), obj1.style()); |
|
93 |
||
94 |
// StyleStrategy QFont::styleStrategy() |
|
95 |
// void QFont::setStyleStrategy(StyleStrategy) |
|
96 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::PreferDefault)); |
|
97 |
QCOMPARE(QFont::StyleStrategy(QFont::PreferDefault), obj1.styleStrategy()); |
|
98 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::PreferBitmap)); |
|
99 |
QCOMPARE(QFont::StyleStrategy(QFont::PreferBitmap), obj1.styleStrategy()); |
|
100 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::PreferDevice)); |
|
101 |
QCOMPARE(QFont::StyleStrategy(QFont::PreferDevice), obj1.styleStrategy()); |
|
102 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::PreferOutline)); |
|
103 |
QCOMPARE(QFont::StyleStrategy(QFont::PreferOutline), obj1.styleStrategy()); |
|
104 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::ForceOutline)); |
|
105 |
QCOMPARE(QFont::StyleStrategy(QFont::ForceOutline), obj1.styleStrategy()); |
|
106 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::PreferMatch)); |
|
107 |
QCOMPARE(QFont::StyleStrategy(QFont::PreferMatch), obj1.styleStrategy()); |
|
108 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::PreferQuality)); |
|
109 |
QCOMPARE(QFont::StyleStrategy(QFont::PreferQuality), obj1.styleStrategy()); |
|
110 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::PreferAntialias)); |
|
111 |
QCOMPARE(QFont::StyleStrategy(QFont::PreferAntialias), obj1.styleStrategy()); |
|
112 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::NoAntialias)); |
|
113 |
QCOMPARE(QFont::StyleStrategy(QFont::NoAntialias), obj1.styleStrategy()); |
|
114 |
obj1.setStyleStrategy(QFont::StyleStrategy(QFont::OpenGLCompatible)); |
|
115 |
QCOMPARE(QFont::StyleStrategy(QFont::OpenGLCompatible), obj1.styleStrategy()); |
|
116 |
} |
|
117 |
||
118 |
tst_QFont::tst_QFont() |
|
119 |
{ |
|
120 |
} |
|
121 |
||
122 |
tst_QFont::~tst_QFont() |
|
123 |
{ |
|
124 |
||
125 |
} |
|
126 |
||
127 |
void tst_QFont::init() |
|
128 |
{ |
|
129 |
// TODO: Add initialization code here. |
|
130 |
// This will be executed immediately before each test is run. |
|
131 |
} |
|
132 |
||
133 |
void tst_QFont::cleanup() |
|
134 |
{ |
|
135 |
// TODO: Add cleanup code here. |
|
136 |
// This will be executed immediately after each test is run. |
|
137 |
} |
|
138 |
||
139 |
void tst_QFont::exactMatch() |
|
140 |
{ |
|
141 |
QFont font; |
|
142 |
||
143 |
// Check if a non-existing font hasn't an exact match |
|
144 |
font = QFont( "BogusFont", 33 ); |
|
145 |
QVERIFY( !font.exactMatch() ); |
|
146 |
||
147 |
#ifdef Q_WS_WIN |
|
148 |
QSKIP("Exact matching on windows misses a lot because of the sample chars", SkipAll); |
|
149 |
return; |
|
150 |
#endif |
|
151 |
||
152 |
QSKIP("This test is bogus on Unix with support for font aliases in fontconfig", SkipAll); |
|
153 |
return; |
|
154 |
||
155 |
QFontDatabase fdb; |
|
156 |
||
157 |
QList<QFontDatabase::WritingSystem> systems = fdb.writingSystems(); |
|
158 |
for (int system = 0; system < systems.count(); ++system) { |
|
159 |
QStringList families = fdb.families(systems[system]); |
|
160 |
if (families.isEmpty()) |
|
161 |
return; |
|
162 |
||
163 |
QStringList::ConstIterator f_it, f_end = families.end(); |
|
164 |
for (f_it = families.begin(); f_it != f_end; ++f_it) { |
|
165 |
const QString &family = *f_it; |
|
166 |
if (family.contains('[')) |
|
167 |
continue; |
|
168 |
||
169 |
QStringList styles = fdb.styles(family); |
|
170 |
QVERIFY(!styles.isEmpty()); |
|
171 |
QStringList::ConstIterator s_it, s_end = styles.end(); |
|
172 |
for (s_it = styles.begin(); s_it != s_end; ++s_it) { |
|
173 |
const QString &style = *s_it; |
|
174 |
||
175 |
if (fdb.isSmoothlyScalable(family, style)) { |
|
176 |
// smoothly scalable font... don't need to load every pointsize |
|
177 |
font = fdb.font(family, style, 12); |
|
178 |
QFontInfo fontinfo(font); |
|
179 |
||
180 |
if (! fontinfo.exactMatch()) { |
|
181 |
// Unfortunately, this can fail, since |
|
182 |
// QFontDatabase does not fill in all font |
|
183 |
// properties. Check to make sure that the |
|
184 |
// test didn't fail for obvious reasons |
|
185 |
||
186 |
if (fontinfo.family().isEmpty() |
|
187 |
&& fontinfo.pointSize() == 0) { |
|
188 |
// this is a box rendering engine... this can happen from |
|
189 |
// time to time, especially on X11 with iso10646-1 or |
|
190 |
// unknown font encodings |
|
191 |
continue; |
|
192 |
} |
|
193 |
||
194 |
#ifdef Q_WS_WIN32 |
|
195 |
if (font.family().startsWith("MS ") || fontinfo.family().startsWith("MS ")) { |
|
196 |
/* qDebug("Family matching skipped for MS-Alias font: %s, fontinfo: %s", |
|
197 |
font.family().latin1(), fontinfo.family().latin1()); |
|
198 |
*/ |
|
199 |
} else |
|
200 |
#endif |
|
201 |
{ |
|
202 |
if (!(font.family() == fontinfo.family() |
|
203 |
|| fontinfo.family().contains(font.family()) |
|
204 |
|| fontinfo.family().isEmpty())) { |
|
205 |
qDebug("Test about to fail for font: %s, fontinfo: %s", |
|
206 |
font.family().toLatin1().constData(), |
|
207 |
fontinfo.family().toLatin1().constData()); |
|
208 |
} |
|
209 |
QVERIFY(font.family() == fontinfo.family() |
|
210 |
|| fontinfo.family().contains(font.family()) |
|
211 |
|| fontinfo.family().isEmpty()); |
|
212 |
} |
|
213 |
if (font.pointSize() != -1) { |
|
214 |
QVERIFY(font.pointSize() == fontinfo.pointSize()); |
|
215 |
} else { |
|
216 |
QVERIFY(font.pixelSize() == fontinfo.pixelSize()); |
|
217 |
} |
|
218 |
QVERIFY(font.italic() == fontinfo.italic()); |
|
219 |
if (font.weight() != fontinfo.weight()) { |
|
220 |
qDebug("font is %s", font.toString().toLatin1().constData()); |
|
221 |
} |
|
222 |
QVERIFY(font.weight() == fontinfo.weight()); |
|
223 |
} else { |
|
224 |
font.setFixedPitch(!fontinfo.fixedPitch()); |
|
225 |
QFontInfo fontinfo1(font); |
|
226 |
QVERIFY( !fontinfo1.exactMatch() ); |
|
227 |
||
228 |
font.setFixedPitch(fontinfo.fixedPitch()); |
|
229 |
QFontInfo fontinfo2(font); |
|
230 |
QVERIFY( fontinfo2.exactMatch() ); |
|
231 |
} |
|
232 |
} |
|
233 |
#if 0 |
|
234 |
// ############## can only work if we have float point sizes in QFD |
|
235 |
else { |
|
236 |
QList<int> sizes = fdb.pointSizes(family, style); |
|
237 |
QVERIFY(!sizes.isEmpty()); |
|
238 |
QList<int>::ConstIterator z_it, z_end = sizes.end(); |
|
239 |
for (z_it = sizes.begin(); z_it != z_end; ++z_it) { |
|
240 |
const int size = *z_it; |
|
241 |
||
242 |
// Initialize the font, and check if it is an exact match |
|
243 |
font = fdb.font(family, style, size); |
|
244 |
QFontInfo fontinfo(font, (QFont::Script) script); |
|
245 |
||
246 |
if (! fontinfo.exactMatch()) { |
|
247 |
// Unfortunately, this can fail, since |
|
248 |
// QFontDatabase does not fill in all font |
|
249 |
// properties. Check to make sure that the |
|
250 |
// test didn't fail for obvious reasons |
|
251 |
||
252 |
if (fontinfo.family().isEmpty() |
|
253 |
&& fontinfo.pointSize() == 0) { |
|
254 |
// this is a box rendering engine... this can happen from |
|
255 |
// time to time, especially on X11 with iso10646-1 or |
|
256 |
// unknown font encodings |
|
257 |
continue; |
|
258 |
} |
|
259 |
||
260 |
// no need to skip MS-fonts here it seems |
|
261 |
if (!(font.family() == fontinfo.family() |
|
262 |
|| fontinfo.family().contains(font.family()) |
|
263 |
|| fontinfo.family().isEmpty())) { |
|
264 |
qDebug("Test about to fail for font: %s, fontinfo: %s", |
|
265 |
font.family().latin1(), fontinfo.family().latin1()); |
|
266 |
} |
|
267 |
QVERIFY(font.family() == fontinfo.family() |
|
268 |
|| fontinfo.family().contains(font.family()) |
|
269 |
|| fontinfo.family().isEmpty()); |
|
270 |
if (font.pointSize() != -1) { |
|
271 |
QVERIFY(font.pointSize() == fontinfo.pointSize()); |
|
272 |
} else { |
|
273 |
QVERIFY(font.pixelSize() == fontinfo.pixelSize()); |
|
274 |
} |
|
275 |
QVERIFY(font.italic() == fontinfo.italic()); |
|
276 |
QVERIFY(font.weight() == fontinfo.weight()); |
|
277 |
} else { |
|
278 |
font.setFixedPitch(!fontinfo.fixedPitch()); |
|
279 |
QFontInfo fontinfo1(font, (QFont::Script) script); |
|
280 |
QVERIFY( !fontinfo1.exactMatch() ); |
|
281 |
||
282 |
font.setFixedPitch(fontinfo.fixedPitch()); |
|
283 |
QFontInfo fontinfo2(font, (QFont::Script) script); |
|
284 |
QVERIFY( fontinfo2.exactMatch() ); |
|
285 |
} |
|
286 |
} |
|
287 |
} |
|
288 |
#endif |
|
289 |
} |
|
290 |
} |
|
291 |
} |
|
292 |
} |
|
293 |
||
294 |
void tst_QFont::italicOblique() |
|
295 |
{ |
|
296 |
QFontDatabase fdb; |
|
297 |
||
298 |
QStringList families = fdb.families(); |
|
299 |
if (families.isEmpty()) |
|
300 |
return; |
|
301 |
||
302 |
QStringList::ConstIterator f_it, f_end = families.end(); |
|
303 |
for (f_it = families.begin(); f_it != f_end; ++f_it) { |
|
304 |
||
305 |
QString family = *f_it; |
|
306 |
QStringList styles = fdb.styles(family); |
|
307 |
QVERIFY(!styles.isEmpty()); |
|
308 |
QStringList::ConstIterator s_it, s_end = styles.end(); |
|
309 |
for (s_it = styles.begin(); s_it != s_end; ++s_it) { |
|
310 |
QString style = *s_it; |
|
311 |
||
312 |
if (fdb.isSmoothlyScalable(family, style)) { |
|
313 |
if (style.contains("Oblique")) { |
|
314 |
style.replace("Oblique", "Italic"); |
|
315 |
} else if (style.contains("Italic")) { |
|
316 |
style.replace("Italic", "Oblique"); |
|
317 |
} else { |
|
318 |
continue; |
|
319 |
} |
|
320 |
QFont f = fdb.font(family, style, 12); |
|
321 |
QVERIFY(f.italic()); |
|
322 |
} |
|
323 |
} |
|
324 |
} |
|
325 |
} |
|
326 |
||
327 |
void tst_QFont::compare() |
|
328 |
{ |
|
329 |
QFont font; |
|
330 |
{ |
|
331 |
QFont font2 = font; |
|
332 |
font2.setPointSize( 24 ); |
|
333 |
QVERIFY( font != font2 ); |
|
334 |
QCOMPARE(font < font2,!(font2 < font)); |
|
335 |
} |
|
336 |
{ |
|
337 |
QFont font2 = font; |
|
338 |
font2.setPixelSize( 24 ); |
|
339 |
QVERIFY( font != font2 ); |
|
340 |
QCOMPARE(font < font2,!(font2 < font)); |
|
341 |
} |
|
342 |
||
343 |
font.setPointSize(12); |
|
344 |
font.setItalic(false); |
|
345 |
font.setWeight(QFont::Normal); |
|
346 |
font.setUnderline(false); |
|
347 |
font.setStrikeOut(false); |
|
348 |
font.setOverline(false); |
|
349 |
{ |
|
350 |
QFont font2 = font; |
|
351 |
font2.setPointSize( 24 ); |
|
352 |
QVERIFY( font != font2 ); |
|
353 |
QCOMPARE(font < font2,!(font2 < font)); |
|
354 |
} |
|
355 |
{ |
|
356 |
QFont font2 = font; |
|
357 |
font2.setPixelSize( 24 ); |
|
358 |
QVERIFY( font != font2 ); |
|
359 |
QCOMPARE(font < font2,!(font2 < font)); |
|
360 |
} |
|
361 |
{ |
|
362 |
QFont font2 = font; |
|
363 |
||
364 |
font2.setItalic(true); |
|
365 |
QVERIFY( font != font2 ); |
|
366 |
QCOMPARE(font < font2,!(font2 < font)); |
|
367 |
font2.setItalic(false); |
|
368 |
QVERIFY( font == font2 ); |
|
369 |
QVERIFY(!(font < font2)); |
|
370 |
||
371 |
font2.setWeight(QFont::Bold); |
|
372 |
QVERIFY( font != font2 ); |
|
373 |
QCOMPARE(font < font2,!(font2 < font)); |
|
374 |
font2.setWeight(QFont::Normal); |
|
375 |
QVERIFY( font == font2 ); |
|
376 |
QVERIFY(!(font < font2)); |
|
377 |
||
378 |
font.setUnderline(true); |
|
379 |
QVERIFY( font != font2 ); |
|
380 |
QCOMPARE(font < font2,!(font2 < font)); |
|
381 |
font.setUnderline(false); |
|
382 |
QVERIFY( font == font2 ); |
|
383 |
QVERIFY(!(font < font2)); |
|
384 |
||
385 |
font.setStrikeOut(true); |
|
386 |
QVERIFY( font != font2 ); |
|
387 |
QCOMPARE(font < font2,!(font2 < font)); |
|
388 |
font.setStrikeOut(false); |
|
389 |
QVERIFY( font == font2 ); |
|
390 |
QVERIFY(!(font < font2)); |
|
391 |
||
392 |
font.setOverline(true); |
|
393 |
QVERIFY( font != font2 ); |
|
394 |
QCOMPARE(font < font2,!(font2 < font)); |
|
395 |
font.setOverline(false); |
|
396 |
QVERIFY( font == font2 ); |
|
397 |
QVERIFY(!(font < font2)); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
398 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
399 |
font.setCapitalization(QFont::SmallCaps); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
400 |
QVERIFY( font != font2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
401 |
QCOMPARE(font < font2,!(font2 < font)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
402 |
font.setCapitalization(QFont::MixedCase); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
403 |
QVERIFY( font == font2 ); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
404 |
QVERIFY(!(font < font2)); |
0 | 405 |
} |
406 |
||
407 |
#if defined(Q_WS_X11) |
|
408 |
{ |
|
409 |
QFont font1, font2; |
|
410 |
font1.setRawName("-Adobe-Helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"); |
|
411 |
font2.setRawName("-Adobe-Helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1"); |
|
412 |
QVERIFY(font1 != font2); |
|
413 |
} |
|
414 |
#endif |
|
415 |
} |
|
416 |
||
417 |
void tst_QFont::resolve() |
|
418 |
{ |
|
419 |
QFont font; |
|
420 |
font.setPointSize(font.pointSize() * 2); |
|
421 |
font.setItalic(false); |
|
422 |
font.setWeight(QFont::Normal); |
|
423 |
font.setUnderline(false); |
|
424 |
font.setStrikeOut(false); |
|
425 |
font.setOverline(false); |
|
426 |
font.setStretch(QFont::Unstretched); |
|
427 |
||
428 |
QFont font1; |
|
429 |
font1.setWeight(QFont::Bold); |
|
430 |
QFont font2 = font1.resolve(font); |
|
431 |
||
432 |
QVERIFY(font2.weight() == font1.weight()); |
|
433 |
||
434 |
QVERIFY(font2.pointSize() == font.pointSize()); |
|
435 |
QVERIFY(font2.italic() == font.italic()); |
|
436 |
QVERIFY(font2.underline() == font.underline()); |
|
437 |
QVERIFY(font2.overline() == font.overline()); |
|
438 |
QVERIFY(font2.strikeOut() == font.strikeOut()); |
|
439 |
QVERIFY(font2.stretch() == font.stretch()); |
|
440 |
||
441 |
QFont font3; |
|
442 |
font3.setStretch(QFont::UltraCondensed); |
|
443 |
QFont font4 = font3.resolve(font1).resolve(font); |
|
444 |
||
445 |
QVERIFY(font4.stretch() == font3.stretch()); |
|
446 |
||
447 |
QVERIFY(font4.weight() == font.weight()); |
|
448 |
QVERIFY(font4.pointSize() == font.pointSize()); |
|
449 |
QVERIFY(font4.italic() == font.italic()); |
|
450 |
QVERIFY(font4.underline() == font.underline()); |
|
451 |
QVERIFY(font4.overline() == font.overline()); |
|
452 |
QVERIFY(font4.strikeOut() == font.strikeOut()); |
|
453 |
||
454 |
||
455 |
QFont f1,f2,f3; |
|
456 |
f2.setPointSize(45); |
|
457 |
f3.setPointSize(55); |
|
458 |
||
459 |
QFont f4 = f1.resolve(f2); |
|
460 |
QCOMPARE(f4.pointSize(), 45); |
|
461 |
f4 = f4.resolve(f3); |
|
462 |
QCOMPARE(f4.pointSize(), 55); |
|
463 |
} |
|
464 |
||
465 |
void tst_QFont::resetFont() |
|
466 |
{ |
|
467 |
QWidget parent; |
|
468 |
QFont parentFont = parent.font(); |
|
469 |
parentFont.setPointSize(parentFont.pointSize() + 2); |
|
470 |
parent.setFont(parentFont); |
|
471 |
||
472 |
QWidget *child = new QWidget(&parent); |
|
473 |
||
474 |
QFont childFont = child->font(); |
|
475 |
childFont.setBold(!childFont.bold()); |
|
476 |
child->setFont(childFont); |
|
477 |
||
478 |
QVERIFY(parentFont.resolve() != 0); |
|
479 |
QVERIFY(childFont.resolve() != 0); |
|
480 |
QVERIFY(childFont != parentFont); |
|
481 |
||
482 |
child->setFont(QFont()); // reset font |
|
483 |
||
484 |
QVERIFY(child->font().resolve() == 0); |
|
485 |
QVERIFY(child->font().pointSize() == parent.font().pointSize()); |
|
486 |
QVERIFY(parent.font().resolve() != 0); |
|
487 |
} |
|
488 |
||
489 |
void tst_QFont::isCopyOf() |
|
490 |
{ |
|
491 |
QFont font; |
|
492 |
QVERIFY(font.isCopyOf(QApplication::font())); |
|
493 |
||
494 |
QFont font2("bogusfont", 23); |
|
495 |
QVERIFY(! font2.isCopyOf(QApplication::font())); |
|
496 |
||
497 |
QFont font3 = font; |
|
498 |
QVERIFY(font3.isCopyOf(font)); |
|
499 |
||
500 |
font3.setPointSize(256); |
|
501 |
QVERIFY(!font3.isCopyOf(font)); |
|
502 |
font3.setPointSize(font.pointSize()); |
|
503 |
QVERIFY(!font3.isCopyOf(font)); |
|
504 |
} |
|
505 |
||
506 |
void tst_QFont::setFontRaw() |
|
507 |
{ |
|
508 |
#ifndef Q_WS_X11 |
|
509 |
QSKIP("Only tested on X11", SkipAll); |
|
510 |
#else |
|
511 |
QFont f; |
|
512 |
f.setRawName("-*-fixed-bold-r-normal--0-0-*-*-*-0-iso8859-1"); |
|
513 |
// qDebug("font family: %s", f.family().utf8()); |
|
514 |
QFontDatabase fdb; |
|
515 |
QStringList families = fdb.families(); |
|
516 |
bool found = false; |
|
517 |
for (int i = 0; i < families.size(); ++i) { |
|
518 |
QString str = families.at(i); |
|
519 |
if (str.contains('[')) |
|
520 |
str = str.left(str.indexOf('[')-1); |
|
521 |
if (str.toLower() == "fixed") |
|
522 |
found = true; |
|
523 |
} |
|
524 |
if (!found) { |
|
525 |
QSKIP("Fixed font not available.", SkipSingle); |
|
526 |
} |
|
527 |
QCOMPARE(QFontInfo(f).family().left(5).toLower(), QString("fixed")); |
|
528 |
#endif |
|
529 |
} |
|
530 |
||
531 |
void tst_QFont::insertAndRemoveSubstitutions() |
|
532 |
{ |
|
533 |
QFont::removeSubstitution("BogusFontFamily"); |
|
534 |
// make sure it is empty before we start |
|
535 |
QVERIFY(QFont::substitutes("BogusFontFamily").isEmpty()); |
|
536 |
QVERIFY(QFont::substitutes("bogusfontfamily").isEmpty()); |
|
537 |
||
538 |
// inserting Foo |
|
539 |
QFont::insertSubstitution("BogusFontFamily", "Foo"); |
|
540 |
QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 1); |
|
541 |
QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 1); |
|
542 |
||
543 |
// inserting Bar and Baz |
|
544 |
QStringList moreFonts; |
|
545 |
moreFonts << "Bar" << "Baz"; |
|
546 |
QFont::insertSubstitutions("BogusFontFamily", moreFonts); |
|
547 |
QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 3); |
|
548 |
QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 3); |
|
549 |
||
550 |
QFont::removeSubstitution("BogusFontFamily"); |
|
551 |
// make sure it is empty again |
|
552 |
QVERIFY(QFont::substitutes("BogusFontFamily").isEmpty()); |
|
553 |
QVERIFY(QFont::substitutes("bogusfontfamily").isEmpty()); |
|
554 |
} |
|
555 |
||
556 |
||
557 |
static QFont copyFont(const QFont &font1) // copy using a QDataStream |
|
558 |
{ |
|
559 |
QBuffer buffer; |
|
560 |
buffer.open(QIODevice::WriteOnly); |
|
561 |
QDataStream ds(&buffer); |
|
562 |
ds << font1; |
|
563 |
buffer.close(); |
|
564 |
||
565 |
buffer.open(QIODevice::ReadOnly); |
|
566 |
QFont font2; |
|
567 |
ds >> font2; |
|
568 |
return font2; |
|
569 |
} |
|
570 |
||
571 |
void tst_QFont::serializeSpacing() |
|
572 |
{ |
|
573 |
QFont font; |
|
574 |
QCOMPARE(font.letterSpacing(), 0.); |
|
575 |
QCOMPARE(font.wordSpacing(), 0.); |
|
576 |
||
577 |
font.setLetterSpacing(QFont::AbsoluteSpacing, 105); |
|
578 |
QCOMPARE(font.letterSpacing(), 105.); |
|
579 |
QCOMPARE(font.letterSpacingType(), QFont::AbsoluteSpacing); |
|
580 |
QCOMPARE(font.wordSpacing(), 0.); |
|
581 |
QFont font2 = copyFont(font); |
|
582 |
QCOMPARE(font2.letterSpacing(), 105.); |
|
583 |
QCOMPARE(font2.letterSpacingType(), QFont::AbsoluteSpacing); |
|
584 |
QCOMPARE(font2.wordSpacing(), 0.); |
|
585 |
||
586 |
font.setWordSpacing(50.0); |
|
587 |
QCOMPARE(font.letterSpacing(), 105.); |
|
588 |
QCOMPARE(font.wordSpacing(), 50.); |
|
589 |
||
590 |
QFont font3 = copyFont(font); |
|
591 |
QCOMPARE(font3.letterSpacing(), 105.); |
|
592 |
QCOMPARE(font3.letterSpacingType(), QFont::AbsoluteSpacing); |
|
593 |
QCOMPARE(font3.wordSpacing(), 50.); |
|
594 |
} |
|
595 |
||
596 |
QTEST_MAIN(tst_QFont) |
|
597 |
#include "tst_qfont.moc" |