tdf#126084 import svg image from ooxml document that use svgBlip elem.

In an OOXML document the svg image is defined in an svgBlip, which
is an OOXML extension. This change checks for the svgBlip element
and imports that instead the normal "blip" element that is still
provided as a fallback (PNG image).

Add roundtrip SVG image test for ODF and OOXML, Impress and Writer.

testGraphicBlipXLSX test failed after this change, because some
component was missing. Changed to enable use_rdb for all chart2
export tests, so issues like this won't happen anymore.

Change-Id: Idf0e754775254d7dcfd0321dfca2ed6d00c42c09
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/157238
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
This commit is contained in:
Tomaž Vajngerl 2023-09-25 09:03:54 +02:00 committed by Tomaž Vajngerl
parent fa38d98155
commit 1db193c6c7
8 changed files with 100 additions and 70 deletions

View file

@ -71,65 +71,7 @@ $(eval $(call gb_CppunitTest_use_sdk_api,chart2_export$(1)))
$(eval $(call gb_CppunitTest_use_ure,chart2_export$(1)))
$(eval $(call gb_CppunitTest_use_vcl,chart2_export$(1)))
$(eval $(call gb_CppunitTest_use_components,chart2_export$(1),\
basic/util/sb \
animations/source/animcore/animcore \
chart2/source/controller/chartcontroller \
chart2/source/chartcore \
comphelper/util/comphelp \
configmgr/source/configmgr \
dbaccess/util/dba \
embeddedobj/util/embobj \
emfio/emfio \
eventattacher/source/evtatt \
filter/source/config/cache/filterconfig1 \
filter/source/odfflatxml/odfflatxml \
filter/source/storagefilterdetect/storagefd \
filter/source/xmlfilteradaptor/xmlfa \
filter/source/xmlfilterdetect/xmlfd \
forms/util/frm \
framework/util/fwk \
i18npool/util/i18npool \
linguistic/source/lng \
oox/util/oox \
package/source/xstor/xstor \
package/util/package2 \
sax/source/expatwrap/expwrap \
sc/util/sc \
sc/util/scd \
sc/util/scfilt \
sw/util/sw \
sw/util/swd \
sw/util/msword \
sd/util/sd \
sd/util/sdd \
$(call gb_Helper_optional,SCRIPTING, \
sc/util/vbaobj) \
scaddins/source/analysis/analysis \
scaddins/source/datefunc/date \
scripting/source/basprov/basprov \
scripting/util/scriptframe \
sfx2/util/sfx \
sot/util/sot \
svl/source/fsstor/fsstorage \
svl/util/svl \
svtools/util/svt \
svx/util/svx \
svx/util/svxcore \
toolkit/util/tk \
vcl/vcl.common \
ucb/source/core/ucb1 \
ucb/source/ucp/file/ucpfile1 \
ucb/source/ucp/tdoc/ucptdoc1 \
unotools/util/utl \
unoxml/source/rdf/unordf \
unoxml/source/service/unoxml \
uui/util/uui \
writerfilter/util/writerfilter \
xmloff/util/xo \
xmlscript/util/xmlscript \
))
$(eval $(call gb_CppunitTest_use_rdb,chart2_export$(1),services))
$(eval $(call gb_CppunitTest_use_uiconfigs,chart2_export$(1), \
modules/swriter \

View file

@ -102,7 +102,8 @@ class BlipExtensionContext final : public ::oox::core::ContextHandler2
public:
explicit BlipExtensionContext(
::oox::core::ContextHandler2Helper const & rParent,
BlipFillProperties& rBlipProps );
BlipFillProperties& rBlipProps,
model::BlipFill* pBlipFill);
virtual ~BlipExtensionContext() override;
virtual ::oox::core::ContextHandlerRef
@ -112,6 +113,7 @@ public:
private:
BlipFillProperties& mrBlipProps;
model::BlipFill* mpBlipFill;
};

View file

@ -149,6 +149,7 @@ const Sequence< beans::Pair< OUString, sal_Int32 > >& NamespaceIds()
{"http://schemas.microsoft.com/office/spreadsheetml/2015/revision2",
NMSP_xr2},
{"http://schemas.microsoft.com/office/drawing/2017/decorative", NMSP_adec},
{"http://schemas.microsoft.com/office/drawing/2016/SVG/main", NMSP_asvg},
};
return SINGLETON;
};

View file

@ -369,7 +369,7 @@ ContextHandlerRef BlipContext::onCreateContext(
return new DuotoneContext( *this, mrBlipProps );
case A_TOKEN( extLst ):
return new BlipExtensionContext( *this, mrBlipProps );
return new BlipExtensionContext(*this, mrBlipProps, mpBlipFill);
case A_TOKEN( lum ):
{
@ -598,9 +598,10 @@ SimpleFillPropertiesContext::~SimpleFillPropertiesContext()
mrColor = getBestSolidColor();
}
BlipExtensionContext::BlipExtensionContext( ContextHandler2Helper const & rParent, BlipFillProperties& rBlipProps ) :
ContextHandler2( rParent ),
mrBlipProps( rBlipProps )
BlipExtensionContext::BlipExtensionContext(ContextHandler2Helper const & rParent, BlipFillProperties& rBlipProps, model::BlipFill* pBlipFill)
: ContextHandler2(rParent)
, mrBlipProps(rBlipProps)
, mpBlipFill(pBlipFill)
{
}
@ -608,16 +609,32 @@ BlipExtensionContext::~BlipExtensionContext()
{
}
ContextHandlerRef BlipExtensionContext::onCreateContext(
sal_Int32 nElement, const AttributeList& )
ContextHandlerRef BlipExtensionContext::onCreateContext(sal_Int32 nElement, const AttributeList& rAttribs)
{
switch( nElement )
{
case A_TOKEN( ext ):
return new BlipExtensionContext( *this, mrBlipProps );
case A_TOKEN(ext):
return new BlipExtensionContext(*this, mrBlipProps, mpBlipFill);
case OOX_TOKEN( a14, imgProps ):
return new ArtisticEffectContext( *this, mrBlipProps.maEffect );
case OOX_TOKEN(a14, imgProps):
return new ArtisticEffectContext(*this, mrBlipProps.maEffect);
case OOX_TOKEN(asvg, svgBlip):
{
if (rAttribs.hasAttribute(R_TOKEN(embed)))
{
// internal picture URL
OUString aFragmentPath = getFragmentPathFromRelId(rAttribs.getStringDefaulted(R_TOKEN(embed)));
if (!aFragmentPath.isEmpty())
{
auto xGraphic = getFilter().getGraphicHelper().importEmbeddedGraphic(aFragmentPath);
mrBlipProps.mxFillGraphic = xGraphic;
if (mpBlipFill)
mpBlipFill->mxGraphic = xGraphic;
}
}
}
break;
}
return nullptr;
}

Binary file not shown.

View file

@ -1927,6 +1927,37 @@ CPPUNIT_TEST_FIXTURE(SdExportTest, testTdf153179)
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getPage(0)->getCount());
}
CPPUNIT_TEST_FIXTURE(SdExportTest, testSvgImageSupport)
{
for (OUString const& rFormat : { u"impress8"_ustr, u"Impress Office Open XML"_ustr })
{
// Load the original file
createSdImpressDoc("odp/SvgImageTest.odp");
const OString sFailedMessage = "Failed on filter: " + rFormat.toUtf8();
saveAndReload(rFormat);
// Check whether graphic was exported well
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_Int32(1),
xDrawPagesSupplier->getDrawPages()->getCount());
uno::Reference<drawing::XDrawPage> xDrawPage(
xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xDrawPage.is());
uno::Reference<drawing::XShape> xImage(xDrawPage->getByIndex(0), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xPropertySet(xImage, uno::UNO_QUERY_THROW);
uno::Reference<graphic::XGraphic> xGraphic;
xPropertySet->getPropertyValue("Graphic") >>= xGraphic;
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
Graphic aGraphic(xGraphic);
auto pVectorGraphic = aGraphic.getVectorGraphicData();
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pVectorGraphic);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), VectorGraphicDataType::Svg,
pVectorGraphic->getType());
}
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Binary file not shown.

View file

@ -68,6 +68,7 @@ public:
void testDropDownFormField();
void testDateFormField();
void testDateFormFieldCharacterFormatting();
void testSvgImageSupport();
CPPUNIT_TEST_SUITE(Test);
CPPUNIT_TEST(testEmbeddedGraphicRoundtrip);
@ -91,6 +92,7 @@ public:
CPPUNIT_TEST(testDropDownFormField);
CPPUNIT_TEST(testDateFormField);
CPPUNIT_TEST(testDateFormFieldCharacterFormatting);
CPPUNIT_TEST(testSvgImageSupport);
CPPUNIT_TEST_SUITE_END();
};
@ -2214,6 +2216,41 @@ void Test::testDateFormFieldCharacterFormatting()
}
}
void Test::testSvgImageSupport()
{
OUString aFilterNames[] = {
"writer8",
"Office Open XML Text",
};
for (OUString const & rFilterName : aFilterNames)
{
// Check whether the export code swaps in the image which was swapped out before by auto mechanism
createSwDoc("SvgImageTest.odt");
// Export the document and import again for a check
saveAndReload(rFilterName);
// Check whether graphic exported well after it was swapped out
const OString sFailedMessage = "Failed on filter: "_ostr + rFilterName.toUtf8();
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 1, getShapes());
// First image
uno::Reference<drawing::XShape> xImage(getShape(1), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xPropertySet(xImage, uno::UNO_QUERY_THROW);
uno::Reference<graphic::XGraphic> xGraphic;
xPropertySet->getPropertyValue("Graphic") >>= xGraphic;
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
Graphic aGraphic(xGraphic);
auto pVectorGraphic = aGraphic.getVectorGraphicData();
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pVectorGraphic);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), VectorGraphicDataType::Svg, pVectorGraphic->getType());
}
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();