From e48b4275ceee82bd0eb128b2947302b9022e9c89 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Mon, 19 Feb 2018 21:47:04 +0900 Subject: report the saved mimetype when saving graphic + mime from stream MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Tomaž Vajngerl --- svx/source/xml/xmlgrhlp.cxx | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'svx') 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 SAL_CALL SvXMLGraphicHelper::loadGraphicFromOu return xGraphic; } -OUString SAL_CALL SvXMLGraphicHelper::saveGraphicByName(css::uno::Reference const & rxGraphic, OUString const & rRequestName) +OUString SAL_CALL SvXMLGraphicHelper::saveGraphicByName(css::uno::Reference const & rxGraphic, + OUString & rOutSavedMimeType, OUString const & rRequestName) { - return implSaveGraphic(rxGraphic, rRequestName); + return implSaveGraphic(rxGraphic, rOutSavedMimeType, rRequestName); } OUString SAL_CALL SvXMLGraphicHelper::saveGraphic(css::uno::Reference const & rxGraphic) { OUString aEmpty; - return implSaveGraphic(rxGraphic, aEmpty); + OUString aOutMimeType; + return implSaveGraphic(rxGraphic, aOutMimeType, aEmpty); } -OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference const & rxGraphic, OUString const & rRequestName) +OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference const & rxGraphic, + OUString & rOutSavedMimeType, OUString const & rRequestName) { Graphic aGraphic(rxGraphic); @@ -1210,6 +1213,7 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::ReferenceWriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); } + rOutSavedMimeType = aMimeType; bSuccess = (pStream->GetError() == ERRCODE_NONE); } else @@ -1220,9 +1224,14 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::ReferenceSetVersion(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(aGraphic.GetGDIMetaFile())); @@ -1247,11 +1257,14 @@ OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::ReferenceWriteBytes(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 const & rxGraphic) override; virtual OUString SAL_CALL - saveGraphicByName(css::uno::Reference const & rxGraphic, OUString const & rRequestName) override; + saveGraphicByName(css::uno::Reference const & rxGraphic, OUString & rOutSavedMimeType, OUString const & rRequestName) override; virtual css::uno::Reference SAL_CALL createInputStream(css::uno::Reference 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 const & rxGraphic, OUString const & rRequestName) +OUString SAL_CALL SvXMLGraphicImportExportHelper::saveGraphicByName(css::uno::Reference const & rxGraphic, + OUString & rOutSavedMimeType, OUString const & rRequestName) { - return m_xGraphicStorageHandler->saveGraphicByName(rxGraphic, rRequestName); + return m_xGraphicStorageHandler->saveGraphicByName(rxGraphic, rOutSavedMimeType, rRequestName); } uno::Reference SAL_CALL SvXMLGraphicImportExportHelper::createInputStream(uno::Reference const & rxGraphic) -- cgit