tdf#131390 PPTX: fix custom slide show is not imported.

Change-Id: I62e1bfaae23d1b18e71a2c16651d01144a26907c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115475
Tested-by: Jenkins
Tested-by: László Németh <nemeth@numbertext.org>
Reviewed-by: László Németh <nemeth@numbertext.org>
This commit is contained in:
Tibor Nagy
2021-05-25 15:44:40 +02:00
committed by László Németh
parent 63ce1ca6d7
commit ecf48b2d4f
5 changed files with 82 additions and 10 deletions
@@ -51,6 +51,7 @@ private:
const oox::ppt::SlidePersistPtr& rPersist );
void importSlide(sal_uInt32 nSlide, bool bFirstSlide, bool bImportNotes);
void saveThemeToGrabBag(const oox::drawingml::ThemePtr& pThemePtr, sal_Int32 nThemeIdx);
void importCustomSlideShow(std::vector<CustomShow>& rCustomShowList);
std::vector< OUString > maSlideMasterVector;
std::vector< OUString > maSlidesVector;
+13 -10
View File
@@ -33,12 +33,12 @@ namespace {
class CustomShowContext : public ::oox::core::FragmentHandler2
{
CustomShow mrCustomShow;
std::vector< CustomShow >& mrCustomShowList;
public:
CustomShowContext( ::oox::core::FragmentHandler2 const & rParent,
const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttribs,
CustomShow const & rCustomShow );
std::vector< CustomShow >& rCustomShowList );
virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs ) override;
};
@@ -47,12 +47,14 @@ public:
CustomShowContext::CustomShowContext( FragmentHandler2 const & rParent,
const Reference< XFastAttributeList >& rxAttribs,
CustomShow const & rCustomShow )
std::vector< CustomShow >& rCustomShowList )
: FragmentHandler2( rParent )
, mrCustomShow( rCustomShow )
, mrCustomShowList( rCustomShowList )
{
mrCustomShow.maCustomShowName = rxAttribs->getOptionalValue( XML_name );
mrCustomShow.mnId = rxAttribs->getOptionalValue( XML_id );
CustomShow aCustomShow;
aCustomShow.maCustomShowName = rxAttribs->getOptionalValue( XML_name );
aCustomShow.mnId = rxAttribs->getOptionalValue( XML_id );
mrCustomShowList.push_back(aCustomShow);
}
::oox::core::ContextHandlerRef CustomShowContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
@@ -60,7 +62,10 @@ CustomShowContext::CustomShowContext( FragmentHandler2 const & rParent,
switch( aElementToken )
{
case PPT_TOKEN( sld ) :
mrCustomShow.maSldLst.push_back( rAttribs.getString( R_TOKEN( id ), OUString() ) );
mrCustomShowList.back().maSldLst.push_back(
getRelations()
.getRelationFromRelId(rAttribs.getString(R_TOKEN(id), OUString()))
->maTarget);
return this;
default:
break;
@@ -86,9 +91,7 @@ CustomShowListContext::~CustomShowListContext( )
{
case PPT_TOKEN( custShow ) :
{
CustomShow aCustomShow;
mrCustomShowList.push_back( aCustomShow );
return new CustomShowContext( *this, rAttribs.getFastAttributeList(), mrCustomShowList.back() );
return new CustomShowContext( *this, rAttribs.getFastAttributeList(), mrCustomShowList );
}
default:
break;
@@ -35,6 +35,10 @@
#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
#include <com/sun/star/presentation/XPresentationPage.hpp>
#include <com/sun/star/task/XStatusIndicator.hpp>
#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
#include <com/sun/star/lang/XSingleServiceFactory.hpp>
#include <com/sun/star/container/XNameContainer.hpp>
#include <oox/drawingml/theme.hxx>
#include <oox/drawingml/drawingmltypes.hxx>
@@ -158,6 +162,49 @@ static void ResolveTextFields( XmlFilterBase const & rFilter )
}
}
void PresentationFragmentHandler::importCustomSlideShow(std::vector<CustomShow>& rCustomShowList)
{
PowerPointImport& rFilter = dynamic_cast<PowerPointImport&>(getFilter());
Reference<frame::XModel> xModel(rFilter.getModel());
Reference<XDrawPagesSupplier> xDrawPagesSupplier(xModel, UNO_QUERY_THROW);
Reference<XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW);
Reference<css::lang::XSingleServiceFactory> mxShowFactory;
Reference<css::container::XNameContainer> mxShows;
Reference<XCustomPresentationSupplier> xShowsSupplier(xModel, UNO_QUERY);
if (xShowsSupplier.is())
{
mxShows = xShowsSupplier->getCustomPresentations();
mxShowFactory.set(mxShows, UNO_QUERY);
}
for (size_t i = 0; i < rCustomShowList.size(); ++i)
{
Reference<com::sun::star::container::XIndexContainer> xShow(mxShowFactory->createInstance(),
UNO_QUERY);
if (xShow.is())
{
static const OUStringLiteral sSlide = u"slides/slide";
for (size_t j = 0; j < rCustomShowList[i].maSldLst.size(); ++j)
{
OUString sCustomSlide = rCustomShowList[i].maSldLst[j];
sal_Int32 nPageNumber = 0;
if (sCustomSlide.match(sSlide))
nPageNumber = sCustomSlide.copy(sSlide.getLength()).toInt32();
Reference<XDrawPage> xPage;
xDrawPages->getByIndex(nPageNumber - 1) >>= xPage;
if (xPage.is())
xShow->insertByIndex(xShow->getCount(), Any(xPage));
}
Any aAny;
aAny <<= xShow;
mxShows->insertByName(rCustomShowList[i].maCustomShowName, aAny);
}
}
}
void PresentationFragmentHandler::saveThemeToGrabBag(const oox::drawingml::ThemePtr& pThemePtr,
sal_Int32 nThemeIdx)
{
@@ -497,6 +544,8 @@ void PresentationFragmentHandler::finalizeImport()
nPagesImported++;
}
ResolveTextFields( rFilter );
if (!maCustomShowList.empty())
importCustomSlideShow(maCustomShowList);
}
catch( uno::Exception& )
{
Binary file not shown.
+19
View File
@@ -86,6 +86,7 @@
#include <com/sun/star/text/XTextCursor.hpp>
#include <com/sun/star/xml/dom/XDocument.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
#include <stlpool.hxx>
#include <comphelper/processfactory.hxx>
@@ -120,6 +121,7 @@ public:
virtual void setUp() override;
void testDocumentLayout();
void testCustomSlideShow();
void testInternalHyperlink();
void testHyperlinkColor();
void testSmoketest();
@@ -239,6 +241,7 @@ public:
CPPUNIT_TEST_SUITE(SdImportTest);
CPPUNIT_TEST(testDocumentLayout);
CPPUNIT_TEST(testCustomSlideShow);
CPPUNIT_TEST(testInternalHyperlink);
CPPUNIT_TEST(testHyperlinkColor);
CPPUNIT_TEST(testSmoketest);
@@ -434,6 +437,22 @@ void SdImportTest::testDocumentLayout()
}
}
void SdImportTest::testCustomSlideShow()
{
::sd::DrawDocShellRef xDocShRef
= loadURL(m_directories.getURLFromSrc(u"/sd/qa/unit/data/pptx/tdf131390.pptx"), PPTX);
css::uno::Reference<css::presentation::XCustomPresentationSupplier> aXCPSup(
xDocShRef->GetModel(), css::uno::UNO_QUERY);
css::uno::Reference<css::container::XNameContainer> aXCont(aXCPSup->getCustomPresentations());
const css::uno::Sequence< OUString> aNameSeq( aXCont->getElementNames() );
// In the document, there are two custom presentations.
CPPUNIT_ASSERT_EQUAL(sal_uInt32(2), aNameSeq.size());
xDocShRef->DoClose();
}
void SdImportTest::testInternalHyperlink()
{
::sd::DrawDocShellRef xDocShRef