From c128724679d0be1defe74a4b6bf45f0235cac6a5 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Fri, 21 Aug 2015 18:28:23 +0200 Subject: tdf#92379: svx: don't overwrite fo:background-color on ODF import MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getSvxBrushItemFromSourceSet() is called once for each property of a frame style that is set, and the "solid" fill-style is set by first applying the BackColorRGB and then BackTransparency property. So there is an intermediate state that has fill-style NONE but a XFillColorItem set - don't reset the color to white in that case! Apparently writerfilter generally relies on the current reset-to-AUTO implementation (loads of test failures), so for now limit the fix for when we know that a frame style is imported from ODF. (regression from 3d399b0e45720354fc64dc3d121ee486e01eff89) (cherry picked from commit 79fb61efb847405fa47235002b52ee8efad5e339) tdf#92379: sw: unit test for frame style background color (cherry picked from commit 982537d77c2db463cc053cfdcd522530a3834c9e) Change-Id: Ia987fe586ec819a1f3cd85acdbfb03c74ca0ec2c Reviewed-on: https://gerrit.libreoffice.org/18037 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- include/svx/unobrushitemhelper.hxx | 3 +- svx/source/unodraw/unobrushitemhelper.cxx | 6 ++-- sw/CppunitTest_sw_odfexport.mk | 3 ++ sw/qa/extras/odfexport/data/tdf92379.fodt | 58 +++++++++++++++++++++++++++++++ sw/qa/extras/odfexport/odfexport.cxx | 13 +++++++ sw/source/core/unocore/unostyle.cxx | 4 +-- 6 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 sw/qa/extras/odfexport/data/tdf92379.fodt diff --git a/include/svx/unobrushitemhelper.hxx b/include/svx/unobrushitemhelper.hxx index eea95b60e6d6..4055c4584008 100644 --- a/include/svx/unobrushitemhelper.hxx +++ b/include/svx/unobrushitemhelper.hxx @@ -46,7 +46,8 @@ SVX_DLLPUBLIC void setSvxBrushItemAsFillAttributesToTargetSet( SVX_DLLPUBLIC SvxBrushItem getSvxBrushItemFromSourceSet( const SfxItemSet& rSourceSet, sal_uInt16 nBackgroundID, - bool bSearchInParents = true); + bool bSearchInParents = true, + bool bXMLImportHack = false); #endif // _UNOBRUSHITEMHELPER_HXX diff --git a/svx/source/unodraw/unobrushitemhelper.cxx b/svx/source/unodraw/unobrushitemhelper.cxx index 42b3d5f7c139..1ae4c1475ef2 100644 --- a/svx/source/unodraw/unobrushitemhelper.cxx +++ b/svx/source/unodraw/unobrushitemhelper.cxx @@ -192,7 +192,7 @@ SvxBrushItem getSvxBrushItemForSolid(const SfxItemSet& rSourceSet, bool bSearchI } //UUUU -SvxBrushItem getSvxBrushItemFromSourceSet(const SfxItemSet& rSourceSet, sal_uInt16 nBackgroundID, bool bSearchInParents) +SvxBrushItem getSvxBrushItemFromSourceSet(const SfxItemSet& rSourceSet, sal_uInt16 nBackgroundID, bool bSearchInParents, bool bXMLImportHack) { const XFillStyleItem* pXFillStyleItem(static_cast< const XFillStyleItem* >(rSourceSet.GetItem(XATTR_FILLSTYLE, bSearchInParents))); @@ -201,8 +201,8 @@ SvxBrushItem getSvxBrushItemFromSourceSet(const SfxItemSet& rSourceSet, sal_uInt // no fill, still need to rescue the evtl. set RGB color, but use as transparent color (we have drawing::FillStyle_NONE) Color aFillColor(static_cast< const XFillColorItem& >(rSourceSet.Get(XATTR_FILLCOLOR, bSearchInParents)).GetColorValue()); - // when fill style is none, then don't allow anything other than 0 or auto. - if (aFillColor.GetColor() != 0) + // for writerfilter: when fill style is none, then don't allow anything other than 0 or auto. + if (!bXMLImportHack && aFillColor.GetColor() != 0) aFillColor.SetColor(COL_AUTO); aFillColor.SetTransparency(0xff); diff --git a/sw/CppunitTest_sw_odfexport.mk b/sw/CppunitTest_sw_odfexport.mk index 7bc7ed826a14..c6ec626fb1ce 100644 --- a/sw/CppunitTest_sw_odfexport.mk +++ b/sw/CppunitTest_sw_odfexport.mk @@ -56,6 +56,9 @@ $(eval $(call gb_CppunitTest_use_components,sw_odfexport,\ embeddedobj/util/embobj \ filter/source/config/cache/filterconfig1 \ filter/source/storagefilterdetect/storagefd \ + filter/source/odfflatxml/odfflatxml \ + filter/source/xmlfilterdetect/xmlfd \ + filter/source/xmlfilteradaptor/xmlfa \ framework/util/fwk \ i18npool/util/i18npool \ linguistic/source/lng \ diff --git a/sw/qa/extras/odfexport/data/tdf92379.fodt b/sw/qa/extras/odfexport/data/tdf92379.fodt new file mode 100644 index 000000000000..280dc5ad893c --- /dev/null +++ b/sw/qa/extras/odfexport/data/tdf92379.fodt @@ -0,0 +1,58 @@ + + + + ms 2015-08-24T21:49:45.305718699LibreOfficeDev/4.3.7.2$Linux_X86_64 LibreOffice_project/8a35821d8636a03b8bf4e15b48f59794652c68ba + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 6cfd040a9bf3..69f97ee0b268 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -232,6 +232,19 @@ DECLARE_ODFEXPORT_TEST(testFdo38244, "fdo38244.odt") CPPUNIT_ASSERT_EQUAL(OUString("M"), getProperty(xPropertySet, "Initials")); } +DECLARE_ODFEXPORT_TEST(testTdf92379, "tdf92379.fodt") +{ + // frame style fo:background-color was not imported + uno::Reference xStyles(getStyles("FrameStyles")); + uno::Reference xStyle(xStyles->getByName("encarts"), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xffcc99), getProperty(xStyle, "BackColorRGB")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xStyle, "BackColorTransparency")); + CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_SOLID, getProperty(xStyle, "FillStyle")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0xffcc99), getProperty(xStyle, "FillColor")); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty(xStyle, "FillTransparence")); +} + DECLARE_ODFEXPORT_TEST(testFdo79358, "fdo79358.odt") { // the boolean properties of the index were not exported properly diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 5a25218b2ab8..fd3b27b7a90c 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -1761,7 +1761,7 @@ static void lcl_SetStyleProperty(const SfxItemPropertySimpleEntry& rEntry, { //UUUU SfxItemSet& rStyleSet = rBase.GetItemSet(); - const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(rStyleSet, RES_BACKGROUND)); + const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(rStyleSet, RES_BACKGROUND, true, pDoc->IsInXMLImport())); SvxBrushItem aChangedBrushItem(aOriginalBrushItem); aChangedBrushItem.PutValue(aValue, nMemberId); @@ -4296,7 +4296,7 @@ uno::Reference< style::XAutoStyle > SwXAutoStyleFamily::insertStyle( case RES_BACKGROUND: { //UUUU - const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND)); + const SvxBrushItem aOriginalBrushItem(getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND, true, pDocShell->GetDoc()->IsInXMLImport())); SvxBrushItem aChangedBrushItem(aOriginalBrushItem); aChangedBrushItem.PutValue(aValue, nMemberId); -- cgit v1.2.3