Kaydet (Commit) d4a44dc4 authored tarafından Tomaž Vajngerl's avatar Tomaž Vajngerl Kaydeden (comit) Tomaž Vajngerl

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/49553Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
Tested-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst 2a6997dd
......@@ -48,6 +48,7 @@ class SVX_DLLPUBLIC SvXMLGraphicHelper final : public cppu::WeakComponentImplHel
css::document::XGraphicStorageHandler,
css::document::XBinaryStreamResolver>
{
private:
typedef ::std::pair< OUString, OUString > URLPair;
typedef ::std::vector< URLPair > URLPairVector;
typedef ::std::vector< GraphicObject > GraphicObjectVector;
......@@ -94,6 +95,8 @@ class SVX_DLLPUBLIC SvXMLGraphicHelper final : public cppu::WeakComponentImplHel
virtual void SAL_CALL disposing() override;
SVX_DLLPRIVATE OUString implSaveGraphic(css::uno::Reference<css::graphic::XGraphic> const & rxGraphic, OUString const & rRequestName);
public:
SvXMLGraphicHelper( SvXMLGraphicHelperMode eCreateMode );
......@@ -111,11 +114,14 @@ public:
// XGraphicStorageHandler
virtual css::uno::Reference<css::graphic::XGraphic> SAL_CALL
loadGraphic(const OUString& aURL) override;
loadGraphic(OUString const & aURL) override;
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;
......
......@@ -15,15 +15,17 @@
module com { module sun { module star { module document {
/** used to load, save and serialize XGraphic objects
/** used to load, save and serialize XGraphic objects to the document storage
*/
interface XGraphicStorageHandler : com::sun::star::uno::XInterface
{
com::sun::star::graphic::XGraphic loadGraphic([in] string aURL);
string saveGraphic([in] com::sun::star::graphic::XGraphic xGraphic);
string saveGraphicByName([in] com::sun::star::graphic::XGraphic xGraphic, [in] string aRequestedName);
com::sun::star::io::XInputStream createInputStream([in] com::sun::star::graphic::XGraphic xGraphic);
};
......
......@@ -695,11 +695,13 @@ 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
{
if( aGraphic.GetType() == GraphicType::Bitmap )
......@@ -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,7 +1025,18 @@ 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);
......@@ -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,11 +1178,13 @@ 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
{
if (aGraphic.GetType() == GraphicType::Bitmap)
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment