From dc802d17d998b62546de0a9725535202d7cbf9e4 Mon Sep 17 00:00:00 2001 From: Thomas Zander Date: Thu, 11 Jun 2009 13:12:30 +0200 Subject: Makes the ODF writer use one text:tab tag for each tab, per ODF spec. We used tab-ref to place multiple tabs compressed into one tag just like text:s does, but thats not what the spec says. We now don't sum up tabs anymore but just simply write out one "" tag per tab. Task: 249110 --- src/gui/text/qtextodfwriter.cpp | 51 +++++++++++------------- tests/auto/qtextodfwriter/tst_qtextodfwriter.cpp | 2 +- 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 75e89d2..bc8ac5b 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -295,28 +295,13 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc writer.writeAttribute(textNS, QString::fromLatin1("style-name"), QString::fromLatin1("c%1") .arg(frag.fragment().charFormatIndex())); bool escapeNextSpace = true; - int precedingSpaces = 0, precedingTabs = 0; + int precedingSpaces = 0; int exportedIndex = 0; for (int i=0; i <= fragmentText.count(); ++i) { - bool isTab = false, isSpace = false; - if (i < fragmentText.count()) { + bool isSpace = false; QChar character = fragmentText[i]; - isTab = character.unicode() == '\t'; isSpace = character.unicode() == ' '; - if (character.unicode() == 0x2028) { // soft-return - writer.writeCharacters(fragmentText.mid(exportedIndex, i)); - writer.writeEmptyElement(textNS, QString::fromLatin1("line-break")); - exportedIndex = i+1; - continue; - } - if (isSpace) { - ++precedingSpaces; - escapeNextSpace = true; - } - else if (isTab) { - precedingTabs++; - } - } + // find more than one space. -> if (!isSpace && escapeNextSpace && precedingSpaces > 1) { const bool startParag = exportedIndex == 0 && i == precedingSpaces; @@ -329,17 +314,27 @@ void QTextOdfWriter::writeBlock(QXmlStreamWriter &writer, const QTextBlock &bloc precedingSpaces = 0; exportedIndex = i; } - // find tabs. -> or - if (!isTab && precedingTabs) { - writer.writeCharacters(fragmentText.mid(exportedIndex, i - precedingTabs - exportedIndex)); - writer.writeEmptyElement(textNS, QString::fromLatin1("tab")); - if (precedingTabs > 1) - writer.writeAttribute(textNS, QString::fromLatin1("tab-ref"), QString::number(precedingTabs)); - precedingTabs = 0; - exportedIndex = i; + + if (i < fragmentText.count()) { + if (character.unicode() == 0x2028) { // soft-return + //if (exportedIndex < i) + writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex)); + writer.writeEmptyElement(textNS, QString::fromLatin1("line-break")); + exportedIndex = i+1; + continue; + } else if (character.unicode() == '\t') { // Tab + //if (exportedIndex < i) + writer.writeCharacters(fragmentText.mid(exportedIndex, i - exportedIndex)); + writer.writeEmptyElement(textNS, QString::fromLatin1("tab")); + exportedIndex = i+1; + precedingSpaces = 0; + } else if (isSpace) { + ++precedingSpaces; + escapeNextSpace = true; + } else if (!isSpace) { + precedingSpaces = 0; + } } - if (!isSpace && !isTab) - precedingSpaces = 0; } writer.writeCharacters(fragmentText.mid(exportedIndex)); diff --git a/tests/auto/qtextodfwriter/tst_qtextodfwriter.cpp b/tests/auto/qtextodfwriter/tst_qtextodfwriter.cpp index f92e30f..f8c7cdf 100644 --- a/tests/auto/qtextodfwriter/tst_qtextodfwriter.cpp +++ b/tests/auto/qtextodfwriter/tst_qtextodfwriter.cpp @@ -133,7 +133,7 @@ void tst_QTextOdfWriter::testWriteParagraph_data() QTest::newRow("tab") << "word\ttab x" << "wordtab x"; QTest::newRow("tab2") << "word\t\ttab\tx" << - "wordtabx"; + "wordtabx"; QTest::newRow("misc") << "foobar word\ttab x" << "foobar wordtab x"; QTest::newRow("misc2") << "\t \tFoo" << -- cgit v0.12