1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <test/bootstrapfixture.hxx>
13 #include <vcl/virdev.hxx>
14 #include <vcl/BitmapReadAccess.hxx>
15 #include <vcl/graphicfilter.hxx>
16 #include <tools/stream.hxx>
17 #include <drawinglayer/geometry/viewinformation2d.hxx>
18 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
19 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
20 #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
22 using namespace drawinglayer
;
24 class VclPixelProcessor2DTest
: public test::BootstrapFixture
26 // if enabled - check the result images with:
27 // "xdg-open ./workdir/CppunitTest/drawinglayer_processors.test.core/"
28 static constexpr const bool mbExportBitmap
= false;
30 void exportDevice(const OUString
& filename
, const VclPtr
<VirtualDevice
>& device
)
34 BitmapEx
aBitmapEx(device
->GetBitmapEx(Point(0, 0), device
->GetOutputSizePixel()));
35 SvFileStream
aStream(filename
, StreamMode::WRITE
| StreamMode::TRUNC
);
36 GraphicFilter::GetGraphicFilter().compressAsPNG(aBitmapEx
, aStream
);
41 VclPixelProcessor2DTest()
42 : BootstrapFixture(true, false)
46 // Test that drawing only a part of a gradient draws the proper part of it.
49 ScopedVclPtr
<VirtualDevice
> device
= VclPtr
<VirtualDevice
>::Create(DeviceFormat::DEFAULT
);
50 device
->SetOutputSizePixel(Size(100, 200));
51 device
->SetBackground(Wallpaper(COL_RED
));
54 drawinglayer::geometry::ViewInformation2D view
;
55 std::unique_ptr
<processor2d::BaseProcessor2D
> processor(
56 processor2d::createBaseProcessor2DFromOutputDevice(*device
, view
));
57 CPPUNIT_ASSERT(processor
);
59 basegfx::B2DRange
definitionRange(0, 0, 100, 200);
60 basegfx::B2DRange
outputRange(0, 100, 100, 200); // Paint only lower half of the gradient.
61 attribute::FillGradientAttribute
attributes(attribute::GradientStyle::Linear
, 0, 0, 0, 0,
62 COL_WHITE
.getBColor(), COL_BLACK
.getBColor());
63 rtl::Reference
<primitive2d::FillGradientPrimitive2D
> gradientPrimitive(
64 new primitive2d::FillGradientPrimitive2D(outputRange
, definitionRange
, attributes
));
65 primitive2d::Primitive2DContainer primitives
;
66 primitives
.push_back(primitive2d::Primitive2DReference(gradientPrimitive
));
67 processor
->process(primitives
);
69 exportDevice("test-tdf139000.png", device
);
70 Bitmap bitmap
= device
->GetBitmap(Point(), device
->GetOutputSizePixel());
71 Bitmap::ScopedReadAccess
access(bitmap
);
72 // The upper half should keep its red background color.
73 CPPUNIT_ASSERT_EQUAL(BitmapColor(COL_RED
), access
->GetColor(Point(0, 99)));
74 // First line of the gradient should not be the start color, but something halfway.
75 CPPUNIT_ASSERT_LESS(static_cast<sal_uInt16
>(16),
76 access
->GetColor(Point(0, 100)).GetColorError(COL_GRAY
));
77 // Last line of the gradient should be the end color, or close.
78 CPPUNIT_ASSERT_LESS(static_cast<sal_uInt16
>(16),
79 access
->GetColor(Point(0, 199)).GetColorError(COL_BLACK
));
82 CPPUNIT_TEST_SUITE(VclPixelProcessor2DTest
);
83 CPPUNIT_TEST(testTdf139000
);
84 CPPUNIT_TEST_SUITE_END();
87 CPPUNIT_TEST_SUITE_REGISTRATION(VclPixelProcessor2DTest
);
89 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */