diff options
author | Michael Stahl <michael.stahl@allotropia.de> | 2021-07-14 19:50:18 +0200 |
---|---|---|
committer | Michael Stahl <michael.stahl@allotropia.de> | 2021-07-16 18:48:46 +0200 |
commit | 86c0f58b6f9f392865196606173d1b98a6897f32 (patch) | |
tree | 740c02474529d6a4c7cb4b52e234068c1b28c227 /xmloff/source | |
parent | 4461e14d08c7d1c1c43b136a5a8e3acb868c0b51 (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>
Diffstat (limited to 'xmloff/source')
-rw-r--r-- | xmloff/source/draw/XMLShapeStyleContext.cxx | 31 | ||||
-rw-r--r-- | xmloff/source/draw/ximpstyl.cxx | 44 | ||||
-rw-r--r-- | xmloff/source/style/PageMasterImportContext.cxx | 69 | ||||
-rw-r--r-- | xmloff/source/text/txtstyli.cxx | 31 |
4 files changed, 117 insertions, 58 deletions
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 { |