summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@suse.cz>2013-09-03 15:23:46 +0200
committerMiklos Vajna <vmiklos@suse.cz>2013-09-03 17:03:26 +0200
commitd74f44882336226990a290eaaf37f7b477c98777 (patch)
tree0e3945657ce1bf09aa8c93c3328271d700d9cdc4
parent6bf4fac3759a4fb986382b032efbb22aa8c23175 (diff)
bnc#816593 DOCX import: fix auto table width wrt nested tables
This is a backport of the fix + 3 other commits from master, which were needed to make the testcase pass on -4-1 as well. (cherry picked from commits 74c5ed19f430327988194cdcd6bdff09591a93fa, 824cc4bf4ae9035d4108e8da8e81eb57284f0b54, 53d27a30ce5f2c9f7d37a4089286116854c16215 and 76d1ca523ddcf89cc269fe51c70e66066943ef5a) Change-Id: I62a1f526cf1d4e4056daa1495d61f1b9f5c0b1b2 Conflicts: sw/qa/extras/ooxmlimport/ooxmlimport.cxx writerfilter/source/dmapper/DomainMapperTableManager.cxx
-rwxr-xr-xsw/qa/extras/ooxmlimport/data/table-auto-nested.docxbin0 -> 10297 bytes
-rwxr-xr-xsw/qa/extras/ooxmlimport/data/table-floating.docxbin0 -> 14996 bytes
-rw-r--r--sw/qa/extras/ooxmlimport/ooxmlimport.cxx32
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableHandler.cxx30
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableHandler.hxx4
-rw-r--r--writerfilter/source/dmapper/DomainMapperTableManager.cxx11
-rw-r--r--writerfilter/source/dmapper/TablePositionHandler.cxx12
-rw-r--r--writerfilter/source/dmapper/TablePositionHandler.hxx2
8 files changed, 80 insertions, 11 deletions
diff --git a/sw/qa/extras/ooxmlimport/data/table-auto-nested.docx b/sw/qa/extras/ooxmlimport/data/table-auto-nested.docx
new file mode 100755
index 000000000000..85f47dbba0b3
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/table-auto-nested.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/data/table-floating.docx b/sw/qa/extras/ooxmlimport/data/table-floating.docx
new file mode 100755
index 000000000000..1e0cb30ece49
--- /dev/null
+++ b/sw/qa/extras/ooxmlimport/data/table-floating.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index 34635419ba19..bbdb706b4751 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -130,6 +130,8 @@ public:
void testTableAutoColumnFixedSize();
void testFdo66474();
void testBnc780044Spacing();
+ void testTableFloating();
+ void testTableAutoNested();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
@@ -209,6 +211,8 @@ void Test::run()
{"table-auto-column-fixed-size.docx", &Test::testTableAutoColumnFixedSize},
{"fdo66474.docx", &Test::testFdo66474},
{"bnc780044_spacing.docx", &Test::testBnc780044Spacing},
+ {"table-floating.docx", &Test::testTableFloating},
+ {"table-auto-nested.docx", &Test::testTableAutoNested},
};
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
{
@@ -1306,6 +1310,34 @@ void Test::testBnc780044Spacing()
CPPUNIT_ASSERT_EQUAL(sal_Int16(1), xCursor->getPage());
}
+void Test::testTableFloating()
+{
+ // Both the size and the position of the table was incorrect.
+ uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
+ // Second table was too wide: 16249, i.e. as wide as the first table.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(11248), getProperty<sal_Int32>(xTables->getByIndex(1), "Width"));
+
+ uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xIndexAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
+ // This was 0, should be the the opposite of (left margin + half of the border width).
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-199), getProperty<sal_Int32>(xFrame, "HoriOrientPosition"));
+ // Was 0 as well, should be the right margin.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(191), getProperty<sal_Int32>(xFrame, "RightMargin"));
+}
+
+void Test::testTableAutoNested()
+{
+ // This was 176, when compat option is not enabled, the auto paragraph bottom margin value was incorrect.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(494), getProperty<sal_Int32>(getParagraph(1), "ParaBottomMargin"));
+
+ uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY);
+ // This was 115596, i.e. the width of the outer table was too large.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(23051), getProperty<sal_Int32>(xTables->getByIndex(1), "Width"));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index d9c5abb1ac21..6647408251ab 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -38,8 +38,6 @@ namespace dmapper {
using namespace ::com::sun::star;
using namespace ::std;
-#define DEF_BORDER_DIST 190 //0,19cm
-
#ifdef DEBUG_DMAPPER_TABLE_HANDLER
static void lcl_printProperties( PropertyMapPtr pProps )
{
@@ -306,7 +304,7 @@ bool lcl_extractTableBorderProperty(PropertyMapPtr pTableProperties, const Prope
}
-TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo & rInfo)
+TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo & rInfo, uno::Sequence<beans::PropertyValue>& rFrameProperties)
{
// will receive the table style if any
TableStyleSheetEntry* pTableStyle = NULL;
@@ -418,7 +416,25 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
aTableBorder.IsLeftLineValid = sal_True;
// Only top level table position depends on border width
if (rInfo.nNestLevel == 1)
- rInfo.nLeftBorderDistance += aLeftBorder.LineWidth * 0.5;
+ {
+ if (!rFrameProperties.hasElements())
+ rInfo.nLeftBorderDistance += aLeftBorder.LineWidth * 0.5;
+ else
+ {
+ // If this is a floating table, then the position of the frame should be adjusted, instead.
+ for (sal_Int32 i = 0; i < rFrameProperties.getLength(); ++i)
+ {
+ beans::PropertyValue& rPropertyValue = rFrameProperties[i];
+ if (rPropertyValue.Name == "HoriOrientPosition")
+ {
+ sal_Int32 nValue = rPropertyValue.Value.get<sal_Int32>();
+ nValue -= aLeftBorder.LineWidth * 0.5;
+ rPropertyValue.Value <<= nValue;
+ break;
+ }
+ }
+ }
+ }
}
if (lcl_extractTableBorderProperty(m_aTableProperties, PROP_RIGHT_BORDER, rInfo, aBorderLine))
{
@@ -710,9 +726,11 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
dmapper_logger->startElement("tablehandler.endTable");
#endif
+ // If we want to make this table a floating one.
+ uno::Sequence<beans::PropertyValue> aFrameProperties = m_rDMapper_Impl.getTableManager().getCurrentTablePosition();
TableInfo aTableInfo;
aTableInfo.nNestLevel = nestedTableLevel;
- aTableInfo.pTableStyle = endTableGetTableStyle(aTableInfo);
+ aTableInfo.pTableStyle = endTableGetTableStyle(aTableInfo, aFrameProperties);
// expands to uno::Sequence< Sequence< beans::PropertyValues > >
CellPropertyValuesSeq_t aCellProperties = endTableGetCellProperties(aTableInfo);
@@ -727,8 +745,6 @@ void DomainMapperTableHandler::endTable(unsigned int nestedTableLevel)
{
uno::Reference<text::XTextRange> xStart;
uno::Reference<text::XTextRange> xEnd;
- // If we want to make this table a floating one.
- uno::Sequence<beans::PropertyValue> aFrameProperties = m_rDMapper_Impl.getTableManager().getCurrentTablePosition();
bool bFloating = aFrameProperties.hasElements();
// Additional checks: if we can do this.
if (bFloating && (*m_pTableSeq)[0].getLength() > 0 && (*m_pTableSeq)[0][0].getLength() > 0)
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
index ea4c42135ed6..792b978b46c0 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
@@ -45,6 +45,8 @@ typedef ::com::sun::star::uno::Sequence< RowPropertyValuesSeq_t> CellProperty
typedef std::vector<PropertyMapPtr> PropertyMapVector1;
typedef std::vector<PropertyMapVector1> PropertyMapVector2;
+#define DEF_BORDER_DIST 190 //0,19cm
+
class DomainMapper_Impl;
class TableStyleSheetEntry;
struct TableInfo;
@@ -66,7 +68,7 @@ class WRITERFILTER_DLLPRIVATE DomainMapperTableHandler : public TableDataHandler
sal_Int32 m_nCellIndex;
sal_Int32 m_nRowIndex;
- TableStyleSheetEntry * endTableGetTableStyle(TableInfo & rInfo);
+ TableStyleSheetEntry * endTableGetTableStyle(TableInfo & rInfo, uno::Sequence<beans::PropertyValue>& rFrameProperties);
CellPropertyValuesSeq_t endTableGetCellProperties(TableInfo & rInfo);
RowPropertyValuesSeq_t endTableGetRowProperties();
diff --git a/writerfilter/source/dmapper/DomainMapperTableManager.cxx b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
index 6362969ecdb7..d07d7e8332c6 100644
--- a/writerfilter/source/dmapper/DomainMapperTableManager.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableManager.cxx
@@ -467,6 +467,7 @@ void DomainMapperTableManager::startLevel( )
m_nCell.push_back( 0 );
m_nTableWidth = 0;
m_nLayoutType = 0;
+ m_nMaxFixedWidth = 0;
// And push it back to the right level.
if (oCurrentWidth)
@@ -477,10 +478,20 @@ void DomainMapperTableManager::endLevel( )
{
m_aTableGrid.pop_back( );
m_aGridSpans.pop_back( );
+
+ // Do the same trick as in startLevel(): pop the value that was pushed too early.
+ boost::optional<sal_Int32> oCurrentWidth;
+ if (m_bPushCurrentWidth && !m_aCellWidths.empty() && !m_aCellWidths.back()->empty())
+ oCurrentWidth.reset(m_aCellWidths.back()->back());
m_aCellWidths.pop_back( );
+ // And push it back to the right level.
+ if (oCurrentWidth)
+ m_aCellWidths.back()->push_back(*oCurrentWidth);
+
m_nCell.pop_back( );
m_nTableWidth = 0;
m_nLayoutType = 0;
+ m_nMaxFixedWidth = 0;
m_aTmpPosition.pop_back( );
m_aTmpTableProperties.pop_back( );
diff --git a/writerfilter/source/dmapper/TablePositionHandler.cxx b/writerfilter/source/dmapper/TablePositionHandler.cxx
index 7ed8bde1d230..30dd2cf5762e 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.cxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.cxx
@@ -7,6 +7,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <TablePositionHandler.hxx>
+#include <DomainMapperTableHandler.hxx>
#include <PropertyMap.hxx>
#include <doctok/resourceids.hxx>
#include <ConversionHelper.hxx>
@@ -28,7 +29,9 @@ TablePositionHandler::TablePositionHandler() :
m_aHorzAnchor( "text" ),
m_aXSpec( ),
m_nY( 0 ),
- m_nX( 0 )
+ m_nX( 0 ),
+ m_nLeftBorderDistance(DEF_BORDER_DIST),
+ m_nRightBorderDistance(DEF_BORDER_DIST)
{
}
@@ -75,7 +78,7 @@ void TablePositionHandler::lcl_sprm(Sprm& /*rSprm*/)
uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() const
{
- uno::Sequence< beans::PropertyValue > aFrameProperties(18);
+ uno::Sequence< beans::PropertyValue > aFrameProperties(19);
beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
pFrameProperties[0].Name = "LeftBorderDistance";
@@ -132,7 +135,7 @@ uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() con
pFrameProperties[13].Name = "HoriOrientRelation";
pFrameProperties[13].Value <<= nHoriOrientRelation;
pFrameProperties[14].Name = "HoriOrientPosition";
- pFrameProperties[14].Value <<= m_nX;
+ pFrameProperties[14].Value <<= m_nX - m_nLeftBorderDistance;
// Vertical positioning
@@ -161,6 +164,9 @@ uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() con
pFrameProperties[17].Name = "VertOrientPosition";
pFrameProperties[17].Value <<= m_nY;
+ pFrameProperties[18].Name = "RightMargin";
+ pFrameProperties[18].Value <<= m_nRightBorderDistance;
+
return aFrameProperties;
}
diff --git a/writerfilter/source/dmapper/TablePositionHandler.hxx b/writerfilter/source/dmapper/TablePositionHandler.hxx
index b6ddd5006d21..43eabbcddae5 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.hxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.hxx
@@ -27,6 +27,8 @@ namespace writerfilter {
OUString m_aXSpec;
sal_Int32 m_nY;
sal_Int32 m_nX;
+ sal_Int32 m_nLeftBorderDistance;
+ sal_Int32 m_nRightBorderDistance;
// Properties
virtual void lcl_attribute(Id Name, Value & val);