include/svx/xmlgrhlp.hxx | 5 +- include/xmloff/xmlexp.hxx | 4 +- offapi/com/sun/star/document/XGraphicStorageHandler.idl | 3 - svx/source/xml/xmlgrhlp.cxx | 28 ++++++++++++---- xmloff/source/core/xmlexp.cxx | 22 ++++++------ xmloff/source/style/ImageStyle.cxx | 3 + 6 files changed, 41 insertions(+), 24 deletions(-)
New commits: commit e48b4275ceee82bd0eb128b2947302b9022e9c89 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Mon Feb 19 21:47:04 2018 +0900 report the saved mimetype when saving graphic + mime from stream When saving we need to determine which mime type to use for the graphic. Return this information back to the caller so the metadata can be written into the file if necessary. Also add function to determine the mime type from the XGraphic by converting it to a stream first (only then we can determine the format that will actually be used and written to the storage file. Change-Id: I796da715e47f29d77dea605a2769a2217ecd6ba5 Reviewed-on: https://gerrit.libreoffice.org/49992 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 0bbdf089d2ac..94cc40d17179 100644 --- a/include/svx/xmlgrhlp.hxx +++ b/include/svx/xmlgrhlp.hxx @@ -95,7 +95,8 @@ private: virtual void SAL_CALL disposing() override; - SVX_DLLPRIVATE OUString implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName); + SVX_DLLPRIVATE OUString implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, + OUString & rOutMimeType, OUString const & rRequestName); public: SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode ); @@ -123,7 +124,7 @@ public: saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override; virtual OUString SAL_CALL - saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) override; + saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString & rOutSavedMimeType, OUString const & rRequestName) override; virtual css::uno::Reference<css::io::XInputStream> SAL_CALL createInputStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override; diff --git a/include/xmloff/xmlexp.hxx b/include/xmloff/xmlexp.hxx index 2d367b433935..cfea8a19a5e9 100644 --- a/include/xmloff/xmlexp.hxx +++ b/include/xmloff/xmlexp.hxx @@ -463,9 +463,9 @@ public: OUString AddEmbeddedGraphicObject( const OUString& rGraphicObjectURL ); - OUString AddEmbeddedXGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestedName = OUString()); + OUString AddEmbeddedXGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType, OUString const & rRequestedName = OUString()); bool AddEmbeddedXGraphicAsBase64(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic); - css::uno::Reference<css::io::XInputStream> GetEmbeddedXGraphicStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic); + bool GetGraphicMimeTypeFromStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType); css::uno::Reference<css::io::XInputStream> GetEmbeddedGraphicObjectStream( const OUString& rGraphicObjectURL); diff --git a/offapi/com/sun/star/document/XGraphicStorageHandler.idl b/offapi/com/sun/star/document/XGraphicStorageHandler.idl index 3c9ae6557efa..309309aefbf2 100644 --- a/offapi/com/sun/star/document/XGraphicStorageHandler.idl +++ b/offapi/com/sun/star/document/XGraphicStorageHandler.idl @@ -19,13 +19,12 @@ module com { module sun { module star { module document { */ 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); - string saveGraphicByName([in] com::sun::star::graphic::XGraphic xGraphic, [in] string aRequestedName); + string saveGraphicByName([in] com::sun::star::graphic::XGraphic xGraphic, [out] string savedMimeType, [in] string aRequestedName); com::sun::star::io::XInputStream createInputStream([in] com::sun::star::graphic::XGraphic xGraphic); }; diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index 08eb4a2c0fa7..ffdf60a21972 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -1052,18 +1052,21 @@ uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicHelper::loadGraphicFromOu return xGraphic; } -OUString SAL_CALL SvXMLGraphicHelper::saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) +OUString SAL_CALL SvXMLGraphicHelper::saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, + OUString & rOutSavedMimeType, OUString const & rRequestName) { - return implSaveGraphic(rxGraphic, rRequestName); + return implSaveGraphic(rxGraphic, rOutSavedMimeType, rRequestName); } OUString SAL_CALL SvXMLGraphicHelper::saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) { OUString aEmpty; - return implSaveGraphic(rxGraphic, aEmpty); + OUString aOutMimeType; + return implSaveGraphic(rxGraphic, aOutMimeType, aEmpty); } -OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) +OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, + OUString & rOutSavedMimeType, OUString const & rRequestName) { Graphic aGraphic(rxGraphic); @@ -1210,6 +1213,7 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X { pStream->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); } + rOutSavedMimeType = aMimeType; bSuccess = (pStream->GetError() == ERRCODE_NONE); } else @@ -1220,9 +1224,14 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X OUString aFormat; if (aGraphic.IsAnimated()) + { aFormat = "gif"; + } else + { aFormat = "png"; + } + rOutSavedMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension(aFormat.toUtf8()); bSuccess = (rFilter.ExportGraphic(aGraphic, "", *pStream, rFilter.GetExportFormatNumberForShortName(aFormat)) == ERRCODE_NONE); } @@ -1230,6 +1239,7 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X { pStream->SetVersion(SOFFICE_FILEFORMAT_8); pStream->SetCompressMode(SvStreamCompressFlags::ZBITMAP); + rOutSavedMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension("svm"); // SJ: first check if this metafile is just a eps file, then we will store the eps instead of svm GDIMetaFile& rMtf(const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile())); @@ -1247,11 +1257,14 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::X pStream->WriteBytes(rLink.GetData(), rLink.GetDataSize()); } else + { rMtf.Write(*pStream); + } bSuccess = (pStream->GetError() == ERRCODE_NONE); } } + if (!bSuccess) return OUString(); @@ -1417,7 +1430,7 @@ protected: saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override; virtual OUString SAL_CALL - saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) override; + saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString & rOutSavedMimeType, OUString const & rRequestName) override; virtual css::uno::Reference<css::io::XInputStream> SAL_CALL createInputStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override; @@ -1490,9 +1503,10 @@ OUString SAL_CALL SvXMLGraphicImportExportHelper::saveGraphic(css::uno::Referenc return m_xGraphicStorageHandler->saveGraphic(rxGraphic); } -OUString SAL_CALL SvXMLGraphicImportExportHelper::saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) +OUString SAL_CALL SvXMLGraphicImportExportHelper::saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, + OUString & rOutSavedMimeType, OUString const & rRequestName) { - return m_xGraphicStorageHandler->saveGraphicByName(rxGraphic, rRequestName); + return m_xGraphicStorageHandler->saveGraphicByName(rxGraphic, rOutSavedMimeType, rRequestName); } uno::Reference<io::XInputStream> SAL_CALL SvXMLGraphicImportExportHelper::createInputStream(uno::Reference<graphic::XGraphic> const & rxGraphic) diff --git a/xmloff/source/core/xmlexp.cxx b/xmloff/source/core/xmlexp.cxx index 4d3533ae4c09..7b3221f5bc3e 100644 --- a/xmloff/source/core/xmlexp.cxx +++ b/xmloff/source/core/xmlexp.cxx @@ -93,6 +93,7 @@ #include <RDFaExportHelper.hxx> #include <comphelper/xmltools.hxx> +#include <comphelper/graphicmimetype.hxx> using namespace ::osl; using namespace ::com::sun::star; @@ -1883,7 +1884,7 @@ OUString SvXMLExport::AddEmbeddedGraphicObject( const OUString& rGraphicObjectUR return sRet; } -OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString const & rRequestedName) +OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType, OUString const & rRequestedName) { OUString sURL; @@ -1900,9 +1901,7 @@ OUString SvXMLExport::AddEmbeddedXGraphic(uno::Reference<graphic::XGraphic> cons if (mxGraphicResolver.is() && xGraphicStorageHandler.is()) { if (!(getExportFlags() & SvXMLExportFlags::EMBEDDED)) - { - sURL = xGraphicStorageHandler->saveGraphicByName(rxGraphic, rRequestedName); - } + sURL = xGraphicStorageHandler->saveGraphicByName(rxGraphic, rOutMimeType, rRequestedName); } } return sURL; @@ -1926,21 +1925,24 @@ Reference< XInputStream > SvXMLExport::GetEmbeddedGraphicObjectStream( const OUS return nullptr; } -uno::Reference<io::XInputStream> SvXMLExport::GetEmbeddedXGraphicStream(uno::Reference<graphic::XGraphic> const & rxGraphic) +bool SvXMLExport::GetGraphicMimeTypeFromStream(uno::Reference<graphic::XGraphic> const & rxGraphic, OUString & rOutMimeType) { - uno::Reference<io::XInputStream> xInputStream; - - if ((getExportFlags() & SvXMLExportFlags::EMBEDDED) && mxGraphicResolver.is()) + if (mxGraphicResolver.is()) { uno::Reference<document::XGraphicStorageHandler> xGraphicStorageHandler(mxGraphicResolver, uno::UNO_QUERY); if (xGraphicStorageHandler.is()) { - xInputStream = xGraphicStorageHandler->createInputStream(rxGraphic); + Reference<XInputStream> xInputStream(xGraphicStorageHandler->createInputStream(rxGraphic)); + if (xInputStream.is()) + { + rOutMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForImageStream(xInputStream); + return true; + } } } - return xInputStream; + return false; } bool SvXMLExport::AddEmbeddedXGraphicAsBase64(uno::Reference<graphic::XGraphic> const & rxGraphic) diff --git a/xmloff/source/style/ImageStyle.cxx b/xmloff/source/style/ImageStyle.cxx index cd8b7fcb4659..5842b659dc11 100644 --- a/xmloff/source/style/ImageStyle.cxx +++ b/xmloff/source/style/ImageStyle.cxx @@ -62,7 +62,8 @@ void XMLImageStyle::exportXML(OUString const & rStrName, uno::Any const & rValue auto xBitmap = rValue.get<uno::Reference<awt::XBitmap>>(); uno::Reference<graphic::XGraphic> xGraphic(xBitmap, uno::UNO_QUERY); - const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic); + OUString aMimeType; + const OUString aStr = rExport.AddEmbeddedXGraphic(xGraphic, aMimeType); // uri if (!aStr.isEmpty()) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits