sfx2/source/control/thumbnailview.cxx | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-)
New commits: commit 9ba4c479d8f510cadf1c76bab5ced4b29745bc6b Author: Justin Luth <jl...@mail.com> AuthorDate: Mon Apr 28 11:19:04 2025 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Tue Apr 29 04:21:52 2025 +0200 tdf#166035 thumbnailview: recognize some MS-format thumbnails The sample I was given had thumbnail.emf. Using Word 2010, I generated a powerpoint presentation that had thumbnail.jpeg, and a spreadsheet that had thumbnail.wmf. I imagine that other formats could easily exist. But I don't know of a generic way to identify them, since there doesn't seem to be any special "this is where you find the thumbnail" pointer. Change-Id: Iad5281df3bdb79688eeecfd992da94ef5c3fa4d5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184722 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sfx2/source/control/thumbnailview.cxx b/sfx2/source/control/thumbnailview.cxx index 3bcbfb648568..79eefc0f4590 100644 --- a/sfx2/source/control/thumbnailview.cxx +++ b/sfx2/source/control/thumbnailview.cxx @@ -35,12 +35,14 @@ #include <vcl/settings.hxx> #include <vcl/event.hxx> #include <vcl/filter/PngImageReader.hxx> +#include <vcl/graphicfilter.hxx> #include <vcl/weldutils.hxx> #include <com/sun/star/accessibility/AccessibleEventId.hpp> #include <com/sun/star/embed/ElementModes.hpp> #include <com/sun/star/embed/StorageFactory.hpp> #include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/packages/zip/ZipFileAccess.hpp> #include <memory> #if !ENABLE_WASM_STRIP_RECENT @@ -97,7 +99,34 @@ BitmapEx ThumbnailView::readThumbnail(const OUString &msURL) catch (const uno::Exception&) { TOOLS_WARN_EXCEPTION("sfx", - "caught exception while trying to access Thumbnail/thumbnail.png of " << msURL); + "caught exception while trying to access Thumbnails/thumbnail.png of " << msURL); + } + + if (!xIStream.is()) + { + // a Micrsosoft formatted template? + uno::Reference<packages::zip::XZipFileAccess2> xNameAccess + = packages::zip::ZipFileAccess::createWithURL(xContext, msURL); + if (xNameAccess.is()) + { + if (xNameAccess->hasByName(u"docProps/thumbnail.emf"_ustr)) + xIStream.set(xNameAccess->getByName(u"docProps/thumbnail.emf"_ustr), + uno::UNO_QUERY); + else if (xNameAccess->hasByName(u"docProps/thumbnail.jpeg"_ustr)) + xIStream.set(xNameAccess->getByName(u"docProps/thumbnail.jpeg"_ustr), + uno::UNO_QUERY); + else if (xNameAccess->hasByName(u"docProps/thumbnail.wmf"_ustr)) + xIStream.set(xNameAccess->getByName(u"docProps/thumbnail.wmf"_ustr), + uno::UNO_QUERY); + std::unique_ptr<SvStream> pStream( + utl::UcbStreamHelper::CreateStream(xIStream, /*CloseStream=*/ true)); + if (pStream) + { + Graphic aGraphic + = GraphicFilter::GetGraphicFilter().ImportUnloadedGraphic(*pStream); + return aGraphic.GetBitmapEx(); + } + } } try @@ -123,7 +152,7 @@ BitmapEx ThumbnailView::readThumbnail(const OUString &msURL) catch (const uno::Exception&) { TOOLS_WARN_EXCEPTION("sfx", - "caught exception while trying to access Thumbnails/thumbnail.png of " << msURL); + "caught exception while trying to access Thumbnail/thumbnail.png of " << msURL); } } catch (const uno::Exception&)