summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-07-14 19:50:18 +0200
committerMichael Stahl <michael.stahl@allotropia.de>2021-07-16 18:48:46 +0200
commit86c0f58b6f9f392865196606173d1b98a6897f32 (patch)
tree740c02474529d6a4c7cb4b52e234068c1b28c227
parent4461e14d08c7d1c1c43b136a5a8e3acb868c0b51 (diff)
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.stahl@allotropia.de>
-rw-r--r--include/svx/xmlgrhlp.hxx4
-rw-r--r--include/xmloff/xmlimppr.hxx12
-rw-r--r--sc/source/filter/xml/xmlwrap.cxx2
-rw-r--r--sd/qa/unit/data/odp/fillbitmap2.odpbin0 -> 11590 bytes
-rw-r--r--sd/qa/unit/export-tests.cxx49
-rw-r--r--sd/source/filter/xml/sdxmlwrp.cxx36
-rw-r--r--svx/source/unodraw/UnoNameItemTable.cxx17
-rw-r--r--svx/source/unodraw/UnoNameItemTable.hxx14
-rw-r--r--svx/source/unodraw/unomtabl.cxx30
-rw-r--r--svx/source/xml/xmlgrhlp.cxx67
-rw-r--r--sw/qa/extras/odfexport/data/fillbitmap3.odtbin0 -> 10748 bytes
-rw-r--r--sw/qa/extras/odfexport/odfexport.cxx59
-rw-r--r--sw/source/filter/xml/swxml.cxx2
-rw-r--r--xmloff/source/draw/XMLShapeStyleContext.cxx31
-rw-r--r--xmloff/source/draw/ximpstyl.cxx44
-rw-r--r--xmloff/source/style/PageMasterImportContext.cxx69
-rw-r--r--xmloff/source/text/txtstyli.cxx31
17 files changed, 353 insertions, 114 deletions
diff --git a/include/svx/xmlgrhlp.hxx b/include/svx/xmlgrhlp.hxx
index 966339451c2f..c733ce5318bb 100644
--- a/include/svx/xmlgrhlp.hxx
+++ b/include/svx/xmlgrhlp.hxx
@@ -122,6 +122,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 c5e32d064998..8ce28dd5c7df 100644
--- a/include/xmloff/xmlimppr.hxx
+++ b/include/xmloff/xmlimppr.hxx
@@ -39,6 +39,7 @@ 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::xml::sax { class XFastAttributeList; }
+namespace com::sun::star::drawing { enum class SAL_DLLPUBLIC_RTTI FillStyle; }
struct XMLPropertyState;
class XMLPropertySetMapper;
@@ -55,8 +56,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
@@ -197,6 +199,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 4b390c412af5..557099bfae1c 100644
--- a/sc/source/filter/xml/xmlwrap.cxx
+++ b/sc/source/filter/xml/xmlwrap.cxx
@@ -543,6 +543,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
--- /dev/null
+++ b/sd/qa/unit/data/odp/fillbitmap2.odp
Binary files differ
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index c44564e201de..61f45e64f692 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -53,6 +53,7 @@ class SdExportTest : public SdModelTestBaseXML
public:
void testBackgroundImage();
void testMediaEmbedding();
+ void testFillBitmapUnused();
void testFdo84043();
void testTdf97630();
void testSwappedOutImageExport();
@@ -98,6 +99,7 @@ public:
CPPUNIT_TEST(testBackgroundImage);
CPPUNIT_TEST(testMediaEmbedding);
+ CPPUNIT_TEST(testFillBitmapUnused);
CPPUNIT_TEST(testFdo84043);
CPPUNIT_TEST(testTdf97630);
CPPUNIT_TEST(testSwappedOutImageExport);
@@ -320,6 +322,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(u"/sd/qa/unit/data/fdo84043.odp"), ODP);
diff --git a/sd/source/filter/xml/sdxmlwrp.cxx b/sd/source/filter/xml/sdxmlwrp.cxx
index 9a6e8d9a9afe..a65c7eee6f99 100644
--- a/sd/source/filter/xml/sdxmlwrp.cxx
+++ b/sd/source/filter/xml/sdxmlwrp.cxx
@@ -668,41 +668,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
- {
- static const OUStringLiteral aName(u"~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 dfa75c460f66..17e952ea5d4c 100644
--- a/svx/source/unodraw/UnoNameItemTable.cxx
+++ b/svx/source/unodraw/UnoNameItemTable.cxx
@@ -68,6 +68,8 @@ SvxUnoNameItemTable::SvxUnoNameItemTable( SdrModel* pModel, sal_uInt16 nWhich, s
SvxUnoNameItemTable::~SvxUnoNameItemTable() noexcept
{
+ SolarMutexGuard aGuard;
+
if( mpModel )
EndListening( *mpModel );
dispose();
@@ -122,20 +124,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 47654aaf4f8f..c1c798869ce5 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 d57e9665156f..bca16038a99d 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 ) noexcept
SvxUnoMarkerTable::~SvxUnoMarkerTable() noexcept
{
+ 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 bdb453579224..6b671c3a245b 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>
@@ -1121,4 +1124,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
--- /dev/null
+++ b/sw/qa/extras/odfexport/data/fillbitmap3.odt
Binary files differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 06e675f48ee9..b8ba81ea9e91 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -2187,6 +2187,65 @@ DECLARE_ODFEXPORT_EXPORTONLY_TEST(testPageStyleBackgroundFullSizeLO70, "pagestyl
"]/style:drawing-page-properties", "opacity", "100%");
}
+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 4d965aca3bf3..089aca4ccc8f 100644
--- a/sw/source/filter/xml/swxml.cxx
+++ b/sw/source/filter/xml/swxml.cxx
@@ -867,6 +867,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 1da9e11cf074..98191b71c8cd 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>
@@ -175,18 +176,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[] =
{
@@ -243,6 +244,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 c9449a900b1f..aa1520fe7047 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>
@@ -138,14 +139,14 @@ public:
const sal_uInt16 MAX_SPECIAL_DRAW_STYLES = 7;
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 }
};
XmlStyleFamily const g_Families[MAX_SPECIAL_DRAW_STYLES] =
{
@@ -257,6 +258,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
@@ -1422,4 +1430,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 685d82b9091a..2a50ae855719 100644
--- a/xmloff/source/style/PageMasterImportContext.cxx
+++ b/xmloff/source/style/PageMasterImportContext.cxx
@@ -201,24 +201,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
@@ -235,7 +235,19 @@ void PageStyleContext::FillPropertySet_PageStyle(
// get property set mapper
const rtl::Reference< XMLPropertySetMapper >& rMapper = xImpPrMap->getPropertySetMapper();
- Reference< XPropertySetInfo > xInfo;
+ Reference<XPropertySetInfo> const xInfo(xPropSet->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?
+ {
+ xPropSet->getPropertyValue("FillStyle") >>= fillStyle;
+ xPropSet->getPropertyValue("HeaderFillStyle") >>= fillStyleHeader;
+ xPropSet->getPropertyValue("FooterFillStyle") >>= fillStyleFooter;
+ }
// handle special attributes which have MID_FLAG_NO_PROPERTY_IMPORT set
for(sal_uInt16 i = 0; aContextIDs[i].nContextID != -1; i++)
@@ -244,27 +256,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);
@@ -273,11 +295,6 @@ void PageStyleContext::FillPropertySet_PageStyle(
// set property
const OUString& rPropertyName = rMapper->GetEntryAPIName(rState.mnIndex);
- if(!xInfo.is())
- {
- xInfo = xPropSet->getPropertySetInfo();
- }
-
if(xInfo->hasPropertyByName(rPropertyName))
{
xPropSet->setPropertyValue(rPropertyName,Any(sStyleName));
@@ -385,12 +402,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 701136e98fb2..5aa600c25c00 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>
@@ -380,21 +381,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
@@ -532,6 +533,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
{