/* -*- 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/.
*/
// Check that imported background image from PPTX exists
{
uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("not exactly one page", static_cast<sal_Int32>(1),
xDoc->getDrawPages()->getCount());
uno::Reference<drawing::XDrawPage> xPage(getPage(0));
uno::Reference<beans::XPropertySet> xPropertySet(xPage, uno::UNO_QUERY);
uno::Any aAny = xPropertySet->getPropertyValue(u"Background"_ustr); if (aAny.has<uno::Reference<beans::XPropertySet>>())
{
uno::Reference<beans::XPropertySet> xBackgroundPropSet;
aAny >>= xBackgroundPropSet;
aAny = xBackgroundPropSet->getPropertyValue(u"FillBitmapName"_ustr);
aAny >>= bgImageName;
}
CPPUNIT_ASSERT_EQUAL_MESSAGE("Slide Background is not imported from PPTX correctly",
u"msFillBitmap 1"_ustr, bgImageName);
uno::Reference<awt::XBitmap> xBitmap = getBitmapFromTable(bgImageName);
CPPUNIT_ASSERT_MESSAGE("Slide Background Bitmap is missing when imported from PPTX",
xBitmap.is());
}
// Save as PPTX, reload and check again so we make sure exporting to PPTX is working correctly
{
saveAndReload(u"Impress Office Open XML"_ustr);
uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("not exactly one page", static_cast<sal_Int32>(1),
xDoc->getDrawPages()->getCount());
uno::Reference<drawing::XDrawPage> xPage(getPage(0));
uno::Reference<beans::XPropertySet> xPropertySet(xPage, uno::UNO_QUERY);
uno::Any aAny = xPropertySet->getPropertyValue(u"Background"_ustr); if (aAny.hasValue())
{
uno::Reference<beans::XPropertySet> xBackgroundPropSet;
aAny >>= xBackgroundPropSet;
aAny = xBackgroundPropSet->getPropertyValue(u"FillBitmapName"_ustr);
aAny >>= bgImageName;
}
CPPUNIT_ASSERT_EQUAL_MESSAGE("Slide Background is not exported from PPTX correctly",
u"msFillBitmap 1"_ustr, bgImageName);
uno::Reference<awt::XBitmap> xBitmap = getBitmapFromTable(bgImageName);
CPPUNIT_ASSERT_MESSAGE("Slide Background Bitmap is missing when exported from PPTX",
xBitmap.is());
}
// Save as ODP, reload and check again so we make sure exporting and importing to ODP is working correctly
{
saveAndReload(u"impress8"_ustr);
uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("not exactly one page", static_cast<sal_Int32>(1),
xDoc->getDrawPages()->getCount());
uno::Reference<drawing::XDrawPage> xPage(getPage(0));
uno::Reference<beans::XPropertySet> xPropertySet(xPage, uno::UNO_QUERY);
uno::Any aAny = xPropertySet->getPropertyValue(u"Background"_ustr); if (aAny.hasValue())
{
uno::Reference<beans::XPropertySet> xBackgroundPropSet;
aAny >>= xBackgroundPropSet;
aAny = xBackgroundPropSet->getPropertyValue(u"FillBitmapName"_ustr);
aAny >>= bgImageName;
}
CPPUNIT_ASSERT_EQUAL_MESSAGE( "Slide Background is not exported or imported from ODP correctly",
u"msFillBitmap 1"_ustr, bgImageName);
uno::Reference<awt::XBitmap> xBitmap = getBitmapFromTable(bgImageName);
CPPUNIT_ASSERT_MESSAGE( "Slide Background Bitmap is missing when exported or imported from ODP", xBitmap.is());
}
}
CPPUNIT_ASSERT(xPropSet.is()); auto aGeomPropSeq = xPropSet->getPropertyValue(u"CustomShapeGeometry"_ustr)
.get<uno::Sequence<beans::PropertyValue>>(); auto aGeomPropVec
= comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>(aGeomPropSeq);
for (size_t i = 0; i < vFormat.size(); i++)
{ // Load the original file with one image
createSdImpressDoc("odp/document_with_two_images.odp"); const OString sFailedMessage = "Failed on filter: " + vFormat[i].toUtf8();
// Export the document and import again for a check
saveAndReload(vFormat[i]);
// Check whether graphic exported well after it was swapped out
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2),
xDrawPagesSupplier->getDrawPages()->getCount());
uno::Reference<drawing::XDrawPage> xDrawPage(
xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW);
// the problem was that legacy OOoXML animations were lost if store // immediately follows load because they were "converted" async by a timer
xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
assertXPath(pXmlDoc, "//anim:par[@presentation:node-type='timing-root']", 26); // currently getting 52 of these without the fix (depends on timing)
assertXPath(pXmlDoc, "//anim:par", 223);
}
CPPUNIT_TEST_FIXTURE(SdExportTest, testBnc480256)
{
createSdImpressDoc("pptx/bnc480256.pptx"); // In the document, there are two tables with table background properties. // Make sure colors are set properly for individual cells.
// TODO: If you are working on improving table background support, expect // this unit test to fail. In that case, feel free to change the numbers.
const SdrPage* pPage = GetPage(1);
sdr::table::SdrTableObj* pTableObj;
uno::Reference<table::XCellRange> xTable;
uno::Reference<beans::XPropertySet> xCell;
Color nColor;
table::BorderLine2 aBorderLine;
// This border should be invisible.
xCell.set(xTable->getCellByPosition(1, 0), uno::UNO_QUERY_THROW);
xCell->getPropertyValue(u"BottomBorder"_ustr) >>= aBorderLine;
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), sal_Int32(aBorderLine.LineWidth));
}
xmlDocUniquePtr pXmlDoc = parseExport(u"content.xml"_ustr);
assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/" "style:style[@style:name='gr1']/" "style:graphic-properties[@foo:non-existent-att='bar']"); // TODO: if the namespace is *known*, the attribute is not preserved, but that seems to be a pre-existing problem, or maybe it's even intentional? // assertXPath(pXmlDoc, "/office:document-content/office:automatic-styles/style:style[@style:name='gr1']/style:graphic-properties[@svg:non-existent-att='blah']"); // this was on style:graphic-properties on the import, but the export moves it to root node which is OK
assertXPathNSDef(pXmlDoc, "/office:document-content", "foo", "http://example.com/");
}
// Without the fix in place, this test would have failed with // - Expected: 0 // - Actual : 1
CPPUNIT_ASSERT_EQUAL(text::WritingMode2::LR_TB, nWritingMode);
}
CPPUNIT_TEST_FIXTURE(SdExportTest, testLinkedGraphicRT)
{ // FIXME: PPTX fails
std::vector<OUString> vFormat{ u"impress8"_ustr, u"MS PowerPoint 97"_ustr }; for (size_t i = 0; i < vFormat.size(); i++)
{ // Load the original file with one image
createSdImpressDoc("odp/document_with_linked_graphic.odp");
// Check if the graphic has been imported correctly (before doing the export/import run)
{ static constexpr OString sFailedImportMessage
= "Failed to correctly import the document"_ostr;
SdXImpressDocument* pXImpressDocument
= dynamic_cast<SdXImpressDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pXImpressDocument);
SdDrawDocument* pDoc = pXImpressDocument->GetDoc();
CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pDoc != nullptr); const SdrPage* pPage = pDoc->GetPage(1);
CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pPage != nullptr);
SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(2));
CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pObject != nullptr);
CPPUNIT_ASSERT_MESSAGE(sFailedImportMessage.getStr(), pObject->IsLinkedGraphic());
CPPUNIT_TEST_FIXTURE(SdExportTest, testImageWithSpecialID)
{ // Check how LO handles when the imported graphic's ID is different from that one // which is generated by LO.
std::vector<OUString> vFormat{ u"impress8"_ustr, u"Impress Office Open XML"_ustr,
u"MS PowerPoint 97"_ustr }; for (size_t i = 0; i < vFormat.size(); i++)
{ // Load the original file
createSdImpressDoc("odp/images_with_special_IDs.odp"); const OString sFailedMessage = "Failed on filter: " + vFormat[i].toUtf8();
saveAndReload(vFormat[i]);
// Check whether graphic was exported well
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(mxComponent,
uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2),
xDrawPagesSupplier->getDrawPages()->getCount());
uno::Reference<drawing::XDrawPage> xDrawPage(
xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY_THROW);
//there should be only *one* shape
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xPage->getCount());
uno::Reference<beans::XPropertySet> xShape(getShape(0, xPage)); //checking Paragraph's Left Margin with expected value
sal_Int32 nParaLeftMargin = 0;
xShape->getPropertyValue(u"ParaLeftMargin"_ustr) >>= nParaLeftMargin;
CPPUNIT_ASSERT_EQUAL(sal_Int32(2000), nParaLeftMargin); //checking Paragraph's First Line Indent with expected value
sal_Int32 nParaFirstLineIndent = 0;
xShape->getPropertyValue(u"ParaFirstLineIndent"_ustr) >>= nParaFirstLineIndent;
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1300), nParaFirstLineIndent);
//Checking the *Text* in TextBox
uno::Reference<text::XTextRange> xParagraph(getParagraphFromShape(0, xShape));
CPPUNIT_ASSERT_EQUAL(u"Hello World"_ustr, xParagraph->getString());
//Saving and Reloading the file
saveAndReload(u"impress8"_ustr);
uno::Reference<drawing::XDrawPage> xPage2(getPage(0)); //there should be only *one* shape
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xPage2->getCount());
uno::Reference<beans::XPropertySet> xShape2(getShape(0, xPage2)); //checking Paragraph's Left Margin with expected value
sal_Int32 nParaLeftMargin2 = 0;
xShape2->getPropertyValue(u"ParaLeftMargin"_ustr) >>= nParaLeftMargin2;
CPPUNIT_ASSERT_EQUAL(sal_Int32(2000), nParaLeftMargin2); //checking Paragraph's First Line Indent with expected value
sal_Int32 nParaFirstLineIndent2 = 0;
xShape2->getPropertyValue(u"ParaFirstLineIndent"_ustr) >>= nParaFirstLineIndent2;
CPPUNIT_ASSERT_EQUAL(sal_Int32(-1300), nParaFirstLineIndent2);
//Checking the *Text* in TextBox
uno::Reference<text::XTextRange> xParagraph2(getParagraphFromShape(0, xShape2));
CPPUNIT_ASSERT_EQUAL(u"Hello World"_ustr, xParagraph2->getString());
}
CPPUNIT_TEST_FIXTURE(SdExportTest, testEmbeddedPdf)
{ auto pPdfium = vcl::pdf::PDFiumLibrary::get(); if (!pPdfium)
{ return;
}
// Without the accompanying fix in place, this test would have failed with: // - Expected: 75 // - Actual : 0 // i.e. the 75% transparent text was turned into a "not transparent at all" text.
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int16>(75), nCharTransparence);
}
uno::Reference<drawing::XDrawPage> xPage = getPage(0);
uno::Reference<drawing::XShape> xShape(xPage->getByIndex(1), uno::UNO_QUERY); // Default subscripts were too large, enlarging the gap between the next line. // The exact size isn't important. Was 18975, now 16604.
CPPUNIT_ASSERT(17000 > xShape->getSize().Height);
}
saveAndReload(u"impress8"_ustr);
uno::Reference<drawing::XDrawPagesSupplier> xDoc(mxComponent, uno::UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL_MESSAGE("There should be exactly one page", static_cast<sal_Int32>(1),
xDoc->getDrawPages()->getCount());
CPPUNIT_TEST_FIXTURE(SdExportTest, testTextRotation)
{ // Save behavior depends on whether ODF strict or extended is used.
Resetter resetter([]() { SetODFDefaultVersion(SvtSaveOptions::ODFVER_LATEST); });
// The contained shape has a text rotation vert="vert" which corresponds to // loext:writing-mode="tb-rl90" in the graphic-properties of the style of the shape in ODF 1.3 // extended. // Save to ODF 1.3 extended. Adapt 3 (=ODFVER_LATEST) to a to be ODFVER_013_EXTENDED when // attribute value "tb-rl90" is included in ODF strict.
{
createSdImpressDoc("pptx/shape-text-rotate.pptx");
saveAndReload(u"impress8"_ustr);
auto aWritingMode = xPropSet->getPropertyValue(u"WritingMode"_ustr).get<sal_Int16>();
CPPUNIT_ASSERT_EQUAL(sal_Int16(text::WritingMode2::TB_RL90), aWritingMode);
} // In ODF 1.3 strict the workaround to use the TextRotateAngle is used instead.
{
SetODFDefaultVersion(SvtSaveOptions::ODFDefaultVersion::ODFVER_013);
// Graphic Bitmap
CPPUNIT_ASSERT_MESSAGE("No bitmap for the bullets", xBitmap.is());
Graphic aGraphic(uno::Reference<graphic::XGraphic>(xBitmap, uno::UNO_QUERY));
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aGraphic.GetType());
CPPUNIT_ASSERT(aGraphic.GetSizeBytes() > o3tl::make_unsigned(0));
// FIXME: what happened here
CPPUNIT_ASSERT_EQUAL(tools::Long(64), aGraphic.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL(tools::Long(64), aGraphic.GetSizePixel().Height());
// Was unable to export iterate container (tdf#99213).
saveAndReload(u"Impress Office Open XML"_ustr); // Was unable to import iterate container (tdf#113822).
save(u"impress8"_ustr);
// IterateContainer was created as ParallelTimeContainer before, so // the iterate type is not set too.
assertXPath(pXmlDoc, "//anim:iterate", "iterate-type", u"by-letter"); // The target of the child animation nodes need to be in the iterate container.
assertXPath(pXmlDoc, "//anim:iterate", "targetElement", u"id1");
assertXPath(pXmlDoc, "//anim:iterate/anim:set", "attributeName", u"text-underline");
assertXPath(pXmlDoc, "//anim:iterate/anim:set", "to", u"solid");
}
// MSO's effect node type Click parallel node, with group node, after group node // were missing.
assertXPath(pXmlDoc, "//draw:page" "/anim:par[@presentation:node-type='timing-root']" "/anim:seq[@presentation:node-type='main-sequence']" "/anim:par[@presentation:node-type='on-click']" "/anim:par[@presentation:node-type='with-previous']" "/anim:par[@presentation:node-type='on-click']" "/anim:animate[@anim:formula='width*sin(2.5*pi*$)']",
1);
}
Color aExpectedColor(0xC2DEEA);
aExpectedColor.SetAlpha(0xF);
// Without the fix in place, this test would have failed with // - Expected: Color: R:194 G:222 B:234 A:240 // - Actual : Color: R:194 G:222 B:234 A:15
CPPUNIT_ASSERT_EQUAL(aExpectedColor, aBitmap.GetPixelColor(960, 540));
}
// Get first paragraph of the text
uno::Reference<text::XTextRange> const xParagraph(getParagraphFromShape(0, xShape));
// Get first run of the paragraph
uno::Reference<text::XTextRange> xRun(getRunFromParagraph(0, xParagraph));
uno::Reference<beans::XPropertySet> xPropSet(xRun, uno::UNO_QUERY_THROW);
// Check character underline, to make sure it has been set correctly
sal_uInt32 nCharUnderline;
xPropSet->getPropertyValue(u"CharUnderline"_ustr) >>= nCharUnderline;
CPPUNIT_ASSERT_EQUAL(sal_uInt32(1), nCharUnderline);
}
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.