diff options
author | Andy Shaw <andy.shaw@qt.io> | 2020-08-11 01:18:05 +0200 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2020-08-22 22:21:35 +0000 |
commit | 37c68503cbada547291ec4c4873dc054a8b82510 (patch) | |
tree | a56566fd78489c77687c490c8c95ca2773d7307f /tests/auto/gui | |
parent | 81e09ae404b632a92e1e4c27f5875bdf027c5401 (diff) |
QFont: Extend the string description to include the missing elements
This extends to/fromString to include style strategy, capitalization,
letter and word spacing and stretch. QFont::fromString() keeps
compatibility with strings from earlier versions as well.
Fixes: QTBUG-67687
Change-Id: I5e95a58f1cd850214af2a7d8906a214facd4e661
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r-- | tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp | 2 | ||||
-rw-r--r-- | tests/auto/gui/text/qfont/tst_qfont.cpp | 33 |
2 files changed, 33 insertions, 2 deletions
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp index 840317347a..1e9e1f40d6 100644 --- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp +++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp @@ -384,7 +384,7 @@ void tst_QGuiVariant::toString_data() #endif QFont font( "times", 12 ); - QTest::newRow( "qfont" ) << QVariant::fromValue( font ) << QString("times,12,-1,5,50,0,0,0,0,0"); + QTest::newRow("qfont") << QVariant::fromValue(font) << QString("times,12,-1,5,50,0,0,0,0,0,0,0,0,0,0,1"); QTest::newRow( "qcolor" ) << QVariant::fromValue( QColor( 10, 10, 10 ) ) << QString( "#0a0a0a" ); } diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index eb9d83c525..83d8d01062 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -588,6 +588,30 @@ void tst_QFont::toAndFromString() QCOMPARE(result, initial); } + + // Since Qt 6.0 it was changed to include more information in the description, so + // this checks for compatibility + const QString fontStringFrom515(QLatin1String("Times New Roman,18,-1,5,75,1,0,0,1,0,Regular")); + QFont fontFrom515("Times New Roman", 18); + fontFrom515.setBold(true); + fontFrom515.setItalic(true); + fontFrom515.setFixedPitch(true); + fontFrom515.setStyleName("Regular"); + QFont from515String; + from515String.fromString(fontStringFrom515); + QCOMPARE(from515String, fontFrom515); + + const QString fontStringFrom60(QLatin1String("Times New Roman,18,-1,5,75,1,0,0,1,0,1,0,150.5,2.5,50,2,Regular")); + QFont fontFrom60 = fontFrom515; + fontFrom60.setStyleStrategy(QFont::PreferBitmap); + fontFrom60.setCapitalization(QFont::AllUppercase); + fontFrom60.setLetterSpacing(QFont::PercentageSpacing, 150.5); + fontFrom60.setWordSpacing(2.5); + fontFrom60.setStretch(50); + QFont from60String; + from60String.fromString(fontStringFrom60); + QCOMPARE(fontFrom60.toString(), fontStringFrom60); + QCOMPARE(from60String, fontFrom60); } void tst_QFont::fromStringWithoutStyleName() @@ -596,10 +620,17 @@ void tst_QFont::fromStringWithoutStyleName() font1.fromString("Noto Sans,12,-1,5,50,0,0,0,0,0,Regular"); QFont font2 = font1; - const QString str = "Times,16,-1,5,50,0,0,0,0,0"; + const QString str = "Times,16,-1,5,50,0,0,0,0,0,0,0,0,0,0,1"; font2.fromString(str); QCOMPARE(font2.toString(), str); + + const QString fontStringFrom60(QLatin1String("Times New Roman,18,-1,5,75,1,0,0,1,0,1,0,150.5,2.5,50,2")); + QFont font3; + font3.fromString("Noto Sans,12,-1,5,50,0,0,0,0,0,Regular"); + QFont font4 = font3; + font4.fromString(fontStringFrom60); + QCOMPARE(font4.toString(), fontStringFrom60); } void tst_QFont::fromDegenerateString_data() |