summaryrefslogtreecommitdiff
path: root/svx/source
diff options
context:
space:
mode:
authorKatarina Behrens <Katarina.Behrens@cib.de>2017-09-04 14:14:39 +0200
committerSamuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>2017-11-29 10:54:38 +0100
commit65066627c26059caedbf239cb41b97c1721334a0 (patch)
tree57d73783d316565575d62e167fe7cf3f1a94f0a0 /svx/source
parentf0a2fee5006f27b8ebf2b2e583964818986caec5 (diff)
tdf#109202: Convert images to desired format in (f)odt filter
Pass down mimetype to SvXMLGraphicHelper Change-Id: I9c81c06d2a1d6168704440094081e99d0bcbbff9 Reviewed-on: https://gerrit.libreoffice.org/41893 Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> (cherry picked from commit 082cdbc991a2e31556bab53a5b8214cb89138354) Reviewed-on: https://gerrit.libreoffice.org/45401 Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'svx/source')
-rw-r--r--svx/source/xml/xmlgrhlp.cxx83
1 files changed, 38 insertions, 45 deletions
diff --git a/svx/source/xml/xmlgrhlp.cxx b/svx/source/xml/xmlgrhlp.cxx
index bfc7414b5211..ff7e4043d519 100644
--- a/svx/source/xml/xmlgrhlp.cxx
+++ b/svx/source/xml/xmlgrhlp.cxx
@@ -27,6 +27,7 @@
#include <com/sun/star/io/NotConnectedException.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
+#include <comphelper/graphicmimetype.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -89,14 +90,15 @@ private:
public:
- explicit SvXMLGraphicInputStream( const OUString& rGraphicId );
+ explicit SvXMLGraphicInputStream( const OUString& rGraphicId, const OUString& rMimeType );
SvXMLGraphicInputStream(const SvXMLGraphicInputStream&) = delete;
SvXMLGraphicInputStream& operator=(const SvXMLGraphicInputStream&) = delete;
bool Exists() const { return mxStmWrapper.is(); }
};
-SvXMLGraphicInputStream::SvXMLGraphicInputStream( const OUString& rGraphicId )
+
+SvXMLGraphicInputStream::SvXMLGraphicInputStream( const OUString& rGraphicId, const OUString& rMimeType )
{
GraphicObject aGrfObject( OUStringToOString(rGraphicId, RTL_TEXTENCODING_ASCII_US) );
@@ -114,30 +116,43 @@ SvXMLGraphicInputStream::SvXMLGraphicInputStream( const OUString& rGraphicId )
if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
{
- pStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
- bRet = ( pStm->GetError() == ERRCODE_NONE );
+ if ( rMimeType.isEmpty() )
+ {
+ pStm->WriteBytes(aGfxLink.GetData(), aGfxLink.GetDataSize());
+ bRet = ( pStm->GetError() == ERRCODE_NONE );
+ }
+ else
+ {
+ GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
+ bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStm, rFilter.GetExportFormatNumberForMediaType( rMimeType ) ) == ERRCODE_NONE );
+ }
}
else
{
if( aGraphic.GetType() == GraphicType::Bitmap )
{
GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
- OUString aFormat;
+ OUString aFormat=rMimeType;
if( aGraphic.IsAnimated() )
- aFormat = "gif";
- else
- aFormat = "png";
+ aFormat = "image/gif";
+ else if( aFormat.isEmpty() )
+ aFormat = "image/png";
- bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStm, rFilter.GetExportFormatNumberForShortName( aFormat ) ) == ERRCODE_NONE );
+ bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStm, rFilter.GetExportFormatNumberForMediaType( aFormat ) ) == ERRCODE_NONE );
}
- else if( aGraphic.GetType() == GraphicType::GdiMetafile )
+ else if( rMimeType.isEmpty() && aGraphic.GetType() == GraphicType::GdiMetafile )
{
pStm->SetVersion( SOFFICE_FILEFORMAT_8 );
pStm->SetCompressMode( SvStreamCompressFlags::ZBITMAP );
const_cast<GDIMetaFile&>( aGraphic.GetGDIMetaFile() ).Write( *pStm );
bRet = ( pStm->GetError() == ERRCODE_NONE );
}
+ else if( !rMimeType.isEmpty() )
+ {
+ GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter();
+ bRet = ( rFilter.ExportGraphic( aGraphic, "", *pStm, rFilter.GetExportFormatNumberForMediaType( rMimeType ) ) == ERRCODE_NONE );
+ }
}
if( bRet )
@@ -450,40 +465,14 @@ SvxGraphicHelperStream_Impl SvXMLGraphicHelper::ImplGetGraphicStream( const OUSt
OUString SvXMLGraphicHelper::ImplGetGraphicMimeType( const OUString& rFileName )
{
- struct XMLGraphicMimeTypeMapper
- {
- const char* pExt;
- const char* pMimeType;
- };
-
- static const XMLGraphicMimeTypeMapper aMapper[] =
- {
- { "gif", "image/gif" },
- { "png", "image/png" },
- { "jpg", "image/jpeg" },
- { "tif", "image/tiff" },
- { "svg", "image/svg+xml" },
- { "pdf", "application/pdf" },
- { "wmf", "image/x-wmf" },
- { "eps", "image/x-eps" },
- { "bmp", "image/bmp" },
- { "pct", "image/x-pict" }
- };
-
- OUString aMimeType;
-
if( ( rFileName.getLength() >= 4 ) && ( rFileName[ rFileName.getLength() - 4 ] == '.' ) )
{
const OString aExt(OUStringToOString(rFileName.copy(rFileName.getLength() - 3),
RTL_TEXTENCODING_ASCII_US));
-
- long const nCount = SAL_N_ELEMENTS(aMapper);
- for( long i = 0; ( i < nCount ) && aMimeType.isEmpty(); ++i )
- if( aExt == aMapper[ i ].pExt )
- aMimeType = OUString( aMapper[ i ].pMimeType, strlen( aMapper[ i ].pMimeType ), RTL_TEXTENCODING_ASCII_US );
+ return comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension( aExt );
}
- return aMimeType;
+ return OUString();
}
Graphic SvXMLGraphicHelper::ImplReadGraphic( const OUString& rPictureStorageName,
@@ -766,29 +755,32 @@ void SvXMLGraphicHelper::ImplInsertGraphicURL( const OUString& rURLStr, sal_uInt
void SvXMLGraphicHelper::Init( const uno::Reference < embed::XStorage >& rXMLStorage,
SvXMLGraphicHelperMode eCreateMode,
- bool bDirect )
+ bool bDirect,
+ const OUString& rGraphicMimeType )
{
mxRootStorage = rXMLStorage;
meCreateMode = eCreateMode;
+ maOutputMimeType = rGraphicMimeType;
mbDirect = meCreateMode != SvXMLGraphicHelperMode::Read || bDirect;
}
rtl::Reference<SvXMLGraphicHelper> SvXMLGraphicHelper::Create( const uno::Reference < embed::XStorage >& rXMLStorage,
SvXMLGraphicHelperMode eCreateMode,
- bool bDirect )
+ bool bDirect,
+ const OUString& rGraphicMimeType )
{
rtl::Reference<SvXMLGraphicHelper> pThis = new SvXMLGraphicHelper;
-
- pThis->Init( rXMLStorage, eCreateMode, bDirect );
+ pThis->Init( rXMLStorage, eCreateMode, bDirect, rGraphicMimeType );
return pThis;
}
-rtl::Reference<SvXMLGraphicHelper> SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode eCreateMode )
+rtl::Reference<SvXMLGraphicHelper> SvXMLGraphicHelper::Create( SvXMLGraphicHelperMode eCreateMode,
+ const OUString& rGraphicMimeType )
{
rtl::Reference<SvXMLGraphicHelper> pThis = new SvXMLGraphicHelper;
- pThis->Init( nullptr, eCreateMode, false );
+ pThis->Init( nullptr, eCreateMode, false, rGraphicMimeType );
return pThis;
}
@@ -846,7 +838,8 @@ Reference< XInputStream > SAL_CALL SvXMLGraphicHelper::getInputStream( const OUS
if( ( SvXMLGraphicHelperMode::Write == meCreateMode ) &&
ImplGetStreamNames( rURL, aPictureStorageName, aGraphicId ) )
{
- SvXMLGraphicInputStream* pInputStream = new SvXMLGraphicInputStream( aGraphicId );
+ OUString sMimeType = comphelper::GraphicMimeTypeHelper::GetMimeTypeForExtension( OUStringToOString( maOutputMimeType, RTL_TEXTENCODING_ASCII_US ) );
+ SvXMLGraphicInputStream* pInputStream = new SvXMLGraphicInputStream( aGraphicId, sMimeType );
if( pInputStream->Exists() )
xRet = pInputStream;