diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2018-02-08 05:13:49 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2018-02-11 07:34:53 +0100 |
commit | d4a44dc4cd5b4a1679a5325bc202dc9ca39d75c5 (patch) | |
tree | f603ba2b15ef0fb2668668bc05659d1d740b1d56 /svx/source/xml | |
parent | 2a6997ddd7b48a2e53f6e53b81de8eccd5e5083b (diff) |
extend XGraphicStorageHandler with saveGraphicByName
We want to save the graphic with a specific name, usually this is
when we want to use the same name that was used when reading the
image from the document.
Change-Id: I7419f0593dea333a60ce513190211e0409480e66
Reviewed-on: https://gerrit.libreoffice.org/49553
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx/source/xml')
-rw-r--r-- | svx/source/xml/xmlgrhlp.cxx | 42 |
1 files changed, 36 insertions, 6 deletions
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx index 296bd3f9a57e..e109defbefbe 100644 --- a/svx/source/xml/xmlgrhlp.cxx +++ b/svx/source/xml/xmlgrhlp.cxx @@ -695,10 +695,12 @@ bool SvXMLGraphicHelper::ImplWriteGraphic( const OUString& rPictureStorageName, // higher PDF version, while aGfxLink still contains the // original data provided by the user. pStream->WriteBytes(rPdfData.getConstArray(), rPdfData.getLength()); - bRet = (pStream->GetError() == ERRCODE_NONE); } else + { pStream->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); + } + bRet = (pStream->GetError() == ERRCODE_NONE); } else { @@ -991,7 +993,7 @@ OUString SAL_CALL SvXMLGraphicHelper::resolveGraphicObjectURL( const OUString& r } // XGraphicStorageHandler -uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicHelper::loadGraphic(const OUString& rURL) +uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicHelper::loadGraphic(OUString const & rURL) { osl::MutexGuard aGuard(maMutex); @@ -1023,8 +1025,19 @@ uno::Reference<graphic::XGraphic> SAL_CALL SvXMLGraphicHelper::loadGraphic(const return xGraphic; } +OUString SAL_CALL SvXMLGraphicHelper::saveGraphicByName(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) +{ + return implSaveGraphic(rxGraphic, rRequestName); +} + OUString SAL_CALL SvXMLGraphicHelper::saveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) { + OUString aEmpty; + return implSaveGraphic(rxGraphic, aEmpty); +} + +OUString SvXMLGraphicHelper::implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName) +{ Graphic aGraphic(rxGraphic); auto aIterator = maExportGraphics.find(aGraphic); @@ -1037,8 +1050,6 @@ OUString SAL_CALL SvXMLGraphicHelper::saveGraphic(css::uno::Reference<css::graph if (aGraphicObject.GetType() != GraphicType::NONE) { - OUString sId = OStringToOUString(aGraphicObject.GetUniqueID(), RTL_TEXTENCODING_ASCII_US); - const GfxLink aGfxLink(aGraphic.GetLink()); OUString aExtension; bool bUseGfxLink = true; @@ -1101,7 +1112,16 @@ OUString SAL_CALL SvXMLGraphicHelper::saveGraphic(css::uno::Reference<css::graph } } - OUString rPictureStreamName = sId + aExtension; + OUString rPictureStreamName; + if (!rRequestName.isEmpty()) + { + rPictureStreamName = rRequestName + aExtension; + } + else + { + OUString sId = OStringToOUString(aGraphicObject.GetUniqueID(), RTL_TEXTENCODING_ASCII_US); + rPictureStreamName = sId + aExtension; + } SvxGraphicHelperStream_Impl aStream(ImplGetGraphicStream(XML_GRAPHICSTORAGE_NAME, rPictureStreamName)); @@ -1158,10 +1178,12 @@ OUString SAL_CALL SvXMLGraphicHelper::saveGraphic(css::uno::Reference<css::graph // higher PDF version, while aGfxLink still contains the // original data provided by the user. pStream->WriteBytes(rPdfData.getConstArray(), rPdfData.getLength()); - bSuccess = (pStream->GetError() == ERRCODE_NONE); } else + { pStream->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize()); + } + bSuccess = (pStream->GetError() == ERRCODE_NONE); } else { @@ -1364,6 +1386,9 @@ protected: virtual OUString SAL_CALL 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; + virtual css::uno::Reference<css::io::XInputStream> SAL_CALL createInputStream(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic) override; @@ -1430,6 +1455,11 @@ 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) +{ + return m_xGraphicStorageHandler->saveGraphicByName(rxGraphic, rRequestName); +} + uno::Reference<io::XInputStream> SAL_CALL SvXMLGraphicImportExportHelper::createInputStream(uno::Reference<graphic::XGraphic> const & rxGraphic) { return m_xGraphicStorageHandler->createInputStream(rxGraphic); |