From 97391be5ebddc62545ddb88f92fc2045bfa10711 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Sat, 4 Jun 2011 14:47:22 +0200 Subject: Allow selecting fonts with irregular style names Fonts like "Helvetica Neue UltraLight" or "Skia Regular Black Condensed" can't be selected in Qt because either they don't report correct numeric values for weight/stretch/etc. or these values are not mapped from QFont enums in a linear way. Thus we provide a shortcut to select these fonts with PostScript name or full name without resorting to family name matching in QFontDatabase (these fonts are not registered in font database anyway). After this, we can simply use: QFont font("Helvetica Neue"); font.setStyleName("UltraLight"); to select these fonts. QCoreTextFontEngineMulti matched like this can be created directly from the CTFontRef instance instead of creating from the font name, making this process faster. The commit also cleaned up the font loading process in Mac font database a bit, moving the code for family matching into a separate function. Add QFontInfo::styleName() and QRawFont::styleName() to access the resolved style name for a font. Task-number: QTBUG-19366 Change-Id: Iad07768c02ed06cc8d6b7395dec554384f410506 Reviewed-on: http://codereview.qt.nokia.com/333 Reviewed-by: Qt Sanity Bot Reviewed-by: Jiang Jiang --- tests/auto/qfont/tst_qfont.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tests/auto') diff --git a/tests/auto/qfont/tst_qfont.cpp b/tests/auto/qfont/tst_qfont.cpp index cfafa78684..711ffc0b53 100644 --- a/tests/auto/qfont/tst_qfont.cpp +++ b/tests/auto/qfont/tst_qfont.cpp @@ -77,6 +77,7 @@ private slots: void insertAndRemoveSubstitutions(); void serializeSpacing(); void lastResortFont(); + void styleName(); }; // Testing get/set functions @@ -612,5 +613,17 @@ void tst_QFont::lastResortFont() QVERIFY(!font.lastResortFont().isEmpty()); } +void tst_QFont::styleName() +{ +#if !defined(Q_WS_MAC) + QSKIP("Only tested on Mac", SkipAll); +#else + QFont font("Helvetica Neue"); + font.setStyleName("UltraLight"); + + QCOMPARE(QFontInfo(font).styleName(), QString("UltraLight")); +#endif +} + QTEST_MAIN(tst_QFont) #include "tst_qfont.moc" -- cgit v1.2.3