25#include <com/sun/star/drawing/XDrawPage.hpp>
26#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
27#include <com/sun/star/drawing/XDrawView.hpp>
28#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
29#include <com/sun/star/drawing/XMasterPageTarget.hpp>
30#include <com/sun/star/frame/Desktop.hpp>
31#include <com/sun/star/frame/XController.hpp>
32#include <com/sun/star/io/IOException.hpp>
33#include <com/sun/star/view/XSelectionSupplier.hpp>
34#include <com/sun/star/drawing/framework/XControllerManager.hpp>
35#include <com/sun/star/drawing/framework/XConfigurationController.hpp>
36#include <com/sun/star/drawing/framework/XConfiguration.hpp>
37#include <com/sun/star/drawing/framework/AnchorBindingMode.hpp>
38#include <com/sun/star/drawing/framework/XResourceId.hpp>
39#include <com/sun/star/drawing/framework/XResource.hpp>
67 constexpr OUStringLiteral constFilterNameDraw =
u"svg_Scalable_Vector_Graphics_Draw";
68 constexpr OUStringLiteral constFilterName =
u"svg_Scalable_Vector_Graphics";
74 mpSVGFontExport( nullptr ),
75 mpSVGWriter( nullptr ),
76 mbSinglePage( false ),
79 mbExportShapeSelection(false),
81 mbShouldCompress(false),
82 mbWriterFilter(false),
84 mbImpressFilter(false),
85 mpDefaultSdrPage( nullptr ),
86 mbPresentation( false )
112 for (
const PropertyValue& rProp : rDescriptor)
114 if (rProp.Name ==
"IsPreview")
121 for (
const PropertyValue& rProp : rDescriptor)
123 if (rProp.Name ==
"FilterName")
125 OUString sFilterName;
126 rProp.Value >>= sFilterName;
127 if(sFilterName ==
"impress_svg_Export")
132 else if(sFilterName ==
"writer_svg_Export")
137 else if(sFilterName ==
"calc_svg_Export")
142 else if(sFilterName ==
"draw_svgz_Export")
170 uno::Reference<io::XInputStream> xInputStream;
174 if(!xInputStream.is())
181 uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier(
mxDstDoc, uno::UNO_QUERY );
183 if(!xDrawPagesSupplier.is())
190 uno::Reference< drawing::XDrawPages > xDrawPages = xDrawPagesSupplier->getDrawPages();
199 sal_Int32 nDrawPageCount(xDrawPages->getCount());
201 if(0 == nDrawPageCount)
208 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex(0), uno::UNO_QUERY );
217 SvxDrawPage* pSvxDrawPage(comphelper::getFromUnoTunnel<SvxDrawPage>(xDrawPage));
219 if(
nullptr == pSvxDrawPage ||
nullptr == pSvxDrawPage->
GetSdrPage())
239 const ErrCode nGraphicFilterErrorCode(
252 if(0 == aGraphicPrefSize.
Width() || 0 == aGraphicPrefSize.
Height())
266 bool bContainsNoGeometry(
false);
268 if(
bool(rVectorGraphicData) && VectorGraphicDataType::Svg == rVectorGraphicData->getType())
272 if(!aContainer.empty())
274 bool bAllAreHiddenGeometry(
true);
276 for(
const auto& rCandidate : aContainer)
280 bAllAreHiddenGeometry =
false;
285 if(bAllAreHiddenGeometry)
287 bContainsNoGeometry =
true;
297 if(!bContainsNoGeometry)
310 Size aGraphicSize(aGraphicPrefSize);
312 if (eDestUnit != eSrcUnit)
325 const double fBorderRelation((
341 aGraphicSize.
Width(),
350 if(!bContainsNoGeometry)
352 aNewSdrGrafObj->SetSnapRect(
371 bool bSelectionOnly =
false;
372 bool bGotSelection =
false;
376 sal_Int32 nPageToExport = -1;
378 for(
const PropertyValue& rProp : rDescriptor )
380 if (rProp.Name ==
"SelectionOnly")
383 rProp.Value >>= bSelectionOnly;
384 bPageProvided =
false;
386 else if (rProp.Name ==
"PagePos")
388 rProp.Value >>= nPageToExport;
389 bPageProvided =
true;
393 uno::Reference<frame::XDesktop2> xDesktop(frame::Desktop::create(
mxContext));
395 if (xDesktop->getCurrentFrame().is() && !bPageProvided)
397 uno::Reference<frame::XFrame>
xFrame(xDesktop->getCurrentFrame(), uno::UNO_SET_THROW);
399 uno::Reference<drawing::XDrawView> xDrawView(
xController, uno::UNO_QUERY_THROW);
400 uno::Reference<drawing::framework::XControllerManager> xManager(
xController, uno::UNO_QUERY_THROW);
401 uno::Reference<drawing::framework::XConfigurationController> xConfigController(xManager->getConfigurationController());
408 const uno::Sequence<uno::Reference<drawing::framework::XResourceId> > aResIds(
409 xConfigController->getCurrentConfiguration()->getResources(
410 uno::Reference<drawing::framework::XResourceId>(),
412 drawing::framework::AnchorBindingMode_INDIRECT));
414 for(
const uno::Reference<drawing::framework::XResourceId>& rResId : aResIds )
417 if( rResId->getResourceURL() ==
"private:resource/view/SlideSorter" )
420 uno::Reference<drawing::framework::XResource> xRes(
421 xConfigController->getResource(rResId));
423 uno::Reference< view::XSelectionSupplier > xSelectionSupplier(
426 if( xSelectionSupplier.is() )
428 uno::Any aSelection = xSelectionSupplier->getSelection();
431 Sequence< Reference< XInterface > > aSelectedPageSequence;
432 aSelection >>= aSelectedPageSequence;
436 uno::Reference< drawing::XDrawPage > xDrawPage( aSelectedPageSequence[j],
461 uno::Reference< drawing::XMasterPagesSupplier > xMasterPagesSupplier(
mxSrcDoc, uno::UNO_QUERY );
462 uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier(
mxSrcDoc, uno::UNO_QUERY );
464 if( xMasterPagesSupplier.is() && xDrawPagesSupplier.is() )
466 uno::Reference< drawing::XDrawPages > xMasterPages = xMasterPagesSupplier->getMasterPages();
467 uno::Reference< drawing::XDrawPages > xDrawPages = xDrawPagesSupplier->getDrawPages();
468 if( xMasterPages.is() && xMasterPages->getCount() &&
469 xDrawPages.is() && xDrawPages->getCount() )
471 sal_Int32 nDPCount = xDrawPages->getCount();
475 for(
i = 0;
i < nDPCount; ++
i )
477 if( nPageToExport != -1 && nPageToExport ==
i )
479 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex(
i ), uno::UNO_QUERY );
484 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex(
i ), uno::UNO_QUERY );
496 Reference< view::XSelectionSupplier > xSelection (
xController, UNO_QUERY);
519 for(
const uno::Reference<drawing::XDrawPage> & mSelectedPage :
mSelectedPages)
521 uno::Reference< drawing::XMasterPageTarget > xMasterPageTarget( mSelectedPage, uno::UNO_QUERY );
522 if( xMasterPageTarget.is() )
524 aMasterPageTargetSet.insert( xMasterPageTarget->getMasterPage() );
530 for (
auto const& masterPageTarget : aMasterPageTargetSet)
532 uno::Reference< drawing::XDrawPage > xMasterPage( masterPageTarget, uno::UNO_QUERY );
550 bool bSelectionOnly =
false;
552 for (
const PropertyValue& rProp : rDescriptor)
554 if (rProp.Name ==
"SelectionOnly")
556 rProp.Value >>= bSelectionOnly;
564 uno::Reference<frame::XDesktop2> xDesktop(frame::Desktop::create(
mxContext));
566 if (xDesktop->getCurrentFrame().is())
568 uno::Reference<frame::XFrame>
xFrame(xDesktop->getCurrentFrame(), uno::UNO_SET_THROW);
572 Reference< view::XSelectionSupplier > xSelection (
xController, UNO_QUERY);
573 if (!xSelection.is())
577 uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier(
mxSrcDoc, uno::UNO_QUERY );
578 uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
579 uno::Reference< drawing::XDrawPage > xDrawPage( xDrawPages->getByIndex(0), uno::UNO_QUERY );
622 const uno::Reference<io::XInputStream>& mxInput;
623 uno::Sequence< sal_Int8 > mnFirstBytes;
624 sal_Int32 mnFirstBytesSize;
625 sal_Int32 mnFirstRead;
629 bool impCheckForMagic(
631 const sal_Int32 nMagicSize)
633 const sal_Int8* pBuffer(mnFirstBytes.getConstArray());
636 pBuffer + mnFirstRead,
638 pMagic + nMagicSize) != pBuffer + mnFirstRead;
641 void impEnsureProcessed()
655 if(0 == mnFirstBytesSize)
660 mnFirstBytes.realloc(mnFirstBytesSize);
662 if(mnFirstBytesSize != mnFirstBytes.getLength())
674 const sal_uInt64 nStreamLen(aStream->remainingSize());
676 if(aStream->GetError())
681 mnFirstRead = aStream->ReadBytes(
682 &mnFirstBytes.getArray()[0],
683 std::min(nStreamLen,
static_cast<sal_uInt64
>(mnFirstBytesSize)));
685 if(aStream->GetError())
691 if (mnFirstBytes[0] == 0x1F &&
static_cast<sal_uInt8>(mnFirstBytes[1]) == 0x8B)
696 mnFirstRead = aCodec.
Read(
698 reinterpret_cast< sal_uInt8*
>(mnFirstBytes.getArray()),
708 const sal_Int8 aMagic[] = {
'<',
's',
'v',
'g'};
711 mbIsSVG = impCheckForMagic(aMagic, nMagicSize);
716 const sal_Int8 aMagic[] = {
'D',
'O',
'C',
'T',
'Y',
'P',
'E',
' ',
's',
'v',
'g'};
719 mbIsSVG = impCheckForMagic(aMagic, nMagicSize);
727 const uno::Reference<io::XInputStream>& xInput)
729 mnFirstBytesSize(2048),
742 mnFirstBytesSize = std::min(sal_Int32(512), mnFirstBytesSize);
743 mnFirstBytesSize = std::max(sal_Int32(16384), mnFirstBytesSize);
748 impEnsureProcessed();
755 impEnsureProcessed();
760 const sal_Int8 aMagic[] = {
'x',
'm',
'l',
'n',
's',
':',
'o',
'o',
'o'};
763 return impCheckForMagic(aMagic, nMagicSize);
771 impEnsureProcessed();
776 const sal_Int8 aMagic[] = {
'o',
'o',
'o',
':',
'm',
'e',
't',
'a',
'_',
's',
'l',
'i',
'd',
'e',
's'};
779 return impCheckForMagic(aMagic, nMagicSize);
801 SVGFileInfo aSVGFileInfo(xInput);
803 if(aSVGFileInfo.isSVG())
806 aRetval = OUString(constFilterNameDraw);
808 if(aSVGFileInfo.isOwnFormat())
811 if(aSVGFileInfo.isImpress())
815 aRetval = OUString(constFilterName);
820 catch (css::io::IOException &)
835 return "com.sun.star.comp.Draw.SVGFilter";
839 return {
"com.sun.star.document.ImportFilter",
840 "com.sun.star.document.ExportFilter",
841 "com.sun.star.document.ExtendedTypeDetection" };
845extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
847 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any>
const&)
849 return cppu::acquire(
new SVGFilter(context));
constexpr OUStringLiteral sServiceName
static vcl::Window * GetFocusWindow()
ErrCode ImportGraphic(Graphic &rGraphic, const INetURLObject &rPath, sal_uInt16 nFormat=GRFILTER_FORMAT_DONTKNOW, sal_uInt16 *pDeterminedFormat=nullptr, GraphicFilterImportFlags nImportFlags=GraphicFilterImportFlags::NONE)
MapMode GetPrefMapMode() const
const std::shared_ptr< VectorGraphicData > & getVectorGraphicData() const
MapUnit GetMapUnit() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
bool filterImpressOrDraw(const Sequence< PropertyValue > &rDescriptor)
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
SVGFontExport * mpSVGFontExport
bool filterWriterOrCalc(const Sequence< PropertyValue > &rDescriptor)
virtual void SAL_CALL cancel() override
SVGActionWriter * mpSVGWriter
std::vector< Reference< css::drawing::XDrawPage > > mMasterPageTargets
virtual void SAL_CALL setTargetDocument(const Reference< XComponent > &xDoc) override
SVGFilter(const Reference< XComponentContext > &rxCtx)
bool implExport(const Sequence< PropertyValue > &rDescriptor)
virtual void SAL_CALL setSourceDocument(const Reference< XComponent > &xDoc) override
SvXMLElementExport * mpSVGDoc
virtual ~SVGFilter() override
bool implExportWriterTextGraphic(const Reference< view::XSelectionSupplier > &xSelectionSupplier)
virtual OUString SAL_CALL detect(Sequence< PropertyValue > &io_rDescriptor) override
virtual OUString SAL_CALL getImplementationName() override
Reference< XComponentContext > mxContext
Generally use members.
rtl::Reference< SVGExport > mpSVGExport
virtual sal_Bool SAL_CALL filter(const Sequence< PropertyValue > &rDescriptor) override
std::unordered_set< Reference< XInterface > > ObjectSet
std::vector< Reference< css::drawing::XDrawPage > > mSelectedPages
Reference< XComponent > mxSrcDoc
Reference< XComponent > mxDstDoc
Reference< css::drawing::XShapes > maShapeSelection
virtual sal_Bool SAL_CALL supportsService(const OUString &sServiceName) override
virtual void adaptSizeAndBorderForAllPages(const Size &rNewSize, tools::Long nLeft=0, tools::Long nRight=0, tools::Long nUpper=0, tools::Long nLower=0)
const SfxItemPool & GetItemPool() const
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
sal_Int32 GetUpperBorder() const
sal_Int32 GetRightBorder() const
sal_Int32 GetLeftBorder() const
SdrModel & getSdrModelFromSdrPage() const
sal_Int32 GetLowerBorder() const
virtual MapUnit GetMetric(sal_uInt16 nWhich) const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
SdrPage * GetSdrPage() const
tools::Long Read(SvStream &rIStm, sal_uInt8 *pData, sal_uInt32 nSize)
tools::Long EndCompression()
void BeginCompression(int nCompressLevel=ZCODEC_DEFAULT_COMPRESSION, bool gzLib=false)
static std::unique_ptr< SvStream > CreateStream(const OUString &rFileName, StreamMode eOpenMode, css::uno::Reference< css::awt::XWindow > xParentWin=nullptr)
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define PRIMITIVE2D_ID_HIDDENGEOMETRYPRIMITIVE2D
#define SAL_N_ELEMENTS(arr)
B2IRange fround(const B2DRange &rRange)
Shape IDs per cluster in DGG atom.
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Reference< XController > xController
Reference< XFrame > xFrame
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * filter_SVGFilter_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)