[Libreoffice-commits] core.git: sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Nov 18 08:50:18 PST 2014


 sw/qa/extras/ooxmlexport/data/paragraph-mark-nonempty.odt |binary
 sw/qa/extras/ooxmlexport/ooxmlexport.cxx                  |   20 ++++++++++++++
 sw/source/filter/ww8/docxattributeoutput.cxx              |    2 -
 sw/source/filter/ww8/wrtw8nds.cxx                         |   13 ++++++++-
 4 files changed, 33 insertions(+), 2 deletions(-)

New commits:
commit 347566d6b6ae12c86aa2eb787cd97f2dcfe8ea2d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Nov 18 17:47:23 2014 +0100

    DOCX export: put either hints or the para attr set into the para marker props
    
    Commit d72237741ed1d8f976032ff2ee5d2a8702d3380e (abi#9930
    DocxAttributeOutput::AddToAttrList: avoid duplicated attributes,
    2014-11-02) added a quick fix to avoid writing duplicated attributes,
    but the validation problem of duplicated elements remained.
    
    Make sure that when writing paragraph marker properties, then we write
    either the hints at the end of the paragraph or the character attributes
    range of the paragraph properties, but not both.
    
    The only exception is the character style that's always set as
    a hint, as explained in commit 4bb872b1924453f22e90bdd14e2898a3e66d5551
    (DOCX export: fix handling of paragraph mark on empty paragraphs,
    2014-10-17).
    
    Change-Id: I494e5bb9871aa535532fef32bd344d8093e9f762

diff --git a/sw/qa/extras/ooxmlexport/data/paragraph-mark-nonempty.odt b/sw/qa/extras/ooxmlexport/data/paragraph-mark-nonempty.odt
new file mode 100644
index 0000000..b12cbf6
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/paragraph-mark-nonempty.odt differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
index 39c559a..964ec96 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx
@@ -41,6 +41,19 @@ protected:
         // If the testcase is stored in some other format, it's pointless to test.
         return (OString(filename).endsWith(".docx") && std::find(vBlacklist.begin(), vBlacklist.end(), filename) == vBlacklist.end());
     }
+
+    /**
+     * Validation handling
+     */
+    bool mustValidate(const char* filename) const SAL_OVERRIDE
+    {
+        const char* aWhitelist[] = {
+            "paragraph-mark-nonempty.odt"
+        };
+        std::vector<const char*> vWhitelist(aWhitelist, aWhitelist + SAL_N_ELEMENTS(aWhitelist));
+
+        return std::find(vWhitelist.begin(), vWhitelist.end(), filename) != vWhitelist.end();
+    }
 protected:
     bool CjkNumberedListTestHelper(sal_Int16 &nValue)
     {
@@ -522,6 +535,13 @@ DECLARE_OOXMLEXPORT_TEST(testParagraphMark, "paragraph-mark.docx")
     CPPUNIT_ASSERT_EQUAL(OUString("Emphasis"), getProperty<OUString>(getRun(getParagraph(1), 1), "CharStyleName"));
 }
 
+DECLARE_OOXMLEXPORT_TEST(testParagraphMarkNonempty, "paragraph-mark-nonempty.odt")
+{
+    if (xmlDocPtr pXmlDoc = parseExport())
+        // There were two <w:sz> elements, make sure the 40 one is is dropped and the 20 one is kept.
+        assertXPath(pXmlDoc, "//w:p/w:pPr/w:rPr/w:sz", "val", "20");
+}
+
 DECLARE_OOXMLEXPORT_TEST(testPageBreakBefore, "page-break-before.docx")
 {
     // This was style::BreakType_PAGE_BEFORE, i.e. page break wasn't ignored, as it should have been.
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 7444240..cacbe97 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -8457,7 +8457,7 @@ void DocxAttributeOutput::AddToAttrList( ::sax_fastparser::FastAttributeList* &p
     {
         sal_Int32 nName = va_arg( args, sal_Int32 );
         const char* pValue = va_arg( args, const char* );
-        if( pValue && !pAttrList->hasAttribute(nName) )
+        if( pValue )
             pAttrList->add( nName, pValue );
     }
     va_end( args );
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index 02f8cae..9487f88 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -2705,7 +2705,16 @@ void MSWordExportBase::OutputTextNode( const SwTxtNode& rNode )
         }
     }
 
+    // The formatting of the paragraph marker has two sources:
+    // 1) If there are hints at the end of the paragraph, then use that.
+    // 2) Else use the RES_CHRATR_BEGIN..RES_TXTATR_END range of the paragraph
+    // properties.
+    //
+    // Exception: if there is a character style hint at the end of the
+    // paragraph only, then still go with 2), as RES_TXTATR_CHARFMT is always
+    // set as a hint.
     SfxItemSet aParagraphMarkerProperties(pDoc->GetAttrPool(), RES_CHRATR_BEGIN, RES_TXTATR_END);
+    bool bCharFormatOnly = true;
     if(const SwpHints* pTxtAttrs = rNode.GetpSwpHints())
     {
         for( size_t i = 0; i < pTxtAttrs->Count(); ++i )
@@ -2723,10 +2732,12 @@ void MSWordExportBase::OutputTextNode( const SwTxtNode& rNode )
                 SAL_INFO( "sw.ww8", "nWhich" << nWhich);
                 if (nWhich == RES_TXTATR_AUTOFMT || nWhich == RES_TXTATR_CHARFMT)
                     aParagraphMarkerProperties.Put(pHt->GetAttr());
+                if (nWhich != RES_TXTATR_CHARFMT)
+                    bCharFormatOnly = false;
             }
         }
     }
-    if (rNode.GetpSwAttrSet())
+    if (rNode.GetpSwAttrSet() && bCharFormatOnly)
     {
         aParagraphMarkerProperties.Put(*rNode.GetpSwAttrSet());
     }


More information about the Libreoffice-commits mailing list