xref: /trunk/main/basebmp/test/polytest.cxx (revision 97c63c1b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // autogenerated file with codegen.pl
25 
26 #include "preextstl.h"
27 #include "gtest/gtest.h"
28 #include "postextstl.h"
29 
30 #include <basegfx/vector/b2isize.hxx>
31 #include <basegfx/range/b2irange.hxx>
32 #include <basegfx/point/b2ipoint.hxx>
33 #include <basegfx/matrix/b2dhommatrix.hxx>
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <basegfx/polygon/b2dpolypolygon.hxx>
37 #include <basegfx/polygon/b2dpolypolygontools.hxx>
38 
39 #include <basebmp/color.hxx>
40 #include <basebmp/scanlineformats.hxx>
41 #include <basebmp/bitmapdevice.hxx>
42 #include <basebmp/debug.hxx>
43 #include "tools.hxx"
44 
45 #include <iostream>
46 #include <fstream>
47 
48 using namespace ::basebmp;
49 
50 namespace
51 {
52 /*
53         std::ofstream output("32bpp_test.dump");
54         debugDump( rDevice, output );
55 */
56 
57 class PolyTest : public ::testing::Test
58 {
59 protected:
60     BitmapDeviceSharedPtr mpDevice1bpp;
61     BitmapDeviceSharedPtr mpDevice32bpp;
62 
implTestEmpty(const BitmapDeviceSharedPtr & rDevice)63     void implTestEmpty(const BitmapDeviceSharedPtr& rDevice)
64     {
65         const Color aCol(0xFFFFFFFF);
66         const Color aBgCol(0);
67         rDevice->clear(aBgCol);
68         basegfx::B2DPolyPolygon aPoly;
69         ::rtl::OUString aSvg;
70 
71         basegfx::tools::importFromSvgD(
72             aPoly,
73             rtl::OUString::createFromAscii(
74                 "M2 2 l7 7 z" ),
75             false, NULL);
76         rDevice->fillPolyPolygon(
77             aPoly,
78             aCol,
79             DrawMode_PAINT );
80         ASSERT_TRUE(countPixel( rDevice, aCol ) == 0) << "number of rendered pixel is not 0";
81 
82         // --------------------------------------------------
83 
84         rDevice->clear(aBgCol);
85         aPoly.clear();
86         basegfx::tools::importFromSvgD(
87             aPoly,
88             rtl::OUString::createFromAscii(
89             "M7 2 l-6 6 z" ),
90             false, NULL);
91         rDevice->fillPolyPolygon(
92             aPoly,
93             aCol,
94             DrawMode_PAINT );
95         ASSERT_TRUE(countPixel( rDevice, aCol ) == 0) << "number of rendered pixel is not 0(b)";
96     }
97 
implTestHairline(const BitmapDeviceSharedPtr & rDevice)98     void implTestHairline(const BitmapDeviceSharedPtr& rDevice)
99     {
100         const Color aCol(0xFFFFFFFF);
101         const Color aBgCol(0);
102         rDevice->clear(aBgCol);
103         basegfx::B2DPolyPolygon aPoly;
104         ::rtl::OUString aSvg;
105 
106         basegfx::tools::importFromSvgD(
107             aPoly,
108             rtl::OUString::createFromAscii(
109                 "M2 2 h1 l7 7 h-1 z" ),
110             false, NULL);
111         rDevice->fillPolyPolygon(
112             aPoly,
113             aCol,
114             DrawMode_PAINT );
115         ASSERT_TRUE(countPixel( rDevice, aCol ) == 7) << "number of rendered pixel is not 7";
116 
117         // --------------------------------------------------
118 
119         rDevice->clear(aBgCol);
120         aPoly.clear();
121         basegfx::tools::importFromSvgD(
122             aPoly,
123             rtl::OUString::createFromAscii(
124             "M7 2 h-1 l-6 6 h1 z" ),
125             false, NULL);
126         rDevice->fillPolyPolygon(
127             aPoly,
128             aCol,
129             DrawMode_PAINT );
130         ASSERT_TRUE(countPixel( rDevice, aCol ) == 6) << "number of rendered pixel is not 6";
131 
132         // --------------------------------------------------
133 
134         rDevice->clear(aBgCol);
135         aPoly.clear();
136         basegfx::tools::importFromSvgD(
137             aPoly,
138             rtl::OUString::createFromAscii(
139             "M0 0 l7 7 h-1 l-5-7 z" ),
140             false, NULL);
141         rDevice->fillPolyPolygon(
142             aPoly,
143             aCol,
144             DrawMode_PAINT );
145         ASSERT_TRUE(countPixel( rDevice, aCol ) == 3) << "number of rendered pixel is not 3";
146     }
147 
implTestPolyPoly(const BitmapDeviceSharedPtr & rDevice)148     void implTestPolyPoly(const BitmapDeviceSharedPtr& rDevice)
149     {
150         const Color aCol(0xFFFFFFFF);
151         const Color aBgCol(0);
152         rDevice->clear(aBgCol);
153         basegfx::B2DPolyPolygon aPoly;
154         ::rtl::OUString aSvg;
155 
156         basegfx::tools::importFromSvgD( aPoly,
157                                         ::rtl::OUString::createFromAscii(
158                                             "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ),
159                                         false, NULL );
160 
161         rDevice->fillPolyPolygon(
162             aPoly,
163             aCol,
164             DrawMode_PAINT );
165         ASSERT_TRUE(countPixel( rDevice, aCol ) == 40) << "number of rendered pixel is not 40";
166     }
167 
implTestPolyPolyClip(const BitmapDeviceSharedPtr & rDevice)168     void implTestPolyPolyClip(const BitmapDeviceSharedPtr& rDevice)
169     {
170         const Color aCol(0xFFFFFFFF);
171         const Color aBgCol(0);
172         rDevice->clear(aBgCol);
173         basegfx::B2DPolyPolygon aPoly;
174         ::rtl::OUString aSvg;
175 
176         basegfx::tools::importFromSvgD( aPoly,
177                                         ::rtl::OUString::createFromAscii(
178                                             "M0 0 h7 v7 h-7 z M2 2 v3 h3 v-3 z" ),
179                                         false, NULL );
180         basegfx::B2DHomMatrix aMat;
181         aMat.translate(-3,-3);
182         aMat.rotate( 1.7 );
183         aMat.translate(6,5);
184         aPoly.transform(aMat);
185 
186         rDevice->fillPolyPolygon(
187             aPoly,
188             aCol,
189             DrawMode_PAINT );
190 
191         ASSERT_TRUE(countPixel( rDevice, aCol ) == 39) << "number of rendered pixel is not 39";
192 
193         BitmapDeviceSharedPtr pClippedDevice(
194             subsetBitmapDevice( rDevice,
195                                 basegfx::B2IRange(3,3,5,8) ));
196 
197         rDevice->clear(aBgCol);
198         pClippedDevice->fillPolyPolygon(
199             aPoly,
200             aCol,
201             DrawMode_PAINT );
202         ASSERT_TRUE(countPixel( rDevice, aCol ) == 7) << "number of rendered pixel is not 7";
203     }
204 
implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr & rDevice)205     void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice)
206     {
207         const Color aCol(0xFFFFFFFF);
208         const Color aBgCol(0);
209         rDevice->clear(aBgCol);
210         basegfx::B2DPolyPolygon aPoly;
211         ::rtl::OUString aSvg;
212 
213         basegfx::tools::importFromSvgD( aPoly,
214                                         ::rtl::OUString::createFromAscii(
215                                             "M0 0 v2 l10 2 v-2 z"
216                                             "M10 6 v-2 l-10 2 v2 z"
217                                             "M1 0 h1 v10 h-1 z"
218                                             "M4 0 h1 v10 h-1 z"
219                                             "M8 0 h1 v10 h-1 z" ),
220                                         false, NULL );
221         rDevice->fillPolyPolygon(
222             aPoly,
223             aCol,
224             DrawMode_PAINT );
225         ASSERT_TRUE(countPixel( rDevice, aCol ) == 46) << "number of rendered pixel is not 46";
226     }
227 
228 
229 public:
SetUp()230     virtual void SetUp()
231     {
232         const basegfx::B2ISize aSize(10,10);
233         mpDevice1bpp = createBitmapDevice( aSize,
234                                            true,
235                                            Format::ONE_BIT_MSB_PAL );
236         mpDevice32bpp = createBitmapDevice( aSize,
237                                             true,
238                                             Format::THIRTYTWO_BIT_TC_MASK );
239     }
240 };
241 
242 
TEST_F(PolyTest,testEmpty)243 TEST_F(PolyTest, testEmpty)
244 {
245     implTestEmpty( mpDevice1bpp );
246     implTestEmpty( mpDevice32bpp );
247 }
248 
TEST_F(PolyTest,testHairline)249 TEST_F(PolyTest, testHairline)
250 {
251     implTestHairline( mpDevice1bpp );
252     implTestHairline( mpDevice32bpp );
253 }
254 
TEST_F(PolyTest,testPolyPoly)255 TEST_F(PolyTest, testPolyPoly)
256 {
257     implTestPolyPoly( mpDevice1bpp );
258     implTestPolyPoly( mpDevice32bpp );
259 }
260 
TEST_F(PolyTest,testPolyPolyClip)261 TEST_F(PolyTest, testPolyPolyClip)
262 {
263     implTestPolyPolyClip(mpDevice1bpp);
264     implTestPolyPolyClip(mpDevice32bpp);
265 }
266 
TEST_F(PolyTest,testPolyPolyCrissCross)267 TEST_F(PolyTest, testPolyPolyCrissCross)
268 {
269     implTestPolyPolyCrissCross(mpDevice1bpp);
270     implTestPolyPolyCrissCross(mpDevice32bpp);
271 }
272 
273 
274 }
275