sfx2/source/control/thumbnailview.cxx |   33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)

New commits:
commit 7cad6f88cc6fdef91e7a71b9b4694559517c2e28
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Mon Apr 28 11:19:04 2025 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Apr 30 08:29:19 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>
    (cherry picked from commit 9ba4c479d8f510cadf1c76bab5ced4b29745bc6b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184739
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sfx2/source/control/thumbnailview.cxx 
b/sfx2/source/control/thumbnailview.cxx
index 7c60a398928c..581399c9942f 100644
--- a/sfx2/source/control/thumbnailview.cxx
+++ b/sfx2/source/control/thumbnailview.cxx
@@ -34,12 +34,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
@@ -96,7 +98,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
@@ -122,7 +151,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&)

Reply via email to