summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2013-06-04 12:21:11 +0200
committerMiklos Vajna <vmiklos@suse.cz>2013-06-04 12:42:20 +0200
commit2ade07126971b79c92f729fae5709f2e2e2b495c (patch)
tree2d5964b06b7ca41f73c1a44afdd36f2059741d88
parent46c4e2463d517a7e4f74ee1759d837c799140fc7 (diff)
fdo#62044 RTF import: don't overwrite existing styles when pasting
Change-Id: I80a83caebc8fa3f038cf2ff080c6c6ec8e93fb70
-rw-r--r--sw/qa/extras/rtfimport/data/fdo62044-paste.rtf7
-rw-r--r--sw/qa/extras/rtfimport/data/fdo62044.rtf7
-rw-r--r--sw/qa/extras/rtfimport/rtfimport.cxx14
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx2
-rw-r--r--writerfilter/source/dmapper/StyleSheetTable.cxx15
-rw-r--r--writerfilter/source/dmapper/StyleSheetTable.hxx2
6 files changed, 39 insertions, 8 deletions
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 000000000000..cea4373f5ca8
--- /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 000000000000..8ab293bbb7ac
--- /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 bb0b0145a512..d39ff516e398 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 dc7f2dd4e445..f88f49441f01 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 e3dac30df1eb..74adb0b11ffd 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 d6689897d1eb..05f5748ae00f 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 );