/* -*- 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/.
*/
namespace
{ /// Tests for svx/source/unodraw/ code. class UnodrawTest : public UnoApiXmlTest
{ public:
UnodrawTest()
: UnoApiXmlTest(u"svx/qa/unit/data/"_ustr)
{
}
};
CPPUNIT_TEST_FIXTURE(UnodrawTest, testWriterGraphicExport)
{ // Load a document with a Writer picture in it.
loadFromFile(u"unodraw-writer-image.odt");
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
uno::Reference<lang::XComponent> xShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
// Export it as JPEG.
uno::Reference<drawing::XGraphicExportFilter> xExportFilter
= drawing::GraphicExportFilter::create(m_xContext); // This resulted in a css::lang::IllegalArgumentException for a Writer // picture.
xExportFilter->setSourceDocument(xShape);
// This resulted in a uno::RuntimeException, assigning a shape to a dialog model's image was // broken.
xModelProps->setPropertyValue(u"ImageURL"_ustr, xShape->getPropertyValue(u"GraphicURL"_ustr));
uno::Reference<graphic::XGraphic> xGraphic;
xModelProps->getPropertyValue(u"Graphic"_ustr) >>= xGraphic;
CPPUNIT_ASSERT(xGraphic.is());
}
// Create a red shadow on it without touching its style.
uno::Reference<beans::XPropertySet> xShapeProps(xShape, uno::UNO_QUERY); // Without the accompanying fix in place, this test would have failed with throwing a // beans.UnknownPropertyException, as shadow-as-direct-formatting on tables were not possible.
xShapeProps->setPropertyValue(u"Shadow"_ustr, uno::Any(true));
Color nRed = COL_LIGHTRED;
xShapeProps->setPropertyValue(u"ShadowColor"_ustr, uno::Any(nRed));
CPPUNIT_ASSERT(xShapeProps->getPropertyValue(u"ShadowColor"_ustr) >>= nRed);
CPPUNIT_ASSERT_EQUAL(COL_LIGHTRED, nRed);
// Without the accompanying fix in place, this test would have failed with: // - Expected: 0 // - Actual : 1 // i.e. there was shadow for the cell text, while here PowerPoint-compatible output is expected, // which has no shadow for cell text (only for cell borders and cell background).
assertXPath(pDocument, "//shadow//sdrblocktext", /*nNumberOfNodes=*/0);
}
CPPUNIT_TEST_FIXTURE(UnodrawTest, testTitleShapeBullets)
{ // Create a title shape with 2 paragraphs in it.
loadFromURL(u"private:factory/simpress"_ustr);
uno::Reference<drawing::XDrawPagesSupplier> xSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<drawing::XDrawPages> xDrawPages = xSupplier->getDrawPages();
uno::Reference<drawing::XDrawPage> xDrawPage(xDrawPages->getByIndex(0), uno::UNO_QUERY); // A default document contains a title shape and a text shape on the first slide.
uno::Reference<drawing::XShape> xTitleShape(xDrawPage->getByIndex(0), uno::UNO_QUERY);
uno::Reference<lang::XServiceInfo> xTitleShapeInfo(xTitleShape, uno::UNO_QUERY);
CPPUNIT_ASSERT(
xTitleShapeInfo->supportsService(u"com.sun.star.presentation.TitleTextShape"_ustr));
uno::Reference<text::XTextRange> xTitleShapeText(xTitleShape, uno::UNO_QUERY);
uno::Reference<text::XText> xText = xTitleShapeText->getText();
uno::Reference<text::XTextRange> xCursor = xText->createTextCursor();
xText->insertString(xCursor, u"foo"_ustr, /*bAbsorb=*/false);
xText->insertControlCharacter(xCursor, text::ControlCharacter::APPEND_PARAGRAPH, /*bAbsorb=*/false);
xText->insertString(xCursor, u"bar"_ustr, /*bAbsorb=*/false);
// Check that the title shape has 2 paragraphs.
uno::Reference<container::XEnumerationAccess> xTextEA(xText, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xTextE = xTextEA->createEnumeration(); // Has a first paragraph.
CPPUNIT_ASSERT(xTextE->hasMoreElements());
xTextE->nextElement(); // Has a second paragraph. // Without the accompanying fix in place, this test would have failed, because the 2 paragraphs // were merged together (e.g. 1 bullet instead of 2 bullets for bulleted paragraphs).
CPPUNIT_ASSERT(xTextE->hasMoreElements());
}
CPPUNIT_TEST_FIXTURE(UnodrawTest, testPngExport)
{ // Given an empty Impress document:
loadFromURL(u"private:factory/simpress"_ustr);
// When exporting that document to PNG with a JSON size:
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY_THROW);
SvMemoryStream aStream;
uno::Reference<io::XOutputStream> xOut = new utl::OOutputStreamWrapper(aStream);
utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor[u"FilterName"_ustr] <<= u"impress_png_Export"_ustr;
aMediaDescriptor[u"FilterOptions"_ustr]
<<= u"{\"PixelHeight\":{\"type\":\"long\",\"value\":\"192\"}," "\"PixelWidth\":{\"type\":\"long\",\"value\":\"192\"}}"_ustr;
aMediaDescriptor[u"OutputStream"_ustr] <<= xOut;
xStorable->storeToURL(u"private:stream"_ustr, aMediaDescriptor.getAsConstPropertyValueList());
// Then make sure that the size request is handled:
aStream.Seek(STREAM_SEEK_TO_BEGIN);
vcl::PngImageReader aPngReader(aStream);
BitmapEx aBitmapEx;
aPngReader.read(aBitmapEx);
Size aSize = aBitmapEx.GetSizePixel(); // Without the accompanying fix in place, this test would have failed with: // - Expected: 192 // - Actual : 595 // i.e. it was not possible to influence the size from the cmdline.
CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(192), aSize.getHeight());
CPPUNIT_ASSERT_EQUAL(static_cast<tools::Long>(192), aSize.getWidth());
}
}
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.