28#include <frozen/bits/defines.h>
29#include <frozen/bits/elsa_std.h>
30#include <frozen/unordered_map.h>
32#include <com/sun/star/container/XNamed.hpp>
33#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
34#include <com/sun/star/drawing/XDrawPages.hpp>
35#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
36#include <com/sun/star/drawing/XMasterPageTarget.hpp>
37#include <com/sun/star/frame/XModel.hpp>
38#include <com/sun/star/io/XInputStream.hpp>
39#include <com/sun/star/text/XTextField.hpp>
40#include <com/sun/star/xml/dom/XDocument.hpp>
41#include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
42#include <com/sun/star/presentation/XPresentationPage.hpp>
43#include <com/sun/star/task/XStatusIndicator.hpp>
44#include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
45#include <com/sun/star/container/XIndexContainer.hpp>
46#include <com/sun/star/lang/XMultiServiceFactory.hpp>
47#include <com/sun/star/lang/XSingleServiceFactory.hpp>
48#include <com/sun/star/container/XNameContainer.hpp>
62#include <oox/token/namespaces.hxx>
63#include <oox/token/tokens.hxx>
65#include <com/sun/star/office/XAnnotation.hpp>
66#include <com/sun/star/office/XAnnotationAccess.hpp>
84constexpr frozen::unordered_map<PredefinedClrSchemeId, sal_Int32, 12> constPredefinedClrTokens
102 auto iterator = constPredefinedClrTokens.find(eID);
103 if (iterator == constPredefinedClrTokens.end())
105 return iterator->second;
110 : FragmentHandler2( rFilter, rFragmentPath )
112 , mbCommentAuthorsRead(false)
115 for (
auto & elem : rParagraphDefaultsVector)
119 elem.getParaBottomMargin() = TextSpacing( 0 );
129 sal_Int32 nMaxPages = rSlidePersist.size();
130 for (sal_Int32 nPage = 0; nPage < nMaxPages; nPage++)
132 auto aShapeMap = rSlidePersist[nPage]->getShapeMap();
133 auto aIter = std::find_if(aShapeMap.begin(), aShapeMap.end(),
134 [](
const std::pair<OUString, ShapePtr>& element) {
135 auto pShapePtr = element.second;
137 && (pShapePtr->getSubType() == XML_title
138 || pShapePtr->getSubType() == XML_ctrTitle));
140 if (aIter != aShapeMap.end())
143 Reference<text::XTextRange> xText(aIter->second->getXShape(), UNO_QUERY_THROW);
144 aTitleText = xText->getString();
146 if (aTitleText.getLength() > 63)
147 aTitleText = aTitleText.copy(0, 63);
148 bool bUseTitleAsSlideName = !aTitleText.isEmpty();
150 if (bUseTitleAsSlideName)
153 Reference<XDrawPagesSupplier> xDPS(rFilter.getModel(), UNO_QUERY_THROW);
154 Reference<XDrawPages> xDrawPages(xDPS->getDrawPages(), UNO_SET_THROW);
155 for (sal_Int32
i = 0;
i < nPage; ++
i)
157 Reference<XDrawPage> xDrawPage(xDrawPages->getByIndex(
i), UNO_QUERY);
158 Reference<container::XNamed> xNamed(xDrawPage, UNO_QUERY_THROW);
159 std::u16string_view sRest;
166 Reference<container::XNamed> xName(rSlidePersist[nPage]->getPage(), UNO_QUERY_THROW);
169 + (
nCount == 1 ? OUString(
"") :
" (" + OUString::number(
nCount) +
")"));
179 Reference<XDrawPagesSupplier> xDrawPagesSupplier(
xModel, UNO_QUERY_THROW);
180 Reference<XDrawPages> xDrawPages(xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW);
182 Reference<css::lang::XSingleServiceFactory> mxShowFactory;
183 Reference<css::container::XNameContainer> mxShows;
184 Reference<XCustomPresentationSupplier> xShowsSupplier(
xModel, UNO_QUERY);
185 if (xShowsSupplier.is())
187 mxShows = xShowsSupplier->getCustomPresentations();
188 mxShowFactory.set(mxShows, UNO_QUERY);
191 for (
size_t i = 0;
i < rCustomShowList.size(); ++
i)
193 Reference<com::sun::star::container::XIndexContainer> xShow(mxShowFactory->createInstance(),
197 static constexpr OUStringLiteral sSlide =
u"slides/slide";
198 for (
size_t j = 0; j < rCustomShowList[
i].maSldLst.size(); ++j)
200 OUString sCustomSlide = rCustomShowList[
i].maSldLst[j];
201 sal_Int32 nPageNumber = 0;
202 if (sCustomSlide.match(sSlide))
203 nPageNumber =
o3tl::toInt32(sCustomSlide.subView(sSlide.getLength()));
205 Reference<XDrawPage> xPage;
206 xDrawPages->getByIndex(nPageNumber - 1) >>= xPage;
208 xShow->insertByIndex(xShow->getCount(),
Any(xPage));
213 mxShows->insertByName(rCustomShowList[
i].maCustomShowName, aAny);
226 uno::Reference<beans::XPropertySet> xDocProps(getFilter().getModel(), uno::UNO_QUERY);
229 uno::Reference<beans::XPropertySetInfo> xPropsInfo = xDocProps->getPropertySetInfo();
231 static constexpr OUStringLiteral aGrabBagPropName =
u"InteropGrabBag";
232 if (xPropsInfo.is() && xPropsInfo->hasPropertyByName(aGrabBagPropName))
241 auto pCurrentTheme = aCurrentTheme.getArray();
243 ClrScheme rClrScheme = pThemePtr->getClrScheme();
247 sal_uInt32
nToken = getPredefinedClrTokens(eID);
251 rClrScheme.getColor(
nToken, nColor);
255 pCurrentTheme[
nId].Value = rColor;
259 uno::Sequence<beans::PropertyValue> aTheme{
264 "ppt/theme/theme" + OUString::number(nThemeIdx) +
".xml", aCurrentTheme),
269 aThemesHashMap << aTheme;
272 aGrabBag.
update(aThemesHashMap);
279 catch (
const uno::Exception&)
281 SAL_WARN(
"oox",
"oox::ppt::PresentationFragmentHandler::saveThemeToGrabBag, Failed to save grab bag");
290 Reference< drawing::XDrawPage > xSlide;
293 Reference< drawing::XDrawPagesSupplier > xDPS(
xModel, uno::UNO_QUERY_THROW );
294 Reference< drawing::XDrawPages > xDrawPages( xDPS->getDrawPages(), uno::UNO_SET_THROW );
299 xDrawPages->getByIndex( 0 ) >>= xSlide;
301 xSlide = xDrawPages->insertNewByIndex( xDrawPages->getCount() );
303 OUString aSlideFragmentPath = getFragmentPathFromRelId(
maSlidesVector[ nSlide ] );
304 if( !aSlideFragmentPath.isEmpty() )
307 SlidePersistPtr pSlidePersistPtr = std::make_shared<SlidePersist>( rFilter,
false,
false, xSlide,
313 OUString aLayoutFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc(
u"slideLayout" );
314 OUString aCommentFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc(
u"comments" );
315 if ( !aLayoutFragmentPath.isEmpty() )
319 OUString aMasterFragmentPath = xLayoutRelations->getFragmentPathFromFirstTypeFromOfficeDoc(
u"slideMaster" );
320 if( !aMasterFragmentPath.isEmpty() )
323 std::vector< SlidePersistPtr >& rMasterPages( rFilter.
getMasterPages() );
324 for (
auto const& masterPage : rMasterPages)
326 if ( ( masterPage->getPath() == aMasterFragmentPath ) && ( masterPage->getLayoutPath() == aLayoutFragmentPath ) )
328 pMasterPersistPtr = masterPage;
333 if ( !pMasterPersistPtr )
335 Reference< drawing::XDrawPage > xMasterPage;
336 Reference< drawing::XMasterPagesSupplier > xMPS(
xModel, uno::UNO_QUERY_THROW );
337 Reference< drawing::XDrawPages > xMasterPages( xMPS->getMasterPages(), uno::UNO_SET_THROW );
343 xMasterPages->getByIndex(
nIndex ) >>= xMasterPage;
347 nIndex = xMasterPages->getCount();
348 xMasterPage = xMasterPages->insertNewByIndex(
nIndex );
351 pMasterPersistPtr = std::make_shared<SlidePersist>( rFilter,
true,
false, xMasterPage,
353 pMasterPersistPtr->setLayoutPath( aLayoutFragmentPath );
359 OUString aThemeFragmentPath = xMasterFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc(
u"theme" );
360 if( !aThemeFragmentPath.isEmpty() )
362 std::map< OUString, oox::drawingml::ThemePtr >& rThemes( rFilter.
getThemes() );
363 std::map< OUString, oox::drawingml::ThemePtr >::iterator aIter2( rThemes.find( aThemeFragmentPath ) );
364 if( aIter2 == rThemes.end() )
367 pMasterPersistPtr->setTheme( pThemePtr );
368 Reference<xml::dom::XDocument> xDoc=
371 auto pTheme = std::make_shared<model::Theme>();
372 pThemePtr->setTheme(pTheme);
375 new ThemeFragmentHandler(rFilter, aThemeFragmentPath, *pThemePtr, *pTheme),
376 Reference<xml::sax::XFastSAXSerializable>(
379 rThemes[ aThemeFragmentPath ] = pThemePtr;
380 pThemePtr->setFragment(xDoc);
385 pMasterPersistPtr->setTheme( (*aIter2).second );
388 importSlide( xMasterFragmentHandler, pMasterPersistPtr );
390 pMasterPersistPtr->createBackground( rFilter );
391 pMasterPersistPtr->createXShapes( rFilter );
396 pTheme->addTheme(pMasterPersistPtr->getPage());
403 if (pMasterPersistPtr) {
404 pSlidePersistPtr->setMasterPersist( pMasterPersistPtr );
405 pSlidePersistPtr->setTheme( pMasterPersistPtr->getTheme() );
406 Reference< drawing::XMasterPageTarget > xMasterPageTarget( pSlidePersistPtr->getPage(), UNO_QUERY );
407 if( xMasterPageTarget.is() )
408 xMasterPageTarget->setMasterPage( pMasterPersistPtr->getPage() );
412 importSlide( xSlideFragmentHandler, pSlidePersistPtr );
413 pSlidePersistPtr->createBackground( rFilter );
414 pSlidePersistPtr->createXShapes( rFilter );
416 if(bImportNotesPage) {
419 OUString aNotesFragmentPath = xSlideFragmentHandler->getFragmentPathFromFirstTypeFromOfficeDoc(
u"notesSlide" );
420 if( !aNotesFragmentPath.isEmpty() )
422 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
423 if ( xPresentationPage.is() )
425 Reference< XDrawPage > xNotesPage( xPresentationPage->getNotesPage() );
426 if ( xNotesPage.is() )
428 SlidePersistPtr pNotesPersistPtr = std::make_shared<SlidePersist>( rFilter,
false,
true, xNotesPage,
433 importSlide( xNotesFragmentHandler, pNotesPersistPtr );
434 pNotesPersistPtr->createBackground( rFilter );
435 pNotesPersistPtr->createXShapes( rFilter );
445 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
446 Reference< XDrawPage > xCommentAuthorsPage( xPresentationPage->getNotesPage() );
448 std::make_shared<SlidePersist>( rFilter,
false,
true, xCommentAuthorsPage,
449 std::make_shared<PPTShape>(
450 Slide,
"com.sun.star.drawing.GroupShape" ),
454 "ppt/commentAuthors.xml",
455 pCommentAuthorsPersistPtr,
458 getFilter().importFragment( xCommentAuthorsFragmentHandler );
461 if( !aCommentFragmentPath.isEmpty() )
463 Reference< XPresentationPage > xPresentationPage( xSlide, UNO_QUERY );
464 Reference< XDrawPage > xCommentsPage( xPresentationPage->getNotesPage() );
466 std::make_shared<SlidePersist>(
467 rFilter,
false,
true, xCommentsPage,
468 std::make_shared<PPTShape>(
469 Slide,
"com.sun.star.drawing.GroupShape" ),
475 aCommentFragmentPath,
478 pCommentsPersistPtr->getCommentsList().cmLst.clear();
479 getFilter().importFragment( xCommentsFragmentHandler );
481 if (!pCommentsPersistPtr->getCommentsList().cmLst.empty())
486 assert(comment_handler);
490 pCommentsPersistPtr->getCommentsList().cmLst.back().setText(
494 pCommentsPersistPtr->getCommentAuthors().setValues(
maAuthorList);
497 for(
int i=0;
i<pCommentsPersistPtr->getCommentsList().getSize();
i++)
500 Comment aComment = pCommentsPersistPtr->getCommentsList().getCommentAtIndex(
i);
501 uno::Reference< office::XAnnotationAccess > xAnnotationAccess( xSlide, UNO_QUERY_THROW );
502 uno::Reference< office::XAnnotation > xAnnotation( xAnnotationAccess->createAndInsertAnnotation() );
503 int nPosX = aComment.
getIntX();
504 int nPosY = aComment.
getIntY();
505 xAnnotation->setPosition(
506 geometry::RealPoint2D(
510 xAnnotation->setDateTime( aComment.
getDateTime() );
511 uno::Reference< text::XText > xText( xAnnotation->getTextRange() );
512 xText->setString( aComment.
get_text());
513 }
catch( css::lang::IllegalArgumentException& ) {}
518 catch( uno::Exception& )
535 rFilterData[
"OriginalPageCount"] <<= nPageCount;
539 if( !aPageRange.getLength() )
541 aPageRange =
"1-" + OUString::number( nPageCount );
545 if (aRangeEnumerator.
size())
548 const Reference< task::XStatusIndicator >& rxStatusIndicator( getFilter().getStatusIndicator() );
549 if ( rxStatusIndicator.is() )
550 rxStatusIndicator->start( OUString(), 10000 );
554 int nPagesImported = 0;
555 for (sal_Int32 elem : aRangeEnumerator)
557 if ( rxStatusIndicator.is() )
558 rxStatusIndicator->setValue((nPagesImported * 10000) / aRangeEnumerator.size());
560 importSlide(elem, !nPagesImported, bImportNotesPages);
567 catch( uno::Exception& )
572 if ( rxStatusIndicator.is() )
573 rxStatusIndicator->end();
578 if (!aVbaFragmentPath.isEmpty())
580 uno::Reference<io::XInputStream> xInStrm = getFilter().openInputStream(aVbaFragmentPath);
584 getFilter().getVbaProject().importVbaProject(*xPrjStrg);
592 switch( aElementToken )
594 case PPT_TOKEN( presentation ):
595 case PPT_TOKEN( sldMasterIdLst ):
596 case PPT_TOKEN( notesMasterIdLst ):
597 case PPT_TOKEN( sldIdLst ):
599 case PPT_TOKEN( sldMasterId ):
602 case PPT_TOKEN( sldId ):
605 case PPT_TOKEN( notesMasterId ):
608 case PPT_TOKEN( sldSz ):
611 case PPT_TOKEN( notesSz ):
614 case PPT_TOKEN( custShowLst ):
616 case PPT_TOKEN( defaultTextStyle ):
618 case PPT_TOKEN( modifyVerifier ):
621 sal_Int32 nAlgorithmSid = rAttribs.
getInteger(XML_cryptAlgorithmSid, 0);
622 sal_Int32 nSpinCount = rAttribs.
getInteger(XML_spinCount, 0);
625 if (sAlgorithmClass ==
"hash" && sAlgorithmType ==
"typeAny" && nAlgorithmSid != 0
626 && !sSalt.isEmpty() && !
sHash.isEmpty())
628 OUString sAlgorithmName;
629 switch (nAlgorithmSid)
632 sAlgorithmName =
"MD2";
635 sAlgorithmName =
"MD4";
638 sAlgorithmName =
"MD5";
641 sAlgorithmName =
"SHA-1";
644 sAlgorithmName =
"MAC";
647 sAlgorithmName =
"RIPEMD";
650 sAlgorithmName =
"RIPEMD-160";
653 sAlgorithmName =
"HMAC";
656 sAlgorithmName =
"SHA-256";
659 sAlgorithmName =
"SHA-384";
662 sAlgorithmName =
"SHA-512";
667 if (!sAlgorithmName.isEmpty())
669 uno::Sequence<beans::PropertyValue> aResult{
677 uno::Reference<beans::XPropertySet> xDocSettings(
679 "com.sun.star.document.Settings"),
681 xDocSettings->setPropertyValue(
"ModifyPasswordInfo",
uno::Any(aResult));
683 catch (
const uno::Exception&)
696 Reference< drawing::XDrawPage > xSlide( rSlidePersistPtr->getPage() );
697 SlidePersistPtr pMasterPersistPtr( rSlidePersistPtr->getMasterPersist() );
698 if ( pMasterPersistPtr )
701 Reference< drawing::XDrawPage > xMasterSlide(pMasterPersistPtr->getPage());
702 const int nCount = xMasterSlide->getCount();
704 uno::Reference< beans::XPropertySet > xSet( xSlide, uno::UNO_QUERY_THROW );
705 xSet->setPropertyValue(
"Layout",
Any( pMasterPersistPtr->getLayoutFromValueToken() ) );
707 while( nCount < xMasterSlide->getCount())
709 Reference< drawing::XShape > xShape;
710 xMasterSlide->getByIndex(xMasterSlide->getCount()-1) >>= xShape;
711 xMasterSlide->remove(xShape);
714 while( xSlide->getCount() )
716 Reference< drawing::XShape > xShape;
717 xSlide->getByIndex(0) >>= xShape;
718 xSlide->remove( xShape );
721 Reference< XPropertySet > xPropertySet( xSlide, UNO_QUERY );
722 if ( xPropertySet.is() )
725 xPropertySet->setPropertyValue(
"Width",
Any( rPageSize.Width ) );
726 xPropertySet->setPropertyValue(
"Height",
Any( rPageSize.Height ) );
729 if ( !rSlidePersistPtr->isMasterPage() )
730 aHeaderFooter.mbSlideNumber = aHeaderFooter.mbHeader = aHeaderFooter.mbFooter = aHeaderFooter.mbDateTime =
false;
733 if ( rSlidePersistPtr->isNotesPage() )
734 xPropertySet->setPropertyValue(
"IsHeaderVisible",
Any( aHeaderFooter.mbHeader ) );
735 xPropertySet->setPropertyValue(
"IsFooterVisible",
Any( aHeaderFooter.mbFooter ) );
736 xPropertySet->setPropertyValue(
"IsDateTimeVisible",
Any( aHeaderFooter.mbDateTime ) );
737 xPropertySet->setPropertyValue(
"IsPageNumberVisible",
Any( aHeaderFooter.mbSlideNumber ) );
739 catch( uno::Exception& )
743 rSlidePersistPtr->setPath( rxSlideFragmentHandler->getFragmentPath() );
744 getFilter().importFragment( rxSlideFragmentHandler );
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
TValueType getUnpackedValueOrDefault(const OUString &sKey, const TValueType &aDefault) const
css::uno::Sequence< css::beans::PropertyValue > getAsConstPropertyValueList() const
void update(const SequenceAsHashMap &rSource)
Provides access to attribute values of an element.
OUString getStringDefaulted(sal_Int32 nAttrToken) const
Returns the string value of the specified attribute, returns an empty string if attribute not present...
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
Returns the 32-bit signed integer value of the specified attribute (decimal).
const css::uno::Reference< css::xml::sax::XFastAttributeList > & getFastAttributeList() const
Returns the wrapped com.sun.star.xml.sax.XFastAttributeList object.
::comphelper::SequenceAsHashMap & getFilterData() const
Returns the FilterData.
const css::uno::Reference< css::frame::XModel > & getModel() const
Returns the document model (always existing).
RelationsRef importRelations(const OUString &rFragmentPath)
Imports the relations fragment associated with the specified fragment.
bool importFragment(const rtl::Reference< FragmentHandler > &rxHandler)
Imports a fragment using the passed fragment handler, which contains the full path to the fragment st...
std::vector< SlidePersistPtr > & getNotesPages()
std::vector< SlidePersistPtr > & getMasterPages()
std::vector< SlidePersistPtr > & getDrawPages()
void setActualSlidePersist(SlidePersistPtr pActualSlidePersist)
std::map< OUString, oox::drawingml::ThemePtr > & getThemes()
static void importSlideNames(::oox::core::XmlFilterBase &rFilter, const std::vector< SlidePersistPtr > &rSlidePersist)
void importSlide(const ::oox::core::FragmentHandlerRef &rSlideFragmentHandler, const oox::ppt::SlidePersistPtr &rPersist)
virtual ~PresentationFragmentHandler() noexcept override
PresentationFragmentHandler(::oox::core::XmlFilterBase &rFilter, const OUString &rFragmentPath)
::oox::drawingml::TextListStylePtr mpTextListStyle
std::vector< OUString > maSlidesVector
CommentAuthorList maAuthorList
virtual void finalizeImport() override
void importCustomSlideShow(std::vector< CustomShow > &rCustomShowList)
bool mbCommentAuthorsRead
std::vector< OUString > maSlideMasterVector
css::awt::Size maSlideSize
void saveThemeToGrabBag(const oox::drawingml::ThemePtr &pThemePtr, sal_Int32 nThemeIdx)
std::vector< OUString > maNotesMasterVector
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 aElementToken, const AttributeList &rAttribs) override
std::vector< CustomShow > maCustomShowList
css::awt::Size maNotesSize
const ::std::vector< OUString > & getCharVector() const
#define TOOLS_WARN_EXCEPTION(area, stream)
#define SAL_WARN(area, stream)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
std::shared_ptr< T > make_shared(Args &&... args)
constexpr bool ends_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
std::shared_ptr< Relations > RelationsRef
::rtl::Reference< FragmentHandler > FragmentHandlerRef
std::u16string_view getPredefinedClrNames(PredefinedClrSchemeId eID)
sal_Int32 convertEmuToHmm(sal_Int64 nValue)
Converts the passed 64-bit integer value from EMUs to 1/100 mm.
awt::Size GetSize2D(const Reference< XFastAttributeList > &xAttribs)
converts the attributes from a CT_Size2D into an awt Size with 1/100thmm
std::shared_ptr< Theme > ThemePtr
std::array< TextParagraphProperties, NUM_TEXT_LIST_STYLE_ENTRIES > TextParagraphPropertiesArray
std::shared_ptr< SlidePersist > SlidePersistPtr
std::shared_ptr< StorageBase > StorageRef
#define CREATE_MSOFFICE_RELATION_TYPE(ascii)
Expands to an OUString containing an MS Office specific relation type created from the passed literal...
Reference< XModel > xModel