[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - 2 commits - chart2/qa include/oox oox/source sd/qa

Sarper Akdemir (via logerrit) logerrit at kemper.freedesktop.org
Wed Jun 23 09:50:50 UTC 2021


 chart2/qa/extras/chart2import.cxx        |    4 -
 chart2/qa/extras/xshape/chart2xshape.cxx |    2 
 include/oox/export/drawingml.hxx         |   18 +++++
 oox/source/drawingml/textbody.cxx        |    1 
 oox/source/export/drawingml.cxx          |  108 ++++++++++++++++++++++---------
 oox/source/ppt/pptshape.cxx              |  104 +++++++++++++++++++++++++++++
 sd/qa/unit/data/pptx/numfmt.pptx         |binary
 sd/qa/unit/data/pptx/slidenum_field.pptx |binary
 sd/qa/unit/import-tests.cxx              |    2 
 9 files changed, 206 insertions(+), 33 deletions(-)

New commits:
commit f9b931e3bd56320b293551c2b51cfd09f787ad01
Author:     Sarper Akdemir <sarper.akdemir at collabora.com>
AuthorDate: Wed Jun 9 07:34:32 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 23 11:50:30 2021 +0200

    tdf#59323: pptx export: add datetime field type helpers
    
    Creates helper functions to convert from LO time and date formats to datetime
    fields on OOXML
    
    Change-Id: Ibbfefa18d0422eddb6c37539294ed23e77fe5f22
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117009
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117627
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index 00049fd94103..f48228633baf 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -45,6 +45,8 @@
 
 class Graphic;
 class SdrObjCustomShape;
+enum class SvxDateFormat;
+enum class SvxTimeFormat;
 
 namespace com::sun::star {
 namespace awt {
@@ -161,6 +163,22 @@ protected:
                   const css::uno::Reference< css::beans::XPropertyState >& rXPropState,
                   const OUString& aName, css::beans::PropertyState& eState );
     OUString GetFieldValue( const css::uno::Reference< css::text::XTextRange >& rRun, bool& bIsURLField );
+    /** Gets OOXML datetime field type from LO Date format
+
+        @param eDate LO Date format
+    */
+    static OUString GetDatetimeTypeFromDate(SvxDateFormat eDate);
+    /** Gets OOXML datetime field type from LO Time format
+
+        @param eTime LO Time format
+    */
+    static OUString GetDatetimeTypeFromTime(SvxTimeFormat eTime);
+    /** Gets OOXML datetime field type from combination of LO Time and Date formats
+
+        @param eDate LO Date format
+        @param eTime LO Time format
+    */
+    static OUString GetDatetimeTypeFromDateTime(SvxDateFormat eDate, SvxTimeFormat eTime);
 
     /// Output the media (including copying a video from vnd.sun.star.Package: to the output if necessary).
     void WriteMediaNonVisualProperties(const css::uno::Reference<css::drawing::XShape>& xShape);
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 263cd5c06b67..bb84716a3a39 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -2213,40 +2213,13 @@ OUString DrawingML::GetFieldValue( const css::uno::Reference< css::text::XTextRa
                 {
                     sal_Int32 nNumFmt = -1;
                     rXPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt;
-                    switch(static_cast<SvxDateFormat>(nNumFmt))
-                    {
-                        case SvxDateFormat::StdSmall:
-                        case SvxDateFormat::A: aFieldValue = "datetime"; // 13/02/96
-                                              break;
-                        case SvxDateFormat::B: aFieldValue = "datetime1"; // 13/02/1996
-                                              break;
-                        case SvxDateFormat::StdBig:
-                        case SvxDateFormat::D: aFieldValue = "datetime3"; // 13 February 1996
-                                              break;
-                        default: break;
-                    }
+                    aFieldValue = GetDatetimeTypeFromDate(static_cast<SvxDateFormat>(nNumFmt));
                 }
                 else if(aFieldKind == "ExtTime")
                 {
                     sal_Int32 nNumFmt = -1;
                     rXPropSet->getPropertyValue(UNO_TC_PROP_NUMFORMAT) >>= nNumFmt;
-                    switch(static_cast<SvxTimeFormat>(nNumFmt))
-                    {
-                        case SvxTimeFormat::Standard:
-                        case SvxTimeFormat::HH24_MM_SS:
-                            aFieldValue = "datetime11"; // 13:49:38
-                            break;
-                        case SvxTimeFormat::HH24_MM:
-                            aFieldValue = "datetime10"; // 13:49
-                            break;
-                        case SvxTimeFormat::HH12_MM:
-                            aFieldValue = "datetime12"; // 01:49 PM
-                            break;
-                        case SvxTimeFormat::HH12_MM_SS:
-                            aFieldValue = "datetime13"; // 01:49:38 PM
-                            break;
-                        default: break;
-                    }
+                    aFieldValue = GetDatetimeTypeFromTime(static_cast<SvxTimeFormat>(nNumFmt));
                 }
                 else if(aFieldKind == "ExtFile")
                 {
@@ -2273,6 +2246,83 @@ OUString DrawingML::GetFieldValue( const css::uno::Reference< css::text::XTextRa
     return aFieldValue;
 }
 
+OUString DrawingML::GetDatetimeTypeFromDate(SvxDateFormat eDate)
+{
+    return GetDatetimeTypeFromDateTime(eDate, SvxTimeFormat::AppDefault);
+}
+
+OUString DrawingML::GetDatetimeTypeFromTime(SvxTimeFormat eTime)
+{
+    return GetDatetimeTypeFromDateTime(SvxDateFormat::AppDefault, eTime);
+}
+
+OUString DrawingML::GetDatetimeTypeFromDateTime(SvxDateFormat eDate, SvxTimeFormat eTime)
+{
+    OUString aDateField;
+    switch (eDate)
+    {
+        case SvxDateFormat::StdSmall:
+        case SvxDateFormat::A:
+            aDateField = "datetime";
+            break;
+        case SvxDateFormat::B:
+            aDateField = "datetime1"; // 13/02/1996
+            break;
+        case SvxDateFormat::StdBig:
+        case SvxDateFormat::C:
+        case SvxDateFormat::D:
+            aDateField = "datetime3"; // 13 February 1996
+            break;
+        case SvxDateFormat::E:
+        case SvxDateFormat::F:
+            aDateField = "datetime2";
+            break;
+        default:
+            break;
+    }
+
+    OUString aTimeField;
+    switch (eTime)
+    {
+        case SvxTimeFormat::Standard:
+        case SvxTimeFormat::HH24_MM_SS:
+        case SvxTimeFormat::HH24_MM_SS_00:
+            aTimeField = "datetime11"; // 13:49:38
+            break;
+        case SvxTimeFormat::HH24_MM:
+            aTimeField = "datetime10"; // 13:49
+            break;
+        case SvxTimeFormat::HH12_MM:
+        case SvxTimeFormat::HH12_MM_AMPM:
+            aTimeField = "datetime12"; // 01:49 PM
+            break;
+        case SvxTimeFormat::HH12_MM_SS:
+        case SvxTimeFormat::HH12_MM_SS_AMPM:
+        case SvxTimeFormat::HH12_MM_SS_00:
+        case SvxTimeFormat::HH12_MM_SS_00_AMPM:
+            aTimeField = "datetime13"; // 01:49:38 PM
+            break;
+        default:
+            break;
+    }
+
+    if (!aDateField.isEmpty() && aTimeField.isEmpty())
+        return aDateField;
+    else if (!aTimeField.isEmpty() && aDateField.isEmpty())
+        return aTimeField;
+    else if (!aDateField.isEmpty() && !aTimeField.isEmpty())
+    {
+        if (aTimeField == "datetime11" || aTimeField == "datetime13")
+            // only datetime format that has Date and HH:MM:SS
+            return "datetime9"; // dd/mm/yyyy H:MM:SS
+        else
+            // only datetime format that has Date and HH:MM
+            return "datetime8"; // dd/mm/yyyy H:MM
+    }
+    else
+        return "";
+}
+
 void DrawingML::WriteRun( const Reference< XTextRange >& rRun,
                           bool& rbOverridingCharHeight, sal_Int32& rnCharHeight,
                           const css::uno::Reference< css::beans::XPropertySet >& rXShapePropSet)
commit 6c9c2ab6437ca28e8deea4ae492bb429165aa243
Author:     Sarper Akdemir <sarper.akdemir at collabora.com>
AuthorDate: Sun Apr 25 15:59:39 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Wed Jun 23 11:50:15 2021 +0200

    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 at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117626
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx
index b3b5a3921d3a..4b7d2fadb88b 100644
--- a/chart2/qa/extras/chart2import.cxx
+++ b/chart2/qa/extras/chart2import.cxx
@@ -821,7 +821,7 @@ void Chart2ImportTest::testBnc864396()
 void Chart2ImportTest::testBnc889755()
 {
     load("/chart2/qa/extras/data/pptx/", "bnc889755.pptx");
-    uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 6), uno::UNO_QUERY_THROW);
+    uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 5), uno::UNO_QUERY_THROW);
     CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider());
 
     uno::Reference< chart2::XInternalDataProvider > xDataProvider( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW );
@@ -849,7 +849,7 @@ void Chart2ImportTest::testBnc889755()
     uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW);
     uno::Reference<drawing::XDrawPage> xPage(xDoc->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW);
     // Shape "Title 3"
-    uno::Reference<beans::XPropertySet> xShapeProps(xPage->getByIndex(5), uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet> xShapeProps(xPage->getByIndex(4), uno::UNO_QUERY_THROW);
     awt::Gradient aTransparence;
     xShapeProps->getPropertyValue("FillTransparenceGradient") >>= aTransparence;
     CPPUNIT_ASSERT(aTransparence.StartColor != aTransparence.EndColor);
diff --git a/chart2/qa/extras/xshape/chart2xshape.cxx b/chart2/qa/extras/xshape/chart2xshape.cxx
index 68dcc1e7e030..bf820fcfd2bf 100644
--- a/chart2/qa/extras/xshape/chart2xshape.cxx
+++ b/chart2/qa/extras/xshape/chart2xshape.cxx
@@ -182,7 +182,7 @@ void Chart2XShapeTest::testTdf76649TrendLineBug()
 void Chart2XShapeTest::testTdf88154LabelRotatedLayout()
 {
     load("chart2/qa/extras/xshape/data/pptx/", "tdf88154_LabelRotatedLayout.pptx");
-    uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 6);
+    uno::Reference<chart::XChartDocument> xChartDoc = getChartDocFromDrawImpress(0, 5);
     uno::Reference<qa::XDumper> xDumper(xChartDoc, UNO_QUERY_THROW);
     OUString rDump = xDumper->dump();
     OString aXmlDump = OUStringToOString(rDump, RTL_TEXTENCODING_UTF8);
diff --git a/oox/source/drawingml/textbody.cxx b/oox/source/drawingml/textbody.cxx
index a419a41d0d83..0d44b81631d5 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -35,6 +35,7 @@ TextBody::TextBody()
 }
 
 TextBody::TextBody( const TextBodyPtr& pBody )
+    : mbHasNoninheritedBodyProperties( false )
 {
     if( pBody ) {
         maTextProperties = pBody->maTextProperties;
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx
index bd47dd0fae7a..5f21f7c459c9 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/container/XNamed.hpp>
 #include <com/sun/star/frame/XModel.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -84,6 +88,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;
@@ -176,6 +193,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;
@@ -184,10 +232,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;
@@ -376,6 +460,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())
diff --git a/sd/qa/unit/data/pptx/numfmt.pptx b/sd/qa/unit/data/pptx/numfmt.pptx
index aca6927101d6..e5f0f5cf151a 100644
Binary files a/sd/qa/unit/data/pptx/numfmt.pptx and b/sd/qa/unit/data/pptx/numfmt.pptx differ
diff --git a/sd/qa/unit/data/pptx/slidenum_field.pptx b/sd/qa/unit/data/pptx/slidenum_field.pptx
index f3c184056905..3388568831d7 100644
Binary files a/sd/qa/unit/data/pptx/slidenum_field.pptx and b/sd/qa/unit/data/pptx/slidenum_field.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index 5e09f0a2996f..f06af50d5110 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -1822,7 +1822,7 @@ void SdImportTest::testTdf95932()
     sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf95932.pptx"), PPTX);
 
     const SdrPage *pPage = GetPage( 1, xDocShRef );
-    SdrObject *const pObj = pPage->GetObj(2);
+    SdrObject *const pObj = pPage->GetObj(1);
     CPPUNIT_ASSERT(pObj);
 
     const XFillStyleItem& rStyleItem = dynamic_cast<const XFillStyleItem&>(


More information about the Libreoffice-commits mailing list