From 9a31d1c83e08600507689dc18f6f0973bc7e4389 Mon Sep 17 00:00:00 2001 From: Vitaliy Anderson Date: Tue, 4 Apr 2017 17:11:12 +0300 Subject: tdf#106742: OOXML import/export: treat "tblInd" properly. Since MS Word 2013+ if you change cell margin at the table, the border won't be shifted. The decision is to do the same ( see https://bugs.documentfoundation.org/show_bug.cgi?id=106742 ). Change-Id: Ia58693c44f63ed21dca2cd99591002ba68927b65 Reviewed-on: https://gerrit.libreoffice.org/36084 Tested-by: Jenkins Reviewed-by: Mike Kaganski --- .../extras/ooxmlexport/data/table-cell-margin.docx | Bin 0 -> 13708 bytes .../extras/ooxmlexport/data/table-position-14.docx | Bin 0 -> 13708 bytes .../extras/ooxmlexport/data/table-position-15.docx | Bin 0 -> 13683 bytes sw/qa/extras/ooxmlexport/data/table-position.docx | Bin 13708 -> 0 bytes sw/qa/extras/ooxmlexport/ooxmlexport2.cxx | 35 ---------- sw/qa/extras/ooxmlexport/ooxmlexport8.cxx | 76 +++++++++++++++++++++ 6 files changed, 76 insertions(+), 35 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/table-cell-margin.docx create mode 100644 sw/qa/extras/ooxmlexport/data/table-position-14.docx create mode 100644 sw/qa/extras/ooxmlexport/data/table-position-15.docx delete mode 100644 sw/qa/extras/ooxmlexport/data/table-position.docx (limited to 'sw/qa') diff --git a/sw/qa/extras/ooxmlexport/data/table-cell-margin.docx b/sw/qa/extras/ooxmlexport/data/table-cell-margin.docx new file mode 100644 index 000000000000..f59a5da11a95 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/table-cell-margin.docx differ diff --git a/sw/qa/extras/ooxmlexport/data/table-position-14.docx b/sw/qa/extras/ooxmlexport/data/table-position-14.docx new file mode 100644 index 000000000000..f59a5da11a95 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/table-position-14.docx differ diff --git a/sw/qa/extras/ooxmlexport/data/table-position-15.docx b/sw/qa/extras/ooxmlexport/data/table-position-15.docx new file mode 100644 index 000000000000..d3dcaec40e78 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/table-position-15.docx differ diff --git a/sw/qa/extras/ooxmlexport/data/table-position.docx b/sw/qa/extras/ooxmlexport/data/table-position.docx deleted file mode 100644 index f59a5da11a95..000000000000 Binary files a/sw/qa/extras/ooxmlexport/data/table-position.docx and /dev/null differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx index a0bd7e490320..3b4445f8585e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx @@ -363,41 +363,6 @@ DECLARE_OOXMLEXPORT_TEST(testTable, "table.odt") assertXPath(parseExport("word/styles.xml"), "//w:style[@w:styleId='Normal']/w:qFormat", 1); } -DECLARE_OOXMLEXPORT_TEST(testTablePosition, "table-position.docx") -{ - sal_Int32 aXCoordsFromOffice[] = { 2500, -1000, 0, 0 }; - sal_Int32 cellLeftMarginFromOffice[] = { 250, 100, 0, 0 }; - - uno::Reference xTablesSupplier(mxComponent, uno::UNO_QUERY); - uno::Reference xModel(mxComponent, uno::UNO_QUERY); - uno::Reference xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY); - - for (int i=0; i<4; i++) { - uno::Reference xTable1 (xTables->getByIndex(i), uno::UNO_QUERY); - // Verify X coord - uno::Reference xCtrl(xModel->getCurrentController(), uno::UNO_QUERY); - xCtrl->select(uno::makeAny(xTable1)); - uno::Reference xTextViewCursorSupplier(xCtrl, uno::UNO_QUERY); - uno::Reference xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); - awt::Point pos = xCursor->getPosition(); - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect X coord computed from docx", - aXCoordsFromOffice[i], pos.X, 1); - - // Verify left margin of 1st cell : - // * Office left margins are measured relative to the right of the border - // * LO left spacing is measured from the center of the border - uno::Reference xCell = xTable1->getCellByName("A1"); - uno::Reference< beans::XPropertySet > xPropSet(xCell, uno::UNO_QUERY_THROW); - sal_Int32 aLeftMargin = -1; - xPropSet->getPropertyValue("LeftBorderDistance") >>= aLeftMargin; - uno::Any aLeftBorder = xPropSet->getPropertyValue("LeftBorder"); - table::BorderLine2 aLeftBorderLine; - aLeftBorder >>= aLeftBorderLine; - CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Incorrect left spacing computed from docx cell margin", - cellLeftMarginFromOffice[i], aLeftMargin - 0.5 * aLeftBorderLine.LineWidth, 1); - } -} - struct SingleLineBorders { sal_Int16 top, bottom, left, right; SingleLineBorders(int t=0, int b=0, int l=0, int r=0) diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx index 5b62695446fc..d751899dee8e 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport8.cxx @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -2096,6 +2097,81 @@ DECLARE_OOXMLEXPORT_TEST(testTdf99140, "tdf99140.docx") CPPUNIT_ASSERT_EQUAL(text::HoriOrientation::LEFT_AND_WIDTH, getProperty(xTableProperties, "HoriOrient")); } +DECLARE_OOXMLEXPORT_TEST( testTableCellMargin, "table-cell-margin.docx" ) +{ + sal_Int32 cellLeftMarginFromOffice[] = { 250, 100, 0, 0 }; + + uno::Reference< text::XTextTablesSupplier > xTablesSupplier( mxComponent, uno::UNO_QUERY ); + uno::Reference< frame::XModel > xModel( mxComponent, uno::UNO_QUERY ); + uno::Reference< container::XIndexAccess > xTables( xTablesSupplier->getTextTables(), uno::UNO_QUERY ); + + for ( int i = 0; i < 4; i++ ) + { + uno::Reference< text::XTextTable > xTable1( xTables->getByIndex( i ), uno::UNO_QUERY ); + + // Verify left margin of 1st cell : + // * Office left margins are measured relative to the right of the border + // * LO left spacing is measured from the center of the border + uno::Reference< table::XCell > xCell = xTable1->getCellByName( "A1" ); + uno::Reference< beans::XPropertySet > xPropSet( xCell, uno::UNO_QUERY_THROW ); + sal_Int32 aLeftMargin = -1; + xPropSet->getPropertyValue( "LeftBorderDistance" ) >>= aLeftMargin; + uno::Any aLeftBorder = xPropSet->getPropertyValue( "LeftBorder" ); + table::BorderLine2 aLeftBorderLine; + aLeftBorder >>= aLeftBorderLine; + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Incorrect left spacing computed from docx cell margin", + cellLeftMarginFromOffice[i], aLeftMargin - 0.5 * aLeftBorderLine.LineWidth, 1 ); + } +} + +// tdf#106742 for DOCX with compatibility level <= 14 (MS Word up to and incl. ver.2010), we should use cell margins when calculating table left border position +DECLARE_OOXMLEXPORT_TEST( testTablePosition14, "table-position-14.docx" ) +{ + sal_Int32 aXCoordsFromOffice[] = { 2500, -1000, 0, 0 }; + + uno::Reference< text::XTextTablesSupplier > xTablesSupplier( mxComponent, uno::UNO_QUERY ); + uno::Reference< frame::XModel > xModel( mxComponent, uno::UNO_QUERY ); + uno::Reference< container::XIndexAccess > xTables( xTablesSupplier->getTextTables(), uno::UNO_QUERY ); + + for ( int i = 0; i < 4; i++ ) + { + uno::Reference< text::XTextTable > xTable1( xTables->getByIndex( i ), uno::UNO_QUERY ); + + // Verify X coord + uno::Reference< view::XSelectionSupplier > xCtrl( xModel->getCurrentController(), uno::UNO_QUERY ); + xCtrl->select( uno::makeAny( xTable1 ) ); + uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupplier( xCtrl, uno::UNO_QUERY ); + uno::Reference< text::XTextViewCursor > xCursor( xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY ); + awt::Point pos = xCursor->getPosition(); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Incorrect X coord computed from docx", + aXCoordsFromOffice[i], pos.X, 1 ); + } +} + +// tdf#106742 for DOCX with compatibility level > 14 (MS Word since ver.2013), we should NOT use cell margins when calculating table left border position +DECLARE_OOXMLEXPORT_TEST( testTablePosition15, "table-position-15.docx" ) +{ + sal_Int32 aXCoordsFromOffice[] = { 2751, -899, 1, 106 }; + + uno::Reference< text::XTextTablesSupplier > xTablesSupplier( mxComponent, uno::UNO_QUERY ); + uno::Reference< frame::XModel > xModel( mxComponent, uno::UNO_QUERY ); + uno::Reference< container::XIndexAccess > xTables( xTablesSupplier->getTextTables(), uno::UNO_QUERY ); + + for ( int i = 0; i < 4; i++ ) + { + uno::Reference< text::XTextTable > xTable1( xTables->getByIndex( i ), uno::UNO_QUERY ); + + // Verify X coord + uno::Reference< view::XSelectionSupplier > xCtrl( xModel->getCurrentController(), uno::UNO_QUERY ); + xCtrl->select( uno::makeAny( xTable1 ) ); + uno::Reference< text::XTextViewCursorSupplier > xTextViewCursorSupplier( xCtrl, uno::UNO_QUERY ); + uno::Reference< text::XTextViewCursor > xCursor( xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY ); + awt::Point pos = xCursor->getPosition(); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE( "Incorrect X coord computed from docx", + aXCoordsFromOffice[i], pos.X, 1 ); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit