From 84bd6d5e10506d179e12f842659d98f7f9ef7e62 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 7 Sep 2009 10:54:35 +0200 Subject: Support setting font size in shorthand font properties The fontSizeAdjustment defaulted to 0 which means "medium" in internal semantics. This will override any font size you set in the short-hand. In other locations, fontSizeAdjustment defaults to -255 which has no meaning attached. To allow setting the font size in short-hand (as in "font: 20px Arial"), we can't default to a specific adjustment. Two tests are added: The first verifies the case that already worked, where you specify the font size using the "font-size" property. The other verifies the short-hand case and would previously fail. Task-number: 207189 Reviewed-by: Simon Hausmann --- src/gui/text/qcssparser.cpp | 2 +- tests/auto/qtextdocument/tst_qtextdocument.cpp | 61 +++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index f252444400..a38f276305 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -1171,7 +1171,7 @@ static void parseShorthandFontProperty(const QVector &values, QFont *font { font->setStyle(QFont::StyleNormal); font->setWeight(QFont::Normal); - *fontSizeAdjustment = 0; + *fontSizeAdjustment = -255; int i = 0; while (i < values.count()) { diff --git a/tests/auto/qtextdocument/tst_qtextdocument.cpp b/tests/auto/qtextdocument/tst_qtextdocument.cpp index 34b6f145dd..0c1d334351 100644 --- a/tests/auto/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/qtextdocument/tst_qtextdocument.cpp @@ -100,6 +100,9 @@ private slots: void task240325(); + void stylesheetFont_data(); + void stylesheetFont(); + void toHtml_data(); void toHtml(); void toHtml2(); @@ -571,6 +574,63 @@ void tst_QTextDocument::task240325() } } +void tst_QTextDocument::stylesheetFont_data() +{ + QTest::addColumn("stylesheet"); + QTest::addColumn("font"); + + { + QFont font; + font.setBold(true); + font.setPixelSize(64); + + QTest::newRow("Regular font specification") + << "font-size: 64px; font-weight: bold;" + << font; + } + + + { + QFont font; + font.setBold(true); + font.setPixelSize(64); + + QTest::newRow("Shorthand font specification") + << "font: normal bold 64px Arial;" + << font; + } + +} + +void tst_QTextDocument::stylesheetFont() +{ + QFETCH(QString, stylesheet); + QFETCH(QFont, font); + + QString html = QString::fromLatin1("" + "" + "
" + "Foobar" + "
" + "" + "").arg(stylesheet); + + qDebug() << html; + doc->setHtml(html); + QCOMPARE(doc->blockCount(), 1); + + // First and only block + QTextBlock block = doc->firstBlock(); + + QString text = block.text(); + QCOMPARE(text, QString::fromLatin1("Foobar")); + + QFont actualFont = block.charFormat().font(); + + QCOMPARE(actualFont.bold(), font.bold()); + QCOMPARE(actualFont.pixelSize(), font.pixelSize()); +} + void tst_QTextDocument::noundo_moreIsModified() { doc->setUndoRedoEnabled(false); @@ -1458,7 +1518,6 @@ void tst_QTextDocument::toHtml_data() QTest::newRow("list-ul-margin") << QTextDocumentFragment(&doc) << QString("EMPTYBLOCK") + QString("
  • Blah
"); - } } -- cgit v1.2.3