diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-07-11 18:26:48 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-07-12 19:35:34 +0200 |
commit | 1ebbe4193f5a7ea928fd4940c2a62bcb773c4a00 (patch) | |
tree | 269ec64df94862fb0d486322af130e56f86a6f08 /filter | |
parent | 32003187445f62fa6f390a09a85949b6d42b55f7 (diff) |
tdf#118232 Allow load and insert of SVGs with no Geometry
Change-Id: Iaf3d6a0423c5f11dda1e623dd730af01dbd6551c
Reviewed-on: https://gerrit.libreoffice.org/57284
Tested-by: Jenkins
Reviewed-by: Armin Le Grand <Armin.Le.Grand@cib.de>
(cherry picked from commit 0613ce41da0b94bc481b94b8141afcf15df8abe7)
Reviewed-on: https://gerrit.libreoffice.org/57350
Diffstat (limited to 'filter')
-rw-r--r-- | filter/Library_svgfilter.mk | 1 | ||||
-rw-r--r-- | filter/source/svg/svgfilter.cxx | 76 |
2 files changed, 63 insertions, 14 deletions
diff --git a/filter/Library_svgfilter.mk b/filter/Library_svgfilter.mk index bdd917a50a0c..21318aa1fd03 100644 --- a/filter/Library_svgfilter.mk +++ b/filter/Library_svgfilter.mk @@ -56,6 +56,7 @@ $(eval $(call gb_Library_use_libraries,svgfilter,\ sax \ salhelper \ comphelper \ + drawinglayer \ basegfx \ cppuhelper \ cppu \ diff --git a/filter/source/svg/svgfilter.cxx b/filter/source/svg/svgfilter.cxx index 9c50869ab593..a5f8ce32b072 100644 --- a/filter/source/svg/svgfilter.cxx +++ b/filter/source/svg/svgfilter.cxx @@ -49,6 +49,9 @@ #include <unotools/streamwrap.hxx> #include <tools/zcodec.hxx> +#include <drawinglayer/primitive2d/baseprimitive2d.hxx> +#include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx> + #include "svgfilter.hxx" #include "svgwriter.hxx" @@ -208,17 +211,59 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto break; } + // tdf#118232 Get the sequence of primitives and check if geometry is completely + // hidden. If so, there is no need to add a SdrObject at all + const VectorGraphicDataPtr& rVectorGraphicData(aGraphic.getVectorGraphicData()); + bool bContainsNoGeometry(false); + + if(bool(rVectorGraphicData) && VectorGraphicDataType::Svg == rVectorGraphicData->getVectorGraphicDataType()) + { + const drawinglayer::primitive2d::Primitive2DContainer aContainer(rVectorGraphicData->getPrimitive2DSequence()); + + if(!aContainer.empty()) + { + bool bAllAreHiddenGeometry(true); + + for(const auto& rCandidate : aContainer) + { + if(rCandidate.is()) + { + // try to cast to BasePrimitive2D implementation + const drawinglayer::primitive2d::BasePrimitive2D* pBasePrimitive( + dynamic_cast< const drawinglayer::primitive2d::BasePrimitive2D* >(rCandidate.get())); + + if(pBasePrimitive && PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D != pBasePrimitive->getPrimitive2DID()) + { + bAllAreHiddenGeometry = false; + break; + } + } + } + + if(bAllAreHiddenGeometry) + { + bContainsNoGeometry = true; + } + } + } + // create a SdrModel-GraphicObject to insert to page SdrPage* pTargetSdrPage(pSvxDrawPage->GetSdrPage()); - std::unique_ptr< SdrGrafObj, SdrObjectFreeOp > aNewSdrGrafObj( - new SdrGrafObj( - pTargetSdrPage->getSdrModelFromSdrPage(), - aGraphic)); + std::unique_ptr< SdrGrafObj, SdrObjectFreeOp > aNewSdrGrafObj; - if(!aNewSdrGrafObj.get()) + // tdf#118232 only add an SdrGrafObj when we have Geometry + if(!bContainsNoGeometry) { - // could not create GraphicObject - break; + aNewSdrGrafObj.reset( + new SdrGrafObj( + pTargetSdrPage->getSdrModelFromSdrPage(), + aGraphic)); + + if(!aNewSdrGrafObj.get()) + { + // could not create GraphicObject + break; + } } // Evtl. adapt the GraphicPrefSize to target-MapMode of target-Model @@ -264,15 +309,18 @@ sal_Bool SAL_CALL SVGFilter::filter( const Sequence< PropertyValue >& rDescripto nAllBorder, nAllBorder); - // set pos/size at SdrGraphicObj - use zero position for + // tdf#118232 set pos/size at SdrGraphicObj - use zero position for // better turn-around results - aNewSdrGrafObj->SetSnapRect( - tools::Rectangle( - Point(0, 0), - aGraphicSize)); + if(!bContainsNoGeometry) + { + aNewSdrGrafObj->SetSnapRect( + tools::Rectangle( + Point(0, 0), + aGraphicSize)); - // insert to page (owner change of SdrGrafObj) - pTargetSdrPage->InsertObject(aNewSdrGrafObj.release()); + // insert to page (owner change of SdrGrafObj) + pTargetSdrPage->InsertObject(aNewSdrGrafObj.release()); + } // done - set positive result now bRet = true; |