Kaydet (Commit) 62b63d9f authored tarafından Miklos Vajna's avatar Miklos Vajna

DOCX export: write wp14:sizeRelH and wp14:sizeRelV for Writer TextFrames

Change-Id: I16ee2682b6fa8c7b194e442d6dbe1437e7743c60
üst 89420ff3
...@@ -408,6 +408,15 @@ protected: ...@@ -408,6 +408,15 @@ protected:
return xShape; return xShape;
} }
/// Get TextFrame by name
uno::Reference<drawing::XShape> getTextFrameByName(OUString aName)
{
uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XNameAccess> xNameAccess(xTextFramesSupplier->getTextFrames(), uno::UNO_QUERY);
uno::Reference<drawing::XShape> xShape(xNameAccess->getByName(aName), uno::UNO_QUERY);
return xShape;
}
void header() void header()
{ {
std::cout << "File tested,Execution Time (ms)" << std::endl; std::cout << "File tested,Execution Time (ms)" << std::endl;
......
...@@ -2524,6 +2524,26 @@ DECLARE_OOXMLEXPORT_TEST(testDrawinglayerPicPos, "drawinglayer-pic-pos.docx") ...@@ -2524,6 +2524,26 @@ DECLARE_OOXMLEXPORT_TEST(testDrawinglayerPicPos, "drawinglayer-pic-pos.docx")
// This was 1828800. // This was 1828800.
assertXPath(pXmlDocument, aXPath, "y", "0"); assertXPath(pXmlDocument, aXPath, "y", "0");
} }
DECLARE_OOXMLEXPORT_TEST(testPageRelSize, "pagerelsize.docx")
{
// First textframe: width is relative from page, but not height.
uno::Reference<drawing::XShape> xTextFrame = getTextFrameByName("Frame1");
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeWidthRelation"));
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeHeightRelation"));
// Second textframe: height is relative from page, but not height.
xTextFrame = getTextFrameByName("Text Box 2");
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeHeightRelation"));
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeWidthRelation"));
}
DECLARE_OOXMLEXPORT_TEST(testRelSizeRound, "rel-size-round.docx")
{
// This was 9: 9.8 was imported as 9 instead of being rounded to 10.
CPPUNIT_ASSERT_EQUAL(sal_Int16(10), getProperty<sal_Int16>(getShape(1), "RelativeHeight"));
}
DECLARE_OOXMLEXPORT_TEST(testShapeThemePreservation, "shape-theme-preservation.docx") DECLARE_OOXMLEXPORT_TEST(testShapeThemePreservation, "shape-theme-preservation.docx")
{ {
xmlDocPtr pXmlDocument = parseExport("word/document.xml"); xmlDocPtr pXmlDocument = parseExport("word/document.xml");
......
...@@ -1756,25 +1756,6 @@ DECLARE_OOXMLIMPORT_TEST(testDMLGroupshapeSdt, "dml-groupshape-sdt.docx") ...@@ -1756,25 +1756,6 @@ DECLARE_OOXMLIMPORT_TEST(testDMLGroupshapeSdt, "dml-groupshape-sdt.docx")
CPPUNIT_ASSERT_EQUAL(OUString("sdt and sdtContent inside groupshape"), uno::Reference<text::XTextRange>(xGroupShape->getByIndex(1), uno::UNO_QUERY)->getString()); CPPUNIT_ASSERT_EQUAL(OUString("sdt and sdtContent inside groupshape"), uno::Reference<text::XTextRange>(xGroupShape->getByIndex(1), uno::UNO_QUERY)->getString());
} }
DECLARE_OOXMLIMPORT_TEST(testPageRelSize, "pagerelsize.docx")
{
// First textframe: width is relative from page, but not height.
uno::Reference<drawing::XShape> xTextFrame = getShape(1);
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeWidthRelation"));
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeHeightRelation"));
// Second textframe: height is relative from page, but not height.
xTextFrame = getShape(2);
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::PAGE_FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeHeightRelation"));
CPPUNIT_ASSERT_EQUAL(text::RelOrientation::FRAME, getProperty<sal_Int16>(xTextFrame, "RelativeWidthRelation"));
}
DECLARE_OOXMLIMPORT_TEST(testRelSizeRound, "rel-size-round.docx")
{
// This was 9: 9.8 was imported as 9 instead of being rounded to 10.
CPPUNIT_ASSERT_EQUAL(sal_Int16(10), getProperty<sal_Int16>(getShape(1), "RelativeHeight"));
}
DECLARE_OOXMLIMPORT_TEST(testDMLGroupShapeCapitalization, "dml-groupshape-capitalization.docx") DECLARE_OOXMLIMPORT_TEST(testDMLGroupShapeCapitalization, "dml-groupshape-capitalization.docx")
{ {
// Capitalization inside a group shape was not imported // Capitalization inside a group shape was not imported
......
...@@ -907,6 +907,29 @@ void DocxSdrExport::writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId) ...@@ -907,6 +907,29 @@ void DocxSdrExport::writeDMLTextFrame(sw::Frame* pParentFrame, int nAnchorId)
pFS->endElementNS(XML_wps, XML_wsp); pFS->endElementNS(XML_wps, XML_wsp);
pFS->endElementNS(XML_a, XML_graphicData); pFS->endElementNS(XML_a, XML_graphicData);
pFS->endElementNS(XML_a, XML_graphic); pFS->endElementNS(XML_a, XML_graphic);
// Relative size of the Text Frame.
if (rSize.GetWidthPercent())
{
pFS->startElementNS(XML_wp14, XML_sizeRelH,
XML_relativeFrom, (rSize.GetWidthPercentRelation() == text::RelOrientation::PAGE_FRAME ? "page" : "margin"),
FSEND);
pFS->startElementNS(XML_wp14, XML_pctWidth, FSEND);
pFS->writeEscaped(OUString::number(rSize.GetWidthPercent() * oox::drawingml::PER_PERCENT));
pFS->endElementNS(XML_wp14, XML_pctWidth);
pFS->endElementNS(XML_wp14, XML_sizeRelH);
}
if (rSize.GetHeightPercent())
{
pFS->startElementNS(XML_wp14, XML_sizeRelV,
XML_relativeFrom, (rSize.GetHeightPercentRelation() == text::RelOrientation::PAGE_FRAME ? "page" : "margin"),
FSEND);
pFS->startElementNS(XML_wp14, XML_pctHeight, FSEND);
pFS->writeEscaped(OUString::number(rSize.GetHeightPercent() * oox::drawingml::PER_PERCENT));
pFS->endElementNS(XML_wp14, XML_pctHeight);
pFS->endElementNS(XML_wp14, XML_sizeRelV);
}
endDMLAnchorInline(&rFrmFmt); endDMLAnchorInline(&rFrmFmt);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment