[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    koffice/libs
From:       Thomas Zander <zander () kde ! org>
Date:       2010-12-18 9:44:24
Message-ID: 20101218094424.E1C483E20A () svn ! kde ! org
[Download RAW message or body]

SVN commit 1207484 by zander:

whitespace

some more tests and move the detection of being inside a paragraph or header
to the xml parser instead of in the layer above.

 M  +6 -5      kotext/opendocument/tests/data/TextContents/Paragraph/whitespace.odt  
 M  +3 -0      kotext/opendocument/tests/data/TextContents/Paragraph/whitespace.qs  
 M  +29 -15    odf/KoXmlReader.cpp  
 M  +12 -3     odf/tests/TestXmlReader.cpp  


--- trunk/koffice/libs/kotext/opendocument/tests/data/TextContents/Paragraph/whitespace.odt \
#1207483:1207484 @@ -1,9 +1,12 @@
-PKo9)(acontent.xmlUT	HHUxMs  LebJi \
blc%]]v7$\y\LuOga@:|FpNy80L!̩0 T \
                R-uxVJqPT4*اU{rՆ^ز-#;&
-bVEW|ytUy{3O,b*ī
-6arY"М`4,g~J3KU}9zO8R|B{6<lwAZi'KcfAqX
                
-+VxTY*";zD0rk2~Of i/N \
2In<=Eꌭw/,Tۺ@"͐P?g%U[t?/b	ti<tu-lǿO:PKn9; \
ometa.xmlUT	HHUxU]k0}0zme,"v)2B7ZE24~1'Ͷ/Es \
w0Vh!(u)T	EZ-5o \
>c*KPZfVX,u(s6+PK=?content.xmlUT	MMuxMs \
Le4IOmgz%	@+DaK/ɰ첻!*ͤ؄tT`I6.Zd#O \
+a)Ljаn P"4S++⮂}XEk-wp_m-;Т?jP+l]Ծ(}]DGYWȰ,.07TU5S2V+m \
ʓ*E0 41䛟e)O.+2GW9s6R#=wAۻ \
}-G&j{,(˲RaJc6|6AMDl7^ \
q&[8u0	Lvnd*jם~ Lb' \
+n_(5k]"HhP?%D$wg+6&1,< \
hiTD?ָ01ڧno+t_[2PKn9; \
ometa.xmlUT	HHUxU]k0}0zme,"v)2B7ZE24~1'Ͷ/Es \
w0Vh!(u)T	EZ-5o >c*KPZfVX,u(s6 zC  \
ڹ&x_bmV$DGj'^X%O@BW&$&j{g hl@	 @@ -28,14 +31,13 \
@@  딳 ˃mwO/kUja/DYmEw`|qC"Cp*s'
 6H:x=vHy"aLnliThJi1Պm/=8݌m>s \
                6D;N{G,)8b=CRfNPK
-n9	META-INF/UT	HHUxPKo9)(a-content.xmlUTHUxPKn9; \
o-meta.xmlUTHUxPK \
+n9	META-INF/UT	HHUxPK=?content.xmlUTMuxPKn9; \
o+meta.xmlUTHUxPK  \
U3^2''-mimetypeUT̓CUxPKn9F-settings.xmlUTHUxPKn9@hk
 +mimetypeUT̓CUxPKn9F+3settings.xmlUTHUxPKn9@hk
                
 -styles.xmlUTHUxPKn9YOa-@META-INF/manifest.xmlUTHUxPK
 +styles.xmlUTHUxPKn9YOa+[META-INF/manifest.xmlUTHUxPK
  n9	-A	META-INF/UTHUxPK	
\ No newline at end of file
+A	META-INF/UTHUxPK	
\ No newline at end of file
--- trunk/koffice/libs/kotext/opendocument/tests/data/TextContents/Paragraph/whitespace.qs \
#1207483:1207484 @@ -25,4 +25,7 @@
 cursor.insertBlock();
 cursor.insertText(" Foo");
 
+cursor.insertBlock();
+cursor.insertText("some words in spans");
+
 document;
--- trunk/koffice/libs/odf/KoXmlReader.cpp #1207483:1207484
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
    Copyright (C) 2005-2006 Ariya Hidayat <ariya@kde.org>
+   Copyright (C) 2010 Thomas Zander <zander@kde.org>
 
    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
@@ -1030,6 +1031,7 @@
 
 };
 
+
 namespace {
 
     class ParseError {
@@ -1042,7 +1044,8 @@
         ParseError() :errorLine(-1), errorColumn(-1), error(false) {}
     };
 
-    void parseElement(QXmlStreamReader &xml, KoXmlPackedDocument &doc);
+    /// @param inText if true this is a subtree under a text:p or text:h
+    void parseElement(QXmlStreamReader &xml, KoXmlPackedDocument &doc, bool inText);
 
     // parse one element as if this were a standalone xml document
     ParseError parseDocument(QXmlStreamReader &xml, KoXmlPackedDocument &doc) {
@@ -1052,7 +1055,7 @@
         while (!xml.atEnd() && xml.tokenType() != QXmlStreamReader::EndDocument) {
             switch (xml.tokenType()) {
             case QXmlStreamReader::StartElement:
-                parseElement(xml, doc);
+                parseElement(xml, doc, false);
                 break;
             case QXmlStreamReader::DTD:
                 doc.addDTD(xml.dtdName().toString());
@@ -1081,30 +1084,41 @@
         return error;
     }
 
-    void parseElementContents(QXmlStreamReader &xml, KoXmlPackedDocument &doc)
+    void parseElementContents(QXmlStreamReader &xml, KoXmlPackedDocument &doc, bool \
inText)  {
         xml.readNext();
-        QString ws;
-        bool sawElement = false;
+        bool appendWhitespace = false;
         while (!xml.atEnd()) {
             switch (xml.tokenType()) {
             case QXmlStreamReader::EndElement:
                 // if an element contains only whitespace, put it in the dom
-                if (!ws.isEmpty() && !sawElement) {
-                    doc.addText(ws);
+                if (appendWhitespace)
+                    doc.addText(QLatin1String(" "));
+                return;
+            case QXmlStreamReader::StartElement: {
+                bool textNode = false;
+                if (!inText) {
+                    const QStringRef name = xml.name();
+                    if (xml.name().size() == 1
+                            && (name.at(0).unicode() == 'p' || name.at(0).unicode() \
== 'h') +                            && KoXmlNS::text == \
xml.namespaceUri().toString()) { +                        // we just stumbled upon a \
'text:h' or 'text:p' +                        textNode = true;
                 }
-                return;
-            case QXmlStreamReader::StartElement:
-                sawElement = true;
-                parseElement(xml, doc);
+                }
+                if (appendWhitespace)
+                    doc.addText(QLatin1String(" "));
+                appendWhitespace = false;
+                parseElement(xml, doc, inText || textNode);
                 break;
+            }
             case QXmlStreamReader::Characters:
                 if (xml.isCDATA()) {
                     doc.addCData(xml.text().toString());
                 } else if (!xml.isWhitespace()) {
                     doc.addText(xml.text().toString());
-                } else if (!sawElement) {
-                    ws += xml.text();
+                } else if (inText) {
+                    appendWhitespace = true;
                 }
                 break;
             case QXmlStreamReader::ProcessingInstruction:
@@ -1117,7 +1131,7 @@
         }
     }
 
-    void parseElement(QXmlStreamReader &xml, KoXmlPackedDocument &doc) {
+    void parseElement(QXmlStreamReader &xml, KoXmlPackedDocument &doc, bool inText) \
{  // reader.tokenType() is now QXmlStreamReader::StartElement
         doc.addElement(xml.qualifiedName().toString(),
                        fixNamespace(xml.namespaceUri().toString()));
@@ -1129,7 +1143,7 @@
                              a->value().toString());
             ++a;
         }
-        parseElementContents(xml, doc);
+        parseElementContents(xml, doc, inText);
         // reader.tokenType() is now QXmlStreamReader::EndElement
         doc.closeElement();
     }
--- trunk/koffice/libs/odf/tests/TestXmlReader.cpp #1207483:1207484
@@ -1543,8 +1543,9 @@
     xmlstream << "<office:document-content ";
     xmlstream << " xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\"";
                
     xmlstream << " xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\">";
-    xmlstream << "   <text:p> </text:p>";
-    xmlstream << "   <text:p> <text:span/> </text:p>";
+    xmlstream << "   <text:p> a</text:p>";
+    xmlstream << "   <text:p> b<text:span/>c </text:p>";
+    xmlstream << "   <text:p>a <text:span text:style-name=\"T6\">b</text:span> \
<text:span text:style-name=\"T7\">c </text:span></text:p>";  xmlstream << \
"</office:document-content>";  xmldevice.close();
 
@@ -1558,14 +1559,22 @@
     p1 = doc.documentElement().firstChild().toElement();
     QCOMPARE(p1.isNull(), false);
     QCOMPARE(p1.isElement(), true);
+    QCOMPARE(p1.text(), QString(" a"));
     QCOMPARE(KoXml::childNodesCount(p1), 1);
 
     KoXmlElement p2;
     p2 = p1.nextSibling().toElement();
     QCOMPARE(p2.isNull(), false);
     QCOMPARE(p2.isElement(), true);
-    QEXPECT_FAIL("", "Whitespace handling should be fixed.", Continue);
+    QCOMPARE(p2.text(), QString(" bc "));
     QCOMPARE(KoXml::childNodesCount(p2), 3);
+
+    KoXmlElement p3;
+    p3 = p2.nextSibling().toElement();
+    QCOMPARE(p3.isNull(), false);
+    QCOMPARE(p3.isElement(), true);
+    QCOMPARE(p3.text(), QString("a b c "));
+    QCOMPARE(KoXml::childNodesCount(p3), 4);
 }
 
 void TestXmlReader::testSimpleOpenDocumentSpreadsheet()


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic