summaryrefslogtreecommitdiffstats
path: root/oox
diff options
context:
space:
mode:
authorSarper Akdemir <sarper.akdemir@collabora.com>2021-04-25 15:59:39 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-06-23 23:31:17 +0200
commitd9b0f478294fc0694844978bb61047341d382bab (patch)
treeaf25f7e66cb3b3e73e9c9c39a66149e360765b8a /oox
parentcid#1486005 Uninitialized scalar field (diff)
downloadcore-d9b0f478294fc0694844978bb61047341d382bab.tar.gz
core-d9b0f478294fc0694844978bb61047341d382bab.zip
tdf#59323: pptx import: import footer fields as properties
Makes footer, slidenum and datetime placeholders that are inserted to the slides themselves on pptx files imported as slide properties if it is possible to do so without losing information (style, position etc.) If that is not the case and the footers have some special style applied to them that isn't inherited from master slides, fallbacks to the current implementation importing them as shapes. Also since the default way of displaying slide footers in LO use the respective text fields on master slides, information in master/layout slide datetime and footer placeholders respectively get replaced with <date/time> text fields and <footer> text fields. Change-Id: Ib2f7d18103b62c0c9a8453e01cfd2fd1aa1d39af Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117008 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117536 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/textbody.cxx1
-rw-r--r--oox/source/ppt/pptshape.cxx104
2 files changed, 105 insertions, 0 deletions
diff --git a/oox/source/drawingml/textbody.cxx b/oox/source/drawingml/textbody.cxx
index 9458f9de82ab..323d654ce971 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -37,6 +37,7 @@ TextBody::TextBody()
}
TextBody::TextBody( const TextBodyPtr& pBody )
+ : mbHasNoninheritedBodyProperties( false )
{
if( pBody.get() ) {
maTextProperties = pBody->maTextProperties;
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx
index 59d0e368620e..6620476d986c 100644
--- a/oox/source/ppt/pptshape.cxx
+++ b/oox/source/ppt/pptshape.cxx
@@ -20,8 +20,12 @@
#include <oox/ppt/pptshape.hxx>
#include <oox/core/xmlfilterbase.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>
@@ -86,6 +90,19 @@ static const char* lclDebugSubType( sal_Int32 nType )
return "unknown - please extend lclDebugSubType";
}
+namespace
+{
+bool ShapeHasNoVisualPropertiesOnImport(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;
@@ -179,6 +196,37 @@ void PPTShape::addShape(
}
break;
case XML_dt :
+ if ( meShapeLocation == Slide && !rSlidePersist.isNotesPage()
+ && getTextBody()->getParagraphs().size() == 1
+ && getTextBody()->getParagraphs().front()->getRuns().size() == 1
+ && ShapeHasNoVisualPropertiesOnImport(*this) )
+ {
+ 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;
@@ -187,10 +235,46 @@ void PPTShape::addShape(
bClearText = true;
break;
case XML_ftr :
+ if ( meShapeLocation == Slide && !rSlidePersist.isNotesPage()
+ && getTextBody()->getParagraphs().size() == 1
+ && getTextBody()->getParagraphs().front()->getRuns().size() == 1
+ && ShapeHasNoVisualPropertiesOnImport(*this) )
+ {
+ 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 (meShapeLocation == Slide && !rSlidePersist.isNotesPage()
+ && getTextBody()->getParagraphs().size() == 1
+ && getTextBody()->getParagraphs().front()->getRuns().size() == 1
+ && ShapeHasNoVisualPropertiesOnImport(*this))
+ {
+ 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;
@@ -409,6 +493,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())