|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
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)); |
|
398 } |
|
399 |
|
400 #if defined(Q_WS_X11) |
|
401 { |
|
402 QFont font1, font2; |
|
403 font1.setRawName("-Adobe-Helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"); |
|
404 font2.setRawName("-Adobe-Helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1"); |
|
405 QVERIFY(font1 != font2); |
|
406 } |
|
407 #endif |
|
408 } |
|
409 |
|
410 void tst_QFont::resolve() |
|
411 { |
|
412 QFont font; |
|
413 font.setPointSize(font.pointSize() * 2); |
|
414 font.setItalic(false); |
|
415 font.setWeight(QFont::Normal); |
|
416 font.setUnderline(false); |
|
417 font.setStrikeOut(false); |
|
418 font.setOverline(false); |
|
419 font.setStretch(QFont::Unstretched); |
|
420 |
|
421 QFont font1; |
|
422 font1.setWeight(QFont::Bold); |
|
423 QFont font2 = font1.resolve(font); |
|
424 |
|
425 QVERIFY(font2.weight() == font1.weight()); |
|
426 |
|
427 QVERIFY(font2.pointSize() == font.pointSize()); |
|
428 QVERIFY(font2.italic() == font.italic()); |
|
429 QVERIFY(font2.underline() == font.underline()); |
|
430 QVERIFY(font2.overline() == font.overline()); |
|
431 QVERIFY(font2.strikeOut() == font.strikeOut()); |
|
432 QVERIFY(font2.stretch() == font.stretch()); |
|
433 |
|
434 QFont font3; |
|
435 font3.setStretch(QFont::UltraCondensed); |
|
436 QFont font4 = font3.resolve(font1).resolve(font); |
|
437 |
|
438 QVERIFY(font4.stretch() == font3.stretch()); |
|
439 |
|
440 QVERIFY(font4.weight() == font.weight()); |
|
441 QVERIFY(font4.pointSize() == font.pointSize()); |
|
442 QVERIFY(font4.italic() == font.italic()); |
|
443 QVERIFY(font4.underline() == font.underline()); |
|
444 QVERIFY(font4.overline() == font.overline()); |
|
445 QVERIFY(font4.strikeOut() == font.strikeOut()); |
|
446 |
|
447 |
|
448 QFont f1,f2,f3; |
|
449 f2.setPointSize(45); |
|
450 f3.setPointSize(55); |
|
451 |
|
452 QFont f4 = f1.resolve(f2); |
|
453 QCOMPARE(f4.pointSize(), 45); |
|
454 f4 = f4.resolve(f3); |
|
455 QCOMPARE(f4.pointSize(), 55); |
|
456 } |
|
457 |
|
458 void tst_QFont::resetFont() |
|
459 { |
|
460 QWidget parent; |
|
461 QFont parentFont = parent.font(); |
|
462 parentFont.setPointSize(parentFont.pointSize() + 2); |
|
463 parent.setFont(parentFont); |
|
464 |
|
465 QWidget *child = new QWidget(&parent); |
|
466 |
|
467 QFont childFont = child->font(); |
|
468 childFont.setBold(!childFont.bold()); |
|
469 child->setFont(childFont); |
|
470 |
|
471 QVERIFY(parentFont.resolve() != 0); |
|
472 QVERIFY(childFont.resolve() != 0); |
|
473 QVERIFY(childFont != parentFont); |
|
474 |
|
475 child->setFont(QFont()); // reset font |
|
476 |
|
477 QVERIFY(child->font().resolve() == 0); |
|
478 QVERIFY(child->font().pointSize() == parent.font().pointSize()); |
|
479 QVERIFY(parent.font().resolve() != 0); |
|
480 } |
|
481 |
|
482 void tst_QFont::isCopyOf() |
|
483 { |
|
484 QFont font; |
|
485 QVERIFY(font.isCopyOf(QApplication::font())); |
|
486 |
|
487 QFont font2("bogusfont", 23); |
|
488 QVERIFY(! font2.isCopyOf(QApplication::font())); |
|
489 |
|
490 QFont font3 = font; |
|
491 QVERIFY(font3.isCopyOf(font)); |
|
492 |
|
493 font3.setPointSize(256); |
|
494 QVERIFY(!font3.isCopyOf(font)); |
|
495 font3.setPointSize(font.pointSize()); |
|
496 QVERIFY(!font3.isCopyOf(font)); |
|
497 } |
|
498 |
|
499 void tst_QFont::setFontRaw() |
|
500 { |
|
501 #ifndef Q_WS_X11 |
|
502 QSKIP("Only tested on X11", SkipAll); |
|
503 #else |
|
504 QFont f; |
|
505 f.setRawName("-*-fixed-bold-r-normal--0-0-*-*-*-0-iso8859-1"); |
|
506 // qDebug("font family: %s", f.family().utf8()); |
|
507 QFontDatabase fdb; |
|
508 QStringList families = fdb.families(); |
|
509 bool found = false; |
|
510 for (int i = 0; i < families.size(); ++i) { |
|
511 QString str = families.at(i); |
|
512 if (str.contains('[')) |
|
513 str = str.left(str.indexOf('[')-1); |
|
514 if (str.toLower() == "fixed") |
|
515 found = true; |
|
516 } |
|
517 if (!found) { |
|
518 QSKIP("Fixed font not available.", SkipSingle); |
|
519 } |
|
520 QCOMPARE(QFontInfo(f).family().left(5).toLower(), QString("fixed")); |
|
521 #endif |
|
522 } |
|
523 |
|
524 void tst_QFont::insertAndRemoveSubstitutions() |
|
525 { |
|
526 QFont::removeSubstitution("BogusFontFamily"); |
|
527 // make sure it is empty before we start |
|
528 QVERIFY(QFont::substitutes("BogusFontFamily").isEmpty()); |
|
529 QVERIFY(QFont::substitutes("bogusfontfamily").isEmpty()); |
|
530 |
|
531 // inserting Foo |
|
532 QFont::insertSubstitution("BogusFontFamily", "Foo"); |
|
533 QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 1); |
|
534 QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 1); |
|
535 |
|
536 // inserting Bar and Baz |
|
537 QStringList moreFonts; |
|
538 moreFonts << "Bar" << "Baz"; |
|
539 QFont::insertSubstitutions("BogusFontFamily", moreFonts); |
|
540 QCOMPARE(QFont::substitutes("BogusFontFamily").count(), 3); |
|
541 QCOMPARE(QFont::substitutes("bogusfontfamily").count(), 3); |
|
542 |
|
543 QFont::removeSubstitution("BogusFontFamily"); |
|
544 // make sure it is empty again |
|
545 QVERIFY(QFont::substitutes("BogusFontFamily").isEmpty()); |
|
546 QVERIFY(QFont::substitutes("bogusfontfamily").isEmpty()); |
|
547 } |
|
548 |
|
549 |
|
550 static QFont copyFont(const QFont &font1) // copy using a QDataStream |
|
551 { |
|
552 QBuffer buffer; |
|
553 buffer.open(QIODevice::WriteOnly); |
|
554 QDataStream ds(&buffer); |
|
555 ds << font1; |
|
556 buffer.close(); |
|
557 |
|
558 buffer.open(QIODevice::ReadOnly); |
|
559 QFont font2; |
|
560 ds >> font2; |
|
561 return font2; |
|
562 } |
|
563 |
|
564 void tst_QFont::serializeSpacing() |
|
565 { |
|
566 QFont font; |
|
567 QCOMPARE(font.letterSpacing(), 0.); |
|
568 QCOMPARE(font.wordSpacing(), 0.); |
|
569 |
|
570 font.setLetterSpacing(QFont::AbsoluteSpacing, 105); |
|
571 QCOMPARE(font.letterSpacing(), 105.); |
|
572 QCOMPARE(font.letterSpacingType(), QFont::AbsoluteSpacing); |
|
573 QCOMPARE(font.wordSpacing(), 0.); |
|
574 QFont font2 = copyFont(font); |
|
575 QCOMPARE(font2.letterSpacing(), 105.); |
|
576 QCOMPARE(font2.letterSpacingType(), QFont::AbsoluteSpacing); |
|
577 QCOMPARE(font2.wordSpacing(), 0.); |
|
578 |
|
579 font.setWordSpacing(50.0); |
|
580 QCOMPARE(font.letterSpacing(), 105.); |
|
581 QCOMPARE(font.wordSpacing(), 50.); |
|
582 |
|
583 QFont font3 = copyFont(font); |
|
584 QCOMPARE(font3.letterSpacing(), 105.); |
|
585 QCOMPARE(font3.letterSpacingType(), QFont::AbsoluteSpacing); |
|
586 QCOMPARE(font3.wordSpacing(), 50.); |
|
587 } |
|
588 |
|
589 QTEST_MAIN(tst_QFont) |
|
590 #include "tst_qfont.moc" |