[Libreoffice-commits] core.git: sw/qa sw/source
Patrick Jaap (via logerrit)
logerrit at kemper.freedesktop.org
Fri Apr 5 13:34:20 UTC 2019
sw/qa/extras/uiwriter/data2/floating-table-position.docx |binary
sw/qa/extras/uiwriter/uiwriter2.cxx | 41 +++
sw/source/filter/ww8/docxattributeoutput.cxx | 197 +++++++++------
3 files changed, 164 insertions(+), 74 deletions(-)
New commits:
commit 2d6f8c36126effc66ea35af2e65da6609fcfe013
Author: Patrick Jaap <patrick.jaap at tu-dresden.de>
AuthorDate: Thu Feb 14 10:08:58 2019 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Apr 5 15:33:48 2019 +0200
FIX: DOCX export: use all updated attributes during table export
In a previous commit only x/y coordinate were considered.
For better overview make use of the OOXML converter for orients and relations.
Change-Id: I9792ccfbc2ebb58fd768c14278cdfd9b54efe62f
Reviewed-on: https://gerrit.libreoffice.org/69523
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/sw/qa/extras/uiwriter/data2/floating-table-position.docx b/sw/qa/extras/uiwriter/data2/floating-table-position.docx
new file mode 100644
index 000000000000..de7a467aac1b
Binary files /dev/null and b/sw/qa/extras/uiwriter/data2/floating-table-position.docx differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 9655d1e9b80c..ddebd9a1a662 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -71,6 +71,7 @@ public:
void testDropDownFormFieldInsertion();
void testMixedFormFieldInsertion();
void testTdf124261();
+ void testDocxAttributeTableExport();
CPPUNIT_TEST_SUITE(SwUiWriterTest2);
CPPUNIT_TEST(testRedlineMoveInsertInDelete);
@@ -100,6 +101,7 @@ public:
CPPUNIT_TEST(testDropDownFormFieldInsertion);
CPPUNIT_TEST(testMixedFormFieldInsertion);
CPPUNIT_TEST(testTdf124261);
+ CPPUNIT_TEST(testDocxAttributeTableExport);
CPPUNIT_TEST_SUITE_END();
virtual std::unique_ptr<Resetter> preTest(const char* filename) override
@@ -1158,6 +1160,45 @@ void SwUiWriterTest2::testTdf124261()
#endif
}
+void SwUiWriterTest2::testDocxAttributeTableExport()
+{
+ createDoc("floating-table-position.docx");
+
+ // get the table frame, set new values and dismiss the references
+ {
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xDrawPage(xDrawPageSupplier->getDrawPage(),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+
+ // change the properties
+ // 8133 -> 8000
+ xShape->setPropertyValue("VertOrientPosition", uno::makeAny(static_cast<sal_Int32>(8000)));
+ // 5964 -> 5000
+ xShape->setPropertyValue("HoriOrientPosition", uno::makeAny(static_cast<sal_Int32>(5000)));
+ // 0 (frame) -> 8 (page print area)
+ xShape->setPropertyValue("VertOrientRelation", uno::makeAny(static_cast<sal_Int16>(8)));
+ // 8 (page print area) -> 0 (frame)
+ xShape->setPropertyValue("HoriOrientRelation", uno::makeAny(static_cast<sal_Int16>(0)));
+ }
+ // save it to docx
+ reload("Office Open XML Text", "floating-table-position.docx");
+
+ uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xDrawPage(xDrawPageSupplier->getDrawPage(),
+ uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
+
+ // test the new values
+ sal_Int32 nValue = getProperty<sal_Int32>(xShape, "VertOrientPosition");
+ CPPUNIT_ASSERT(sal_Int32(7999) <= nValue && nValue <= sal_Int32(8001));
+ nValue = getProperty<sal_Int32>(xShape, "HoriOrientPosition");
+ CPPUNIT_ASSERT(sal_Int32(4999) <= nValue && nValue <= sal_Int32(5001));
+
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(8), getProperty<sal_Int16>(xShape, "VertOrientRelation"));
+ CPPUNIT_ASSERT_EQUAL(sal_Int16(0), getProperty<sal_Int16>(xShape, "HoriOrientRelation"));
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index c1a20445fc09..e4ce85632f08 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -500,8 +500,6 @@ static OString convertToOOXMLVertOrient(sal_Int16 nOrient)
{
switch( nOrient )
{
- case text::VertOrientation::NONE:
- return OString();
case text::VertOrientation::CENTER:
case text::VertOrientation::LINE_CENTER:
return OString( "center" );
@@ -512,8 +510,9 @@ static OString convertToOOXMLVertOrient(sal_Int16 nOrient)
case text::VertOrientation::TOP:
return OString( "top" );
case text::VertOrientation::LINE_TOP:
- default:
return OString( "inside" );
+ default:
+ return OString();
}
}
@@ -521,17 +520,19 @@ static OString convertToOOXMLHoriOrient(sal_Int16 nOrient, bool bIsPosToggle)
{
switch( nOrient )
{
- case text::HoriOrientation::NONE:
- return OString();
case text::HoriOrientation::LEFT:
return OString( bIsPosToggle ? "inside" : "left" );
+ case text::HoriOrientation::INSIDE:
+ return OString( "inside" );
case text::HoriOrientation::RIGHT:
return OString( bIsPosToggle ? "outside" : "right" );
+ case text::HoriOrientation::OUTSIDE:
+ return OString( "outside" );
case text::HoriOrientation::CENTER:
- // fall-through intended
case text::HoriOrientation::FULL:
- default:
return OString( "center" );
+ default:
+ return OString();
}
}
@@ -3845,84 +3846,132 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t
uno::Sequence<beans::PropertyValue> aTablePosition = rGrabBagElement.second.get<uno::Sequence<beans::PropertyValue> >();
// look for a surrounding frame and take it's position values
const ww8::Frame* pFrame = m_rExport.GetFloatingTableFrame();
- for (sal_Int32 i = 0; i < aTablePosition.getLength(); ++i)
+ if( pFrame )
{
- if (aTablePosition[i].Name == "vertAnchor" && !aTablePosition[i].Value.get<OUString>().isEmpty())
- {
- OString strTemp = OUStringToOString(aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
- attrListTablePos->add( FSNS( XML_w, XML_vertAnchor ), strTemp.getStr() );
- }
- else if (aTablePosition[i].Name == "tblpYSpec" && !aTablePosition[i].Value.get<OUString>().isEmpty())
- {
- OString strTemp = OUStringToOString(aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
- attrListTablePos->add( FSNS( XML_w, XML_tblpYSpec ), strTemp.getStr() );
- }
- else if (aTablePosition[i].Name == "horzAnchor" && !aTablePosition[i].Value.get<OUString>().isEmpty())
- {
- OString strTemp = OUStringToOString(aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
- attrListTablePos->add( FSNS( XML_w, XML_horzAnchor ), strTemp.getStr() );
- }
- else if (aTablePosition[i].Name == "tblpXSpec" && !aTablePosition[i].Value.get<OUString>().isEmpty())
- {
- OString strTemp = OUStringToOString(aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
- attrListTablePos->add( FSNS( XML_w, XML_tblpXSpec ), strTemp.getStr() );
- }
- else if (aTablePosition[i].Name == "bottomFromText")
- {
- attrListTablePos->add( FSNS( XML_w, XML_bottomFromText ), OString::number( aTablePosition[i].Value.get<sal_Int32>() ) );
- }
- else if (aTablePosition[i].Name == "leftFromText")
- {
- attrListTablePos->add( FSNS( XML_w, XML_leftFromText ), OString::number( aTablePosition[i].Value.get<sal_Int32>() ) );
- }
- else if (aTablePosition[i].Name == "rightFromText")
- {
- attrListTablePos->add( FSNS( XML_w, XML_rightFromText ), OString::number( aTablePosition[i].Value.get<sal_Int32>() ) );
- }
- else if (aTablePosition[i].Name == "topFromText")
- {
- attrListTablePos->add( FSNS( XML_w, XML_topFromText ), OString::number( aTablePosition[i].Value.get<sal_Int32>() ) );
- }
- else if (aTablePosition[i].Name == "tblpX")
+ // we export the values of the surrounding Frame
+ OString sOrientation;
+ sal_Int32 nValue;
+
+ // If tblpXSpec or tblpYSpec are present, we do not write tblpX or tblpY!
+ OString sTblpXSpec = convertToOOXMLHoriOrient( pFrame->GetFrameFormat().GetHoriOrient().GetHoriOrient(), pFrame->GetFrameFormat().GetHoriOrient().IsPosToggle() );
+ OString sTblpYSpec = convertToOOXMLVertOrient( pFrame->GetFrameFormat().GetVertOrient().GetVertOrient() );
+
+ sOrientation = convertToOOXMLVertOrientRel( pFrame->GetFrameFormat().GetVertOrient().GetRelationOrient() );
+ if(sOrientation != "page") // do not write default
+ attrListTablePos->add( FSNS( XML_w, XML_vertAnchor ), sOrientation.getStr() );
+
+ if( !sTblpYSpec.isEmpty() )
+ attrListTablePos->add( FSNS( XML_w, XML_tblpYSpec ), sTblpYSpec.getStr() );
+
+ sOrientation = convertToOOXMLHoriOrientRel( pFrame->GetFrameFormat().GetHoriOrient().GetRelationOrient() );
+ if(sOrientation != "page") // do not wirte default
+ attrListTablePos->add( FSNS( XML_w, XML_horzAnchor ), sOrientation.getStr() );
+
+ if( !sTblpXSpec.isEmpty() )
+ attrListTablePos->add( FSNS( XML_w, XML_tblpXSpec ), sTblpXSpec.getStr() );
+
+ nValue = pFrame->GetFrameFormat().GetULSpace().GetLower();
+ if( nValue != 0 )
+ attrListTablePos->add( FSNS( XML_w, XML_bottomFromText ), OString::number( nValue ) );
+
+ nValue = pFrame->GetFrameFormat().GetLRSpace().GetLeft();
+ if( nValue != 0 )
+ attrListTablePos->add( FSNS( XML_w, XML_leftFromText ), OString::number( nValue ) );
+
+ nValue = pFrame->GetFrameFormat().GetLRSpace().GetRight();
+ if( nValue != 0 )
+ attrListTablePos->add( FSNS( XML_w, XML_rightFromText ), OString::number( nValue ) );
+
+ nValue = pFrame->GetFrameFormat().GetULSpace().GetUpper();
+ if( nValue != 0 )
+ attrListTablePos->add( FSNS( XML_w, XML_topFromText ), OString::number( nValue ) );
+
+ if( sTblpXSpec.isEmpty() ) // do not write tblpX if tblpXSpec is present
{
- sal_Int32 nValue = 0;
- if (pFrame)
+ nValue = pFrame->GetFrameFormat().GetHoriOrient().GetPos();
+ // we need to revert the additional shift introduced by
+ // lcl_DecrementHoriOrientPosition() in writerfilter
+ // 1st: left distance of the table
+ const SwTableBox * pTabBox = pTableTextNodeInfoInner->getTableBox();
+ const SwFrameFormat * pFrameFormat = pTabBox->GetFrameFormat();
+ const SvxBoxItem& rBox = pFrameFormat->GetBox( );
+ sal_uInt16 nLeftDistance = rBox.GetDistance(SvxBoxItemLine::LEFT);
+ nValue += nLeftDistance;
+
+ // 2nd: if a left border is given, revert the shift by half the width
+ // from lcl_DecrementHoriOrientPosition() in writerfilter
+ if (const editeng::SvxBorderLine* pLeftBorder = rBox.GetLeft())
{
- nValue = pFrame->GetFrameFormat().GetHoriOrient().GetPos();
- // we need to revert the additional shift introduced by
- // lcl_DecrementHoriOrientPosition() in writerfilter
- // 1st: left distance of the table
- const SwTableBox * pTabBox = pTableTextNodeInfoInner->getTableBox();
- const SwFrameFormat * pFrameFormat = pTabBox->GetFrameFormat();
- const SvxBoxItem& rBox = pFrameFormat->GetBox( );
- sal_uInt16 nLeftDistance = rBox.GetDistance(SvxBoxItemLine::LEFT);
- nValue += nLeftDistance;
-
- // 2nd: if a left border is given, revert the shift by half the width
- // from lcl_DecrementHoriOrientPosition() in writerfilter
- if (const editeng::SvxBorderLine* pLeftBorder = rBox.GetLeft())
- {
- long nWidth = pLeftBorder->GetWidth();
- nValue += (nWidth / 2);
- }
+ long nWidth = pLeftBorder->GetWidth();
+ nValue += (nWidth / 2);
}
- else
- nValue = aTablePosition[i].Value.get<sal_Int32>();
attrListTablePos->add( FSNS( XML_w, XML_tblpX ), OString::number( nValue ) );
}
- else if (aTablePosition[i].Name == "tblpY")
- {
- sal_Int32 nValue = 0;
- if (pFrame)
- // no additional shift occur (like in the tblpX case)
- nValue = pFrame->GetFrameFormat().GetVertOrient().GetPos();
- else
- nValue = aTablePosition[i].Value.get<sal_Int32>();
+ if( sTblpYSpec.isEmpty() ) // do not write tblpY if tblpYSpec is present
+ {
+ nValue = pFrame->GetFrameFormat().GetVertOrient().GetPos();
attrListTablePos->add( FSNS( XML_w, XML_tblpY ), OString::number( nValue ) );
}
}
+ else // ( pFrame = 0 )
+ {
+ // we export the values from the grabBag
+ for (sal_Int32 i = 0; i < aTablePosition.getLength(); ++i)
+ {
+ if (aTablePosition[i].Name == "vertAnchor" && !aTablePosition[i].Value.get<OUString>().isEmpty())
+ {
+ OString sOrientation = OUStringToOString( aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
+ attrListTablePos->add( FSNS( XML_w, XML_vertAnchor ), sOrientation.getStr() );
+ }
+ else if (aTablePosition[i].Name == "tblpYSpec" && !aTablePosition[i].Value.get<OUString>().isEmpty())
+ {
+ OString sOrientation = OUStringToOString( aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
+ attrListTablePos->add( FSNS( XML_w, XML_tblpYSpec ), sOrientation.getStr() );
+ }
+ else if (aTablePosition[i].Name == "horzAnchor" && !aTablePosition[i].Value.get<OUString>().isEmpty())
+ {
+ OString sOrientation = OUStringToOString( aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
+ attrListTablePos->add( FSNS( XML_w, XML_horzAnchor ), sOrientation.getStr() );
+ }
+ else if (aTablePosition[i].Name == "tblpXSpec" && !aTablePosition[i].Value.get<OUString>().isEmpty())
+ {
+ OString sOrientation = OUStringToOString( aTablePosition[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8);
+ attrListTablePos->add( FSNS( XML_w, XML_tblpXSpec ), sOrientation.getStr() );
+ }
+ else if (aTablePosition[i].Name == "bottomFromText")
+ {
+ sal_Int32 nValue = aTablePosition[i].Value.get<sal_Int32>();
+ attrListTablePos->add( FSNS( XML_w, XML_bottomFromText ), OString::number( nValue ) );
+ }
+ else if (aTablePosition[i].Name == "leftFromText")
+ {
+ sal_Int32 nValue = aTablePosition[i].Value.get<sal_Int32>();
+ attrListTablePos->add( FSNS( XML_w, XML_leftFromText ), OString::number( nValue ) );
+ }
+ else if (aTablePosition[i].Name == "rightFromText")
+ {
+ sal_Int32 nValue = aTablePosition[i].Value.get<sal_Int32>();
+ attrListTablePos->add( FSNS( XML_w, XML_rightFromText ), OString::number( nValue ) );
+ }
+ else if (aTablePosition[i].Name == "topFromText")
+ {
+ sal_Int32 nValue = aTablePosition[i].Value.get<sal_Int32>();
+ attrListTablePos->add( FSNS( XML_w, XML_topFromText ), OString::number( nValue ) );
+ }
+ else if (aTablePosition[i].Name == "tblpX")
+ {
+ sal_Int32 nValue = aTablePosition[i].Value.get<sal_Int32>();
+ attrListTablePos->add( FSNS( XML_w, XML_tblpX ), OString::number( nValue ) );
+ }
+ else if (aTablePosition[i].Name == "tblpY")
+ {
+ sal_Int32 nValue = aTablePosition[i].Value.get<sal_Int32>();
+ attrListTablePos->add( FSNS( XML_w, XML_tblpY ), OString::number( nValue ) );
+ }
+ }
+ }
XFastAttributeListRef xAttrListTablePosRef( attrListTablePos );
More information about the Libreoffice-commits
mailing list