diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-08-07 13:46:37 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-08-07 16:01:10 +0200 |
commit | 6e31cbb4eaea3c6600248ba59a22853acc1d6606 (patch) | |
tree | b27f2dfc6dbc6fb219460716f52684af93cdd177 | |
parent | 6c65f932e2bc7e291b691fc9afc05e0e3ee076d7 (diff) |
DOCX export: avoid empty attributes in paragraph shading
Change-Id: I4bdf3f2d7f2aee3ce735a52185e736a8861d85e4
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/para-shading.docx | bin | 0 -> 12609 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 14 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 37 |
3 files changed, 29 insertions, 22 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/para-shading.docx b/sw/qa/extras/ooxmlexport/data/para-shading.docx Binary files differnew file mode 100644 index 000000000000..9c2af1ad5e28 --- /dev/null +++ b/sw/qa/extras/ooxmlexport/data/para-shading.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index b2427148c464..6cd31bc80310 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -3474,6 +3474,20 @@ DECLARE_OOXMLEXPORT_TEST(testFdo80902, "fdo80902.docx") assertXPath(pXmlDoc, "/w:document/w:body/w:sectPr/w:docGrid", "type", "lines"); } +DECLARE_OOXMLEXPORT_TEST(testParaShading, "para-shading.docx") +{ + // Make sure the themeColor attribute is not written when it would be empty. + if (xmlDocPtr pXmlDoc = parseExport("word/document.xml")) + { + xmlXPathObjectPtr pXPath = getXPathNode(pXmlDoc, "/w:document/w:body/w:p/w:pPr/w:shd"); + xmlNodeSetPtr pXmlNodes = pXPath->nodesetval; + CPPUNIT_ASSERT_EQUAL(1, xmlXPathNodeSetGetLength(pXmlNodes)); + xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0]; + // The attribute existed, so xmlGetProp() returned non-NULL. + CPPUNIT_ASSERT_EQUAL(static_cast<xmlChar*>(0), xmlGetProp(pXmlNode, BAD_CAST("themeColor"))); + } +} + DECLARE_OOXMLEXPORT_TEST(testFirstHeaderFooter, "first-header-footer.docx") { // Test import and export of a section's headerf/footerf properties. diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 2ba2b4be5221..cfd3ef49915f 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -7710,42 +7710,35 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) { uno::Sequence<beans::PropertyValue> aGrabBagSeq; i->second >>= aGrabBagSeq; - OUString sVal, sShdFill, sShdColor, - sThemeColor, sThemeTint, sThemeShade, - sThemeFill, sThemeFillTint, sThemeFillShade; + for (sal_Int32 j=0; j < aGrabBagSeq.getLength(); ++j) { + OString sVal = OUStringToOString(aGrabBagSeq[j].Value.get<OUString>(), RTL_TEXTENCODING_UTF8); + + if (sVal.isEmpty()) + continue; + if (aGrabBagSeq[j].Name == "val") - aGrabBagSeq[j].Value >>= sVal; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_val), sVal.getStr()); else if (aGrabBagSeq[j].Name == "color") - aGrabBagSeq[j].Value >>= sShdColor; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_color), sVal.getStr()); else if (aGrabBagSeq[j].Name == "themeColor") - aGrabBagSeq[j].Value >>= sThemeColor; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeColor), sVal.getStr()); else if (aGrabBagSeq[j].Name == "themeTint") - aGrabBagSeq[j].Value >>= sThemeTint; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeTint), sVal.getStr()); else if (aGrabBagSeq[j].Name == "themeShade") - aGrabBagSeq[j].Value >>= sThemeShade; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeShade), sVal.getStr()); else if (aGrabBagSeq[j].Name == "fill") - aGrabBagSeq[j].Value >>= sShdFill; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_fill), sVal.getStr()); else if (aGrabBagSeq[j].Name == "themeFill") - aGrabBagSeq[j].Value >>= sThemeFill; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeFill), sVal.getStr()); else if (aGrabBagSeq[j].Name == "themeFillTint") - aGrabBagSeq[j].Value >>= sThemeFillTint; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeFillTint), sVal.getStr()); else if (aGrabBagSeq[j].Name == "themeFillShade") - aGrabBagSeq[j].Value >>= sThemeFillShade; + AddToAttrList(m_pBackgroundAttrList, FSNS(XML_w, XML_themeFillShade), sVal.getStr()); else if (aGrabBagSeq[j].Name == "originalColor") aGrabBagSeq[j].Value >>= m_sOriginalBackgroundColor; } - AddToAttrList(m_pBackgroundAttrList, 9, - FSNS(XML_w, XML_val), OUStringToOString(sVal, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_color), OUStringToOString(sShdColor, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_themeColor), OUStringToOString(sThemeColor, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_themeTint), OUStringToOString(sThemeTint, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_themeShade), OUStringToOString(sThemeShade, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_fill), OUStringToOString(sShdFill, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_themeFill), OUStringToOString(sThemeFill, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_themeFillTint), OUStringToOString(sThemeFillTint, RTL_TEXTENCODING_UTF8).getStr(), - FSNS(XML_w, XML_themeFillShade), OUStringToOString(sThemeFillShade, RTL_TEXTENCODING_UTF8).getStr()); } else if (i->first == "SdtPr") { |