diff options
Diffstat (limited to 'oox/source/ppt/pptshape.cxx')
-rw-r--r-- | oox/source/ppt/pptshape.cxx | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index 71b94c727132..6208a7107f23 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -19,9 +19,14 @@ #include <oox/ppt/pptshape.hxx> #include <oox/core/xmlfilterbase.hxx> +#include <drawingml/customshapeproperties.hxx> #include <drawingml/textbody.hxx> +#include <drawingml/textparagraph.hxx> +#include <drawingml/textfield.hxx> #include <drawingml/table/tableproperties.hxx> +#include <editeng/flditem.hxx> +#include <com/sun/star/text/XTextField.hpp> #include <com/sun/star/awt/Rectangle.hpp> #include <com/sun/star/container/XNamed.hpp> #include <com/sun/star/beans/XMultiPropertySet.hpp> @@ -50,6 +55,7 @@ PPTShape::PPTShape( const oox::ppt::ShapeLocation eShapeLocation, const sal_Char : Shape( pServiceName ) , meShapeLocation( eShapeLocation ) , mbReferenced( false ) +, mbHasNoninheritedShapeProperties( false ) { } @@ -85,6 +91,19 @@ static const char* lclDebugSubType( sal_Int32 nType ) return "unknown - please extend lclDebugSubType"; } +namespace +{ +bool ShapeHasNoVisualPropertiesOnImport(const oox::ppt::PPTShape& rPPTShape) +{ + return !rPPTShape.hasNonInheritedShapeProperties() + && !rPPTShape.hasShapeStyleRefs() + && !rPPTShape.getTextBody()->hasVisualRunProperties() + && !rPPTShape.getTextBody()->hasNoninheritedBodyProperties() + && !rPPTShape.getTextBody()->hasListStyleOnImport() + && !rPPTShape.getTextBody()->hasParagraphProperties(); +} +} + oox::drawingml::TextListStylePtr PPTShape::getSubTypeTextListStyle( const SlidePersist& rSlidePersist, sal_Int32 nSubType ) { oox::drawingml::TextListStylePtr pTextListStyle; @@ -110,6 +129,27 @@ oox::drawingml::TextListStylePtr PPTShape::getSubTypeTextListStyle( const SlideP return pTextListStyle; } +bool PPTShape::IsPlaceHolderCandidate(const SlidePersist& rSlidePersist) const +{ + if (meShapeLocation != Slide) + return false; + if (rSlidePersist.isNotesPage()) + return false; + auto pTextBody = getTextBody(); + if (!pTextBody) + return false; + auto rParagraphs = pTextBody->getParagraphs(); + if (rParagraphs.size() != 1) + return false; + if (rParagraphs.front()->getRuns().size() != 1) + return false; + // If the placeholder has a shape other than rectangle, + // we have to place it in the slide as a CustomShape. + if (!mpCustomShapePropertiesPtr->representsDefaultShape()) + return false; + return ShapeHasNoVisualPropertiesOnImport(*this); +} + void PPTShape::addShape( oox::core::XmlFilterBase& rFilterBase, const SlidePersist& rSlidePersist, @@ -178,6 +218,34 @@ void PPTShape::addShape( } break; case XML_dt : + if (IsPlaceHolderCandidate(rSlidePersist)) + { + TextRunPtr& pTextRun = getTextBody()->getParagraphs().front()->getRuns().front(); + oox::drawingml::TextField* pTextField = dynamic_cast<oox::drawingml::TextField*>(pTextRun.get()); + if (pTextField) + { + OUString aType = pTextField->getType(); + if ( aType.startsWith("datetime") ) + { + SvxDateFormat eDateFormat = drawingml::TextField::getLODateFormat(aType); + SvxTimeFormat eTimeFormat = drawingml::TextField::getLOTimeFormat(aType); + Reference< XPropertySet > xPropertySet( rSlidePersist.getPage(), UNO_QUERY ); + + if( eDateFormat != SvxDateFormat::AppDefault + || eTimeFormat != SvxTimeFormat::AppDefault ) + { + // DateTimeFormat property looks for the date in 4 LSBs + // and looks for time format in the 4 bits after that + sal_Int32 nDateTimeFormat = static_cast<sal_Int32>(eDateFormat) | + static_cast<sal_Int32>(eTimeFormat) << 4; + xPropertySet->setPropertyValue( "IsDateTimeVisible", Any(true) ); + xPropertySet->setPropertyValue( "IsDateTimeFixed", Any(false) ); + xPropertySet->setPropertyValue( "DateTimeFormat", Any(nDateTimeFormat) ); + return; + } + } + } + } sServiceName = "com.sun.star.presentation.DateTimeShape"; bClearText = true; break; @@ -186,10 +254,40 @@ void PPTShape::addShape( bClearText = true; break; case XML_ftr : + if (IsPlaceHolderCandidate(rSlidePersist)) + { + const OUString& rFooterText = getTextBody()->toString(); + + if( !rFooterText.isEmpty() ) + { + // if it is possible to get the footer as a property the LO way, + // get it and discard the shape + Reference< XPropertySet > xPropertySet( rSlidePersist.getPage(), UNO_QUERY ); + xPropertySet->setPropertyValue( "IsFooterVisible", Any( true ) ); + xPropertySet->setPropertyValue( "FooterText", Any(rFooterText) ); + return; + } + } sServiceName = "com.sun.star.presentation.FooterShape"; bClearText = true; break; case XML_sldNum : + if (IsPlaceHolderCandidate(rSlidePersist)) + { + TextRunPtr& pTextRun + = getTextBody()->getParagraphs().front()->getRuns().front(); + oox::drawingml::TextField* pTextField + = dynamic_cast<oox::drawingml::TextField*>(pTextRun.get()); + if (pTextField && pTextField->getType() == "slidenum") + { + // if it is possible to get the slidenum placeholder as a property + // do that and discard the shape + Reference<XPropertySet> xPropertySet(rSlidePersist.getPage(), + UNO_QUERY); + xPropertySet->setPropertyValue("IsPageNumberVisible", Any(true)); + return; + } + } sServiceName = "com.sun.star.presentation.SlideNumberShape"; bClearText = true; break; @@ -227,6 +325,16 @@ void PPTShape::addShape( } } + // Since it is not possible to represent custom shaped placeholders in Impress + // Need to use service name css.drawing.CustomShape if they have a non default shape. + // This workaround has the drawback of them not really being processed as placeholders + // so it is only done for slide footers... + if ((mnSubType == XML_sldNum || mnSubType == XML_dt || mnSubType == XML_ftr) + && meShapeLocation == Slide && !mpCustomShapePropertiesPtr->representsDefaultShape()) + { + sServiceName = "com.sun.star.drawing.CustomShape"; + } + if (sServiceName != "com.sun.star.drawing.TableShape") { if (TextBodyPtr pTextBody = getTextBody()) @@ -408,6 +516,26 @@ void PPTShape::addShape( } } + // we will be losing whatever information there is in the footer placeholder on master/layout slides + // since they should have the "<footer>" textfield in them in order to make LibreOffice process them as expected + // likewise DateTime placeholder data on master/layout slides will be lost and replaced + if( (mnSubType == XML_ftr || mnSubType == XML_dt) && meShapeLocation != Slide ) + { + OUString aFieldType; + if( mnSubType == XML_ftr ) + aFieldType = "com.sun.star.presentation.TextField.Footer"; + else + aFieldType = "com.sun.star.presentation.TextField.DateTime"; + Reference < XTextField > xField( xServiceFact->createInstance( aFieldType ), UNO_QUERY ); + Reference < XText > xText(mxShape, UNO_QUERY); + if(xText.is()) + { + xText->setString(""); + Reference < XTextCursor > xTextCursor = xText->createTextCursor(); + xText->insertTextContent( xTextCursor, xField, false); + } + } + // if this is a group shape, we have to add also each child shape Reference<XShapes> xShapes(xShape, UNO_QUERY); if (xShapes.is()) |