[Libreoffice-commits] core.git: 3 commits - sw/qa writerfilter/source
Miklos Vajna
vmiklos at suse.cz
Thu Aug 15 08:09:38 PDT 2013
sw/qa/extras/ooxmlimport/data/table-floating-margins.docx |binary
sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 16 +++++-
writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 37 ++++++++------
writerfilter/source/dmapper/DomainMapperTableHandler.hxx | 2
writerfilter/source/dmapper/TablePositionHandler.cxx | 33 ++++++++----
writerfilter/source/dmapper/TablePositionHandler.hxx | 6 +-
writerfilter/source/ooxml/model.xml | 12 +++-
7 files changed, 71 insertions(+), 35 deletions(-)
New commits:
commit 66b4bfe302e248fc1503c5c74b83f4fb5fee4026
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Thu Aug 15 17:06:57 2013 +0200
DOCX import: handle custom left cell margin for float table position
Change-Id: I5bc51b739c663d3e123c9d7fb4c2a70f01f8c841
diff --git a/sw/qa/extras/ooxmlimport/data/table-floating-margins.docx b/sw/qa/extras/ooxmlimport/data/table-floating-margins.docx
new file mode 100755
index 0000000..81f6f6c
Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/table-floating-margins.docx differ
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index bf7db73..3f62931 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -129,6 +129,7 @@ public:
void testGroupshapeRotation();
void testBnc780044Spacing();
void testTableFloating();
+ void testTableFloatingMargins();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
@@ -223,6 +224,7 @@ void Test::run()
{"groupshape-rotation.docx", &Test::testGroupshapeRotation},
{"bnc780044_spacing.docx", &Test::testBnc780044Spacing},
{"table-floating.docx", &Test::testTableFloating},
+ {"table-floating-margins.docx", &Test::testTableFloatingMargins},
};
header();
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1569,6 +1571,18 @@ void Test::testTableFloating()
CPPUNIT_ASSERT_EQUAL(sal_Int32(250), getProperty<sal_Int32>(xFrame, "RightMargin"));
}
+void Test::testTableFloatingMargins()
+{
+ // In case the table had custom left cell margin, the horizontal position was still incorrect (too small, -199).
+ 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);
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(-499), getProperty<sal_Int32>(xFrame, "HoriOrientPosition"));
+ // These were 0 as well, due to lack of import.
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(1000), getProperty<sal_Int32>(xFrame, "TopMargin"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2000), getProperty<sal_Int32>(xFrame, "BottomMargin"));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
index 72d7c74..3d99fa2 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx
@@ -38,6 +38,8 @@ 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,6 +308,22 @@ bool lcl_extractTableBorderProperty(PropertyMapPtr pTableProperties, const Prope
}
+void lcl_DecrementHoriOrientPosition(uno::Sequence<beans::PropertyValue>& rFrameProperties, sal_Int32 nAmount)
+{
+ // Shifts the frame left by the given value.
+ 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 -= nAmount;
+ rPropertyValue.Value <<= nValue;
+ return;
+ }
+ }
+}
+
TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo & rInfo, uno::Sequence<beans::PropertyValue>& rFrameProperties)
{
// will receive the table style if any
@@ -401,8 +419,10 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
m_aTableProperties->Insert( PROP_TABLE_BORDER_DISTANCES, uno::makeAny( aDistances ) );
+ if (rFrameProperties.hasElements())
+ lcl_DecrementHoriOrientPosition(rFrameProperties, rInfo.nLeftBorderDistance);
+
// Set table above/bottom spacing to 0.
- // TODO: handle 'Around' text wrapping mode
m_aTableProperties->Insert( PROP_TOP_MARGIN, uno::makeAny( sal_Int32( 0 ) ) );
m_aTableProperties->Insert( PROP_BOTTOM_MARGIN, uno::makeAny( sal_Int32( 0 ) ) );
@@ -430,20 +450,7 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo
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;
- }
- }
- }
+ lcl_DecrementHoriOrientPosition(rFrameProperties, aLeftBorder.LineWidth * 0.5);
}
}
if (lcl_extractTableBorderProperty(m_aTableProperties, PROP_RIGHT_BORDER, rInfo, aBorderLine))
diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
index 792b978..3dc75af 100644
--- a/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
+++ b/writerfilter/source/dmapper/DomainMapperTableHandler.hxx
@@ -45,8 +45,6 @@ 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;
diff --git a/writerfilter/source/dmapper/TablePositionHandler.cxx b/writerfilter/source/dmapper/TablePositionHandler.cxx
index 1ecf6c6..e584a2e 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.cxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.cxx
@@ -33,8 +33,7 @@ TablePositionHandler::TablePositionHandler() :
m_nLeftFromText(0),
m_nRightFromText(0),
m_nTopFromText(0),
- m_nBottomFromText(0),
- m_nLeftBorderDistance(DEF_BORDER_DIST)
+ m_nBottomFromText(0)
{
}
@@ -150,7 +149,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 - m_nLeftBorderDistance;
+ pFrameProperties[14].Value <<= m_nX;
// Vertical positioning
diff --git a/writerfilter/source/dmapper/TablePositionHandler.hxx b/writerfilter/source/dmapper/TablePositionHandler.hxx
index d68800c..a264dff 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.hxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.hxx
@@ -31,7 +31,6 @@ namespace writerfilter {
sal_Int32 m_nRightFromText;
sal_Int32 m_nTopFromText;
sal_Int32 m_nBottomFromText;
- sal_Int32 m_nLeftBorderDistance;
// Properties
virtual void lcl_attribute(Id Name, Value & val);
commit 26d9efd36a16d2095d8fb885290c6816082ec814
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Thu Aug 15 10:40:35 2013 +0200
DOCX import: handle w:leftFromText and w:rightFromText for floating tables
Left margin wasn't implemented, that's simple. Right margin of the table
was set to the cell margin in commit
53d27a30ce5f2c9f7d37a4089286116854c16215, which turns out to be wrong:
it's true that the right margin should be >0, but not because of the
cell margin but because of the table margin. The new behavior matches
what the binary import always did.
Change-Id: Ifc24e4f086c49d5d575defdfca1d27e497fa03dc
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index c85b288..bf7db73 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -1566,7 +1566,7 @@ void Test::testTableFloating()
// 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"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(250), getProperty<sal_Int32>(xFrame, "RightMargin"));
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
diff --git a/writerfilter/source/dmapper/TablePositionHandler.cxx b/writerfilter/source/dmapper/TablePositionHandler.cxx
index 19613a0..1ecf6c6 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.cxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.cxx
@@ -30,10 +30,11 @@ TablePositionHandler::TablePositionHandler() :
m_aXSpec( ),
m_nY( 0 ),
m_nX( 0 ),
+ m_nLeftFromText(0),
+ m_nRightFromText(0),
m_nTopFromText(0),
m_nBottomFromText(0),
- m_nLeftBorderDistance(DEF_BORDER_DIST),
- m_nRightBorderDistance(DEF_BORDER_DIST)
+ m_nLeftBorderDistance(DEF_BORDER_DIST)
{
}
@@ -64,6 +65,12 @@ void TablePositionHandler::lcl_attribute(Id rName, Value& rVal)
case NS_ooxml::LN_CT_TblPPr_tblpX:
m_nX = rVal.getInt();
break;
+ case NS_ooxml::LN_CT_TblPPr_leftFromText:
+ m_nLeftFromText = rVal.getInt();
+ break;
+ case NS_ooxml::LN_CT_TblPPr_rightFromText:
+ m_nRightFromText = rVal.getInt();
+ break;
case NS_ooxml::LN_CT_TblPPr_topFromText:
m_nTopFromText = rVal.getInt();
break;
@@ -86,7 +93,7 @@ void TablePositionHandler::lcl_sprm(Sprm& /*rSprm*/)
uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() const
{
- uno::Sequence< beans::PropertyValue > aFrameProperties(19);
+ uno::Sequence< beans::PropertyValue > aFrameProperties(18);
beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
pFrameProperties[0].Name = "LeftBorderDistance";
@@ -99,9 +106,9 @@ uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() con
pFrameProperties[3].Value <<= sal_Int32(0);
pFrameProperties[4].Name = "LeftMargin";
- pFrameProperties[4].Value <<= sal_Int32(0);
+ pFrameProperties[4].Value <<= ConversionHelper::convertTwipToMM100(m_nLeftFromText);
pFrameProperties[5].Name = "RightMargin";
- pFrameProperties[5].Value <<= sal_Int32(0);
+ pFrameProperties[5].Value <<= ConversionHelper::convertTwipToMM100(m_nRightFromText);
pFrameProperties[6].Name = "TopMargin";
pFrameProperties[6].Value <<= ConversionHelper::convertTwipToMM100(m_nTopFromText);
pFrameProperties[7].Name = "BottomMargin";
@@ -172,9 +179,6 @@ 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 366a6e4..d68800c 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.hxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.hxx
@@ -27,10 +27,11 @@ namespace writerfilter {
OUString m_aXSpec;
sal_Int32 m_nY;
sal_Int32 m_nX;
+ sal_Int32 m_nLeftFromText;
+ sal_Int32 m_nRightFromText;
sal_Int32 m_nTopFromText;
sal_Int32 m_nBottomFromText;
sal_Int32 m_nLeftBorderDistance;
- sal_Int32 m_nRightBorderDistance;
// Properties
virtual void lcl_attribute(Id Name, Value & val);
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 402323f..ea8f082 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -17985,11 +17985,11 @@
</define>
<define name="CT_TblPPr">
<attribute name="leftFromText">
- <text/>
+ <ref name="ST_SignedTwipsMeasure"/>
<xs:documentation>Distance From Left of Table to Text</xs:documentation>
</attribute>
<attribute name="rightFromText">
- <text/>
+ <ref name="ST_SignedTwipsMeasure"/>
<xs:documentation>(Distance From Right of Table to Text</xs:documentation>
</attribute>
<attribute name="topFromText">
@@ -22913,6 +22913,8 @@
<attribute name="tblpXSpec" tokenid="ooxml:CT_TblPPr_tblpXSpec"/>
<attribute name="tblpY" tokenid="ooxml:CT_TblPPr_tblpY"/>
<attribute name="tblpX" tokenid="ooxml:CT_TblPPr_tblpX"/>
+ <attribute name="leftFromText" tokenid="ooxml:CT_TblPPr_leftFromText"/>
+ <attribute name="rightFromText" tokenid="ooxml:CT_TblPPr_rightFromText"/>
<attribute name="topFromText" tokenid="ooxml:CT_TblPPr_topFromText"/>
<attribute name="bottomFromText" tokenid="ooxml:CT_TblPPr_bottomFromText"/>
</resource>
commit 69fd51d606619d90f291059b1cd82ec65a2c91e5
Author: Miklos Vajna <vmiklos at suse.cz>
Date: Thu Aug 15 10:21:00 2013 +0200
DOCX import: handle w:topFromText and w:bottomFromText for floating tables
Change-Id: Ia3a95d785d19f7be750e3723c1c159395ae8476f
diff --git a/writerfilter/source/dmapper/TablePositionHandler.cxx b/writerfilter/source/dmapper/TablePositionHandler.cxx
index 6d32bba..19613a0 100644
--- a/writerfilter/source/dmapper/TablePositionHandler.cxx
+++ b/writerfilter/source/dmapper/TablePositionHandler.cxx
@@ -30,6 +30,8 @@ TablePositionHandler::TablePositionHandler() :
m_aXSpec( ),
m_nY( 0 ),
m_nX( 0 ),
+ m_nTopFromText(0),
+ m_nBottomFromText(0),
m_nLeftBorderDistance(DEF_BORDER_DIST),
m_nRightBorderDistance(DEF_BORDER_DIST)
{
@@ -62,6 +64,12 @@ void TablePositionHandler::lcl_attribute(Id rName, Value& rVal)
case NS_ooxml::LN_CT_TblPPr_tblpX:
m_nX = rVal.getInt();
break;
+ case NS_ooxml::LN_CT_TblPPr_topFromText:
+ m_nTopFromText = rVal.getInt();
+ break;
+ case NS_ooxml::LN_CT_TblPPr_bottomFromText:
+ m_nBottomFromText = rVal.getInt();
+ break;
default:
#ifdef DEBUG_DOMAINMAPPER
dmapper_logger->element("unhandled");
@@ -95,9 +103,9 @@ uno::Sequence<beans::PropertyValue> TablePositionHandler::getTablePosition() con
pFrameProperties[5].Name = "RightMargin";
pFrameProperties[5].Value <<= sal_Int32(0);
pFrameProperties[6].Name = "TopMargin";
- pFrameProperties[6].Value <<= sal_Int32(0);
+ pFrameProperties[6].Value <<= ConversionHelper::convertTwipToMM100(m_nTopFromText);
pFrameProperties[7].Name = "BottomMargin";
- pFrameProperties[7].Value <<= sal_Int32(0);
+ pFrameProperties[7].Value <<= ConversionHelper::convertTwipToMM100(m_nBottomFromText);
table::BorderLine2 aEmptyBorder;
pFrameProperties[8].Name = "TopBorder";
diff --git a/writerfilter/source/dmapper/TablePositionHandler.hxx b/writerfilter/source/dmapper/TablePositionHandler.hxx
index 43eabbc..366a6e4 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_nTopFromText;
+ sal_Int32 m_nBottomFromText;
sal_Int32 m_nLeftBorderDistance;
sal_Int32 m_nRightBorderDistance;
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 64126ce..402323f 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -17993,11 +17993,11 @@
<xs:documentation>(Distance From Right of Table to Text</xs:documentation>
</attribute>
<attribute name="topFromText">
- <text/>
+ <ref name="ST_SignedTwipsMeasure"/>
<xs:documentation>Distance From Top of Table to Text</xs:documentation>
</attribute>
<attribute name="bottomFromText">
- <text/>
+ <ref name="ST_SignedTwipsMeasure"/>
<xs:documentation>Distance From Bottom of Table to Text</xs:documentation>
</attribute>
<attribute name="vertAnchor">
@@ -22913,6 +22913,8 @@
<attribute name="tblpXSpec" tokenid="ooxml:CT_TblPPr_tblpXSpec"/>
<attribute name="tblpY" tokenid="ooxml:CT_TblPPr_tblpY"/>
<attribute name="tblpX" tokenid="ooxml:CT_TblPPr_tblpX"/>
+ <attribute name="topFromText" tokenid="ooxml:CT_TblPPr_topFromText"/>
+ <attribute name="bottomFromText" tokenid="ooxml:CT_TblPPr_bottomFromText"/>
</resource>
<resource name="CT_TblGridCol" resource="Value" tag="table">
<attribute name="w" tokenid="ooxml:CT_TblGridCol_w" action="setValue"/>
More information about the Libreoffice-commits
mailing list