diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-05-22 16:13:32 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-05-22 18:50:23 +0200 |
commit | 9eb8e2737d3a4d52ce1b0cc44091a3b7ecf59e3b (patch) | |
tree | d09e1c5743d329396febeb84ff4734a82720e3cc /oox/source/ppt/pptimport.cxx | |
parent | e8a742344d612067a7a0ba5c752176d12a559967 (diff) |
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@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'oox/source/ppt/pptimport.cxx')
-rw-r--r-- | oox/source/ppt/pptimport.cxx | 41 |
1 files changed, 41 insertions, 0 deletions
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) |