sw/qa/extras/ooxmlimport/data/caption.docx      |binary
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx        |    7 ++++++
 writerfilter/source/dmapper/StyleSheetTable.cxx |   28 ++++++++++++++++++++++++
 3 files changed, 35 insertions(+)

New commits:
commit c12a78e42e1cbaaf4ea021c82acbec5ea177b1f6
Author: Miklos Vajna <vmik...@collabora.co.uk>
Date:   Wed Jun 4 12:19:46 2014 +0200

    writerfilter: reset properties of reused styles
    
    When we have a style to import and the name is already taken, we reuse
    the style (we can't use replaceByName(), it only works with user-defined
    styles). If that happens, reset non-default properties of it, so the
    result will be what was in the file, not a merge of Writer defaults and
    what was in the file.
    
    Change-Id: Ifb1098f78254a061b11fd6c6d2a2fa8d85a00d60

diff --git a/sw/qa/extras/ooxmlimport/data/caption.docx 
b/sw/qa/extras/ooxmlimport/data/caption.docx
new file mode 100644
index 0000000..301472c
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/caption.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx 
b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index fe9c686..b9ecb55 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -2164,6 +2164,13 @@ DECLARE_OOXMLIMPORT_TEST(testBnc875718, "bnc875718.docx")
     CPPUNIT_ASSERT_EQUAL( OUString( "Text\n" ), text->getString());
 }
 
+DECLARE_OOXMLIMPORT_TEST(testCaption, "caption.docx")
+{
+    uno::Reference<beans::XPropertySet> 
xStyle(getStyles("ParagraphStyles")->getByName("Caption"), uno::UNO_QUERY);
+    // This was awt::FontSlant_ITALIC: Writer default was used instead of what 
is in the document.
+    CPPUNIT_ASSERT_EQUAL(awt::FontSlant_NONE, 
getProperty<awt::FontSlant>(xStyle, "CharPosture"));
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx 
b/writerfilter/source/dmapper/StyleSheetTable.cxx
index a8da876..3ff8e59 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -41,6 +41,7 @@
 #include <stdio.h>
 #include <rtl/ustrbuf.hxx>
 #include <comphelper/string.hxx>
+#include <comphelper/sequenceasvector.hxx>
 
 #include <dmapperLoggers.hxx>
 
@@ -938,6 +939,33 @@ void StyleSheetTable::ApplyStyleSheets( FontTablePtr 
rFontTable )
                             continue;
                         }
                         xStyles->getByName( sConvertedStyleName ) >>= xStyle;
+
+                        // See if the existing style has any non-default 
properties. If so, reset them back to default.
+                        uno::Reference<beans::XPropertySet> 
xPropertySet(xStyle, uno::UNO_QUERY);
+                        uno::Reference<beans::XPropertySetInfo> 
xPropertySetInfo = xPropertySet->getPropertySetInfo();
+                        uno::Sequence<beans::Property> aProperties = 
xPropertySetInfo->getProperties();
+                        comphelper::SequenceAsVector<OUString> aPropertyNames;
+                        for (sal_Int32 i = 0; i < aProperties.getLength(); ++i)
+                        {
+                            aPropertyNames.push_back(aProperties[i].Name);
+                        }
+
+                        uno::Reference<beans::XPropertyState> 
xPropertyState(xStyle, uno::UNO_QUERY);
+                        uno::Sequence<beans::PropertyState> aStates = 
xPropertyState->getPropertyStates(aPropertyNames.getAsConstList());
+                        for (sal_Int32 i = 0; i < aStates.getLength(); ++i)
+                        {
+                            if (aStates[i] == 
beans::PropertyState_DIRECT_VALUE)
+                            {
+                                try
+                                {
+                                    
xPropertyState->setPropertyToDefault(aPropertyNames[i]);
+                                }
+                                catch(const uno::Exception& rException)
+                                {
+                                    SAL_INFO("writerfilter", 
"setPropertyToDefault(" << aPropertyNames[i] << ") failed: " << 
rException.Message);
+                                }
+                            }
+                        }
                     }
                     else
                     {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to