From 24231f2a336c50eac5e6a1621c57e60ebe1e1cf4 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 17 Feb 2022 18:00:24 +0100 Subject: svtools: fix lost replacement non-rendered graphic when updating it fails This is similar to commit 8780fa41dcd164af244742461f4e57a4bcf4c7a4 (svtools: fix lost replacement grpahic when updating it via OLE fails, 2018-10-30), but that case was when we already had an old mpImpl->pGraphic, the updated failed and then we already lost the old one but didn't have a new one. Here what happened is that in case tools -> update -> update-all was used for an OLE object which had bad native data but a good preview, then the result was bad preview, depending on if you first scrolled to the OLE object to trigger rendering (good) or not (bad). The reason for this is that scrolling to the object calls GetGraphic(), which sets mpImpl->pGraphic using GetReplacement(bUpdate=false), which works, but svt::EmbeddedObjectRef::UpdateReplacement() calls GetReplacement(bUpdate=true). That explains why the update breaks the preview, but not when scrolling to it first. Fix the problem by improving svt::EmbeddedObjectRef::GetReplacement(): if getting an updated graphic fails, try to get a non-updated graphic. The result is that GetGraphic() after an UpdateReplacement() not only always return a non-nullptr Graphic, but also it's no longer of type None. Change-Id: I8e5ff4aaaefdc58e032b325bb4001f2a604ccc8a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130086 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- svtools/source/misc/embedhlp.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'svtools/source') diff --git a/svtools/source/misc/embedhlp.cxx b/svtools/source/misc/embedhlp.cxx index 4f4a5ce3e364..6e56dc3137e8 100644 --- a/svtools/source/misc/embedhlp.cxx +++ b/svtools/source/misc/embedhlp.cxx @@ -471,6 +471,15 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate ) } std::unique_ptr pGraphicStream(GetGraphicStream( bUpdate )); + if (!pGraphicStream && aOldGraphic.IsNone()) + { + // We have no old graphic, tried to get an updated one, but that failed. Try to get an old + // graphic instead of having no graphic at all. + pGraphicStream = GetGraphicStream(false); + SAL_WARN("svtools.misc", + "EmbeddedObjectRef::GetReplacement: failed to get updated graphic stream"); + } + if ( pGraphicStream ) { GraphicFilter& rGF = GraphicFilter::GetGraphicFilter(); @@ -487,7 +496,7 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate ) // failed. Go back to the old graphic instead of having no graphic at // all. mpImpl->pGraphic.reset(new Graphic(aOldGraphic)); - SAL_WARN("svtools.misc", "EmbeddedObjectRef::GetReplacement: update failed"); + SAL_WARN("svtools.misc", "EmbeddedObjectRef::GetReplacement: failed to update graphic"); } } -- cgit