[Libreoffice-commits] core.git: oox/source

Miklos Vajna vmiklos at collabora.co.uk
Mon May 22 16:50:45 UTC 2017


 oox/source/ppt/pptimport.cxx |   41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

New commits:
commit 9eb8e2737d3a4d52ce1b0cc44091a3b7ecf59e3b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon May 22 16:13:32 2017 +0200

    PPTX import: import JPEG images ahead of time
    
    So that they can be later imported in parallel, and when they are
    referenced, we just take the import result from the cache.
    
    Change-Id: Icc0efbbc8df03ee727fafe07f9983f3999dc34e2
    Reviewed-on: https://gerrit.libreoffice.org/37909
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/oox/source/ppt/pptimport.cxx b/oox/source/ppt/pptimport.cxx
index 6d54520f7436..74285e7dbe97 100644
--- a/oox/source/ppt/pptimport.cxx
+++ b/oox/source/ppt/pptimport.cxx
@@ -86,6 +86,30 @@ PowerPointImport::~PowerPointImport()
 {
 }
 
+/// Visits the relations from pRelations which are of type rType.
+static void visitRelations(PowerPointImport& rImport, core::RelationsRef pRelations, const OUString& rType, std::vector<OUString>& rImageFragments)
+{
+    if (core::RelationsRef pRelationsOfType = pRelations->getRelationsFromTypeFromOfficeDoc(rType))
+    {
+        for (const auto& rRelation : *pRelationsOfType)
+        {
+            OUString aFragment = pRelationsOfType->getFragmentPathFromRelation(rRelation.second);
+            if (core::RelationsRef pFragmentRelations = rImport.importRelations(aFragment))
+            {
+                // See if the fragment has images.
+                if (core::RelationsRef pImages = pFragmentRelations->getRelationsFromTypeFromOfficeDoc("image"))
+                {
+                    for (const auto& rImage : *pImages)
+                        rImageFragments.push_back(pImages->getFragmentPathFromRelation(rImage.second));
+                }
+
+                // See if the fragment has a slide layout, and recurse.
+                visitRelations(rImport, pFragmentRelations, "slideLayout", rImageFragments);
+            }
+        }
+    }
+}
+
 bool PowerPointImport::importDocument()
 {
     /*  to activate the PPTX dumper, define the environment variable
@@ -98,6 +122,23 @@ bool PowerPointImport::importDocument()
     OUString aFragmentPath = getFragmentPathFromFirstTypeFromOfficeDoc( "officeDocument" );
     FragmentHandlerRef xPresentationFragmentHandler( new PresentationFragmentHandler( *this, aFragmentPath ) );
     maTableStyleListPath = xPresentationFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc( "tableStyles" );
+
+    // importRelations() is cheap, it will do an actual import for the first time only.
+    if (core::RelationsRef pFragmentRelations = importRelations(aFragmentPath))
+    {
+        std::vector<OUString> aImageFragments;
+        visitRelations(*this, pFragmentRelations, "slide", aImageFragments);
+        visitRelations(*this, pFragmentRelations, "slideMaster", aImageFragments);
+
+        for (const auto& rImage : aImageFragments)
+        {
+            // Safe subset: e.g. WMF may have an external header from the
+            // referencing fragment.
+            if (rImage.endsWith(".jpg") || rImage.endsWith(".jpeg"))
+                getGraphicHelper().importEmbeddedGraphic(rImage);
+        }
+    }
+
     bool bRet = importFragment(xPresentationFragmentHandler);
 
     if (mbMissingExtDrawing)


More information about the Libreoffice-commits mailing list