Hi,
I have submitted a patch for review:
https://gerrit.libreoffice.org/4149
To pull it, you can do:
git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/49/4149/1
fdo#62044 RTF import: don't overwrite existing styles when pasting
(cherry picked from commit 2ade07126971b79c92f729fae5709f2e2e2b495c)
Conflicts:
sw/qa/extras/rtfimport/rtfimport.cxx
Change-Id: I80a83caebc8fa3f038cf2ff080c6c6ec8e93fb70
---
A sw/qa/extras/rtfimport/data/fdo62044-paste.rtf
A sw/qa/extras/rtfimport/data/fdo62044.rtf
M sw/qa/extras/rtfimport/rtfimport.cxx
M writerfilter/source/dmapper/DomainMapper_Impl.hxx
M writerfilter/source/dmapper/StyleSheetTable.cxx
M writerfilter/source/dmapper/StyleSheetTable.hxx
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 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 2e99c27..2e33f8e 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -149,6 +149,7 @@
void testFdo63023();
void testFdo62977();
void testFdo64671();
+ void testFdo62044();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
@@ -268,6 +269,7 @@
{"fdo63023.rtf", &Test::testFdo63023},
{"fdo62977.rtf", &Test::testFdo62977},
{"fdo64671.rtf", &Test::testFdo64671},
+ {"fdo62044.rtf", &Test::testFdo62044},
};
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
{
@@ -1230,6 +1232,18 @@
getRun(getParagraph(1), 1, OUString("\xC5\xBD", 2, RTL_TEXTENCODING_UTF8));
}
+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 20065e7..d060bd3 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -476,7 +476,7 @@
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 b5413b8..cf2ae05 100644
--- a/writerfilter/source/dmapper/StyleSheetTable.cxx
+++ b/writerfilter/source/dmapper/StyleSheetTable.cxx
@@ -280,19 +280,21 @@
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.) );
@@ -347,10 +349,10 @@
}
-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) )
{
}
@@ -710,7 +712,8 @@
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 @@
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 );
--
To view, visit https://gerrit.libreoffice.org/4149
To unsubscribe, visit https://gerrit.libreoffice.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I80a83caebc8fa3f038cf2ff080c6c6ec8e93fb70
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-0
Gerrit-Owner: Miklos Vajna <vmiklos@suse.cz>
Context
- [PATCH libreoffice-4-0] fdo#62044 RTF import: don't overwrite existing styles when p... · Miklos Vajna (via Code Review)
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.