diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-01-08 09:08:57 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2016-01-27 13:46:04 +0000 |
commit | 5f6df9fd46e28ba579bac90e7f5431b95f0a490f (patch) | |
tree | 2aaa08ef37bc1c9810ec98fc2eb47160bd1e86e4 | |
parent | ac799946e58f91ab08d127e56af5119c091732c2 (diff) |
tdf#96308 RTF import: fix tab stop inheritance inside table cells
The tab stop list is a paragraph property, and RTF requires to repeat it
after \s as direct formatting, otherwise the parser should be assumed
that the tab stop list is cleared as a direct formatting.
Non-buffered text handles that in getDefaultSPRM(), handle it directly
in the RTF_PARD code for buffered text.
(cherry picked from commits 1f1ddaad5dd401b70ae69fb18f7873d652242154 and
1ec88cdb82a28851c4b97d7f043d8bcec3c675e8)
Change-Id: I16b09bc4c177df5a74d16653b829b198aa1a800f
Reviewed-on: https://gerrit.libreoffice.org/21688
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r-- | sw/qa/extras/rtfimport/data/tdf96308-deftab.rtf | 8 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/data/tdf96308-tabpos.rtf | 12 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 24 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 12 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 2 |
5 files changed, 57 insertions, 1 deletions
diff --git a/sw/qa/extras/rtfimport/data/tdf96308-deftab.rtf b/sw/qa/extras/rtfimport/data/tdf96308-deftab.rtf new file mode 100644 index 000000000000..49ad344fcb0b --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf96308-deftab.rtf @@ -0,0 +1,8 @@ +{\rtf1 +{\stylesheet +{ +\s23\pvpg Slogan;} +} +\deftab284 +hello\par +} diff --git a/sw/qa/extras/rtfimport/data/tdf96308-tabpos.rtf b/sw/qa/extras/rtfimport/data/tdf96308-tabpos.rtf new file mode 100644 index 000000000000..59fdb8fbffc4 --- /dev/null +++ b/sw/qa/extras/rtfimport/data/tdf96308-tabpos.rtf @@ -0,0 +1,12 @@ +{\rtf1 +{\stylesheet +{\s30\tx2552 Body Text 3;} +} +\deftab284 +\pard\plain\par +\trowd\cellx2694\cellx4678 \pard\intbl\tx284 A1\cell +\pard\intbl\tx2694 before\par +\pard\plain\s30\intbl 7.\tab Champion\par +\pard\plain\intbl after\cell\row +\pard\par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index f7e16fc2db28..24325c3b8a42 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -2446,6 +2446,30 @@ DECLARE_RTFIMPORT_TEST(testLandscape, "landscape.rtf") CPPUNIT_ASSERT_EQUAL(sal_True, getProperty<sal_Bool>(xStylePage, "IsLandscape")); } +DECLARE_RTFIMPORT_TEST(testTdf96308Deftab, "tdf96308-deftab.rtf") +{ + uno::Reference<lang::XMultiServiceFactory> xTextFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xDefaults(xTextFactory->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY); + // This was 1270 as \deftab was ignored on import. + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(convertTwipToMm100(284)), getProperty<sal_Int32>(xDefaults, "TabStopDistance")); +} + +DECLARE_RTFIMPORT_TEST(testTdf96308Tabpos, "tdf96308-tabpos.rtf") +{ + // Get the tab stops of the second para in the B1 cell of the first table in the document. + uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); + uno::Reference<container::XEnumerationAccess> xParaEnumAccess(xCell->getText(), uno::UNO_QUERY); + uno::Reference<container::XEnumeration> xParaEnum = xParaEnumAccess->createEnumeration(); + xParaEnum->nextElement(); + uno::Reference<text::XTextRange> xPara(xParaEnum->nextElement(), uno::UNO_QUERY); + auto aTabStops = getProperty< uno::Sequence<style::TabStop> >(xPara, "ParaTabStops"); + // This failed: tab stops were not deleted as direct formatting on the paragraph. + CPPUNIT_ASSERT(!aTabStops.hasElements()); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 9748fe634be8..92ba692fa9d0 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -704,6 +704,14 @@ oox::GraphicHelper& RTFDocumentImpl::getGraphicHelper() return *m_pGraphicHelper; } +bool RTFDocumentImpl::isStyleSheetImport() +{ + if (m_aStates.empty()) + return false; + Destination eDestination = m_aStates.top().eDestination; + return eDestination == Destination::STYLESHEET || eDestination == Destination::STYLEENTRY; +} + void RTFDocumentImpl::resolve(Stream& rMapper) { m_pMapperStream = &rMapper; @@ -2979,6 +2987,8 @@ RTFError RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) { // We are still in a table. m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_inTbl, std::make_shared<RTFValue>(1)); + // Ideally getDefaultSPRM() would take care of this, but it would not when we're buffering. + m_aStates.top().aParagraphSprms.set(NS_ooxml::LN_CT_PPrBase_tabs, std::make_shared<RTFValue>()); } m_aStates.top().resetFrame(); @@ -6335,7 +6345,7 @@ RTFFrame::RTFFrame(RTFParserState* pParserState) void RTFFrame::setSprm(Id nId, Id nValue) { - if (m_pParserState->m_pDocumentImpl->getFirstRun()) + if (m_pParserState->m_pDocumentImpl->getFirstRun() && !m_pParserState->m_pDocumentImpl->isStyleSheetImport()) { m_pParserState->m_pDocumentImpl->checkFirstRun(); m_pParserState->m_pDocumentImpl->setNeedPar(false); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index d0671a1b5bb4..7ef2b4fdce70 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -395,6 +395,8 @@ public: /// Get the default parser state. RTFParserState& getDefaultState(); oox::GraphicHelper& getGraphicHelper(); + /// Are we inside the stylesheet table? + bool isStyleSheetImport(); private: SvStream& Strm(); |