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

List:       koffice-devel
Subject:    Re: [PATCH] two kotext fixes for 1.6
From:       "Benjamin K. Stuhl" <benjamin.stuhl () colorado ! edu>
Date:       2006-07-27 2:50:45
Message-ID: 20060726205045.15e0becc () localhost
[Download RAW message or body]

Thomas,
  Here's a new patch against what's in the 1.6 branch that implements
our discussion from earlier today. In particular, it splits
loadOasisSpan() into two variants, one that is easy to use (i.e. just
has a bool stripLeadingSpace = false) and one that actually does the
work by adding a bool *hasTrailingSpace so as to get the recursion
right. KWord and KPresenter both compile, and KWord still renders your
test document the same way OO.o does.

Thanks,
-- BKS
["kword-odt-loading-fix-v3.patch" (text/x-patch)]

Index: koffice/kword/KWTextDocument.cpp
===================================================================
--- koffice/kword/KWTextDocument.cpp	(revision 566774)
+++ koffice/kword/KWTextDocument.cpp	(working copy)
@@ -198,8 +198,7 @@
                 context.styleStack().save();
                 // We have a reference to a bookmark (### TODO)
                 // As we do not support it now, treat it as a <span> without \
                formatting
-                bool leadingSpace = false;
-                parag->loadOasisSpan( tag, context, pos, leadingSpace ); // recurse
+                parag->loadOasisSpan( tag, context, pos ); // recurse
                 context.styleStack().restore();
             }
             else
Index: koffice/lib/kotext/KoTextParag.h
===================================================================
--- koffice/lib/kotext/KoTextParag.h	(revision 566774)
+++ koffice/lib/kotext/KoTextParag.h	(working copy)
@@ -330,11 +330,19 @@
      * Load a section of text from a oasis based xml tree.
      * @param parent the xml element that has content as children.
      * @param context the context
-     * @param stripLeadingSpace Set to true to remove a leading space from the \
                content even if
-     *        the xml contains one.
+     * @param stripLeadingSpace whether to remove leading literal whitespace
      */
-    void loadOasisSpan( const QDomElement& parent, KoOasisContext& context, uint& \
pos, bool stripLeadingSpace = false); +    void loadOasisSpan( const QDomElement& \
parent, KoOasisContext& context, uint& pos, bool stripLeadingSpace = false );  
+    /**
+     * Load a section of text from a oasis based xml tree.
+     * @param parent the xml element that has content as children.
+     * @param context the context
+     * @param stripLeadingSpace whether to remove leading literal whitespace
+     * @param hasTrailingSpace whether there was trailing literal whitespace in the \
span's text +     */
+    void loadOasisSpan( const QDomElement& parent, KoOasisContext& context, uint& \
pos, bool stripLeadingSpace, bool *hasTrailingSpace ); +
     void applyListStyle( KoOasisContext& context, int restartNumbering, bool \
orderedList, bool heading, int level );  
 #ifndef NDEBUG
Index: koffice/lib/kotext/KoTextParag.cpp
===================================================================
--- koffice/lib/kotext/KoTextParag.cpp	(revision 566774)
+++ koffice/lib/kotext/KoTextParag.cpp	(working copy)
@@ -2732,8 +2732,15 @@
     return text;
 }
 
-void KoTextParag::loadOasisSpan( const QDomElement& parent, KoOasisContext& context, \
uint& pos, bool leadingSpace ) +void KoTextParag::loadOasisSpan( const QDomElement& \
parent, KoOasisContext& context, uint& pos, bool stripLeadingSpace )  {
+    bool dummy;
+
+    return loadOasisSpan( parent, context, pos, stripLeadingSpace, &dummy );
+}
+
+void KoTextParag::loadOasisSpan( const QDomElement& parent, KoOasisContext& context, \
uint& pos, bool stripLeadingSpace, bool *hasTrailingSpace ) +{
     // Parse every child node of the parent
     // Can't use forEachElement here since we also care about text nodes
     QDomNode node;
@@ -2751,14 +2758,22 @@
         // Try to keep the order of the tag names by probability of happening
         if ( node.isText() )
         {
-            textData = normalizeWhitespace( node.toText().data(), leadingSpace );
-            leadingSpace = textData[textData.length() - 1].isSpace();
+            textData = normalizeWhitespace( node.toText().data(), stripLeadingSpace \
); +            *hasTrailingSpace = stripLeadingSpace = textData[textData.length() - \
1].isSpace();  }
         else if ( isTextNS && localName == "span" ) // text:span
         {
             context.styleStack().save();
             context.fillStyleStack( ts, KoXmlNS::text, "style-name", "text" );
-            loadOasisSpan( ts, context, pos, leadingSpace ); // recurse
+
+            // the ODF spec states that whitespace is compressed through tags: e.g.
+            //   "Foo <text:span> Bar </text:span> Baz"
+            // should only have one space between each of "Foo", "Bar", and "Baz"
+            // so we need to keep track of whether there was any trailing whitespace
+            // in sub-spans so that we can propogate the whitespace compression \
state +            // back up to the parent element
+            loadOasisSpan( ts, context, pos, stripLeadingSpace, hasTrailingSpace ); \
// recurse +            stripLeadingSpace = *hasTrailingSpace;
             context.styleStack().restore();
         }
         else if ( isTextNS && localName == "s" ) // text:s
@@ -2882,8 +2897,7 @@
 
     // Load text
     // OO.o compatibility: ignore leading whitespace in <p> and <h> elements
-    bool leadingWhitespace = true;
-    loadOasisSpan( parent, context, pos, leadingWhitespace );
+    loadOasisSpan( parent, context, pos, true );
 
     // Apply default format to trailing space
     const int len = str->length();
Index: koffice/lib/kotext/KoTextObject.cpp
===================================================================
--- koffice/lib/kotext/KoTextObject.cpp	(revision 566774)
+++ koffice/lib/kotext/KoTextObject.cpp	(working copy)
@@ -2167,8 +2167,7 @@
                 context.fillStyleStack( tagToLoad, KoXmlNS::text, "style-name", \
"paragraph" );  
                 // OO.o compatibility: ignore leading whitespace in <p> and <h> \
                elements
-                bool leadingSpace = true;
-                lastParagraph->loadOasisSpan( tagToLoad, context, pos, leadingSpace \
); +                lastParagraph->loadOasisSpan( tagToLoad, context, pos, true );
                 context.styleStack().restore();
 
                 lastParagraph->setChanged( true );



_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel


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

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