[Libreoffice-commits] core.git: sw/qa writerfilter/source

Miklos Vajna vmiklos at suse.cz
Tue Jun 4 03:42:45 PDT 2013


 sw/qa/extras/rtfimport/data/fdo62044-paste.rtf    |    7 +++++++
 sw/qa/extras/rtfimport/data/fdo62044.rtf          |    7 +++++++
 sw/qa/extras/rtfimport/rtfimport.cxx              |   14 ++++++++++++++
 writerfilter/source/dmapper/DomainMapper_Impl.hxx |    2 +-
 writerfilter/source/dmapper/StyleSheetTable.cxx   |   15 +++++++++------
 writerfilter/source/dmapper/StyleSheetTable.hxx   |    2 +-
 6 files changed, 39 insertions(+), 8 deletions(-)

New commits:
commit 2ade07126971b79c92f729fae5709f2e2e2b495c
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Tue Jun 4 12:21:11 2013 +0200

    fdo#62044 RTF import: don't overwrite existing styles when pasting
    
    Change-Id: I80a83caebc8fa3f038cf2ff080c6c6ec8e93fb70

diff --git a/sw/qa/extras/rtfimport/data/fdo62044-paste.rtf b/sw/qa/extras/rtfimport/data/fdo62044-paste.rtf
new file mode 100644
index 0000000..cea4373
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/fdo62044-paste.rtf
@@ -0,0 +1,7 @@
+{\rtf
+{\stylesheet
+{\s14\fs36 Heading1;}
+}
+from impress
+\par
+}
diff --git a/sw/qa/extras/rtfimport/data/fdo62044.rtf b/sw/qa/extras/rtfimport/data/fdo62044.rtf
new file mode 100644
index 0000000..8ab293b
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/fdo62044.rtf
@@ -0,0 +1,7 @@
+{\rtf1
+{\stylesheet
+{\s1\fs20 Heading 1;}
+}
+\s1 this is heading 1
+\par
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index bb0b014..d39ff51 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -138,6 +138,7 @@ public:
     void testN818997();
     void testFdo64671();
     void testPageBackground();
+    void testFdo62044();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -265,6 +266,7 @@ void Test::run()
         {"n818997.rtf", &Test::testN818997},
         {"fdo64671.rtf", &Test::testFdo64671},
         {"page-background.rtf", &Test::testPageBackground},
+        {"fdo62044.rtf", &Test::testFdo62044},
     };
     header();
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1257,6 +1259,18 @@ void Test::testPageBackground()
     CPPUNIT_ASSERT_EQUAL(sal_Int32(0x92D050), getProperty<sal_Int32>(xPageStyle, "BackColor"));
 }
 
+void Test::testFdo62044()
+{
+    // The problem was that RTF import during copy&paste did not ignore existing paragraph styles.
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xText(xTextDocument->getText(), uno::UNO_QUERY);
+    uno::Reference<text::XTextRange> xEnd = xText->getEnd();
+    paste("fdo62044-paste.rtf", xEnd);
+
+    uno::Reference<beans::XPropertySet> xPropertySet(getStyles("ParagraphStyles")->getByName("Heading 1"), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(10.f, getProperty<float>(xPropertySet, "CharHeight")); // Was 18, i.e. reset back to original value.
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index dc7f2dd..f88f494 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -481,7 +481,7 @@ public:
     StyleSheetTablePtr GetStyleSheetTable()
     {
         if(!m_pStyleSheetTable)
-            m_pStyleSheetTable.reset(new StyleSheetTable( m_rDMapper, m_xTextDocument ));
+            m_pStyleSheetTable.reset(new StyleSheetTable( m_rDMapper, m_xTextDocument, m_bIsNewDoc ));
         return m_pStyleSheetTable;
     }
     ListsManager::Pointer GetListTable();
diff --git a/writerfilter/source/dmapper/StyleSheetTable.cxx b/writerfilter/source/dmapper/StyleSheetTable.cxx
index e3dac30..74adb0b 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -275,19 +275,21 @@ struct StyleSheetTable_Impl
     PropertyMapPtr                          m_pCurrentProps;
     StringPairMap_t                         m_aStyleNameMap;
     ListCharStylePropertyVector_t           m_aListCharStylePropertyVector;
+    bool                                    m_bIsNewDoc;
 
-    StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument);
+    StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc);
 
     OUString HasListCharStyle( const PropertyValueVector_t& rCharProperties );
 };
 
 
-StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument ) :
+StyleSheetTable_Impl::StyleSheetTable_Impl(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc ) :
             m_rDMapper( rDMapper ),
             m_xTextDocument( xTextDocument ),
             m_pCurrentEntry(),
             m_pDefaultParaProps(new PropertyMap),
-            m_pDefaultCharProps(new PropertyMap)
+            m_pDefaultCharProps(new PropertyMap),
+            m_bIsNewDoc(bIsNewDoc)
 {
     //set font height default to 10pt
     uno::Any aVal = uno::makeAny( double(10.) );
@@ -342,10 +344,10 @@ OUString StyleSheetTable_Impl::HasListCharStyle( const PropertyValueVector_t& rP
 }
 
 
-StyleSheetTable::StyleSheetTable(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument)
+StyleSheetTable::StyleSheetTable(DomainMapper& rDMapper, uno::Reference< text::XTextDocument> xTextDocument, bool bIsNewDoc)
 : LoggedProperties(dmapper_logger, "StyleSheetTable")
 , LoggedTable(dmapper_logger, "StyleSheetTable")
-, m_pImpl( new StyleSheetTable_Impl(rDMapper, xTextDocument) )
+, m_pImpl( new StyleSheetTable_Impl(rDMapper, xTextDocument, bIsNewDoc) )
 {
 }
 
@@ -722,7 +724,8 @@ void StyleSheetTable::ApplyStyleSheets( FontTablePtr rFontTable )
                     uno::Reference< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : xCharStyles;
                     uno::Reference< style::XStyle > xStyle;
                     OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName );
-                    if(xStyles->hasByName( sConvertedStyleName ))
+                    // When pasting, don't update existing styles.
+                    if(xStyles->hasByName( sConvertedStyleName ) && m_pImpl->m_bIsNewDoc)
                         xStyles->getByName( sConvertedStyleName ) >>= xStyle;
                     else
                     {
diff --git a/writerfilter/source/dmapper/StyleSheetTable.hxx b/writerfilter/source/dmapper/StyleSheetTable.hxx
index d668989..05f5748 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.hxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.hxx
@@ -81,7 +81,7 @@ class StyleSheetTable :
 
 public:
     StyleSheetTable( DomainMapper& rDMapper,
-                        ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextDocument> xTextDocument );
+                        ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextDocument> xTextDocument, bool bIsNewDoc );
     virtual ~StyleSheetTable();
 
     void ApplyStyleSheets( FontTablePtr rFontTable );


More information about the Libreoffice-commits mailing list