diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2012-11-13 17:30:18 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-11-14 09:43:51 +0100 |
commit | c4b91ae3178011c66c76c711c1a6469ba658872e (patch) | |
tree | e9d2dd98a395cb1cff67fe53fe77a18694010ca2 | |
parent | 8030ea8a94405751ed47d2adf8ab239ba284a323 (diff) |
fdo#55525 import RTF_TRLEFT
Additionally:
1) Make sure cell margins are zero when they are not defined.
2) Handle cellx values in case of a negative left margin.
Change-Id: I9b8fb700b6459e622396c98e4344aba79f62c96e
-rw-r--r-- | sw/qa/extras/rtfimport/data/fdo55525.rtf | 12 | ||||
-rw-r--r-- | sw/qa/extras/rtfimport/rtfimport.cxx | 15 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 37 |
3 files changed, 64 insertions, 0 deletions
diff --git a/sw/qa/extras/rtfimport/data/fdo55525.rtf b/sw/qa/extras/rtfimport/data/fdo55525.rtf new file mode 100644 index 000000000000..0b966c1c747b --- /dev/null +++ b/sw/qa/extras/rtfimport/data/fdo55525.rtf @@ -0,0 +1,12 @@ +{\rtf1 +\marglsxn1418\margrsxn1418 +\trowd\trql\trleft-1064\cellx-250\cellx-106\cellx8006 +\pard\plain \intbl +A1 +\cell\pard\plain\intbl +A2 +\cell\pard\plain\intbl +A3 +\cell\row\pard +\pard\plain \par +} diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx index 5d2c183ea89d..c24c87aad9cb 100644 --- a/sw/qa/extras/rtfimport/rtfimport.cxx +++ b/sw/qa/extras/rtfimport/rtfimport.cxx @@ -42,6 +42,7 @@ #include <com/sun/star/table/BorderLineStyle.hpp> #include <com/sun/star/text/RelOrientation.hpp> #include <com/sun/star/text/SizeType.hpp> +#include <com/sun/star/text/TableColumnSeparator.hpp> #include <com/sun/star/text/TextContentAnchorType.hpp> #include <com/sun/star/text/XFootnotesSupplier.hpp> #include <com/sun/star/text/XPageCursor.hpp> @@ -124,6 +125,7 @@ public: void testFdo56512(); void testFdo52989(); void testFdo48442(); + void testFdo55525(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -199,6 +201,7 @@ void Test::run() {"fdo56512.rtf", &Test::testFdo56512}, {"fdo52989.rtf", &Test::testFdo52989}, {"fdo48442.rtf", &Test::testFdo48442}, + {"fdo55525.rtf", &Test::testFdo55525}, }; for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i) { @@ -917,6 +920,18 @@ void Test::testFdo48442() CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_PRINT_AREA, getProperty<sal_Int16>(xShape, "VertOrientRelation")); // was FRAME } +void Test::testFdo55525() +{ + 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); + // Negative left margin was ~missing, -191 + CPPUNIT_ASSERT_EQUAL(sal_Int32(-1877), getProperty<sal_Int32>(xTable, "LeftMargin")); + // Cell width of A1 was 3332 (e.g. not set, 30% percent of total width) + uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int16(1016), getProperty< uno::Sequence<text::TableColumnSeparator> >(xTableRows->getByIndex(0), "TableColumnSeparators")[0].Position); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index fd00febd19cd..8ef259fdad2c 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -1699,6 +1699,22 @@ int RTFDocumentImpl::dispatchSymbol(RTFKeyword nKeyword) RTFValue::Pointer_t pRowValue(new RTFValue(1)); if (m_aStates.top().nCells > 0) m_aStates.top().aTableRowSprms.set(NS_sprm::LN_PRow, pRowValue); + + RTFValue::Pointer_t pCellMar = m_aStates.top().aTableRowSprms.find(NS_ooxml::LN_CT_TblPrBase_tblCellMar); + if (!pCellMar.get()) + { + // If no cell margins are defined, the default left/right margin is 0 in Word, but not in Writer. + RTFSprms aAttributes; + aAttributes.set(NS_ooxml::LN_CT_TblWidth_type, RTFValue::Pointer_t(new RTFValue(NS_ooxml::LN_Value_ST_TblWidth_dxa))); + aAttributes.set(NS_ooxml::LN_CT_TblWidth_w, RTFValue::Pointer_t(new RTFValue(0))); + lcl_putNestedSprm(m_aStates.top().aTableRowSprms, + NS_ooxml::LN_CT_TblPrBase_tblCellMar, NS_ooxml::LN_CT_TblCellMar_left, + RTFValue::Pointer_t(new RTFValue(aAttributes))); + lcl_putNestedSprm(m_aStates.top().aTableRowSprms, + NS_ooxml::LN_CT_TblPrBase_tblCellMar, NS_ooxml::LN_CT_TblCellMar_right, + RTFValue::Pointer_t(new RTFValue(aAttributes))); + } + writerfilter::Reference<Properties>::Pointer_t const pTableRowProperties( new RTFReferenceProperties(m_aStates.top().aTableRowAttributes, m_aStates.top().aTableRowSprms) ); @@ -2845,6 +2861,16 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) case RTF_CELLX: { int nCellX = nParam - m_aStates.top().nCellX; + + // If there is a negative left margin, then the first cellx is relateve to that. + RTFValue::Pointer_t pTblInd = m_aStates.top().aTableRowSprms.find(NS_ooxml::LN_CT_TblPrBase_tblInd); + if (m_aStates.top().nCellX == 0 && pTblInd.get()) + { + RTFValue::Pointer_t pWidth = pTblInd->getAttributes().find(NS_ooxml::LN_CT_TblWidth_w); + if (pWidth.get() && pWidth->getInt() < 0) + nCellX = -1 * (pWidth->getInt() - nParam); + } + m_aStates.top().nCellX = nParam; RTFValue::Pointer_t pXValue(new RTFValue(nCellX)); m_aStates.top().aTableRowSprms.set(NS_ooxml::LN_CT_TblGridBase_gridCol, pXValue, false); @@ -2880,6 +2906,17 @@ int RTFDocumentImpl::dispatchValue(RTFKeyword nKeyword, int nParam) NS_ooxml::LN_CT_TrPrBase_trHeight, NS_ooxml::LN_CT_Height_hRule, pHRule); } break; + case RTF_TRLEFT: + { + // the value is in twips + lcl_putNestedAttribute(m_aStates.top().aTableRowSprms, + NS_ooxml::LN_CT_TblPrBase_tblInd, NS_ooxml::LN_CT_TblWidth_type, + RTFValue::Pointer_t(new RTFValue(NS_ooxml::LN_Value_ST_TblWidth_dxa))); + lcl_putNestedAttribute(m_aStates.top().aTableRowSprms, + NS_ooxml::LN_CT_TblPrBase_tblInd, NS_ooxml::LN_CT_TblWidth_w, + RTFValue::Pointer_t(new RTFValue(nParam))); + } + break; case RTF_COLS: lcl_putNestedAttribute(m_aStates.top().aSectionSprms, NS_ooxml::LN_EG_SectPrContents_cols, NS_ooxml::LN_CT_Columns_num, pIntValue); |