From 6621da38b3cd217314c2d2295fd1e71be7e1875e Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Mon, 14 Sep 2015 09:10:04 +0200 Subject: tdf#92586 xmloff: fix import of stretched background image The bug document has: When a stretched background image is set on a page style using the Writer UI, then these two style:repeat attributes always match, but not in the bugdoc. The later used to have priority, till commit 7d9bb549d498d6beed2c4050c402d09643febdfa (Related: #i124638# Second step of DrawingLayer FillAttributes..., 2014-06-02). Fix the problem by extending XMLBackgroundImageContext::EndElement(): if we know that the sets the FillBitmapMode property, then don't blindly set BackGraphicLocation, but try to overwrite the exiting FillBitmapMode one. Change-Id: I64ab4363b20cc95003d35acd63ea421472b1c071 --- include/xmloff/PageMasterStyleMap.hxx | 1 + sw/qa/extras/odfimport/data/tdf92586.odt | Bin 0 -> 10517 bytes sw/qa/extras/odfimport/odfimport.cxx | 7 ++++ xmloff/inc/XMLBackgroundImageContext.hxx | 2 ++ xmloff/source/style/PageMasterStyleMap.cxx | 2 +- xmloff/source/style/PagePropertySetContext.cxx | 1 + xmloff/source/style/XMLBackgroundImageContext.cxx | 38 +++++++++++++++++++++- xmloff/source/text/XMLTextPropertySetContext.cxx | 1 + xmloff/source/text/XMLTextShapeStyleContext.cxx | 1 + 9 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 sw/qa/extras/odfimport/data/tdf92586.odt diff --git a/include/xmloff/PageMasterStyleMap.hxx b/include/xmloff/PageMasterStyleMap.hxx index 859f3e0e6e84..59f04df2abd9 100644 --- a/include/xmloff/PageMasterStyleMap.hxx +++ b/include/xmloff/PageMasterStyleMap.hxx @@ -96,6 +96,7 @@ #define CTF_PM_FILLHATCHNAME (XML_PM_CTF_START + 0x0040) #define CTF_PM_FILLBITMAPNAME (XML_PM_CTF_START + 0x0041) #define CTF_PM_FILLTRANSNAME (XML_PM_CTF_START + 0x0042) +#define CTF_PM_FILLBITMAPMODE (XML_PM_CTF_START + 0x0043) #define CTF_PM_SCALETO (XML_PM_CTF_START + 0x0051) // calc specific #define CTF_PM_SCALETOPAGES (XML_PM_CTF_START + 0x0052) diff --git a/sw/qa/extras/odfimport/data/tdf92586.odt b/sw/qa/extras/odfimport/data/tdf92586.odt new file mode 100644 index 000000000000..894571b628bf Binary files /dev/null and b/sw/qa/extras/odfimport/data/tdf92586.odt differ diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx index 708704d70f47..2f8239ccfb20 100644 --- a/sw/qa/extras/odfimport/odfimport.cxx +++ b/sw/qa/extras/odfimport/odfimport.cxx @@ -631,6 +631,13 @@ DECLARE_ODFIMPORT_TEST(testBnc800714, "bnc800714.fodt") CPPUNIT_ASSERT(getProperty(getParagraph(2), "ParaKeepTogether")); } +DECLARE_ODFIMPORT_TEST(testTdf92586, "tdf92586.odt") +{ + uno::Reference xPageStyle(getStyles("PageStyles")->getByName("Standard"), uno::UNO_QUERY); + // This was BitmapMode_NO_REPEAT. + CPPUNIT_ASSERT_EQUAL(drawing::BitmapMode_STRETCH, getProperty(xPageStyle, "FillBitmapMode")); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/xmloff/inc/XMLBackgroundImageContext.hxx b/xmloff/inc/XMLBackgroundImageContext.hxx index 3fb3ca15f4ce..36f68fe224b1 100644 --- a/xmloff/inc/XMLBackgroundImageContext.hxx +++ b/xmloff/inc/XMLBackgroundImageContext.hxx @@ -30,6 +30,7 @@ namespace com { namespace sun { namespace star { class XMLBackgroundImageContext : public XMLElementPropertyContext { XMLPropertyState aPosProp; + sal_Int32 m_nBitmapModeIdx; XMLPropertyState aFilterProp; XMLPropertyState aTransparencyProp; @@ -58,6 +59,7 @@ public: sal_Int32 nPosIdx, sal_Int32 nFilterIdx, sal_Int32 nTransparencyIdx, + sal_Int32 nBitmapModeIdx, ::std::vector< XMLPropertyState > &rProps ); virtual ~XMLBackgroundImageContext(); diff --git a/xmloff/source/style/PageMasterStyleMap.cxx b/xmloff/source/style/PageMasterStyleMap.cxx index 092e694fed64..02c248d5249a 100644 --- a/xmloff/source/style/PageMasterStyleMap.cxx +++ b/xmloff/source/style/PageMasterStyleMap.cxx @@ -140,7 +140,7 @@ const XMLPropertyMapEntry aXMLPageMasterStyleMap[] = PLMAP( "FillBitmapLogicalSize", XML_NAMESPACE_DRAW, XML_FILL_IMAGE_WIDTH, XML_SW_TYPE_LOGICAL_SIZE|MID_FLAG_MULTI_PROPERTY, 0 ), PLMAP( "FillBitmapSizeY", XML_NAMESPACE_DRAW, XML_FILL_IMAGE_HEIGHT, XML_SW_TYPE_FILLBITMAPSIZE|MID_FLAG_MULTI_PROPERTY, 0 ), PLMAP( "FillBitmapLogicalSize", XML_NAMESPACE_DRAW, XML_FILL_IMAGE_HEIGHT, XML_SW_TYPE_LOGICAL_SIZE|MID_FLAG_MULTI_PROPERTY, 0 ), - PLMAP( "FillBitmapMode", XML_NAMESPACE_STYLE, XML_REPEAT, XML_SW_TYPE_BITMAP_MODE|MID_FLAG_MULTI_PROPERTY, 0 ), + PLMAP( "FillBitmapMode", XML_NAMESPACE_STYLE, XML_REPEAT, XML_SW_TYPE_BITMAP_MODE|MID_FLAG_MULTI_PROPERTY, CTF_PM_FILLBITMAPMODE ), PLMAP( "FillBitmapPositionOffsetX", XML_NAMESPACE_DRAW, XML_FILL_IMAGE_REF_POINT_X, XML_TYPE_PERCENT, 0 ), PLMAP( "FillBitmapPositionOffsetY", XML_NAMESPACE_DRAW, XML_FILL_IMAGE_REF_POINT_Y, XML_TYPE_PERCENT, 0 ), PLMAP( "FillBitmapRectanglePoint", XML_NAMESPACE_DRAW, XML_FILL_IMAGE_REF_POINT, XML_SW_TYPE_BITMAP_REFPOINT, 0 ), diff --git a/xmloff/source/style/PagePropertySetContext.cxx b/xmloff/source/style/PagePropertySetContext.cxx index c8d6e4dec8cf..9fa55fb4c47c 100644 --- a/xmloff/source/style/PagePropertySetContext.cxx +++ b/xmloff/source/style/PagePropertySetContext.cxx @@ -96,6 +96,7 @@ SvXMLImportContext *PagePropertySetContext::CreateChildContext( rProp.mnIndex-2, rProp.mnIndex-1, -1, + mxMapper->getPropertySetMapper()->FindEntryIndex(CTF_PM_FILLBITMAPMODE), rProperties ); break; diff --git a/xmloff/source/style/XMLBackgroundImageContext.cxx b/xmloff/source/style/XMLBackgroundImageContext.cxx index 5acd95109076..a0ee84b2b7de 100644 --- a/xmloff/source/style/XMLBackgroundImageContext.cxx +++ b/xmloff/source/style/XMLBackgroundImageContext.cxx @@ -19,6 +19,7 @@ #include +#include #include @@ -332,9 +333,11 @@ XMLBackgroundImageContext::XMLBackgroundImageContext( sal_Int32 nPosIdx, sal_Int32 nFilterIdx, sal_Int32 nTransparencyIdx, + sal_Int32 nBitmapModeIdx, ::std::vector< XMLPropertyState > &rProps ) : XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ), aPosProp( nPosIdx ), + m_nBitmapModeIdx(nBitmapModeIdx), aFilterProp( nFilterIdx ), aTransparencyProp( nTransparencyIdx ), nTransparency( 0 ) @@ -399,7 +402,40 @@ void XMLBackgroundImageContext::EndElement() XMLElementPropertyContext::EndElement(); if( -1 != aPosProp.mnIndex ) - rProperties.push_back( aPosProp ); + { + // See if a FillBitmapMode property is already set, in that case + // BackGraphicLocation will be ignored. + bool bFound = false; + if (m_nBitmapModeIdx != -1) + { + for (XMLPropertyState& rProperty : rProperties) + { + if (rProperty.mnIndex == m_nBitmapModeIdx) + { + bFound = true; + + // Found, so map the old property to the new one. + switch (ePos) + { + case GraphicLocation_TILED: + rProperty.maValue <<= drawing::BitmapMode_REPEAT; + break; + case GraphicLocation_AREA: + rProperty.maValue <<= drawing::BitmapMode_STRETCH; + break; + case GraphicLocation_MIDDLE_MIDDLE: + rProperty.maValue <<= drawing::BitmapMode_NO_REPEAT; + break; + default: + break; + } + break; + } + } + } + if (!bFound) + rProperties.push_back( aPosProp ); + } if( -1 != aFilterProp.mnIndex ) rProperties.push_back( aFilterProp ); if( -1 != aTransparencyProp.mnIndex ) diff --git a/xmloff/source/text/XMLTextPropertySetContext.cxx b/xmloff/source/text/XMLTextPropertySetContext.cxx index 2afbd9635c24..308451e6a6f3 100644 --- a/xmloff/source/text/XMLTextPropertySetContext.cxx +++ b/xmloff/source/text/XMLTextPropertySetContext.cxx @@ -114,6 +114,7 @@ SvXMLImportContext *XMLTextPropertySetContext::CreateChildContext( rProp.mnIndex-2, rProp.mnIndex-1, nTranspIndex, + -1, rProperties ); } break; diff --git a/xmloff/source/text/XMLTextShapeStyleContext.cxx b/xmloff/source/text/XMLTextShapeStyleContext.cxx index 59351c5b8b36..19c38ba5b2c9 100644 --- a/xmloff/source/text/XMLTextShapeStyleContext.cxx +++ b/xmloff/source/text/XMLTextShapeStyleContext.cxx @@ -111,6 +111,7 @@ SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext( rProp.mnIndex-2, rProp.mnIndex-1, rProp.mnIndex-3, + -1, rProperties ); break; } -- cgit v1.2.3