include/oox/export/drawingml.hxx | 40 +++++++++++++++++++++++++++++++++++++++ oox/source/export/drawingml.cxx | 34 ++++++++++++--------------------- 2 files changed, 53 insertions(+), 21 deletions(-)
New commits: commit 33c2443134cfd2110258d5424645ace9e1db127f Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Apr 11 07:52:38 2023 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Tue Apr 25 06:58:07 2023 +0200 oox: extract image / graphic export into GraphicExport class Change-Id: Ib37aee6c5f664e80d45530dae0de9c172e0773a9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150259 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx index 8fb8d6ba2e52..82deea172ef7 100644 --- a/include/oox/export/drawingml.hxx +++ b/include/oox/export/drawingml.hxx @@ -139,6 +139,30 @@ protected: virtual ~DMLTextExport() {} }; +constexpr const char* getComponentDir(DocumentType eDocumentType) +{ + switch (eDocumentType) + { + case DOCUMENT_DOCX: return "word"; + case DOCUMENT_PPTX: return "ppt"; + case DOCUMENT_XLSX: return "xl"; + } + + return ""; +} + +constexpr const char* getRelationCompPrefix(DocumentType eDocumentType) +{ + switch (eDocumentType) + { + case DOCUMENT_DOCX: return ""; + case DOCUMENT_PPTX: + case DOCUMENT_XLSX: return "../"; + } + + return ""; +} + class OOX_DLLPUBLIC GraphicExportCache { private: @@ -226,6 +250,22 @@ public: } }; +class GraphicExport +{ + sax_fastparser::FSHelperPtr mpFS; + oox::core::XmlFilterBase* mpFilterBase; + DocumentType meDocumentType; + +public: + GraphicExport(sax_fastparser::FSHelperPtr pFS, ::oox::core::XmlFilterBase* pFilterBase, DocumentType eDocumentType) + : mpFS(pFS) + , mpFilterBase(pFilterBase) + , meDocumentType(eDocumentType) + {} + + OUString write(const Graphic& rGraphic, bool bRelPathToMedia); +}; + class OOX_DLLPUBLIC DrawingML { diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 773aa6c4ae0c..97c5210d95f6 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -1467,29 +1467,15 @@ void DrawingML::WriteOutline( const Reference<XPropertySet>& rXPropSet, Referenc const char* DrawingML::GetComponentDir() const { - switch ( meDocumentType ) - { - case DOCUMENT_DOCX: return "word"; - case DOCUMENT_PPTX: return "ppt"; - case DOCUMENT_XLSX: return "xl"; - } - - return "unknown"; + return getComponentDir(meDocumentType); } const char* DrawingML::GetRelationCompPrefix() const { - switch ( meDocumentType ) - { - case DOCUMENT_DOCX: return ""; - case DOCUMENT_PPTX: - case DOCUMENT_XLSX: return "../"; - } - - return "unknown"; + return getRelationCompPrefix(meDocumentType); } -OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) +OUString GraphicExport::write(const Graphic& rGraphic , bool bRelPathToMedia) { GfxLink aLink = rGraphic.GetGfxLink (); BitmapChecksum aChecksum = rGraphic.GetChecksum(); @@ -1586,9 +1572,9 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) } sal_Int32 nImageCount = rGraphicExportCache.nextImageCount(); - Reference<XOutputStream> xOutStream = mpFB->openFragmentStream( + Reference<XOutputStream> xOutStream = mpFilterBase->openFragmentStream( OUStringBuffer() - .appendAscii(GetComponentDir()) + .appendAscii(getComponentDir(meDocumentType)) .append("/media/image" + OUString::number(nImageCount)) .appendAscii(pExtension) .makeStringAndClear(), @@ -1601,7 +1587,7 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) if (bRelPathToMedia) sRelationCompPrefix = "../"; else - sRelationCompPrefix = GetRelationCompPrefix(); + sRelationCompPrefix = getRelationCompPrefix(meDocumentType); sPath = OUStringBuffer() .appendAscii(sRelationCompPrefix.getStr()) .appendAscii(sRelPathToMedia.getStr()) @@ -1612,13 +1598,19 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) rGraphicExportCache.addExportGraphics(aChecksum, sPath); } - sRelId = mpFB->addRelation( mpFS->getOutputStream(), + sRelId = mpFilterBase->addRelation( mpFS->getOutputStream(), oox::getRelationship(Relationship::IMAGE), sPath ); return sRelId; } +OUString DrawingML::WriteImage( const Graphic& rGraphic , bool bRelPathToMedia ) +{ + GraphicExport exporter(mpFS, mpFB, meDocumentType); + return exporter.write(rGraphic, bRelPathToMedia); +} + void DrawingML::WriteMediaNonVisualProperties(const css::uno::Reference<css::drawing::XShape>& xShape) { SdrMediaObj* pMediaObj = dynamic_cast<SdrMediaObj*>(SdrObject::getSdrObjectFromXShape(xShape));