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

Make linked graphic register into LinkedManager again

Change-Id: I16b162f86d6221d120f6355f9a52c1abfcd0ac73
Reviewed-on: https://gerrit.libreoffice.org/52911Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTomaž Vajngerl <quikee@gmail.com>
üst ba69036c
......@@ -16,6 +16,9 @@ namespace vcl
{
namespace graphic
{
Graphic VCL_DLLPUBLIC loadFromURL(OUString const& rURL, sal_Int16 nExtWidth, sal_Int16 nExtHeight,
sal_Int16 nExtMapMode);
Graphic VCL_DLLPUBLIC loadFromURL(OUString const& rURL);
}
} // end vcl::graphic
......
......@@ -33,6 +33,7 @@
#include <com/sun/star/uno/Reference.hxx>
#include <vcl/vectorgraphicdata.hxx>
#include <basegfx/vector/b2dsize.hxx>
#include <vcl/GraphicExternalLink.hxx>
enum class GraphicType
......@@ -114,6 +115,7 @@ public:
public:
Graphic();
Graphic( const GraphicExternalLink& rGraphicLink );
Graphic( const Graphic& rGraphic );
Graphic( Graphic&& rGraphic );
Graphic( const Bitmap& rBmp );
......
......@@ -27,6 +27,7 @@
#include <oox/token/tokens.hxx>
#include <sfx2/docfile.hxx>
#include <vcl/GraphicLoader.hxx>
#include <vcl/GraphicExternalLink.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
......@@ -161,7 +162,8 @@ BlipContext::BlipContext( ContextHandler2Helper const & rParent,
// code rework.
OUString aRelId = rAttribs.getString( R_TOKEN( link ), OUString() );
OUString aTargetLink = getFilter().getAbsoluteUrl( getRelations().getExternalTargetFromRelId( aRelId ) );
Graphic aGraphic = vcl::graphic::loadFromURL(aTargetLink);
GraphicExternalLink aLink(aTargetLink);
Graphic aGraphic(aLink);
mrBlipProps.mxFillGraphic = aGraphic.GetXGraphic();
}
}
......
......@@ -76,7 +76,7 @@ SvFileObject::~SvFileObject()
bool SvFileObject::GetData( css::uno::Any & rData,
const OUString & rMimeType,
bool bGetSynchron )
bool /*bGetSynchron*/ )
{
SotClipboardFormatId nFmt = SotExchange::RegisterFormatMimeType( rMimeType );
switch( nType )
......@@ -92,101 +92,11 @@ bool SvFileObject::GetData( css::uno::Any & rData,
break;
case FILETYPE_GRF:
if( !bLoadError )
if (SotClipboardFormatId::GDIMETAFILE == nFmt
|| SotClipboardFormatId::BITMAP == nFmt
|| SotClipboardFormatId::SVXB == nFmt)
{
tools::SvRef<SfxMedium> xTmpMed;
if( SotClipboardFormatId::GDIMETAFILE == nFmt || SotClipboardFormatId::BITMAP == nFmt ||
SotClipboardFormatId::SVXB == nFmt )
{
Graphic aGrf;
// If the native format is requested, has to be reset at the
// end of the flag. Is solely in the sw/ndgrf.cxx used when
// the link is removed form GraphicNode.
bool bOldNativFormat = bNativFormat;
// If about to print, waiting for the data to be available
if( bGetSynchron )
{
// call a LoadFile every second time to test the loading
if( !xMed.is() )
LoadFile_Impl();
if( !bInCallDownload )
{
xTmpMed = xMed;
while( bWaitForData )
Application::Reschedule();
xMed = xTmpMed;
bClearMedium = true;
}
}
if( !bWaitForData && ( xMed.is() || // was loaded as URL
( bSynchron && LoadFile_Impl() && xMed.is() ) ) )
{
// If it was loaded from the Internet, do not retry
if( !bGetSynchron )
bLoadAgain = !xMed->IsRemote();
bLoadError = !GetGraphic_Impl( aGrf, xMed->GetInStream() );
}
else if( !LoadFile_Impl() ||
!GetGraphic_Impl( aGrf, xMed.is() ? xMed->GetInStream() : nullptr ))
{
if( !xMed.is() )
break;
aGrf.SetDefaultType();
}
if( SotClipboardFormatId::SVXB != nFmt )
nFmt = (bLoadError || GraphicType::Bitmap == aGrf.GetType())
? SotClipboardFormatId::BITMAP
: SotClipboardFormatId::GDIMETAFILE;
SvMemoryStream aMemStm( 0, 65535 );
switch ( nFmt )
{
case SotClipboardFormatId::SVXB:
if( GraphicType::NONE != aGrf.GetType() )
{
aMemStm.SetVersion( SOFFICE_FILEFORMAT_50 );
WriteGraphic( aMemStm, aGrf );
}
break;
case SotClipboardFormatId::BITMAP:
{
const Bitmap aBitmap(aGrf.GetBitmap());
if(!aBitmap.IsEmpty())
{
WriteDIB(aBitmap, aMemStm, false, true);
}
break;
}
default:
if( aGrf.GetGDIMetaFile().GetActionSize() )
{
GDIMetaFile aMeta( aGrf.GetGDIMetaFile() );
aMeta.Write( aMemStm );
}
}
rData <<= css::uno::Sequence< sal_Int8 >( static_cast<sal_Int8 const *>(aMemStm.GetData()),
aMemStm.Seek( STREAM_SEEK_TO_END ) );
bNativFormat = bOldNativFormat;
// Everything ready?
if( xMed.is() && !bSynchron && bClearMedium )
{
xMed.clear();
bClearMedium = false;
}
}
rData <<= sFileNm;
}
break;
case FILETYPE_OBJECT:
......
......@@ -40,6 +40,7 @@
#include <sfx2/request.hxx>
#include <vcl/dibtools.hxx>
#include <unotools/charclass.hxx>
#include <vcl/GraphicLoader.hxx>
#include "fileobj.hxx"
#include "impldde.hxx"
......@@ -498,12 +499,26 @@ SotClipboardFormatId LinkManager::RegisterStatusInfoId()
bool LinkManager::GetGraphicFromAny( const OUString& rMimeType,
const css::uno::Any & rValue,
Graphic& rGrf )
Graphic& rGraphic )
{
bool bRet = false;
css::uno::Sequence< sal_Int8 > aSeq;
if( rValue.hasValue() && ( rValue >>= aSeq ) )
if (!rValue.hasValue())
return bRet;
if (rValue.has<OUString>())
{
OUString sURL = rValue.get<OUString>();
rGraphic = vcl::graphic::loadFromURL(sURL);
if (!rGraphic)
rGraphic.SetDefaultType();
rGraphic.setOriginURL(sURL);
return true;
}
else if (rValue.has<css::uno::Sequence<sal_Int8>>())
{
auto aSeq = rValue.get<css::uno::Sequence<sal_Int8>>();
SvMemoryStream aMemStm( const_cast<sal_Int8 *>(aSeq.getConstArray()), aSeq.getLength(),
StreamMode::READ );
aMemStm.Seek( 0 );
......@@ -512,7 +527,7 @@ bool LinkManager::GetGraphicFromAny( const OUString& rMimeType,
{
case SotClipboardFormatId::SVXB:
{
ReadGraphic( aMemStm, rGrf );
ReadGraphic( aMemStm, rGraphic );
bRet = true;
}
break;
......@@ -520,7 +535,7 @@ bool LinkManager::GetGraphicFromAny( const OUString& rMimeType,
{
GDIMetaFile aMtf;
aMtf.Read( aMemStm );
rGrf = aMtf;
rGraphic = aMtf;
bRet = true;
}
break;
......@@ -528,7 +543,7 @@ bool LinkManager::GetGraphicFromAny( const OUString& rMimeType,
{
Bitmap aBmp;
ReadDIB(aBmp, aMemStm, true);
rGrf = aBmp;
rGraphic = aBmp;
bRet = true;
}
break;
......
......@@ -102,6 +102,7 @@ const Graphic ImpLoadLinkedGraphic( const OUString& aFileName, const OUString& a
// that it is a SVG graphic, but only because no one yet tried to interpret it.
rGF.ImportGraphic( aGraphic, aFileName, *pInStrm, nFilter, nullptr, GraphicFilterImportFlags::NONE, &aFilterData );
}
aGraphic.setOriginURL(aFileName);
return aGraphic;
}
......@@ -227,8 +228,7 @@ void SdrGraphicLink::RemoveGraphicUpdater()
Graphic aGraphic;
if( sfx2::LinkManager::GetGraphicFromAny( rMimeType, rValue, aGraphic ))
{
rGrafObj.NbcSetGraphic( aGraphic );
rGrafObj.ActionChanged();
rGrafObj.ImpSetLinkedGraphic(aGraphic);
}
else if( SotExchange::GetFormatIdFromMimeType( rMimeType ) != sfx2::LinkManager::RegisterStatusInfoId() )
{
......@@ -278,7 +278,6 @@ sdr::contact::ViewContact* SdrGrafObj::CreateObjectSpecificViewContact()
return new sdr::contact::ViewContactOfGraphic(*this);
}
// check if SVG and if try to get ObjectInfoPrimitive2D and extract info
void SdrGrafObj::onGraphicChanged()
......@@ -426,7 +425,6 @@ const GraphicObject& SdrGrafObj::GetGraphicObject(bool bForceSwapIn) const
{
if (bForceSwapIn)
ForceSwapIn();
return *mpGraphicObject.get();
}
......@@ -460,15 +458,29 @@ void SdrGrafObj::NbcSetGraphic(const Graphic& rGraphic)
onGraphicChanged();
}
void SdrGrafObj::SetGraphic( const Graphic& rGrf )
void SdrGrafObj::SetGraphic( const Graphic& rGraphic )
{
NbcSetGraphic(rGrf);
if (!rGraphic.getOriginURL().isEmpty())
{
ImpDeregisterLink();
aFileName = rGraphic.getOriginURL();
aReferer = "";
aFilterName = "";
}
NbcSetGraphic(rGraphic);
if (!rGraphic.getOriginURL().isEmpty())
{
ImpRegisterLink();
mpGraphicObject->SetUserData();
}
SetChanged();
BroadcastObjectChange();
ForceSwapIn();
}
const Graphic& SdrGrafObj::GetGraphic() const
{
ForceSwapIn();
return mpGraphicObject->GetGraphic();
}
......@@ -597,9 +609,13 @@ Size SdrGrafObj::getOriginalSize() const
return aSize;
}
// TODO Remove
void SdrGrafObj::ForceSwapIn() const
{
if (pGraphicLink && (mpGraphicObject->GetType() == GraphicType::NONE ||
mpGraphicObject->GetType() == GraphicType::Default) )
{
pGraphicLink->Update();
}
}
void SdrGrafObj::ImpRegisterLink()
......@@ -630,15 +646,11 @@ void SdrGrafObj::ImpDeregisterLink()
}
}
void SdrGrafObj::SetGraphicLink(const OUString& rFileName, const OUString& rReferer, const OUString& rFilterName)
void SdrGrafObj::SetGraphicLink(const OUString& rFileName, const OUString& /*rReferer*/, const OUString& /*rFilterName*/)
{
ImpDeregisterLink();
aFileName = rFileName;
aReferer = rReferer;
aFilterName = rFilterName;
ImpRegisterLink();
mpGraphicObject->SetUserData();
SetGraphic(vcl::graphic::loadFromURL(aFileName));
Graphic aGraphic;
aGraphic.setOriginURL(rFileName);
SetGraphic(aGraphic);
}
void SdrGrafObj::ReleaseGraphicLink()
......@@ -862,6 +874,7 @@ SdrObject* SdrGrafObj::getFullDragClone() const
// temporary interaction object and load graphic
if(pRetval && IsLinkedGraphic())
{
pRetval->ForceSwapIn();
pRetval->ReleaseGraphicLink();
}
......
......@@ -73,11 +73,19 @@ SwGrfNode::SwGrfNode(
mbLinkedInputStreamReady( false ),
mbIsStreamReadOnly( false )
{
OUString sURLLink(pGraphic->getOriginURL());
if (sURLLink.isEmpty() && !rGrfName.isEmpty())
{
sURLLink = rGrfName;
Graphic aGraphic(*pGraphic);
aGraphic.setOriginURL(sURLLink);
}
bInSwapIn = bChgTwipSize =
bFrameInPaint = bScaleImageMap = false;
bGraphicArrived = true;
ReRead(rGrfName, rFltName, pGraphic, nullptr, false);
ReRead(sURLLink, rFltName, pGraphic, nullptr, false);
}
SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere,
......@@ -472,9 +480,52 @@ bool SwGrfNode::ImportGraphic( SvStream& rStrm )
* @return true if ReRead or reading successful,
* false if not loaded
*/
bool SwGrfNode::SwapIn( bool /*bWaitForData*/ )
bool SwGrfNode::SwapIn(bool bWaitForData)
{
return true;
if(bInSwapIn) // not recursively!
return true;
bool bRet = false;
bInSwapIn = true;
SwBaseLink* pLink = static_cast<SwBaseLink*>( refLink.get() );
if( pLink )
{
if( GraphicType::NONE == maGrfObj.GetType() ||
GraphicType::Default == maGrfObj.GetType() )
{
// link was not loaded yet
if( pLink->SwapIn( bWaitForData ) )
{
bRet = true;
}
else if( GraphicType::Default == maGrfObj.GetType() )
{
// no default bitmap anymore, thus re-paint
delete mpReplacementGraphic;
mpReplacementGraphic = nullptr;
maGrfObj.SetGraphic( Graphic() );
onGraphicChanged();
SwMsgPoolItem aMsgHint( RES_GRAPHIC_PIECE_ARRIVED );
ModifyNotification( &aMsgHint, &aMsgHint );
}
}
else
{
bRet = true;
}
}
else
bRet = true;
if (bRet)
{
if( !nGrfSize.Width() && !nGrfSize.Height() )
SetTwipSize( ::GetGraphicSizeTwip( maGrfObj.GetGraphic(), nullptr ) );
}
bInSwapIn = false;
return bRet;
}
bool SwGrfNode::SwapOut()
......
......@@ -265,7 +265,7 @@ ErrCode SwView::InsertGraphic( const OUString &rPath, const OUString &rFilter,
OUString sURL = URIHelper::SmartRel2Abs(
aTemp, rPath, URIHelper::GetMaybeFileHdl() );
aGraphic.setOriginURL(sURL);
rShell.Insert( sURL, rFilter, aGraphic, &aFrameManager );
}
else
......
......@@ -17,6 +17,7 @@
#include <vcl/vectorgraphicdata.hxx>
#include <vcl/metaact.hxx>
#include <vcl/timer.hxx>
#include <vcl/GraphicExternalLink.hxx>
#include <officecfg/Office/Common.hxx>
#include <unotools/configmgr.hxx>
......@@ -62,6 +63,7 @@ public:
std::shared_ptr<ImpGraphic> newInstance(const VectorGraphicDataPtr& rVectorGraphicDataPtr);
std::shared_ptr<ImpGraphic> newInstance(const Animation& rAnimation);
std::shared_ptr<ImpGraphic> newInstance(const GDIMetaFile& rMtf);
std::shared_ptr<ImpGraphic> newInstance(const GraphicExternalLink& rGraphicLink);
};
}
} // end namespace vcl::graphic
......
......@@ -31,6 +31,8 @@
#include <com/sun/star/graphic/XGraphic.hpp>
#include <cppuhelper/typeprovider.hxx>
#include <graphic/UnoGraphic.hxx>
#include <vcl/GraphicExternalLink.hxx>
using namespace ::com::sun::star;
......@@ -199,6 +201,11 @@ Graphic::Graphic(Graphic&& rGraphic)
{
}
Graphic::Graphic(GraphicExternalLink const & rGraphicExternalLink)
: mxImpGraphic(vcl::graphic::Manager::get().newInstance(rGraphicExternalLink))
{
}
Graphic::Graphic(const Bitmap& rBmp)
: mxImpGraphic(vcl::graphic::Manager::get().newInstance(rBmp))
{
......
......@@ -226,6 +226,16 @@ ImpGraphic::ImpGraphic(ImpGraphic&& rImpGraphic)
rImpGraphic.mbDummyContext = false;
}
ImpGraphic::ImpGraphic(GraphicExternalLink const & rGraphicExternalLink) :
meType ( GraphicType::Default ),
mnSizeBytes ( 0 ),
mbSwapOut ( false ),
mbDummyContext ( false ),
maGraphicExternalLink(rGraphicExternalLink),
maLastUsed (std::chrono::high_resolution_clock::now())
{
}
ImpGraphic::ImpGraphic( const Bitmap& rBitmap ) :
maEx ( rBitmap ),
meType ( !rBitmap.IsEmpty() ? GraphicType::Bitmap : GraphicType::NONE ),
......
......@@ -10,11 +10,9 @@
#include <vcl/GraphicLoader.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/graphic/GraphicProvider.hpp>
#include <com/sun/star/graphic/XGraphicProvider.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <unotools/ucbstreamhelper.hxx>
#include <vcl/graphicfilter.hxx>
#include <vcl/wmf.hxx>
using namespace css;
......@@ -22,35 +20,38 @@ namespace vcl
{
namespace graphic
{
Graphic loadFromURL(OUString const& rURL)
Graphic loadFromURL(OUString const& rURL, sal_Int16 nExtWidth, sal_Int16 nExtHeight,
sal_Int16 nExtMapMode)
{
// Define APM Header if goal height and width are defined
WmfExternal aExtHeader;
aExtHeader.xExt = nExtWidth;
aExtHeader.yExt = nExtHeight;
aExtHeader.mapMode = nExtMapMode;
WmfExternal* pExtHeader = nullptr;
if (nExtMapMode > 0)
pExtHeader = &aExtHeader;
Graphic aGraphic;
try
{
uno::Reference<css::graphic::XGraphic> xGraphic;
uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
uno::Reference<css::graphic::XGraphicProvider> xProvider;
xProvider.set(css::graphic::GraphicProvider::create(xContext));
uno::Sequence<beans::PropertyValue> aLoadProps(1);
aLoadProps[0].Name = "URL";
aLoadProps[0].Value <<= rURL;
xGraphic = xProvider->queryGraphic(aLoadProps);
if (xGraphic.is())
aGraphic = Graphic(xGraphic);
else
aGraphic.SetDefaultType();
aGraphic.setOriginURL(rURL);
}
catch (uno::Exception const&)
std::unique_ptr<SvStream> pInputStream;
pInputStream.reset(utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ));
if (pInputStream)
{
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
ErrCode nError
= rFilter.ImportGraphic(aGraphic, rURL, *pInputStream, GRFILTER_FORMAT_DONTKNOW,
nullptr, GraphicFilterImportFlags::NONE, pExtHeader);
if (nError != ERRCODE_NONE || aGraphic.GetType() == GraphicType::NONE)
return Graphic();
}
return aGraphic;
}
Graphic loadFromURL(OUString const& rURL) { return loadFromURL(rURL, 0, 0, 0); }
}
} // end vcl::graphic
......
......@@ -179,6 +179,13 @@ std::shared_ptr<ImpGraphic> Manager::newInstance(const GDIMetaFile& rMetaFile)
return pReturn;
}
std::shared_ptr<ImpGraphic> Manager::newInstance(const GraphicExternalLink& rGraphicLink)
{
auto pReturn = std::make_shared<ImpGraphic>(rGraphicLink);
registerGraphic(pReturn, "GraphicExternalLink");
return pReturn;
}
void Manager::swappedIn(const ImpGraphic* pImpGraphic)
{
mnUsedSize += pImpGraphic->ImplGetSizeBytes();
......
......@@ -62,6 +62,7 @@
#include <unotools/fontcvt.hxx>
#include <o3tl/make_unique.hxx>
#include <xmloff/fasttokenhandler.hxx>
#include <vcl/GraphicExternalLink.hxx>
#include <com/sun/star/rdf/XMetadatable.hpp>
#include <com/sun/star/rdf/XRepositorySupplier.hpp>
......@@ -1370,19 +1371,10 @@ uno::Reference<graphic::XGraphic> SvXMLImport::loadGraphicByURL(OUString const &
}
else
{
uno::Reference<graphic::XGraphicProvider> xProvider(graphic::GraphicProvider::create(GetComponentContext()));
OUString const & rAbsoluteURL = GetAbsoluteReference(rURL);
uno::Sequence<beans::PropertyValue> aLoadProperties(comphelper::InitPropertySequence(
{
{ "URL", uno::makeAny(rAbsoluteURL) }
}));
xGraphic = xProvider->queryGraphic(aLoadProperties);
if (xGraphic.is())
{
Graphic aGraphic(xGraphic);
aGraphic.setOriginURL(rAbsoluteURL);
}
GraphicExternalLink aExternalLink(rAbsoluteURL);
Graphic aGraphic(aExternalLink);
xGraphic = aGraphic.GetXGraphic();
}
}
......
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