[Libreoffice-commits] core.git: oox/inc oox/source sd/qa

Tamás Zolnai tamas.zolnai at collabora.com
Thu Nov 17 18:01:41 UTC 2016


 oox/inc/drawingml/textbody.hxx         |    8 ++++-
 oox/inc/drawingml/textparagraph.hxx    |    7 ++++
 oox/source/drawingml/textbody.cxx      |   34 +++++++++++++++++++++-
 oox/source/drawingml/textparagraph.cxx |   51 ++++++++++++++++++++++-----------
 oox/source/ppt/pptshape.cxx            |   11 +++++++
 sd/qa/unit/data/pptx/tdf103876.pptx    |binary
 sd/qa/unit/import-tests.cxx            |   21 +++++++++++++
 7 files changed, 113 insertions(+), 19 deletions(-)

New commits:
commit 5c7f3e4a7190bf9821bed102f96a926c9a894e59
Author: Tamás Zolnai <tamas.zolnai at collabora.com>
Date:   Tue Nov 15 23:18:03 2016 +0100

    tdf#103876: PPTX import: Title shape's character properties are wrong
    
    Text properties are applied on a shape during text insertion,
    but if a placeholder shape has no text, then it has a placehodler
    text which should have the right text properties.
    
    Change-Id: I54175d52dd25915ee4d7153298e01ec07c6be1f6
    Reviewed-on: https://gerrit.libreoffice.org/30881
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
    Tested-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/oox/inc/drawingml/textbody.hxx b/oox/inc/drawingml/textbody.hxx
index 5f8b053..0435297 100644
--- a/oox/inc/drawingml/textbody.hxx
+++ b/oox/inc/drawingml/textbody.hxx
@@ -59,7 +59,13 @@ public:
                             const css::uno::Reference < css::text::XTextCursor > & xAt,
                             const TextCharacterProperties& rTextStyleProperties,
                             const TextListStylePtr& pMasterTextListStyle ) const;
-    bool isEmpty();
+    bool isEmpty() const;
+
+    void                ApplyStyleEmpty(
+                            const ::oox::core::XmlFilterBase& rFilterBase,
+                            const css::uno::Reference < css::text::XText > & xText,
+                            const TextCharacterProperties& rTextStyleProperties,
+                            const TextListStylePtr& pMasterTextListStylePtr) const;
 protected:
     TextParagraphVector maParagraphs;
     TextBodyProperties  maTextProperties;
diff --git a/oox/inc/drawingml/textparagraph.hxx b/oox/inc/drawingml/textparagraph.hxx
index 8a02a67..337d507 100644
--- a/oox/inc/drawingml/textparagraph.hxx
+++ b/oox/inc/drawingml/textparagraph.hxx
@@ -53,6 +53,13 @@ public:
     TextCharacterProperties&         getEndProperties() { return maEndProperties; }
     const TextCharacterProperties&   getEndProperties() const { return maEndProperties; }
 
+    TextCharacterProperties          getCharacterStyle(
+        const TextCharacterProperties& rTextStyleProperties,
+        const TextListStyle& rTextListStyle) const;
+
+    TextParagraphPropertiesPtr      getParagraphStyle(
+        const TextListStyle& rTextListStyle) const;
+
     void                        insertAt(
                                     const ::oox::core::XmlFilterBase& rFilterBase,
                                     const css::uno::Reference < css::text::XText > & xText,
diff --git a/oox/source/drawingml/textbody.cxx b/oox/source/drawingml/textbody.cxx
index 3aa835e..662a52f 100644
--- a/oox/source/drawingml/textbody.cxx
+++ b/oox/source/drawingml/textbody.cxx
@@ -22,9 +22,11 @@
 #include <com/sun/star/text/XTextCursor.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include "drawingml/textparagraph.hxx"
+#include "oox/helper/propertyset.hxx"
 
 using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::text;
+using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::frame;
 
 namespace oox { namespace drawingml {
@@ -69,7 +71,7 @@ void TextBody::insertAt(
         (*aIt)->insertAt( rFilterBase, xText, xAt, rTextStyleProperties, aCombinedTextStyle, aIt == aBeg, nCharHeight );
 }
 
-bool TextBody::isEmpty()
+bool TextBody::isEmpty() const
 {
     if ( maParagraphs.size() <= 0 )
         return true;
@@ -85,6 +87,36 @@ bool TextBody::isEmpty()
     return aRuns[0]->getText().getLength() <= 0;
 }
 
+void TextBody::ApplyStyleEmpty(
+    const ::oox::core::XmlFilterBase& rFilterBase,
+    const Reference < XText > & xText,
+    const TextCharacterProperties& rTextStyleProperties,
+    const TextListStylePtr& pMasterTextListStylePtr) const
+{
+    assert(isEmpty());
+
+    // Apply character properties
+    TextListStyle aCombinedTextStyle;
+    aCombinedTextStyle.apply( *pMasterTextListStylePtr );
+    aCombinedTextStyle.apply( maTextListStyle );
+
+    PropertySet aPropSet(xText);
+    TextCharacterProperties aTextCharacterProps(maParagraphs[0]->getCharacterStyle(rTextStyleProperties, aCombinedTextStyle));
+    aTextCharacterProps.pushToPropSet(aPropSet, rFilterBase);
+
+    // Apply paragraph properties
+    TextParagraphPropertiesPtr pTextParagraphStyle = maParagraphs[0]->getParagraphStyle(aCombinedTextStyle);
+    if (pTextParagraphStyle.get())
+    {
+        Reference< XPropertySet > xProps(xText, UNO_QUERY);
+        PropertyMap aioBulletList;
+        float nCharHeight = xProps->getPropertyValue("CharHeight").get<float>();
+        TextParagraphProperties aParaProp;
+        aParaProp.apply(*pTextParagraphStyle);
+        aParaProp.pushToPropSet(&rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), false, nCharHeight, true);
+    }
+}
+
 } }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx
index 24879f1..444832b 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -44,6 +44,37 @@ TextParagraph::~TextParagraph()
 {
 }
 
+TextCharacterProperties TextParagraph::getCharacterStyle (
+    const TextCharacterProperties& rTextStyleProperties,
+    const TextListStyle& rTextListStyle) const
+{
+    TextParagraphPropertiesPtr pTextParagraphStyle = getParagraphStyle(rTextListStyle);
+
+    TextCharacterProperties aTextCharacterStyle;
+    if (pTextParagraphStyle.get())
+        aTextCharacterStyle.assignUsed(pTextParagraphStyle->getTextCharacterProperties());
+    aTextCharacterStyle.assignUsed(rTextStyleProperties);
+    aTextCharacterStyle.assignUsed(maProperties.getTextCharacterProperties());
+    return aTextCharacterStyle;
+}
+
+TextParagraphPropertiesPtr TextParagraph::getParagraphStyle(
+    const TextListStyle& rTextListStyle) const
+{
+    sal_Int16 nLevel = maProperties.getLevel();
+
+    SAL_INFO("oox", "TextParagraph::getParagraphStyle - level " << nLevel);
+
+    const TextParagraphPropertiesVector& rListStyle = rTextListStyle.getListStyle();
+    if (nLevel >= static_cast< sal_Int16 >(rListStyle.size()))
+        nLevel = 0;
+    TextParagraphPropertiesPtr pTextParagraphStyle = nullptr;
+    if (rListStyle.size())
+        pTextParagraphStyle = rListStyle[nLevel];
+
+    return pTextParagraphStyle;
+}
+
 void TextParagraph::insertAt(
         const ::oox::core::XmlFilterBase& rFilterBase,
         const Reference < XText > &xText,
@@ -53,23 +84,7 @@ void TextParagraph::insertAt(
 {
     try {
         sal_Int32 nParagraphSize = 0;
-
-        sal_Int16 nLevel = maProperties.getLevel();
-
-        SAL_INFO("oox", "TextParagraph::insertAt() - level " << nLevel);
-
-        const TextParagraphPropertiesVector& rListStyle = rTextListStyle.getListStyle();
-        if ( nLevel >= static_cast< sal_Int16 >( rListStyle.size() ) )
-            nLevel = 0;
-        TextParagraphPropertiesPtr pTextParagraphStyle;
-        if ( rListStyle.size() )
-            pTextParagraphStyle = rListStyle[ nLevel ];
-
-        TextCharacterProperties aTextCharacterStyle;
-        if ( pTextParagraphStyle.get() )
-            aTextCharacterStyle.assignUsed( pTextParagraphStyle->getTextCharacterProperties() );
-        aTextCharacterStyle.assignUsed( rTextStyleProperties );
-        aTextCharacterStyle.assignUsed( maProperties.getTextCharacterProperties() );
+        TextCharacterProperties aTextCharacterStyle = getCharacterStyle(rTextStyleProperties, rTextListStyle);
 
         if( !bFirst )
         {
@@ -105,6 +120,8 @@ void TextParagraph::insertAt(
 
         PropertyMap aioBulletList;
         Reference< XPropertySet > xProps( xAt, UNO_QUERY);
+
+        TextParagraphPropertiesPtr pTextParagraphStyle = getParagraphStyle(rTextListStyle);
         if ( pTextParagraphStyle.get() )
         {
             TextParagraphProperties aParaProp;
diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx
index 18a2565..08e2df8 100644
--- a/oox/source/ppt/pptshape.cxx
+++ b/oox/source/ppt/pptshape.cxx
@@ -350,6 +350,17 @@ void PPTShape::addShape(
 
                 }
             }
+
+            // Apply text properties on placeholder text inside this placeholder shape
+            if (mpPlaceholder.get() != nullptr && getTextBody() && getTextBody()->isEmpty())
+            {
+                Reference < XText > xText(mxShape, UNO_QUERY);
+                if (xText.is())
+                {
+                    TextCharacterProperties aCharStyleProperties;
+                    getTextBody()->ApplyStyleEmpty(rFilterBase, xText, aCharStyleProperties, mpMasterTextListStyle);
+                }
+            }
             if (pShapeMap)
             {
                 // bnc#705982 - if optional model id reference is
diff --git a/sd/qa/unit/data/pptx/tdf103876.pptx b/sd/qa/unit/data/pptx/tdf103876.pptx
new file mode 100755
index 0000000..5eb7e86
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf103876.pptx differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index a4d6dbe..f9f40cc 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -128,6 +128,7 @@ public:
     void testTdf49561();
     void testTdf103473();
     void testTdf103792();
+    void testTdf103876();
 
     CPPUNIT_TEST_SUITE(SdImportTest);
 
@@ -181,6 +182,7 @@ public:
     CPPUNIT_TEST(testTdf49561);
     CPPUNIT_TEST(testTdf103473);
     CPPUNIT_TEST(testTdf103792);
+    CPPUNIT_TEST(testTdf103876);
 
     CPPUNIT_TEST_SUITE_END();
 };
@@ -1524,6 +1526,25 @@ void SdImportTest::testTdf103792()
     xDocShRef->DoClose();
 }
 
+void SdImportTest::testTdf103876()
+{
+    // Title text shape's placeholder text did not inherit the corresponding text properties
+    sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf103876.pptx"), PPTX);
+    uno::Reference< beans::XPropertySet > xShape( getShapeFromPage( 0, 0, xDocShRef ) );
+
+    // Check paragraph alignment
+    sal_Int16 nParaAdjust = 0;
+    xShape->getPropertyValue( "ParaAdjust" ) >>= nParaAdjust;
+    CPPUNIT_ASSERT_EQUAL(style::ParagraphAdjust_CENTER, static_cast<style::ParagraphAdjust>(nParaAdjust));
+
+    // Check character color
+    sal_Int32 nCharColor;
+    xShape->getPropertyValue( "CharColor" ) >>= nCharColor;
+    CPPUNIT_ASSERT_EQUAL( sal_Int32(0xFF0000), nCharColor );
+
+    xDocShRef->DoClose();
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list