include/svx/xmlgrhlp.hxx | 3 offapi/com/sun/star/document/XGraphicStorageHandler.idl | 1 svx/source/xml/xmlgrhlp.cxx | 59 ++++++++++++---- 3 files changed, 51 insertions(+), 12 deletions(-)
New commits: commit 94dbc40e739267d5567257fcd88af445e07e955c Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Sun Feb 11 12:25:21 2018 +0900 XGraphicStorageHandler: support loading graphic from stream Needed for all the loading of images from base64 strings.. Change-Id: Ic1cb262b5d064e91690b0dc3bb3ab0e9ca0cda53 Reviewed-on: https://gerrit.libreoffice.org/49556 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/xmlgrhlp.hxx b/include/svx/xmlgrhlp.hxx index a9eca5495a20..0bbdf089d2ac 100644 --- a/include/svx/xmlgrhlp.hxx +++ b/include/svx/xmlgrhlp.hxx @@ -116,6 +116,9 @@ public: virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL loadGraphic(OUString const & aURL) override; + virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL + loadGraphicFromOutputStream(css::uno::Reference<css::io::XOutputStream> const & rxOutputStream) override; + virtual OUString SAL_CALL saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override; diff --git a/offapi/com/sun/star/document/XGraphicStorageHandler.idl b/offapi/com/sun/star/document/XGraphicStorageHandler.idl index b0c9ee2efa26..3c9ae6557efa 100644 --- a/offapi/com/sun/star/document/XGraphicStorageHandler.idl +++ b/offapi/com/sun/star/document/XGraphicStorageHandler.idl @@ -21,6 +21,7 @@ interface XGraphicStorageHandler : com::sun::star::uno::XInterface { com::sun::star::graphic::XGraphic loadGraphic([in] string aURL); + com::sun::star::graphic::XGraphic loadGraphicFromOutputStream([in] com::sun::star::io::XOutputStream xOutputStream); string saveGraphic([in] com::sun::star::graphic::XGraphic xGraphic); diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index e109defbefbe..08eb4a2c0fa7 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -373,6 +373,7 @@ public: bool Exists() const { return mxStmWrapper.is(); } const GraphicObject& GetGraphicObject(); + Graphic GetGraphic(); }; SvXMLGraphicOutputStream::SvXMLGraphicOutputStream() @@ -421,16 +422,16 @@ void SAL_CALL SvXMLGraphicOutputStream::closeOutput() mbClosed = true; } -const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject() +Graphic SvXMLGraphicOutputStream::GetGraphic() { + Graphic aGraphic; + if (mbClosed && mxGrfObj->GetType() == GraphicType::NONE && mpOStm) { - Graphic aGraphic; - mpOStm->Seek( 0 ); sal_uInt16 nFormat = GRFILTER_FORMAT_DONTKNOW; sal_uInt16 nDeterminedFormat = GRFILTER_FORMAT_DONTKNOW; - GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, "", *mpOStm ,nFormat,&nDeterminedFormat ); + GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, "", *mpOStm ,nFormat, &nDeterminedFormat ); if (nDeterminedFormat == GRFILTER_FORMAT_DONTKNOW) { @@ -479,17 +480,25 @@ const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject() } } } + } - mxGrfObj.reset(new GraphicObject(aGraphic)); - if (mxGrfObj->GetType() != GraphicType::NONE) - { - delete mpOStm; - mpOStm = nullptr; - delete mpTmp; - mpTmp = nullptr; - } + if (aGraphic.GetType() != GraphicType::NONE) + { + delete mpOStm; + mpOStm = nullptr; + delete mpTmp; + mpTmp = nullptr; } + return aGraphic; +} +const GraphicObject& SvXMLGraphicOutputStream::GetGraphicObject() +{ + Graphic aGraphic(GetGraphic()); + if (aGraphic.GetType() != GraphicType::NONE) + { + mxGrfObj.reset(new GraphicObject(aGraphic)); + } return *mxGrfObj; } @@ -1025,6 +1034,24 @@ uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicHelper::loadGraphic(OUStr return xGraphic; } +uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicHelper::loadGraphicFromOutputStream(uno::Reference<io::XOutputStream> const & rxOutputStream) +{ + osl::MutexGuard aGuard(maMutex); + + uno::Reference<graphic::XGraphic> xGraphic; + + if ((SvXMLGraphicHelperMode::Read == meCreateMode) && rxOutputStream.is()) + { + + SvXMLGraphicOutputStream* pGraphicOutputStream = static_cast<SvXMLGraphicOutputStream*>(rxOutputStream.get()); + if (pGraphicOutputStream) + { + xGraphic = pGraphicOutputStream->GetGraphic().GetXGraphic(); + } + } + return xGraphic; +} + OUString SAL_CALL SvXMLGraphicHelper::saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) { return implSaveGraphic(rxGraphic, rRequestName); @@ -1383,6 +1410,9 @@ protected: virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL loadGraphic(const OUString& aURL) override; + virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL + loadGraphicFromOutputStream(css::uno::Reference<css::io::XOutputStream> const & rxOutputStream) override; + virtual OUString SAL_CALL saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override; @@ -1450,6 +1480,11 @@ uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicImportExportHelper::loadG return m_xGraphicStorageHandler->loadGraphic(rURL); } +uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicImportExportHelper::loadGraphicFromOutputStream(uno::Reference<io::XOutputStream> const & rxOutputStream) +{ + return m_xGraphicStorageHandler->loadGraphicFromOutputStream(rxOutputStream); +} + OUString SAL_CALL SvXMLGraphicImportExportHelper::saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) { return m_xGraphicStorageHandler->saveGraphic(rxGraphic); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits