diff options
author | Justin Luth <justin.luth@collabora.com> | 2018-12-26 10:49:55 +0300 |
---|---|---|
committer | Justin Luth <justin_luth@sil.org> | 2018-12-29 05:11:22 +0100 |
commit | 43836a58ffe943e2fc65be638f9a7d343102cb07 (patch) | |
tree | 3f853f2ee2864d63ad86c6d8d23e20af668dff14 | |
parent | 17875c59a7277a31d4b1953b23bead089e7a4988 (diff) |
tdf#47471 odfexport: use stylename if autostyle missing.
My guess is the autoStylePool can be invalidated by some events
(like clearing all attributes), and if nothing is done that
re-creates the autostyle, then Find() returns an empty string.
The normal case when all attributes are reset is that since
there are no attributes, it doesn't bother looking for the
AutoStyle, and just sticks with the given "parent" style.
However, some attributes (like lists) aren't reset, and
in those cases the autoPool didn't exist, and yet it still
looked for something, returning an empty string when
nothing was found.
If there is a style, but autostyle returns nothing, then it
should be safe to always use the given style. There are two
more areas with similar coding that I will change in separate
commits. (However, note that bug 90221 shows that an empty
autostyle might not be exactly like the given style).
Change-Id: I6a3d7b1608160f555004ca9cf1c93ec301177288
Reviewed-on: https://gerrit.libreoffice.org/65616
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth@sil.org>
-rw-r--r-- | sw/qa/extras/uiwriter/data2/tdf47471_paraStyleBackground.odt | bin | 0 -> 13816 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 35 | ||||
-rw-r--r-- | xmloff/source/text/txtparae.cxx | 5 |
3 files changed, 38 insertions, 2 deletions
diff --git a/sw/qa/extras/uiwriter/data2/tdf47471_paraStyleBackground.odt b/sw/qa/extras/uiwriter/data2/tdf47471_paraStyleBackground.odt Binary files differnew file mode 100644 index 000000000000..1d6f1a5f22fe --- /dev/null +++ b/sw/qa/extras/uiwriter/data2/tdf47471_paraStyleBackground.odt diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 0ab26ac25485..67aa3b7d7145 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -34,6 +34,7 @@ class SwUiWriterTest2 : public SwModelTestBase public: void testRedlineMoveInsertInDelete(); void testRedlineInHiddenSection(); + void testTdf47471_paraStyleBackground(); void testTdf101534(); void testTdf54819(); void testTdf108687_tabstop(); @@ -45,6 +46,7 @@ public: CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST(testRedlineMoveInsertInDelete); CPPUNIT_TEST(testRedlineInHiddenSection); + CPPUNIT_TEST(testTdf47471_paraStyleBackground); CPPUNIT_TEST(testTdf101534); CPPUNIT_TEST(testTdf54819); CPPUNIT_TEST(testTdf108687_tabstop); @@ -87,6 +89,39 @@ SwDoc* SwUiWriterTest2::createDoc(const char* pName) return pTextDoc->GetDocShell()->GetDoc(); } +void SwUiWriterTest2::testTdf47471_paraStyleBackground() +{ + SwDoc* pDoc = createDoc("tdf47471_paraStyleBackground.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + CPPUNIT_ASSERT_EQUAL(OUString("00Background"), + getProperty<OUString>(getParagraph(2), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(14729933), getProperty<sal_Int32>(getParagraph(2), "FillColor")); + + pWrtShell->EndPara(/*bSelect=*/true); + pWrtShell->EndPara(/*bSelect=*/true); + pWrtShell->EndPara(/*bSelect=*/true); + lcl_dispatchCommand(mxComponent, ".uno:ResetAttributes", {}); + + // the background color should revert to the color for 00Background style + //CPPUNIT_ASSERT_EQUAL(sal_Int32(14605542), getProperty<sal_Int32>(getParagraph(2), "FillColor")); + // the paragraph style should not be reset + CPPUNIT_ASSERT_EQUAL(OUString("00Background"), + getProperty<OUString>(getParagraph(2), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(OUString("00Background"), + getProperty<OUString>(getParagraph(3), "ParaStyleName")); + + // Save it and load it back. + reload("writer8", "tdf47471_paraStyleBackgroundRT.odt"); + + //CPPUNIT_ASSERT_EQUAL(sal_Int32(14605542), getProperty<sal_Int32>(getParagraph(2), "FillColor")); + // on round-trip, the paragraph style name was lost + CPPUNIT_ASSERT_EQUAL(OUString("00Background"), + getProperty<OUString>(getParagraph(2), "ParaStyleName")); + CPPUNIT_ASSERT_EQUAL(OUString("00Background"), + getProperty<OUString>(getParagraph(3), "ParaStyleName")); +} + void SwUiWriterTest2::testTdf101534() { // Copy the first paragraph of the document. diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx index c59198bb92b3..9a7776eec9e3 100644 --- a/xmloff/source/text/txtparae.cxx +++ b/xmloff/source/text/txtparae.cxx @@ -1941,8 +1941,9 @@ void XMLTextParagraphExport::exportParagraph( } } - OUString sAutoStyle( sStyle ); - sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet, sStyle ); + OUString sAutoStyle = Find( XML_STYLE_FAMILY_TEXT_PARAGRAPH, xPropSet, sStyle ); + if ( sAutoStyle.isEmpty() ) + sAutoStyle = sStyle; if( !sAutoStyle.isEmpty() ) GetExport().AddAttribute( XML_NAMESPACE_TEXT, XML_STYLE_NAME, GetExport().EncodeStyleName( sAutoStyle ) ); |