summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2021-07-14 19:50:18 +0200
committerThorsten Behrens <thorsten.behrens@allotropia.de>2021-07-19 01:53:55 +0200
commit6511448b408887811f5026ccdd1b170e3731afd8 (patch)
treebc74f0d7e2e1ac1c35e0d3fb96355d56fa4e96a4 /sd
parentb7b21c2d622672dc7f9bddbd1d685ef5db65b106 (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> (cherry picked from commit 86c0f58b6f9f392865196606173d1b98a6897f32) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119036 Reviewed-by: Thorsten Behrens <thorsten.behrens@allotropia.de>
Diffstat (limited to 'sd')
-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
3 files changed, 50 insertions, 35 deletions
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() )