1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  */
10 
11 #include <test/outputdevice.hxx>
12 
13 namespace vcl::test
14 {
15 namespace
16 {
drawRectOffset(OutputDevice & rDevice,tools::Rectangle const & rRect,int nOffset)17 void drawRectOffset(OutputDevice& rDevice, tools::Rectangle const& rRect, int nOffset)
18 {
19     rDevice.DrawRect(tools::Rectangle(rRect.Left() + nOffset, rRect.Top() + nOffset,
20                                       rRect.Right() - nOffset, rRect.Bottom() - nOffset));
21 }
22 
drawInvertOffset(OutputDevice & rDevice,tools::Rectangle const & rRect,int nOffset,InvertFlags eFlags)23 void drawInvertOffset(OutputDevice& rDevice, tools::Rectangle const& rRect, int nOffset,
24                       InvertFlags eFlags)
25 {
26     tools::Rectangle aRectangle(rRect.Left() + nOffset, rRect.Top() + nOffset,
27                                 rRect.Right() - nOffset, rRect.Bottom() - nOffset);
28     rDevice.Invert(aRectangle, eFlags);
29 }
30 
31 } // end anonymous namespace
32 
setupFilledRectangle(bool useLineColor)33 Bitmap OutputDeviceTestRect::setupFilledRectangle(bool useLineColor)
34 {
35     initialSetup(13, 13, constBackgroundColor);
36 
37     if (useLineColor)
38         mpVirtualDevice->SetLineColor(constLineColor);
39     else
40         mpVirtualDevice->SetLineColor();
41     mpVirtualDevice->SetFillColor(constFillColor);
42 
43     drawRectOffset(*mpVirtualDevice, maVDRectangle, 2);
44 
45     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
46 }
47 
setupRectangle(bool bEnableAA)48 Bitmap OutputDeviceTestRect::setupRectangle(bool bEnableAA)
49 {
50     initialSetup(13, 13, constBackgroundColor, bEnableAA);
51 
52     mpVirtualDevice->SetLineColor(constLineColor);
53     mpVirtualDevice->SetFillColor();
54 
55     drawRectOffset(*mpVirtualDevice, maVDRectangle, 2);
56     drawRectOffset(*mpVirtualDevice, maVDRectangle, 5);
57 
58     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
59 }
60 
setupInvert_NONE()61 Bitmap OutputDeviceTestRect::setupInvert_NONE()
62 {
63     initialSetup(20, 20, COL_WHITE);
64 
65     mpVirtualDevice->SetLineColor();
66     mpVirtualDevice->SetFillColor(COL_LIGHTRED);
67     mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 2), Size(8, 8)));
68     mpVirtualDevice->SetFillColor(COL_LIGHTGREEN);
69     mpVirtualDevice->DrawRect(tools::Rectangle(Point(10, 2), Size(8, 8)));
70     mpVirtualDevice->SetFillColor(COL_LIGHTBLUE);
71     mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 10), Size(8, 8)));
72 
73     drawInvertOffset(*mpVirtualDevice, maVDRectangle, 2, InvertFlags::NONE);
74 
75     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
76 }
77 
setupInvert_N50()78 Bitmap OutputDeviceTestRect::setupInvert_N50()
79 {
80     initialSetup(20, 20, COL_WHITE);
81 
82     mpVirtualDevice->SetLineColor();
83     mpVirtualDevice->SetFillColor(COL_LIGHTRED);
84     mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 2), Size(8, 8)));
85     mpVirtualDevice->SetFillColor(COL_LIGHTGREEN);
86     mpVirtualDevice->DrawRect(tools::Rectangle(Point(10, 2), Size(8, 8)));
87     mpVirtualDevice->SetFillColor(COL_LIGHTBLUE);
88     mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 10), Size(8, 8)));
89 
90     drawInvertOffset(*mpVirtualDevice, maVDRectangle, 2, InvertFlags::N50);
91 
92     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
93 }
94 
setupInvert_TrackFrame()95 Bitmap OutputDeviceTestRect::setupInvert_TrackFrame()
96 {
97     initialSetup(20, 20, COL_WHITE);
98 
99     mpVirtualDevice->SetLineColor();
100     mpVirtualDevice->SetFillColor(COL_LIGHTRED);
101     mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 2), Size(8, 8)));
102     mpVirtualDevice->SetFillColor(COL_LIGHTGREEN);
103     mpVirtualDevice->DrawRect(tools::Rectangle(Point(10, 2), Size(8, 8)));
104     mpVirtualDevice->SetFillColor(COL_LIGHTBLUE);
105     mpVirtualDevice->DrawRect(tools::Rectangle(Point(2, 10), Size(8, 8)));
106 
107     drawInvertOffset(*mpVirtualDevice, maVDRectangle, 2, InvertFlags::TrackFrame);
108 
109     return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize());
110 }
111 
112 } // end namespace vcl::test
113 
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
115