include/svx/xmlgrhlp.hxx | 4 + include/xmloff/xmlimppr.hxx | 12 +++- sc/source/filter/xml/xmlwrap.cxx | 2 sd/qa/unit/data/odp/fillbitmap2.odp |binary sd/qa/unit/export-tests.cxx | 49 +++++++++++++++++ sd/source/filter/xml/sdxmlwrp.cxx | 36 ------------ svx/source/unodraw/UnoNameItemTable.cxx | 17 +++-- svx/source/unodraw/UnoNameItemTable.hxx | 14 ++++ svx/source/unodraw/unomtabl.cxx | 30 ++++++---- svx/source/xml/xmlgrhlp.cxx | 67 +++++++++++++++++++++++ sw/qa/extras/odfexport/data/fillbitmap3.odt |binary sw/qa/extras/odfexport/odfexport.cxx | 59 ++++++++++++++++++++ sw/source/filter/xml/swxml.cxx | 2 xmloff/source/draw/XMLShapeStyleContext.cxx | 31 ++++++---- xmloff/source/draw/ximpstyl.cxx | 44 ++++++++++++--- xmloff/source/style/PageMasterImportContext.cxx | 69 ++++++++++++++---------- xmloff/source/text/txtstyli.cxx | 31 ++++++---- 17 files changed, 353 insertions(+), 114 deletions(-)
New commits: commit fe5d05de0f853d8f4219f1523edcb86cb6cd2b22 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Wed Jul 14 19:50:18 2021 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Mon Jul 26 12:14:09 2021 +0200 tdf#92796 ODF import: remove unused bitmap fills With CWS impress64 a partial fix for this was implemented to drop unreferenced named items including all non-color fills after ODF import, but this is only done in sd so move the code that does that to svx and call it from sc and sw as well. Implement some UNO interface for this, it's at least better than a magic string, and not obvious how a better solution would look like since it's known only at the end of the import if a bitmap is used or not. Another problem: when the Area tab is used to change to a different kind of fill, the items with the details for the previous fill aren't cleared, and so they are written to ODF files. Hence bitmaps in the file can be referenced even if they aren't actually used, and bloat up the files. Fix this by dropping all unused draw:fill-image-name attributes in ODF import. Also do the same for Gradient and Hatch fills; Transparency gradients can be combined with anything so leave them as they are. Change-Id: I0b591fd9f963d974d0c3e7208b99621ad61dd93c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118950 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit 86c0f58b6f9f392865196606173d1b98a6897f32) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119036 Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> (cherry picked from commit 6511448b408887811f5026ccdd1b170e3731afd8) diff --git a/include/svx/xmlgrhlp.hxx b/include/svx/xmlgrhlp.hxx index 37d8c63bda35..fd39e0b29fbc 100644 --- a/include/svx/xmlgrhlp.hxx +++ b/include/svx/xmlgrhlp.hxx @@ -120,6 +120,10 @@ public: virtual OUString SAL_CALL resolveOutputStream( const css::uno::Reference< css::io::XOutputStream >& rxBinaryStream ) override; }; +namespace svx { + SVXCORE_DLLPUBLIC void DropUnusedNamedItems(css::uno::Reference<css::uno::XInterface> const& xModel); +} + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/xmloff/xmlimppr.hxx b/include/xmloff/xmlimppr.hxx index 5f5a72d17cb3..7e825cf17586 100644 --- a/include/xmloff/xmlimppr.hxx +++ b/include/xmloff/xmlimppr.hxx @@ -37,6 +37,7 @@ namespace com::sun::star::uno { class Any; } namespace com::sun::star::uno { template <typename > class Reference; } namespace com::sun::star::uno { template <typename > class Sequence; } namespace com::sun::star::xml::sax { class XAttributeList; } +namespace com::sun::star::drawing { enum class SAL_DLLPUBLIC_RTTI FillStyle; } struct XMLPropertyState; class XMLPropertySetMapper; @@ -53,8 +54,9 @@ class SvXMLImport; */ struct ContextID_Index_Pair { - sal_Int16 nContextID; + sal_Int16 /*const*/ nContextID; sal_Int32 nIndex; + css::drawing::FillStyle /*const*/ nExpectedFillStyle; }; class XMLOFF_DLLPUBLIC SvXMLImportPropertyMapper : public salhelper::SimpleReferenceObject @@ -182,6 +184,14 @@ inline const rtl::Reference< XMLPropertySetMapper >& return maPropMapper; } +namespace xmloff { + +bool IsIgnoreFillStyleNamedItem( + css::uno::Reference<css::beans::XPropertySet> const& xProps, + css::drawing::FillStyle nExpectedFillStyle); + +} + #endif // INCLUDED_XMLOFF_XMLIMPPR_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/xml/xmlwrap.cxx b/sc/source/filter/xml/xmlwrap.cxx index 7712bfcc265f..4651a5f1f26d 100644 --- a/sc/source/filter/xml/xmlwrap.cxx +++ b/sc/source/filter/xml/xmlwrap.cxx @@ -544,6 +544,8 @@ bool ScXMLImportWrapper::Import( ImportFlags nMode, ErrCode& rError ) else bRet = true; + ::svx::DropUnusedNamedItems(xModel); + // set BuildId on XModel for later OLE object loading if( xInfoSet.is() ) { diff --git a/sd/qa/unit/data/odp/fillbitmap2.odp b/sd/qa/unit/data/odp/fillbitmap2.odp new file mode 100644 index 000000000000..2bf258df01ca Binary files /dev/null and b/sd/qa/unit/data/odp/fillbitmap2.odp differ diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx index b5db56f0bf7a..45e304260631 100644 --- a/sd/qa/unit/export-tests.cxx +++ b/sd/qa/unit/export-tests.cxx @@ -45,6 +45,7 @@ class SdExportTest : public SdModelTestBaseXML public: void testBackgroundImage(); void testMediaEmbedding(); + void testFillBitmapUnused(); void testFdo84043(); void testTdf97630(); void testSwappedOutImageExport(); @@ -82,6 +83,7 @@ public: CPPUNIT_TEST(testBackgroundImage); CPPUNIT_TEST(testMediaEmbedding); + CPPUNIT_TEST(testFillBitmapUnused); CPPUNIT_TEST(testFdo84043); CPPUNIT_TEST(testTdf97630); CPPUNIT_TEST(testSwappedOutImageExport); @@ -311,6 +313,53 @@ void SdExportTest::testMediaEmbedding() xDocShRef->DoClose(); } +void SdExportTest::testFillBitmapUnused() +{ + ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/odp/fillbitmap2.odp"), ODP); + utl::TempFile aTempFile; + xDocShRef = saveAndReload(xDocShRef.get(), ODP, &aTempFile); + + xmlDocUniquePtr pXmlDoc = parseExport(aTempFile, "content.xml"); + // shapes + assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fill='bitmap']", 1); + assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fill='bitmap']", "fill-image-name", "nav_5f_up"); + assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fill='solid']", 1); + assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fill='solid' and @draw:fill-image-name]", 0); + assertXPath(pXmlDoc, "//style:style[@style:family='graphic']/style:graphic-properties[@draw:fill='solid']", "fill-color", "#808080"); + + xmlDocUniquePtr pStyles = parseExport(aTempFile, "styles.xml"); + // master slide presentation style + assertXPath(pStyles, + "/office:document-styles/office:styles/style:style[@style:family='presentation' and @style:name='Default-background']/style:graphic-properties", "fill", "bitmap"); + assertXPath(pStyles, + "/office:document-styles/office:styles/style:style[@style:family='presentation' and @style:name='Default-background']/style:graphic-properties", "fill-image-name", "nav_5f_up"); + assertXPath(pStyles, + "/office:document-styles/office:styles/style:style[@style:family='presentation' and @style:name='Default_20_1-background']/style:graphic-properties", "fill", "solid"); + assertXPath(pStyles, + "/office:document-styles/office:styles/style:style[@style:family='presentation' and @style:name='Default_20_1-background']/style:graphic-properties", "fill-color", "#808080"); + assertXPath(pStyles, + "/office:document-styles/office:styles/style:style[@style:family='presentation' and @style:name='Default_20_1-background']/style:graphic-properties[@draw:fill-image-name]", 0); + // master slide drawing-page style + assertXPath(pStyles, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp1']/style:drawing-page-properties", "fill", "bitmap"); + assertXPath(pStyles, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp1']/style:drawing-page-properties", "fill-image-name", "nav_5f_up"); + assertXPath(pStyles, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp2']/style:drawing-page-properties", "fill", "solid"); + assertXPath(pStyles, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp2']/style:drawing-page-properties", "fill-color", "#808080"); + assertXPath(pStyles, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp2']/style:drawing-page-properties[@draw:fill-image-name]", 0); + + // the named items + assertXPath(pStyles, + "/office:document-styles/office:styles/draw:fill-image", 1); + assertXPath(pStyles, + "/office:document-styles/office:styles/draw:fill-image", "name", "nav_5f_up"); + + xDocShRef->DoClose(); +} + void SdExportTest::testFdo84043() { ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/fdo84043.odp"), ODP); diff --git a/sd/source/filter/xml/sdxmlwrp.cxx b/sd/source/filter/xml/sdxmlwrp.cxx index 9b20d9d7b322..002062080ce6 100644 --- a/sd/source/filter/xml/sdxmlwrp.cxx +++ b/sd/source/filter/xml/sdxmlwrp.cxx @@ -672,41 +672,7 @@ bool SdXMLFilter::Import( ErrCode& nError ) // clear unused named items from item pool - uno::Reference< lang::XMultiServiceFactory> xModelFactory( mxModel, uno::UNO_QUERY ); - if( xModelFactory.is() ) - { - try - { - const OUString aName("~clear~" ); - uno::Reference< container::XNameContainer > xGradient( xModelFactory->createInstance( "com.sun.star.drawing.GradientTable" ), uno::UNO_QUERY ); - if( xGradient.is() ) - xGradient->removeByName( aName ); - - uno::Reference< container::XNameContainer > xHatch( xModelFactory->createInstance( "com.sun.star.drawing.HatchTable" ), uno::UNO_QUERY ); - if( xHatch.is() ) - xHatch->removeByName( aName ); - - uno::Reference< container::XNameContainer > xBitmap( xModelFactory->createInstance( "com.sun.star.drawing.BitmapTable" ), uno::UNO_QUERY ); - if( xBitmap.is() ) - xBitmap->removeByName( aName ); - - uno::Reference< container::XNameContainer > xTransGradient( xModelFactory->createInstance( "com.sun.star.drawing.TransparencyGradientTable" ), uno::UNO_QUERY ); - if( xTransGradient.is() ) - xTransGradient->removeByName( aName ); - - uno::Reference< container::XNameContainer > xMarker( xModelFactory->createInstance( "com.sun.star.drawing.MarkerTable" ), uno::UNO_QUERY ); - if( xMarker.is() ) - xMarker->removeByName( aName ); - - uno::Reference< container::XNameContainer > xDashes( xModelFactory->createInstance( "com.sun.star.drawing.DashTable" ), uno::UNO_QUERY ); - if( xDashes.is() ) - xDashes->removeByName( aName ); - } - catch (const Exception&) - { - TOOLS_WARN_EXCEPTION( "sd.filter","sd::SdXMLFilter::Import(), exception during clearing of unused named items"); - } - } + ::svx::DropUnusedNamedItems(mxModel); // set BuildId on XModel for later OLE object loading if( xInfoSet.is() ) diff --git a/svx/source/unodraw/UnoNameItemTable.cxx b/svx/source/unodraw/UnoNameItemTable.cxx index 612877880ada..a95433de654e 100644 --- a/svx/source/unodraw/UnoNameItemTable.cxx +++ b/svx/source/unodraw/UnoNameItemTable.cxx @@ -47,6 +47,8 @@ SvxUnoNameItemTable::SvxUnoNameItemTable( SdrModel* pModel, sal_uInt16 nWhich, s SvxUnoNameItemTable::~SvxUnoNameItemTable() throw() { + SolarMutexGuard aGuard; + if( mpModel ) EndListening( *mpModel ); dispose(); @@ -101,20 +103,19 @@ void SAL_CALL SvxUnoNameItemTable::insertByName( const OUString& aApiName, const ImplInsertByName( aName, aElement ); } +void SAL_CALL SvxUnoNameItemTable::cancel() +{ + SolarMutexGuard aGuard; + // drop all items that are owned by this service and not the document + // (i.e. they are unused) + dispose(); +} void SAL_CALL SvxUnoNameItemTable::removeByName( const OUString& aApiName ) { SolarMutexGuard aGuard; comphelper::ProfileZone aZone("SvxUnoNameItemTable::removeByName"); - // a little quickfix for 2.0 to let applications clear api - // created items that are not used - if ( aApiName == "~clear~" ) - { - dispose(); - return; - } - OUString sName = SvxUnogetInternalNameForItem(mnWhich, aApiName); auto aIter = std::find_if(maItemSetVector.begin(), maItemSetVector.end(), diff --git a/svx/source/unodraw/UnoNameItemTable.hxx b/svx/source/unodraw/UnoNameItemTable.hxx index 1bb0b8276bba..5f65baf4d35d 100644 --- a/svx/source/unodraw/UnoNameItemTable.hxx +++ b/svx/source/unodraw/UnoNameItemTable.hxx @@ -22,6 +22,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/container/XNameContainer.hpp> +#include <com/sun/star/util/XCancellable.hpp> #include <cppuhelper/implbase.hxx> @@ -35,8 +36,12 @@ class SfxItemPool; class SfxItemSet; typedef std::vector< std::unique_ptr< SfxItemSet > > ItemPoolVector; -class SvxUnoNameItemTable : public cppu::WeakImplHelper< css::container::XNameContainer, css::lang::XServiceInfo >, - public SfxListener +class SvxUnoNameItemTable + : public cppu::WeakImplHelper< + css::util::XCancellable, + css::container::XNameContainer, + css::lang::XServiceInfo > + , public SfxListener { private: SdrModel* mpModel; @@ -44,6 +49,8 @@ private: sal_uInt16 mnWhich; sal_uInt8 mnMemberId; + /// vector contains all items that were created by this service and will + /// keep them alive even if nothing in the document references them ItemPoolVector maItemSetVector; void ImplInsertByName( const OUString& aName, const css::uno::Any& aElement ); @@ -63,6 +70,9 @@ public: // XServiceInfo virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; + // XCancellable + virtual void SAL_CALL cancel() override; + // XNameContainer virtual void SAL_CALL insertByName( const OUString& aName, const css::uno::Any& aElement ) override; virtual void SAL_CALL removeByName( const OUString& Name ) override; diff --git a/svx/source/unodraw/unomtabl.cxx b/svx/source/unodraw/unomtabl.cxx index b930fed67205..df27af67450c 100644 --- a/svx/source/unodraw/unomtabl.cxx +++ b/svx/source/unodraw/unomtabl.cxx @@ -24,6 +24,7 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/drawing/PointSequence.hpp> +#include <com/sun/star/util/XCancellable.hpp> #include <comphelper/sequence.hxx> #include <cppuhelper/implbase.hxx> @@ -51,8 +52,12 @@ typedef std::vector<std::unique_ptr<SfxItemSet>> ItemPoolVector; namespace { -class SvxUnoMarkerTable : public WeakImplHelper< container::XNameContainer, lang::XServiceInfo >, - public SfxListener +class SvxUnoMarkerTable + : public WeakImplHelper< + util::XCancellable, + container::XNameContainer, + lang::XServiceInfo> + , public SfxListener { private: SdrModel* mpModel; @@ -76,6 +81,9 @@ public: virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; virtual uno::Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; + // XCancellable + virtual void SAL_CALL cancel() override; + // XNameContainer virtual void SAL_CALL insertByName( const OUString& aName, const uno::Any& aElement ) override; virtual void SAL_CALL removeByName( const OUString& Name ) override; @@ -105,6 +113,8 @@ SvxUnoMarkerTable::SvxUnoMarkerTable( SdrModel* pModel ) throw() SvxUnoMarkerTable::~SvxUnoMarkerTable() throw() { + SolarMutexGuard aGuard; + if( mpModel ) EndListening( *mpModel ); dispose(); @@ -174,17 +184,17 @@ void SAL_CALL SvxUnoMarkerTable::insertByName( const OUString& aApiName, const u ImplInsertByName( aName, aElement ); } -void SAL_CALL SvxUnoMarkerTable::removeByName( const OUString& aApiName ) +void SAL_CALL SvxUnoMarkerTable::cancel() { SolarMutexGuard aGuard; + // drop all items that are owned by this service and not the document + // (i.e. they are unused) + dispose(); +} - // a little quickfix for 2.0 to let applications clear api - // created items that are not used - if ( aApiName == "~clear~" ) - { - dispose(); - return; - } +void SAL_CALL SvxUnoMarkerTable::removeByName( const OUString& aApiName ) +{ + SolarMutexGuard aGuard; OUString aName = SvxUnogetInternalNameForItem(XATTR_LINEEND, aApiName); diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index f9839c38b8ed..af17ae539554 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -26,6 +26,8 @@ #include <com/sun/star/io/NotConnectedException.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/util/XCancellable.hpp> #include <comphelper/fileformat.h> #include <comphelper/graphicmimetype.hxx> #include <cppuhelper/compbase.hxx> @@ -40,6 +42,7 @@ #include <vcl/gfxlink.hxx> #include <vcl/metaact.hxx> #include <tools/zcodec.hxx> +#include <tools/diagnose_ex.h> #include <vcl/GraphicObject.hxx> #include <vcl/graphicfilter.hxx> @@ -1117,4 +1120,68 @@ com_sun_star_comp_Svx_GraphicExportHelper_get_implementation( return cppu::acquire(new SvXMLGraphicImportExportHelper(SvXMLGraphicHelperMode::Write)); } +namespace svx { + + void DropUnusedNamedItems(css::uno::Reference<css::uno::XInterface> const& xModel) + { + uno::Reference<lang::XMultiServiceFactory> const xModelFactory(xModel, uno::UNO_QUERY); + assert(xModelFactory.is()); + try + { + uno::Reference<util::XCancellable> const xGradient( + xModelFactory->createInstance("com.sun.star.drawing.GradientTable"), + uno::UNO_QUERY ); + if (xGradient.is()) + { + xGradient->cancel(); + } + + uno::Reference<util::XCancellable> const xHatch( + xModelFactory->createInstance("com.sun.star.drawing.HatchTable"), + uno::UNO_QUERY ); + if (xHatch.is()) + { + xHatch->cancel(); + } + + uno::Reference<util::XCancellable> const xBitmap( + xModelFactory->createInstance("com.sun.star.drawing.BitmapTable"), + uno::UNO_QUERY ); + if (xBitmap.is()) + { + xBitmap->cancel(); + } + + uno::Reference<util::XCancellable> const xTransGradient( + xModelFactory->createInstance("com.sun.star.drawing.TransparencyGradientTable"), + uno::UNO_QUERY ); + if (xTransGradient.is()) + { + xTransGradient->cancel(); + } + + uno::Reference<util::XCancellable> const xMarker( + xModelFactory->createInstance("com.sun.star.drawing.MarkerTable"), + uno::UNO_QUERY ); + if (xMarker.is()) + { + xMarker->cancel(); + } + + uno::Reference<util::XCancellable> const xDashes( + xModelFactory->createInstance("com.sun.star.drawing.DashTable"), + uno::UNO_QUERY ); + if (xDashes.is()) + { + xDashes->cancel(); + } + } + catch (const Exception&) + { + TOOLS_WARN_EXCEPTION("svx", "dropUnusedNamedItems(): exception during clearing of unused named items"); + } + } + +} // namespace svx + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/odfexport/data/fillbitmap3.odt b/sw/qa/extras/odfexport/data/fillbitmap3.odt new file mode 100644 index 000000000000..90308a5ec433 Binary files /dev/null and b/sw/qa/extras/odfexport/data/fillbitmap3.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index 33356e1dd5ca..306555c425ad 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -1692,6 +1692,65 @@ DECLARE_ODFEXPORT_TEST(testMasterPageWithDrawingPage, "sw_hatch.odt") CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty<sal_Int16>(xStyle, "FillTransparence")); } +DECLARE_ODFEXPORT_EXPORTONLY_TEST(testFillBitmapUnused, "fillbitmap3.odt") +{ + // nav_5f_home and all its references are completely gone + xmlDocUniquePtr pXmlDoc = parseExport("styles.xml"); + + // paragraph style + assertXPath(pXmlDoc, + "/office:document-styles/office:styles/style:style[@style:name='Text_20_body']/loext:graphic-properties", "fill", "solid"); + assertXPath(pXmlDoc, + "/office:document-styles/office:styles/style:style[@style:name='Text_20_body']/loext:graphic-properties", "fill-color", "#c0c0c0"); + assertXPath(pXmlDoc, + "/office:document-styles/office:styles/style:style[@style:name='Text_20_body']/loext:graphic-properties[@draw:fill-image-name]", 0); + + // page style page-layout + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm1']/style:page-layout-properties", "fill", "bitmap"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm1']/style:page-layout-properties", "fill-image-name", "nav_5f_up"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm1']/style:header-style/style:header-footer-properties", "fill", "bitmap"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm1']/style:header-style/style:header-footer-properties", "fill-image-name", "nav_5f_up"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm1']/style:footer-style/style:header-footer-properties", "fill", "bitmap"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm1']/style:footer-style/style:header-footer-properties", "fill-image-name", "nav_5f_up"); + + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm2']/style:page-layout-properties", "fill", "solid"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm2']/style:page-layout-properties[@draw:fill-image-name]", 0); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm2']/style:header-style/style:header-footer-properties", "fill", "solid"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm2']/style:header-style/style:header-footer-properties[@draw:fill-image-name]", 0); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm2']/style:footer-style/style:header-footer-properties", "fill", "solid"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:page-layout[@style:name='Mpm2']/style:footer-style/style:header-footer-properties[@draw:fill-image-name]", 0); + + // page style drawing-page + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp1']/style:drawing-page-properties", "fill", "bitmap"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp1']/style:drawing-page-properties", "fill-image-name", "nav_5f_up"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp2']/style:drawing-page-properties", "fill", "solid"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp2']/style:drawing-page-properties", "fill-color", "#c0c0c0"); + assertXPath(pXmlDoc, + "/office:document-styles/office:automatic-styles/style:style[@style:name='Mdp2']/style:drawing-page-properties[@draw:fill-image-name]", 0); + + // the named items + assertXPath(pXmlDoc, + "/office:document-styles/office:styles/draw:fill-image", 1); + assertXPath(pXmlDoc, + "/office:document-styles/office:styles/draw:fill-image", "name", "nav_5f_up"); +} + DECLARE_ODFEXPORT_TEST(testCellUserDefineAttr, "userdefattr-tablecell.odt") { CPPUNIT_ASSERT_EQUAL(1, getPages()); diff --git a/sw/source/filter/xml/swxml.cxx b/sw/source/filter/xml/swxml.cxx index d36e206e167f..37daee7beede 100644 --- a/sw/source/filter/xml/swxml.cxx +++ b/sw/source/filter/xml/swxml.cxx @@ -859,6 +859,8 @@ ErrCode XMLReader::Read( SwDoc &rDoc, const OUString& rBaseURL, SwPaM &rPaM, con nRet = nRet ? nRet : (nWarn ? nWarn : (nWarn2 ? nWarn2 : nWarnRDF ) ); + ::svx::DropUnusedNamedItems(xModelComp); + m_aOption.ResetAllFormatsOnly(); // redline password diff --git a/xmloff/source/draw/XMLShapeStyleContext.cxx b/xmloff/source/draw/XMLShapeStyleContext.cxx index b7036dd5df4e..258e6045d7f2 100644 --- a/xmloff/source/draw/XMLShapeStyleContext.cxx +++ b/xmloff/source/draw/XMLShapeStyleContext.cxx @@ -22,6 +22,7 @@ #include <xmloff/XMLShapeStyleContext.hxx> #include <XMLShapePropertySetContext.hxx> #include <xmloff/contextid.hxx> +#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/XControlShape.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertySetInfo.hpp> @@ -186,18 +187,18 @@ void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet struct ContextID_Index_Pair aContextIDs[] = { - { CTF_DASHNAME , -1 }, - { CTF_LINESTARTNAME , -1 }, - { CTF_LINEENDNAME , -1 }, - { CTF_FILLGRADIENTNAME, -1 }, - { CTF_FILLTRANSNAME , -1 }, - { CTF_FILLHATCHNAME , -1 }, - { CTF_FILLBITMAPNAME , -1 }, - { CTF_SD_OLE_VIS_AREA_IMPORT_LEFT, -1 }, - { CTF_SD_OLE_VIS_AREA_IMPORT_TOP, -1 }, - { CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH, -1 }, - { CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT, -1 }, - { -1, -1 } + { CTF_DASHNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_LINESTARTNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_LINEENDNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT }, + { CTF_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, + { CTF_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, + { CTF_SD_OLE_VIS_AREA_IMPORT_LEFT, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_SD_OLE_VIS_AREA_IMPORT_TOP, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { -1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE } }; static const XmlStyleFamily aFamilies[] = { @@ -254,6 +255,12 @@ void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet break; } + if (::xmloff::IsIgnoreFillStyleNamedItem(rPropSet, aContextIDs[i].nExpectedFillStyle)) + { + SAL_INFO("xmloff.style", "ShapeStyleContext: dropping fill named item: " << sStyleName); + break; // ignore it, it's not used + } + try { diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx index b0968f1b6612..92c45ae5e65f 100644 --- a/xmloff/source/draw/ximpstyl.cxx +++ b/xmloff/source/draw/ximpstyl.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/style/XStyle.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/presentation/XPresentationPage.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/XDrawPages.hpp> #include <com/sun/star/container/XNamed.hpp> #include <com/sun/star/beans/XPropertySet.hpp> @@ -153,14 +154,14 @@ public: static const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7; static ContextID_Index_Pair const g_ContextIDs[MAX_SPECIAL_DRAW_STYLES+1] = { - { CTF_DASHNAME , -1 }, - { CTF_LINESTARTNAME , -1 }, - { CTF_LINEENDNAME , -1 }, - { CTF_FILLGRADIENTNAME, -1 }, - { CTF_FILLTRANSNAME , -1 }, - { CTF_FILLHATCHNAME , -1 }, - { CTF_FILLBITMAPNAME , -1 }, - { -1, -1 } + { CTF_DASHNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_LINESTARTNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_LINEENDNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT}, + { CTF_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, + { CTF_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, + { -1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE } }; static XmlStyleFamily const g_Families[MAX_SPECIAL_DRAW_STYLES] = { @@ -287,6 +288,13 @@ void XMLDrawingPageStyleContext::FillPropertySet( struct XMLPropertyState& rState = GetProperties()[nIndex]; OUString sStyleName; rState.maValue >>= sStyleName; + + if (::xmloff::IsIgnoreFillStyleNamedItem(rPropSet, m_pContextIDs[i].nExpectedFillStyle)) + { + SAL_INFO("xmloff.style", "XMLDrawingPageStyleContext: dropping fill named item: " << sStyleName); + break; // ignore it, it's not used + } + sStyleName = GetImport().GetStyleDisplayName( m_pFamilies[i], sStyleName ); // get property set mapper @@ -1541,4 +1549,24 @@ void SdXMLHeaderFooterDeclContext::Characters( const OUString& rChars ) maStrText += rChars; } +namespace xmloff { + +bool IsIgnoreFillStyleNamedItem( + css::uno::Reference<css::beans::XPropertySet> const& xProps, + drawing::FillStyle const nExpectedFillStyle) +{ + assert(xProps.is()); + if (nExpectedFillStyle == drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE) + { + return false; + } + + // note: the caller must have called FillPropertySet() previously + drawing::FillStyle fillStyle{drawing::FillStyle_NONE}; + xProps->getPropertyValue("FillStyle") >>= fillStyle; + return fillStyle != nExpectedFillStyle; +} + +} // namespace xmloff + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/style/PageMasterImportContext.cxx b/xmloff/source/style/PageMasterImportContext.cxx index 2918d744856e..a036bf31d1fe 100644 --- a/xmloff/source/style/PageMasterImportContext.cxx +++ b/xmloff/source/style/PageMasterImportContext.cxx @@ -206,24 +206,24 @@ void PageStyleContext::FillPropertySet_PageStyle( // properties that need special handling because they need the used name to be translated first struct ContextID_Index_Pair aContextIDs[] = { - { CTF_PM_FILLGRADIENTNAME, -1 }, - { CTF_PM_FILLTRANSNAME, -1 }, - { CTF_PM_FILLHATCHNAME, -1 }, - { CTF_PM_FILLBITMAPNAME, -1 }, + { CTF_PM_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT }, + { CTF_PM_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_PM_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, + { CTF_PM_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, // also need to special handling for header entries - { CTF_PM_HEADERFILLGRADIENTNAME, -1 }, - { CTF_PM_HEADERFILLTRANSNAME, -1 }, - { CTF_PM_HEADERFILLHATCHNAME, -1 }, - { CTF_PM_HEADERFILLBITMAPNAME, -1 }, + { CTF_PM_HEADERFILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT }, + { CTF_PM_HEADERFILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_PM_HEADERFILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, + { CTF_PM_HEADERFILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, // also need to special handling for footer entries - { CTF_PM_FOOTERFILLGRADIENTNAME, -1 }, - { CTF_PM_FOOTERFILLTRANSNAME, -1 }, - { CTF_PM_FOOTERFILLHATCHNAME, -1 }, - { CTF_PM_FOOTERFILLBITMAPNAME, -1 }, + { CTF_PM_FOOTERFILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT }, + { CTF_PM_FOOTERFILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_PM_FOOTERFILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, + { CTF_PM_FOOTERFILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, - {-1, -1} + {-1, -1, drawing::FillStyle::FillStyle_GRADIENT} }; // the style families associated with the same index modulo 4 @@ -240,7 +240,19 @@ void PageStyleContext::FillPropertySet_PageStyle( // get property set mapper const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper(); - Reference< XPropertySetInfo > xInfo; + Reference<XPropertySetInfo> const xInfo(rPropSet->getPropertySetInfo()); + + // don't look at the attributes, look at the property, could + // theoretically be inherited and we don't want to delete erroneously + drawing::FillStyle fillStyle{drawing::FillStyle_NONE}; + drawing::FillStyle fillStyleHeader{drawing::FillStyle_NONE}; + drawing::FillStyle fillStyleFooter{drawing::FillStyle_NONE}; + if (xInfo->hasPropertyByName("FillStyle")) // SwXTextDefaults lacks it? + { + rPropSet->getPropertyValue("FillStyle") >>= fillStyle; + rPropSet->getPropertyValue("HeaderFillStyle") >>= fillStyleHeader; + rPropSet->getPropertyValue("FooterFillStyle") >>= fillStyleFooter; + } // handle special attributes which have MID_FLAG_NO_PROPERTY_IMPORT set for(sal_uInt16 i = 0; aContextIDs[i].nContextID != -1; i++) @@ -249,27 +261,37 @@ void PageStyleContext::FillPropertySet_PageStyle( if(nIndex != -1) { + drawing::FillStyle const* pFillStyle(nullptr); switch(aContextIDs[i].nContextID) { case CTF_PM_FILLGRADIENTNAME: case CTF_PM_FILLTRANSNAME: case CTF_PM_FILLHATCHNAME: case CTF_PM_FILLBITMAPNAME: - + pFillStyle = &fillStyle; + [[fallthrough]]; case CTF_PM_HEADERFILLGRADIENTNAME: case CTF_PM_HEADERFILLTRANSNAME: case CTF_PM_HEADERFILLHATCHNAME: case CTF_PM_HEADERFILLBITMAPNAME: - + if (!pFillStyle) { pFillStyle = &fillStyleHeader; } + [[fallthrough]]; case CTF_PM_FOOTERFILLGRADIENTNAME: case CTF_PM_FOOTERFILLTRANSNAME: case CTF_PM_FOOTERFILLHATCHNAME: case CTF_PM_FOOTERFILLBITMAPNAME: { + if (!pFillStyle) { pFillStyle = &fillStyleFooter; } struct XMLPropertyState& rState = GetProperties()[nIndex]; OUString sStyleName; rState.maValue >>= sStyleName; + if (aContextIDs[i].nExpectedFillStyle != drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE + && aContextIDs[i].nExpectedFillStyle != *pFillStyle) + { + SAL_INFO("xmloff.style", "PageStyleContext: dropping fill named item: " << sStyleName); + break; // ignore it, it's not used + } // translate the used name from ODF intern to the name used in the Model sStyleName = GetImport().GetStyleDisplayName(aFamilies[i%4], sStyleName); @@ -278,11 +300,6 @@ void PageStyleContext::FillPropertySet_PageStyle( // set property const OUString& rPropertyName = rMapper->GetEntryAPIName(rState.mnIndex); - if(!xInfo.is()) - { - xInfo = rPropSet->getPropertySetInfo(); - } - if(xInfo->hasPropertyByName(rPropertyName)) { rPropSet->setPropertyValue(rPropertyName,Any(sStyleName)); @@ -326,12 +343,12 @@ void PageStyleContext::FillPropertySet_PageStyle( extern ContextID_Index_Pair const g_MasterPageContextIDs[] = { - { CTF_PM_FILLGRADIENTNAME, -1 }, - { CTF_PM_FILLTRANSNAME, -1 }, - { CTF_PM_FILLHATCHNAME, -1 }, - { CTF_PM_FILLBITMAPNAME, -1 }, + { CTF_PM_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT }, + { CTF_PM_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_PM_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, + { CTF_PM_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, - {-1, -1} + {-1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE} }; extern XmlStyleFamily const g_MasterPageFamilies[] = diff --git a/xmloff/source/text/txtstyli.cxx b/xmloff/source/text/txtstyli.cxx index 4bf3ba743397..b66a731b0ef8 100644 --- a/xmloff/source/text/txtstyli.cxx +++ b/xmloff/source/text/txtstyli.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/frame/XModel.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/style/ParagraphStyleCategory.hpp> @@ -398,21 +399,21 @@ void XMLTextStyleContext::FillPropertySet( // intelligent solution. struct ContextID_Index_Pair aContextIDs[] = { - { CTF_COMBINED_CHARACTERS_FIELD, -1 }, - { CTF_KEEP_TOGETHER, -1 }, - { CTF_BORDER_MODEL, -1 }, - { CTF_TEXT_DISPLAY, -1 }, - { CTF_FONTFAMILYNAME, -1 }, - { CTF_FONTFAMILYNAME_CJK, -1 }, - { CTF_FONTFAMILYNAME_CTL, -1 }, + { CTF_COMBINED_CHARACTERS_FIELD, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_KEEP_TOGETHER, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_BORDER_MODEL, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_TEXT_DISPLAY, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FONTFAMILYNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FONTFAMILYNAME_CJK, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FONTFAMILYNAME_CTL, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, //UUU need special handling for DrawingLayer FillStyle names - { CTF_FILLGRADIENTNAME, -1 }, - { CTF_FILLTRANSNAME, -1 }, - { CTF_FILLHATCHNAME, -1 }, - { CTF_FILLBITMAPNAME, -1 }, + { CTF_FILLGRADIENTNAME, -1, drawing::FillStyle::FillStyle_GRADIENT }, + { CTF_FILLTRANSNAME, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE }, + { CTF_FILLHATCHNAME, -1, drawing::FillStyle::FillStyle_HATCH }, + { CTF_FILLBITMAPNAME, -1, drawing::FillStyle::FillStyle_BITMAP }, - { -1, -1 } + { -1, -1, drawing::FillStyle::FillStyle_MAKE_FIXED_SIZE } }; // the style families associated with the same index modulo 4 @@ -550,6 +551,12 @@ void XMLTextStyleContext::FillPropertySet( break; } + if (::xmloff::IsIgnoreFillStyleNamedItem(rPropSet, aContextIDs[i].nExpectedFillStyle)) + { + SAL_INFO("xmloff.style", "XMLTextStyleContext: dropping fill named item: " << sStyleName); + break; // ignore it, it's not used + } + // Still needed if it's not an AutomaticStyle (!) try { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits