diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2015-11-23 16:17:37 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2015-11-28 11:31:46 +0000 |
commit | 29dfcc7521311e547fc069466cc3edc9fcbdbe03 (patch) | |
tree | 2c722f313c2cdd16d9af856e6a335ad85a0ef207 /editeng | |
parent | 9e36549c68ecb4d96c56614df5d9f369db95e128 (diff) |
tdf#94088 add import of HTML inline graphics
Related: fdo#63211 for saving. This one adds the import side, plus
fallbacks to use the new FillStyle attributes in HTML im/export in a
SvxBrushItem. Also added graphic import for inline graphics. Comment
markers inserted at places where functionality may be added in the
future when the new FillStyle attributes would be more used in this
content. Unit test checks PageBackground and ParagraphBaground import.
Change-Id: I3f198677db553ad198e0add3162603a4735398f1
Reviewed-on: https://gerrit.libreoffice.org/20129
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Tested-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/items/frmitems.cxx | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/editeng/source/items/frmitems.cxx b/editeng/source/items/frmitems.cxx index 5bb17666b627..10211e45db97 100644 --- a/editeng/source/items/frmitems.cxx +++ b/editeng/source/items/frmitems.cxx @@ -3904,7 +3904,6 @@ void SvxBrushItem::PurgeMedium() const DELETEZ( pImpl->pStream ); } - const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) const { if ( bLoadAgain && !maStrLink.isEmpty() && !pImpl->pGraphicObject ) @@ -3913,26 +3912,53 @@ const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) co if (SvtSecurityOptions().isUntrustedReferer(referer)) { return nullptr; } + + // tdf#94088 prepare graphic and state + Graphic aGraphic; + bool bGraphicLoaded = false; + + // try to create stream directly from given URL pImpl->pStream = utl::UcbStreamHelper::CreateStream( maStrLink, STREAM_STD_READ ); + + // tdf#94088 if we have a stream, try to load it directly as graphic if( pImpl->pStream && !pImpl->pStream->GetError() ) { - Graphic aGraphic; - int nRes; - pImpl->pStream->Seek( STREAM_SEEK_TO_BEGIN ); - nRes = GraphicFilter::GetGraphicFilter(). - ImportGraphic( aGraphic, maStrLink, *pImpl->pStream, - GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::DontSetLogsizeForJpeg ); - - if( nRes != GRFILTER_OK ) + if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic( aGraphic, maStrLink, *pImpl->pStream, + GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::DontSetLogsizeForJpeg )) { - bLoadAgain = false; + bGraphicLoaded = true; } - else + } + + // tdf#94088 if no succeeded, try if the string (which is not epty) contains + // a 'data:' scheme url and try to load that (embedded graphics) + if(!bGraphicLoaded) + { + INetURLObject aGraphicURL( maStrLink ); + + if( INetProtocol::Data == aGraphicURL.GetProtocol() ) { - pImpl->pGraphicObject = new GraphicObject; - pImpl->pGraphicObject->SetGraphic( aGraphic ); - const_cast < SvxBrushItem*> (this)->ApplyGraphicTransparency_Impl(); - } + std::unique_ptr<SvMemoryStream> const pStream(aGraphicURL.getData()); + if (pStream) + { + if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream)) + { + bGraphicLoaded = true; + + // tdf#94088 delete the no longer needed data scheme URL which + // is potentially pretty // large, containing a base64 encoded copy of the graphic + const_cast< SvxBrushItem* >(this)->maStrLink.clear(); + } + } + } + } + + // tdf#94088 when we got a graphic, set it + if(bGraphicLoaded && GRAPHIC_NONE != aGraphic.GetType()) + { + pImpl->pGraphicObject = new GraphicObject; + pImpl->pGraphicObject->SetGraphic( aGraphic ); + const_cast < SvxBrushItem*> (this)->ApplyGraphicTransparency_Impl(); } else { |