[Libreoffice-commits] core.git: sw/qa sw/source writerfilter/source
Justin Luth (via logerrit)
logerrit at kemper.freedesktop.org
Tue Apr 7 09:30:20 UTC 2020
sw/qa/extras/ooxmlexport/data/table-position-15.docx |binary
sw/qa/extras/ooxmlexport/data/tdf119760_tableInTablePosition.docx |binary
sw/qa/extras/ooxmlexport/ooxmlexport10.cxx | 26 ++++++++--
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 3 -
sw/source/filter/ww8/docxattributeoutput.cxx | 8 +--
writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 13 +++--
6 files changed, 39 insertions(+), 11 deletions(-)
New commits:
commit d2db4bc9507653a46fdea282d41b9683910a072f
Author: Justin Luth <justin.luth at collabora.com>
AuthorDate: Thu Apr 2 10:22:45 2020 +0300
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Apr 7 11:29:27 2020 +0200
tdf#119760 docx: table starts at left, not mid-border
related to compatibilityMode = 15; the new export default.
In Word 2013+, it appears that the table starts immediately,
and then the border is added. In Writer, the table is
considered to start mid-border. So that difference needs
to be emulated by adjusting the table margin.
The same appears to be true for nested tables.
Negative margins appear to just be ignored for nested tables,
and Word's UI does not accept a negative value.
I modified the existing table-position-15.docx slightly (in Word 2016),
just to remove spacing between the caption and the table
so that it would be easy to visually compare the table position.
One slight difference is that WORD seems to add a small "margin"
to the the paragraph shading area - don't let that throw you off.
The existing unit test enforced settings that didn't match
how Word 2013 was showing the files, despite being written to
test exactly that. I assume the author was focusing more on
OLDER versions of Word and didn't care too much about the
NEW version. A man after my own heart.
MISC:
-I removed my earlier TODO which was just plain wrong.
-the ambiguous make::any caused me untold problems,
so I made it unambiguous by moving it into a variable.
Change-Id: I0685ab74777f1def2841c7d18ff1cdaf2753f47b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91608
Tested-by: Jenkins
Reviewed-by: Justin Luth <justin_luth at sil.org>
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/qa/extras/ooxmlexport/data/table-position-15.docx b/sw/qa/extras/ooxmlexport/data/table-position-15.docx
index d3dcaec40e78..91fbdbef00a2 100644
Binary files a/sw/qa/extras/ooxmlexport/data/table-position-15.docx and b/sw/qa/extras/ooxmlexport/data/table-position-15.docx differ
diff --git a/sw/qa/extras/ooxmlexport/data/tdf119760_tableInTablePosition.docx b/sw/qa/extras/ooxmlexport/data/tdf119760_tableInTablePosition.docx
new file mode 100644
index 000000000000..0456fe206edb
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf119760_tableInTablePosition.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index 1057ab93485c..f19a95342714 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -1192,7 +1192,8 @@ DECLARE_OOXMLEXPORT_TEST(testTableMarginAdjustment, "table.fodt")
// (old) Word: margin 0 means paragraph in table starts at 0
auto const xTable(getParagraphOrTable(1));
- CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(xTable, "LeftMargin"));
+ // shifted very slightly to account for half of the thin border width, so 4, not 0.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(4), getProperty<sal_Int32>(xTable, "LeftMargin"));
// Now that compatibilityMode is set to 2013's 15 (new), expect the new values,
// since LO is exporting in the NEW way now instead of the OLD way.
@@ -1204,6 +1205,24 @@ DECLARE_OOXMLEXPORT_TEST(testTableMarginAdjustment, "table.fodt")
assertXPath(pXmlDoc, "//w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "w", "0");
}
+DECLARE_OOXMLEXPORT_TEST(testTdf119760_tableInTablePosition, "tdf119760_tableInTablePosition.docx")
+{
+ if ( mbExported )
+ {
+ xmlDocPtr pXmlDoc = parseExport("word/document.xml");
+
+ assertXPath(pXmlDoc, "//w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]/w:tblPr[1]/w:tblInd[1]", "type", "dxa");
+ assertXPath(pXmlDoc, "//w:tbl[1]/w:tr[1]/w:tc[1]/w:tbl[1]//w:tblPr[1]/w:tblInd[1]", "w", "0");
+ }
+
+ uno::Reference< text::XTextTablesSupplier > xTablesSupplier( mxComponent, uno::UNO_QUERY );
+ uno::Reference< container::XIndexAccess > xTables( xTablesSupplier->getTextTables(), uno::UNO_QUERY );
+ uno::Reference< text::XTextTable > xTable( xTables->getByIndex(0), uno::UNO_QUERY );
+ // For compatibilityMode 15: margin 0 means table border starts at 0,
+ // shifted to account for half of the thick border width, so 106, not 0.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(106), getProperty<sal_Int32>(xTable, "LeftMargin"));
+}
+
DECLARE_OOXMLEXPORT_TEST( testTableCellMargin, "table-cell-margin.docx" )
{
sal_Int32 const cellLeftMarginFromOffice[] = { 250, 100, 0, 0 };
@@ -1268,10 +1287,11 @@ DECLARE_OOXMLEXPORT_TEST( testTablePosition14, "table-position-14.docx" )
}
}
-// 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
+// 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. But we do need to use border width.
DECLARE_OOXMLEXPORT_TEST( testTablePosition15, "table-position-15.docx" )
{
- sal_Int32 const aXCoordsFromOffice[] = { 2751, -899, 1, 106 };
+ sal_Int32 const aXCoordsFromOffice[] = { 2751, -899, 1, 212 };
uno::Reference< text::XTextTablesSupplier > xTablesSupplier( mxComponent, uno::UNO_QUERY );
uno::Reference< frame::XModel > xModel( mxComponent, uno::UNO_QUERY );
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 5e758f642624..7369dac8f1a7 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -495,8 +495,9 @@ DECLARE_OOXMLIMPORT_TEST(testN779627, "n779627.docx")
uno::Any aValue = xTableProperties->getPropertyValue("LeftMargin");
sal_Int32 nLeftMargin;
aValue >>= nLeftMargin;
+ // only border width considered.
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Left margin shouldn't take tableCellMar into account in nested tables",
- sal_Int32(0), nLeftMargin);
+ sal_Int32(9), nLeftMargin);
/*
* Another problem tested with this document is the unnecessary loading of the shapes
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 8505571f545d..a8ed8e88a47d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4091,11 +4091,13 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t
// LO uses a higher compatibility than 2010's 14.
sal_Int32 nMode = lcl_getWordCompatibilityMode( *m_rExport.m_pDoc );
+ const SwFrameFormat* pFrameFormat = pTableTextNodeInfoInner->getTableBox()->GetFrameFormat();
if ((0 < nMode && nMode <= 14) && m_tableReference->m_nTableDepth == 0)
+ nIndent += pFrameFormat->GetBox().GetDistance( SvxBoxItemLine::LEFT );
+ else
{
- const SwTableBox* pTabBox = pTableTextNodeInfoInner->getTableBox();
- const SwFrameFormat* pFrameFormat = pTabBox->GetFrameFormat();
- nIndent += sal_Int32( pFrameFormat->GetBox().GetDistance( SvxBoxItemLine::LEFT ) );
+ // adjust for SW considering table to start mid-border instead of nested/2013's left-side-of-border.
+ nIndent -= pFrameFormat->GetBox().CalcLineWidth( SvxBoxItemLine::LEFT ) / 2;
}
break;
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index b5a737d626b7..b7151f26cb9f 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -595,8 +595,6 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
// - nested tables: the goal is to have left-most border starting at table_indent pos
// Only top level table position depends on border width of Column A.
- // TODO: Position based on last row (at least in MSOffice 2016), but first row in Office 2003.
- // Export code is also based on first cell, so using first row here...
if ( !m_aCellProperties.empty() && !m_aCellProperties[0].empty() )
{
// aLeftBorder already contains tblBorder; overwrite if cell is different.
@@ -623,11 +621,18 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
if (((nMode < 0) || (0 < nMode && nMode <= 14)) && rInfo.nNestLevel == 1)
{
- m_aTableProperties->Insert( PROP_LEFT_MARGIN, uno::makeAny( nLeftMargin - nGapHalf - rInfo.nLeftBorderDistance ) );
+ const sal_Int32 nAdjustedMargin = nLeftMargin - nGapHalf - rInfo.nLeftBorderDistance;
+ m_aTableProperties->Insert( PROP_LEFT_MARGIN, uno::makeAny( nAdjustedMargin ) );
}
else
{
- m_aTableProperties->Insert( PROP_LEFT_MARGIN, uno::makeAny( nLeftMargin - nGapHalf ) );
+ // Writer starts a table in the middle of the border.
+ // Word starts a table at the left edge of the border,
+ // so emulate that by adding the half the width. (also see docxattributeoutput)
+ if ( rInfo.nNestLevel > 1 && nLeftMargin < 0 )
+ nLeftMargin = 0;
+ const sal_Int32 nAdjustedMargin = nLeftMargin - nGapHalf + (aLeftBorder.LineWidth / 2);
+ m_aTableProperties->Insert( PROP_LEFT_MARGIN, uno::makeAny( nAdjustedMargin ) );
}
sal_Int32 nTableWidth = 0;
More information about the Libreoffice-commits
mailing list