summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2021-05-04 21:26:18 +0200
committerLuboš Luňák <l.lunak@collabora.com>2021-05-06 11:23:11 +0200
commit7603d51e7747a0ea2e628bd467af7d17597a9b10 (patch)
tree462193e0c9f6271305942d184427f0f9fa149cf0
parent402acbcfadbc8fd9f45330b46a4bfaad3e02eb39 (diff)
add a unittest for impress drawing a dotted line in tdf#136957
Change-Id: Icabe039df29e9b3b9155656863120e3df7ef650b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115118 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
-rw-r--r--drawinglayer/CppunitTest_drawinglayer_processors.mk56
-rw-r--r--drawinglayer/Module_drawinglayer.mk4
-rw-r--r--drawinglayer/qa/unit/vclmetafileprocessor2d.cxx176
3 files changed, 236 insertions, 0 deletions
diff --git a/drawinglayer/CppunitTest_drawinglayer_processors.mk b/drawinglayer/CppunitTest_drawinglayer_processors.mk
new file mode 100644
index 000000000000..2c898e9b484a
--- /dev/null
+++ b/drawinglayer/CppunitTest_drawinglayer_processors.mk
@@ -0,0 +1,56 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,drawinglayer_processors))
+
+$(eval $(call gb_CppunitTest_use_api,drawinglayer_processors,\
+ offapi \
+ udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,drawinglayer_processors, \
+ basegfx \
+ cppcanvas \
+ cppu \
+ cppuhelper \
+ sal \
+ salhelper \
+ drawinglayer \
+ vcl \
+ test \
+ tl \
+ unotest \
+ svt \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,drawinglayer_processors,\
+ boost_headers \
+ libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,drawinglayer_processors, \
+ drawinglayer/qa/unit/vclmetafileprocessor2d \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,drawinglayer_processors))
+
+$(eval $(call gb_CppunitTest_use_vcl,drawinglayer_processors))
+
+$(eval $(call gb_CppunitTest_use_components,drawinglayer_processors,\
+ canvas/source/vcl/vclcanvas \
+ canvas/source/factory/canvasfactory \
+ configmgr/source/configmgr \
+ i18npool/util/i18npool \
+ ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,drawinglayer_processors))
+
+# vim: set noet sw=4 ts=4:
diff --git a/drawinglayer/Module_drawinglayer.mk b/drawinglayer/Module_drawinglayer.mk
index 6d329e95c60a..f9460b64fe3a 100644
--- a/drawinglayer/Module_drawinglayer.mk
+++ b/drawinglayer/Module_drawinglayer.mk
@@ -13,6 +13,10 @@ $(eval $(call gb_Module_add_targets,drawinglayer,\
Library_drawinglayer \
))
+$(eval $(call gb_Module_add_check_targets,drawinglayer,\
+ CppunitTest_drawinglayer_processors \
+))
+
$(eval $(call gb_Module_add_slowcheck_targets,drawinglayer,\
CppunitTest_drawinglayer_border \
))
diff --git a/drawinglayer/qa/unit/vclmetafileprocessor2d.cxx b/drawinglayer/qa/unit/vclmetafileprocessor2d.cxx
new file mode 100644
index 000000000000..a8088bf99560
--- /dev/null
+++ b/drawinglayer/qa/unit/vclmetafileprocessor2d.cxx
@@ -0,0 +1,176 @@
+/* -*- 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/.
+ *
+ */
+
+#include <test/bootstrapfixture.hxx>
+
+#include <vcl/virdev.hxx>
+#include <vcl/BitmapReadAccess.hxx>
+#include <vcl/canvastools.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <vcl/metaact.hxx>
+#include <vcl/gdimtf.hxx>
+#include <tools/stream.hxx>
+#include <drawinglayer/geometry/viewinformation2d.hxx>
+#include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
+#include <drawinglayer/processor2d/baseprocessor2d.hxx>
+#include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
+#include <cppcanvas/vclfactory.hxx>
+
+#include <com/sun/star/rendering/XBitmap.hpp>
+#include <com/sun/star/rendering/XCanvas.hpp>
+#include <com/sun/star/rendering/XBitmapCanvas.hpp>
+#include <com/sun/star/rendering/CompositeOperation.hpp>
+
+using namespace drawinglayer;
+using namespace com::sun::star;
+
+class VclMetaFileProcessor2DTest : public test::BootstrapFixture
+{
+ VclPtr<VirtualDevice> mVclDevice;
+ uno::Reference<rendering::XCanvas> mCanvas;
+ rendering::ViewState mViewState;
+ rendering::RenderState mRenderState;
+ uno::Sequence<double> mColorBlack;
+
+ // if enabled - check the result images with:
+ // "xdg-open ./workdir/CppunitTest/drawinglayer_processors.test.core/"
+ static constexpr const bool mbExportBitmap = false;
+
+ void exportDevice(const OUString& filename, const VclPtr<VirtualDevice>& device)
+ {
+ if (mbExportBitmap)
+ {
+ BitmapEx aBitmapEx(device->GetBitmapEx(Point(0, 0), device->GetOutputSizePixel()));
+ SvFileStream aStream(filename, StreamMode::WRITE | StreamMode::TRUNC);
+ GraphicFilter::GetGraphicFilter().compressAsPNG(aBitmapEx, aStream);
+ }
+ }
+
+public:
+ VclMetaFileProcessor2DTest()
+ : BootstrapFixture(true, false)
+ {
+ }
+
+ virtual void setUp() override
+ {
+ BootstrapFixture::setUp();
+ mColorBlack = vcl::unotools::colorToStdColorSpaceSequence(COL_BLACK);
+ // Geometry init
+ com::sun::star::geometry::AffineMatrix2D aUnit(1, 0, 0, 0, 1, 0);
+ mViewState.AffineTransform = aUnit;
+ mRenderState.AffineTransform = aUnit;
+ mRenderState.DeviceColor = mColorBlack;
+ mRenderState.CompositeOperation = rendering::CompositeOperation::OVER;
+ }
+
+ virtual void tearDown() override
+ {
+ mVclDevice.clear();
+ mCanvas = uno::Reference<rendering::XCanvas>();
+ BootstrapFixture::tearDown();
+ }
+
+ void setupCanvas(const Size& size, Color backgroundColor = COL_WHITE, bool alpha = false)
+ {
+ mVclDevice
+ = alpha ? VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT, DeviceFormat::DEFAULT)
+ : VclPtr<VirtualDevice>::Create(DeviceFormat::DEFAULT);
+ mVclDevice->SetOutputSizePixel(size);
+ mVclDevice->SetBackground(Wallpaper(backgroundColor));
+ mVclDevice->Erase();
+ mCanvas = mVclDevice->GetCanvas();
+ CPPUNIT_ASSERT(mCanvas.is());
+ }
+
+ // Test drawing a dotted line in Impress presentation mode.
+ void testTdf136957()
+ {
+ // Impress presentation mode first draws the slide to a metafile.
+ GDIMetaFile metafile;
+ // I got these values by adding debug output to cppcanvas::internal::ImplRenderer::ImplRenderer().
+ metafile.SetPrefMapMode(MapMode(MapUnit::Map100thMM));
+ metafile.SetPrefSize(Size(14548, 3350));
+ ScopedVclPtrInstance<VirtualDevice> metadevice;
+ metafile.Record(metadevice);
+ drawinglayer::geometry::ViewInformation2D view;
+ std::unique_ptr<processor2d::BaseProcessor2D> processor(
+ processor2d::createBaseProcessor2DFromOutputDevice(*metadevice, view));
+ CPPUNIT_ASSERT(processor);
+ // Match the values Impress uses.
+ basegfx::B2DPolygon polygon = { { 15601, 0 }, { 15602, 5832 } };
+ attribute::LineAttribute lineAttributes(
+ basegfx::BColor(0.047058823529411764, 0.19607843137254902, 0.17254901960784313), 35,
+ basegfx::B2DLineJoin::Miter, css::drawing::LineCap_ROUND);
+ attribute::StrokeAttribute strokeAttributes({ 0.35, 69.65 });
+ rtl::Reference<primitive2d::PolygonStrokePrimitive2D> strokePrimitive(
+ new primitive2d::PolygonStrokePrimitive2D(polygon, lineAttributes, strokeAttributes));
+ primitive2d::Primitive2DContainer primitives;
+ primitives.push_back(primitive2d::Primitive2DReference(strokePrimitive));
+ processor->process(primitives);
+ metafile.Stop();
+ metafile.WindStart();
+
+ // Now verify that the metafile has the one PolyLine action with the right dashing.
+ int lineActionCount = 0;
+ for (std::size_t i = 0; i < metafile.GetActionSize(); ++i)
+ {
+ const MetaAction* metaAction = metafile.GetAction(i);
+ if (metaAction->GetType() == MetaActionType::POLYLINE)
+ {
+ const MetaPolyLineAction* action
+ = static_cast<const MetaPolyLineAction*>(metaAction);
+
+ CPPUNIT_ASSERT_EQUAL(35.0, action->GetLineInfo().GetWidth());
+ CPPUNIT_ASSERT_EQUAL(LineStyle::Dash, action->GetLineInfo().GetStyle());
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(1), action->GetLineInfo().GetDashCount());
+ CPPUNIT_ASSERT_EQUAL(0.35, action->GetLineInfo().GetDashLen());
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0), action->GetLineInfo().GetDotCount());
+ CPPUNIT_ASSERT_EQUAL(0.0, action->GetLineInfo().GetDotLen());
+ CPPUNIT_ASSERT_EQUAL(69.65, action->GetLineInfo().GetDistance());
+ lineActionCount++;
+ }
+ }
+ CPPUNIT_ASSERT_EQUAL(1, lineActionCount);
+
+ // Now draw the metafile using canvas and verify that the line is drawn.
+ setupCanvas(Size(1920, 1080));
+ cppcanvas::CanvasSharedPtr cppCanvas = cppcanvas::VCLFactory::createCanvas(mCanvas);
+ // I got these matrices from a breakpoint in drawing the polyline, and walking up
+ // the stack to the canvas code.
+ cppCanvas->setTransformation(
+ basegfx::B2DHomMatrix(0.056662828121770453, 0, 0, 0, 0.056640419947506564, 0));
+ cppcanvas::RendererSharedPtr renderer = cppcanvas::VCLFactory::createRenderer(
+ cppCanvas, metafile, cppcanvas::Renderer::Parameters());
+ renderer->setTransformation(basegfx::B2DHomMatrix(14548, 0, -2, 0, 3350, 3431));
+ CPPUNIT_ASSERT(renderer->draw());
+ exportDevice("test-tdf136957", mVclDevice);
+ Bitmap bitmap = mVclDevice->GetBitmap(Point(), Size(1920, 1080));
+ Bitmap::ScopedReadAccess access(bitmap);
+ // There should be a dotted line, without the fix it wouldn't be there, so check
+ // there's a sufficient amount of non-white pixels and that's the line.
+ int nonWhiteCount = 0;
+ for (tools::Long y = 193; y <= 524; ++y)
+ for (tools::Long x = 883; x <= 885; ++x)
+ if (access->GetColor(y, x) != COL_WHITE)
+ ++nonWhiteCount;
+ CPPUNIT_ASSERT_GREATER(100, nonWhiteCount);
+ }
+
+ CPPUNIT_TEST_SUITE(VclMetaFileProcessor2DTest);
+ CPPUNIT_TEST(testTdf136957);
+ CPPUNIT_TEST_SUITE_END();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(VclMetaFileProcessor2DTest);
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */