/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
class Test : public SwModelTestBase
{ public:
Test() : SwModelTestBase(u"/sw/qa/extras/ooxmlexport/data/"_ustr, u"Office Open XML Text"_ustr) {}
protected: // We import OOXML's EMUs into integral mm100 internal representation, then export back into // EMUs. This results in inaccuracies. void assertXPathHasApproxEMU(const xmlDocUniquePtr& pXmlDoc, constchar* pXPath, constchar* pAttribute, sal_Int64 nAttributeVal)
{
OUString val = getXPath(pXmlDoc, pXPath, pAttribute); // Use precision of 1/2 of 100th of mm, which is 180 EMU
CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
OString(OString::Concat("XPath: ") + pXPath + "\nAttribute: " + pAttribute).getStr(), nAttributeVal,
val.toInt64(), 180);
}
};
CPPUNIT_TEST_FIXTURE(Test, testChildNodesOfCubicBezierTo)
{
loadAndSave("FDO74774.docx"); /* Number of children required by cubicBexTo is 3 of type "pt". While exporting, sometimes the child nodes are less than 3. The test case ensures that there are 3 child nodes of type "pt" for cubicBexTo
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
DECLARE_OOXMLEXPORT_TEST(testGroupshapeThemeFont, "groupshape-theme-font.docx")
{ // Font was specified using a theme reference, which wasn't handled.
uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xGroup->getByIndex(0), uno::UNO_QUERY_THROW)->getText();
uno::Reference<text::XTextRange> xRun = getRun(getParagraphOfText(1, xText),1); // This was Calibri.
CPPUNIT_ASSERT_EQUAL(u"Cambria"_ustr, getProperty<OUString>(xRun, u"CharFontName"_ustr));
}
DECLARE_OOXMLEXPORT_TEST(testDkVert, "dkvert.docx")
{ // <a:pattFill prst="dkVert"> was exported as ltVert.
uno::Reference<container::XIndexAccess> xGroup(getShape(1), uno::UNO_QUERY);
uno::Reference<beans::XPropertySet> xShape(xGroup->getByIndex(0), uno::UNO_QUERY); // This was 50.
CPPUNIT_ASSERT_EQUAL(sal_Int32(25), getProperty<drawing::Hatch>(xShape, u"FillHatch"_ustr).Distance);
}
CPPUNIT_TEST_FIXTURE(Test, testTextWatermark)
{
loadAndSave("textWatermark.docx"); //The problem was that the watermark ID was not preserved, //and Word uses the object ID to identify if it is a watermark. //It has to have the 'PowerPlusWaterMarkObject' string in it
xmlDocUniquePtr pXmlHeader2 = parseExport(u"word/header2.xml"_ustr);
//The second problem was that Word uses also "o:spid" const OUString sSpid = getXPath(pXmlHeader2, "/w:hdr[1]/w:p[1]/w:r[1]/w:pict[1]/v:shape[1]","spid");
CPPUNIT_ASSERT(!sSpid.isEmpty());
}
CPPUNIT_TEST_FIXTURE(Test, testPictureWatermark)
{
loadAndSave("pictureWatermark.docx"); //The problem was that the watermark ID was not preserved, //and Word uses the object ID to identify if it is a watermark. //It has to have the 'WordPictureWaterMarkObject' string in it
// Check the watermark ID
assertXPath(pXmlHeader2, "/w:hdr[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Fallback[1]/w:pict[1]/v:shape[1]","id",u"WordPictureWatermark11962361");
}
CPPUNIT_TEST_FIXTURE(Test, testFdo76249)
{
loadAndSave("fdo76249.docx"); /* * The Locked Canvas is imported correctly, but while exporting * the drawing element is exported inside a textbox. However the drawing has to exported * as a Locked Canvas inside a text-box for the RT file to work in MS Word, as drawing elements * are not allowed inside the textboxes.
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc, "/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Fallback[1]/w:pict[1]/v:rect[1]/v:textbox[1]/w:txbxContent[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:inline[1]/a:graphic[1]/a:graphicData[1]/lc:lockedCanvas[1]",1);
}
CPPUNIT_TEST_FIXTURE(Test, testFdo76979)
{
loadAndSave("fdo76979.docx"); // The problem was that black was exported as "auto" fill color, resulting in well-formed, but invalid XML.
xmlDocUniquePtr pXmlDoc = parseExport(u"word/header2.xml"_ustr); // This was "auto", not "FFFFFF".
assertXPath(pXmlDoc, "//wps:spPr/a:solidFill/a:srgbClr", "val", u"FFFFFF");
}
// first picture: glow effect with theme color and transformations, 3d rotation and extrusion
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/" "wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:glow", "rad", u"228600");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/" "wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:glow/a:srgbClr", "val", u"267de6");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/" "wp:anchor/a:graphic/a:graphicData/pic:pic/pic:spPr/a:effectLst/a:glow/a:srgbClr/a:alpha", "val", u"40000");
CPPUNIT_TEST_FIXTURE(Test, testNestedAlternateContent)
{
loadAndSave("nestedAlternateContent.docx");
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // We check alternateContent could not contains alternateContent (i.e. nested alternateContent)
assertXPath(pXmlDoc,"/w:document[1]/w:body[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/a:graphic[1]/a:graphicData[1]/wpg:wgp[1]/wps:wsp[2]/wps:txbx[1]/w:txbxContent[1]/w:p[1]/w:r[2]/mc:AlternateContent[1]",0);
}
#if 0 // Currently LibreOffice exports custom geometry for this hexagon, not preset shape. // When LibreOffice can export preset shapes with correct modifiers, then this test can be re-enabled.
DECLARE_OOXMLEXPORT_TEST(testTdf77219_backgroundShape, "tdf77219_backgroundShape.docx")
{
CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape is in front of the paragraph", false, getProperty<bool>(getShape(1), u"Opaque"_ustr));
// tdf#126533: gradient is purple foreground to white background (top-right to bottom-left)
uno::Reference<beans::XPropertySet> xRectangle(getShape(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xRectangle, u"FillStyle"_ustr));
awt::Gradient2 aGradient = getProperty<awt::Gradient2>(xRectangle, u"FillGradient"_ustr);
CPPUNIT_ASSERT_EQUAL(size_t(2), aColorStops.size());
CPPUNIT_ASSERT_EQUAL(0.0, aColorStops[0].getStopOffset());
CPPUNIT_ASSERT_EQUAL(Color(0x5f497a), Color(aColorStops[0].getStopColor()));
CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 1.0));
CPPUNIT_ASSERT_EQUAL(COL_WHITE, Color(aColorStops[1].getStopColor()));
CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style); // without the fix, this was 1350 (visually the colors were reversed)
CPPUNIT_ASSERT_EQUAL(sal_Int16(3150), aGradient.Angle);
}
DECLARE_OOXMLEXPORT_TEST(testTdf126533_axialAngle, "tdf126533_axialAngle.docx")
{ // axial gradient is purple foreground/lime background in the middle (top-left to bottom-right)
uno::Reference<beans::XPropertySet> xPageStyle(getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xPageStyle, u"FillStyle"_ustr));
awt::Gradient2 aGradient = getProperty<awt::Gradient2>(xPageStyle, u"FillGradient"_ustr);
// without the fix, this was 1350 (visually the colors were reversed)
CPPUNIT_ASSERT_EQUAL(sal_Int16(2250), aGradient.Angle);
CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTGREEN), aGradient.StartColor);
CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTMAGENTA), aGradient.EndColor);
}
DECLARE_OOXMLEXPORT_TEST(testTdf126533_axialAngle2, "tdf126533_axialAngle2.docx")
{ // axial gradient is purple foreground/lime background in the middle (top-right to bottom-left)
uno::Reference<beans::XPropertySet> xPageStyle(getStyles(u"PageStyles"_ustr)->getByName(u"Standard"_ustr),
uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, getProperty<drawing::FillStyle>(xPageStyle, u"FillStyle"_ustr));
awt::Gradient2 aGradient = getProperty<awt::Gradient2>(xPageStyle, u"FillGradient"_ustr);
DECLARE_OOXMLEXPORT_TEST(testTdf77219_foregroundShape, "tdf77219_foregroundShape.docx")
{
CPPUNIT_ASSERT_EQUAL_MESSAGE("Shape is in front of the paragraph", true, getProperty<bool>(getShape(1), u"Opaque"_ustr));
}
DECLARE_OOXMLEXPORT_TEST(testTdf108973_backgroundTextbox, "tdf108973_backgroundTextbox.docx")
{
CPPUNIT_ASSERT_EQUAL_MESSAGE("Textbox is in front of the paragraph", false, getProperty<bool>(getShape(1), u"Opaque"_ustr));
}
DECLARE_OOXMLEXPORT_TEST(testTdf108973_foregroundTextbox, "tdf108973_foregroundTextbox.docx")
{
CPPUNIT_ASSERT_EQUAL_MESSAGE("Textbox is in front of the paragraph", true, getProperty<bool>(getShape(1), u"Opaque"_ustr));
}
DECLARE_OOXMLEXPORT_TEST(testPresetShape, "preset-shape.docx")
{ // Document contains a flowChartMultidocument preset shape, our date for that shape wasn't correct.
uno::Reference<beans::XPropertySet> xPropertySet(getShape(1), uno::UNO_QUERY);
comphelper::SequenceAsHashMap aCustomShapeGeometry(xPropertySet->getPropertyValue(u"CustomShapeGeometry"_ustr));
comphelper::SequenceAsHashMap aPath(aCustomShapeGeometry[u"Path"_ustr]);
uno::Sequence<awt::Size> aSubViewSize((aPath[u"SubViewSize"_ustr]).get<uno::Sequence<awt::Size> >() );
// This was 0.
CPPUNIT_ASSERT_EQUAL(sal_Int32(21600), aSubViewSize[0].Height);
}
CPPUNIT_TEST_FIXTURE(Test, testWordArtWithinDraingtool)
{
loadAndSave("testWordArtWithinDraingtool.docx"); /* * Within a file, there is a 2007 wordArt enclosed in a drawing tool * LO was exporting it as below: * Sample XML as in Original file: * <p> <r> <ac> <drawing> <txbx> <txbxContent> .. <pict> </pict> </txbxContent></txbx> </drawing> </ac> </r> </p> * After RT : * <p> <r> <ac> <drawing> <txbx> <txbxContent> .. <drawing> <txbx> <txbxContent> .. </txbxContent></txbx> </drawing> .. </txbxContent></txbx> </drawing> </ac> </r> </p> * Expected : as there is nesting of a 2007 Word Art within a drawing tool, then can be separated in two different runs.
* */
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent",1);
assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Fallback/w:pict/v:rect/v:textbox/w:txbxContent/w:p/w:r/w:pict/v:shape",1); // Make sure that the shape inside a shape is exported as VML-only, no embedded mc:AlternateContent before w:pict.
assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent/w:p/w:r/w:pict",1);
}
CPPUNIT_TEST_FIXTURE(Test, testfdo78663)
{
loadAndSave("fdo78663.docx"); /* * A 2007 word art tool is enclosed in a 2010 drawing toolWithin a file, * Originally the file has the following xml tag hierarchy. * * <p> <r> <ac> <drawing> <txbx> <txbxContent> <pict><shapetype> <shape> ...</shape></shapetype> </pict> </txbxContent></txbx> </drawing> </ac> </r> </p> * After RT : * <p> <r> <ac> <drawing> <txbx> <txbxContent> <pict><shapetype> <shape> <textbox><txbxContent> ... </txbxContent></textbox></shape></shapetype> </pict> </txbxContent></txbx> </drawing> </ac> </r> </p> * MSO doesn't allow nesting of txbxContent tags. * As the text of the wordart tool is written in the tag <v:textpath string="Welcome to... "History is fun and informative"/> * We shouldn't repeat it again in <shapetype><shape> <textbox><txbxContent>
* */
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent/w:p/w:r/w:pict/v:shape/v:path",1);
assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Fallback/w:pict/v:rect/v:textbox/w:txbxContent/w:p/w:r/w:pict/v:shape/v:path",1); // Make sure that the shape inside a shape is exported as VML-only, no embedded mc:AlternateContent before w:pict.
assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent/w:p/w:r/w:pict",1);
}
const sal_Int64 IntMax = SAL_MAX_INT32;
sal_Int64 cx = 0, cy = 0;
cx = getXPath(pXmlHeader,"/w:hdr[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:extent[1]","cx").toInt64();
cy = getXPath(pXmlHeader,"/w:hdr[1]/w:p[1]/w:r[1]/mc:AlternateContent[1]/mc:Choice[1]/w:drawing[1]/wp:anchor[1]/wp:extent[1]","cy").toInt64(); // Here we check the values of extent width & height
CPPUNIT_ASSERT(cx <= IntMax );
CPPUNIT_ASSERT(cy >= 0 );
}
CPPUNIT_TEST_FIXTURE(Test, testfdo79256)
{
loadAndSave("fdo79256.docx"); /* corruption issue also solved by fixing tdf#108064: * since that LO keeps MSO preset dash styles during OOXML export
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
CPPUNIT_TEST_FIXTURE(Test, testDashedLine_CustDash1000thOfPercent)
{
loadAndSave("dashed_line_custdash_1000th_of_percent.docx"); /* Make sure that preset line is exported correctly as "1000th of a percent". * This test-file has a CUSTOM dash-line that is defined as '1000th of a percent'. * This should be imported by LO as-is, and exported back with the same values.
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
CPPUNIT_TEST_FIXTURE(Test, testDashedLine_CustDashPercentage)
{
loadAndSave("dashed_line_custdash_percentage.docx"); /* Make sure that preset line is exported correctly as "1000th of a percent". * This test-file has a CUSTOM dash-line that is defined as percentages. * This should be imported by LO as '1000th of a percent', and exported back * as '1000th of a percent'.
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
// Test that the shape is a rounded rectangle.
CPPUNIT_ASSERT_EQUAL(u"ooxml-roundRect"_ustr, aCustomShapeGeometry[u"Type"_ustr].get<OUString>());
// The shape text should start with a table, with "a" in its A1 cell.
uno::Reference<text::XText> xText = uno::Reference<text::XTextRange>(xShape, uno::UNO_QUERY_THROW)->getText();
uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1, xText), uno::UNO_QUERY);
uno::Reference<text::XTextRange> xCell(xTable->getCellByName(u"A1"_ustr), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(u"a"_ustr, xCell->getString());
}
CPPUNIT_TEST_FIXTURE(Test, testfdo79591)
{
loadAndSave("fdo79591.docx"); /* Values set for docPr name and shape ID attributes * in RT file were not valid as per UTF-8 encoding format * and hence was showing RT document as corrupt with error * message "invalid character"
*/
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
DECLARE_OOXMLEXPORT_TEST(testBnc884615, "bnc884615.docx")
{ // The problem was that the shape in the header wasn't in the background.
CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(getShape(1), u"Opaque"_ustr));
}
// Rotation value was not roundtripped for textframe.
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r[2]/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:xfrm", "rot",u"16200000");
// w:enforcement defaults to off if not explicitly specified, so DocProtect forms should not be enabled.
uno::Reference<text::XTextSectionsSupplier> xTextSectionsSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xSections(xTextSectionsSupplier->getTextSections(), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL_MESSAGE("No protected sections", sal_Int32(0), xSections->getCount());
}
CPPUNIT_TEST_FIXTURE(Test, testfdo80895)
{
loadAndSave("fdo80895.docx"); // DML shapes in header and footer were not getting rendered in LO and the same were not preserved after RT. // In actual there was a shape but because of fetching wrong theme for header.xml or footer.xml // resultant shape was with <a:noFill/> prop in <wps:spPr> hence was not visible. // Checking there is a shape in header without <a:noFill/> element.
// w:sectPr is not exported
assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:r[2]/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor" "/a:graphic/a:graphicData/wps:wsp/wps:txbx/w:txbxContent/w:p[2]/w:pPr/w:sectPr", 0);
// and drawing is no longer in the document
assertXPath(pXmlDocument, "/w:document/w:body/w:p[1]/w:r[3]", 0);
//but it's in the header
pXmlDocument = parseExport(u"word/header1.xml"_ustr);
CPPUNIT_TEST_FIXTURE(Test, testWrapTightThrough)
{
loadAndSave("wrap-tight-through.docx"); // These were wrapSquare without a wrap polygon before.
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr); // The first shape should be wrapThrough with a wrap polygon (was wrapSquare).
assertXPath(pXmlDoc, "//w:drawing/wp:anchor[1]/wp:wrapThrough/wp:wrapPolygon/wp:start", "x", u"-1104"); // The second shape should be wrapTight with a wrap polygon (was wrapSquare).
assertXPath(pXmlDoc, "//w:drawing/wp:anchor[1]/wp:wrapTight/wp:wrapPolygon/wp:start", "y", u"792");
}
DECLARE_OOXMLEXPORT_TEST(testPictureWrapPolygon, "picture-wrap-polygon.docx")
{ // The problem was that the wrap polygon was ignored during export.
drawing::PointSequenceSequence aSeqSeq = getProperty<drawing::PointSequenceSequence>(getShape(1), u"ContourPolyPolygon"_ustr); // This was 0: the polygon list was empty.
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), aSeqSeq.getLength());
CPPUNIT_TEST_FIXTURE(Test, testPictureColormodeGrayscale)
{
loadAndSave("picture_colormode_grayscale.docx"); // The problem was that the grayscale was not exported
xmlDocUniquePtr pXmlDoc = parseExport (u"word/document.xml"_ustr);
CPPUNIT_TEST_FIXTURE(Test, testExportShadow)
{
loadAndSave("bnc637947.odt");
CPPUNIT_ASSERT_EQUAL(1, getShapes());
CPPUNIT_ASSERT_EQUAL(1, getPages()); // The problem was that shadows of shapes from non-OOXML origin were not exported to DrawingML
xmlDocUniquePtr pXmlDoc = parseExport(u"word/document.xml"_ustr);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.