diff --git a/src/gui/text/qcssparser.cpp b/src/gui/text/qcssparser.cpp index b5489c7ed9..45f1ca596e 100644 --- a/src/gui/text/qcssparser.cpp +++ b/src/gui/text/qcssparser.cpp @@ -222,6 +222,7 @@ static const QCssKnownValue values[NumKnownValues - 1] = { { "outset", Value_Outset }, { "overline", Value_Overline }, { "pre", Value_Pre }, + { "pre-line", Value_PreLine }, { "pre-wrap", Value_PreWrap }, { "ridge", Value_Ridge }, { "right", Value_Right }, @@ -248,10 +249,10 @@ static const QCssKnownValue values[NumKnownValues - 1] = { }; //Map id to strings as they appears in the 'values' array above -static const short indexOfId[NumKnownValues] = { 0, 41, 48, 42, 49, 54, 35, 26, 70, 71, 25, 43, 5, 63, 47, - 29, 58, 59, 27, 51, 61, 6, 10, 39, 56, 19, 13, 17, 18, 20, 21, 50, 24, 46, 67, 37, 3, 2, 40, 62, 16, - 11, 57, 14, 32, 64, 33, 65, 55, 66, 34, 69, 8, 28, 38, 12, 36, 60, 7, 9, 4, 68, 53, 22, 23, 30, 31, - 1, 15, 0, 52, 45, 44 }; +static const short indexOfId[NumKnownValues] = { 0, 41, 48, 42, 49, 50, 55, 35, 26, 71, 72, 25, 43, 5, 64, 48, + 29, 59, 60, 27, 52, 62, 6, 10, 39, 56, 19, 13, 17, 18, 20, 21, 51, 24, 46, 68, 37, 3, 2, 40, 63, 16, + 11, 58, 14, 32, 65, 33, 66, 56, 67, 34, 70, 8, 28, 38, 12, 36, 61, 7, 9, 4, 69, 54, 22, 23, 30, 31, + 1, 15, 0, 53, 45, 44 }; QString Value::toString() const { diff --git a/src/gui/text/qcssparser_p.h b/src/gui/text/qcssparser_p.h index b0fa4be682..ddc46803ae 100644 --- a/src/gui/text/qcssparser_p.h +++ b/src/gui/text/qcssparser_p.h @@ -205,6 +205,7 @@ enum KnownValue { Value_Normal, Value_Pre, Value_NoWrap, + Value_PreLine, Value_PreWrap, Value_Small, Value_Medium, diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index 1905d9a1b1..8ad1300e6c 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -576,6 +576,9 @@ bool QTextHtmlImporter::appendNodeText() && ch != QChar::Nbsp && ch != QChar::ParagraphSeparator) { + if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && (ch == QLatin1Char('\n') || ch == QLatin1Char('\r'))) + compressNextWhitespace = PreserveWhiteSpace; + if (compressNextWhitespace == CollapseWhiteSpace) compressNextWhitespace = RemoveWhiteSpace; // allow this one, and remove the ones coming next. else if(compressNextWhitespace == RemoveWhiteSpace) @@ -592,7 +595,9 @@ bool QTextHtmlImporter::appendNodeText() } } else if (wsm != QTextHtmlParserNode::WhiteSpacePreWrap) { compressNextWhitespace = RemoveWhiteSpace; - if (wsm == QTextHtmlParserNode::WhiteSpaceNoWrap) + if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && (ch == QLatin1Char('\n') || ch == QLatin1Char('\r'))) + { } + else if (wsm == QTextHtmlParserNode::WhiteSpaceNoWrap) ch = QChar::Nbsp; else ch = QLatin1Char(' '); @@ -605,6 +610,8 @@ bool QTextHtmlImporter::appendNodeText() || ch == QChar::ParagraphSeparator) { if (!textToInsert.isEmpty()) { + if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && textToInsert.at(textToInsert.length() - 1) == QChar(' ')) + textToInsert = textToInsert.chopped(1); cursor.insertText(textToInsert, format); textToInsert.clear(); } diff --git a/src/gui/text/qtexthtmlparser.cpp b/src/gui/text/qtexthtmlparser.cpp index 1ee317d27c..43b32e7e2c 100644 --- a/src/gui/text/qtexthtmlparser.cpp +++ b/src/gui/text/qtexthtmlparser.cpp @@ -649,7 +649,7 @@ void QTextHtmlParser::parseTag() parseExclamationTag(); if (nodes.last().wsm != QTextHtmlParserNode::WhiteSpacePre && nodes.last().wsm != QTextHtmlParserNode::WhiteSpacePreWrap - && !textEditMode) + && !textEditMode) eatSpace(); return; } @@ -717,7 +717,8 @@ void QTextHtmlParser::parseTag() // in a white-space preserving environment strip off a initial newline // since the element itself already generates a newline if ((node->wsm == QTextHtmlParserNode::WhiteSpacePre - || node->wsm == QTextHtmlParserNode::WhiteSpacePreWrap) + || node->wsm == QTextHtmlParserNode::WhiteSpacePreWrap + || node->wsm == QTextHtmlParserNode::WhiteSpacePreLine) && node->isBlock()) { if (pos < len - 1 && txt.at(pos) == QLatin1Char('\n')) ++pos; @@ -761,7 +762,8 @@ void QTextHtmlParser::parseCloseTag() // in a new block for elements following the
// ...foo\nblah -> foo
blah
if ((at(p).wsm == QTextHtmlParserNode::WhiteSpacePre
- || at(p).wsm == QTextHtmlParserNode::WhiteSpacePreWrap)
+ || at(p).wsm == QTextHtmlParserNode::WhiteSpacePreWrap
+ || at(p).wsm == QTextHtmlParserNode::WhiteSpacePreLine)
&& at(p).isBlock()) {
if (at(last()).text.endsWith(QLatin1Char('\n')))
nodes[last()].text.chop(1);
@@ -1278,6 +1280,7 @@ void QTextHtmlParserNode::applyCssDeclarations(const QVector a b c
Blub")
<< QString("\nBlah\nBlub");
+ QTest::newRow("9") << QString(" white space \n\n here ")
+ << QString::fromLatin1("white space here ");
+
+ QTest::newRow("10") << QString(" white space \n\n here ")
+ << QString::fromLatin1("white space\n\nhere ");
+
QTest::newRow("task116492") << QString("Blah