fdo#62044 RTF import: don't overwrite existing styles when pasting

Change-Id: I80a83caebc8fa3f038cf2ff080c6c6ec8e93fb70
This commit is contained in:
Miklos Vajna 2013-06-04 12:21:11 +02:00
parent 46c4e2463d
commit 2ade071269
6 changed files with 39 additions and 8 deletions

View File

@ -0,0 +1,7 @@
{\rtf
{\stylesheet
{\s14\fs36 Heading1;}
}
from impress
\par
}

View File

@ -0,0 +1,7 @@
{\rtf1
{\stylesheet
{\s1\fs20 Heading 1;}
}
\s1 this is heading 1
\par
}

View File

@ -138,6 +138,7 @@ public:
void testN818997(); void testN818997();
void testFdo64671(); void testFdo64671();
void testPageBackground(); void testPageBackground();
void testFdo62044();
CPPUNIT_TEST_SUITE(Test); CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT) #if !defined(MACOSX) && !defined(WNT)
@ -265,6 +266,7 @@ void Test::run()
{"n818997.rtf", &Test::testN818997}, {"n818997.rtf", &Test::testN818997},
{"fdo64671.rtf", &Test::testFdo64671}, {"fdo64671.rtf", &Test::testFdo64671},
{"page-background.rtf", &Test::testPageBackground}, {"page-background.rtf", &Test::testPageBackground},
{"fdo62044.rtf", &Test::testFdo62044},
}; };
header(); header();
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i) 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")); 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_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();

View File

@ -481,7 +481,7 @@ public:
StyleSheetTablePtr GetStyleSheetTable() StyleSheetTablePtr GetStyleSheetTable()
{ {
if(!m_pStyleSheetTable) 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; return m_pStyleSheetTable;
} }
ListsManager::Pointer GetListTable(); ListsManager::Pointer GetListTable();

View File

@ -275,19 +275,21 @@ struct StyleSheetTable_Impl
PropertyMapPtr m_pCurrentProps; PropertyMapPtr m_pCurrentProps;
StringPairMap_t m_aStyleNameMap; StringPairMap_t m_aStyleNameMap;
ListCharStylePropertyVector_t m_aListCharStylePropertyVector; 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 ); 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_rDMapper( rDMapper ),
m_xTextDocument( xTextDocument ), m_xTextDocument( xTextDocument ),
m_pCurrentEntry(), m_pCurrentEntry(),
m_pDefaultParaProps(new PropertyMap), m_pDefaultParaProps(new PropertyMap),
m_pDefaultCharProps(new PropertyMap) m_pDefaultCharProps(new PropertyMap),
m_bIsNewDoc(bIsNewDoc)
{ {
//set font height default to 10pt //set font height default to 10pt
uno::Any aVal = uno::makeAny( double(10.) ); 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") : LoggedProperties(dmapper_logger, "StyleSheetTable")
, LoggedTable(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< container::XNameContainer > xStyles = bParaStyle ? xParaStyles : xCharStyles;
uno::Reference< style::XStyle > xStyle; uno::Reference< style::XStyle > xStyle;
OUString sConvertedStyleName = ConvertStyleName( pEntry->sStyleName ); 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; xStyles->getByName( sConvertedStyleName ) >>= xStyle;
else else
{ {

View File

@ -81,7 +81,7 @@ class StyleSheetTable :
public: public:
StyleSheetTable( DomainMapper& rDMapper, 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(); virtual ~StyleSheetTable();
void ApplyStyleSheets( FontTablePtr rFontTable ); void ApplyStyleSheets( FontTablePtr rFontTable );