diff options
Diffstat (limited to 'basebmp/test/polytest.cxx')
-rw-r--r-- | basebmp/test/polytest.cxx | 105 |
1 files changed, 100 insertions, 5 deletions
diff --git a/basebmp/test/polytest.cxx b/basebmp/test/polytest.cxx index 8cc51d4921ee..63485000b7f9 100644 --- a/basebmp/test/polytest.cxx +++ b/basebmp/test/polytest.cxx @@ -65,7 +65,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, @@ -100,7 +99,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, @@ -150,7 +148,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( @@ -170,7 +167,6 @@ private: const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( @@ -204,13 +200,98 @@ private: countPixel( rDevice, aCol ) == 7); } + void implTestLineDrawClip(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + + // create rectangular subset, such that we can 'see' extra + // pixel outside + BitmapDeviceSharedPtr pClippedDevice=( + subsetBitmapDevice( rDevice, + basegfx::B2IBox(3,3,5,9) )); + + // trigger "alternate bresenham" case in + // clippedlinerenderer.hxx, first point not clipped + const basegfx::B2IPoint aPt1(3,3); + const basegfx::B2IPoint aPt2(4,2); + pClippedDevice->drawLine( aPt1, aPt2, aCol, DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 1", + countPixel( rDevice, aCol ) == 1); + + // trigger "alternate bresenham" case in + // clippedlinerenderer.hxx, both start and endpoint clipped + const basegfx::B2IPoint aPt3(0,4); + pClippedDevice->drawLine( aPt3, aPt2, aCol, DrawMode_XOR ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 0", + countPixel( rDevice, aCol ) == 0); + + // trigger "standard bresenham" case in + // clippedlinerenderer.hxx, first point not clipped + const basegfx::B2IPoint aPt4(6,2); + pClippedDevice->drawLine( aPt1, aPt4, aCol, DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 2", + countPixel( rDevice, aCol ) == 2); + + // trigger "clipCode1 & aMinFlag/bMinFlag" cases in + // clippedlinerenderer.hxx (note1: needs forcing end point to + // be clipped as well, otherwise optimisation kicks in. note2: + // needs forcing end point to clip on two edges, not only on + // one, otherwise swap kicks in) + const basegfx::B2IPoint aPt5(1,1); + const basegfx::B2IPoint aPt6(6,10); + pClippedDevice->drawLine( aPt5, aPt6, aCol, DrawMode_XOR ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 6", + countPixel( rDevice, aCol ) == 6); + + // trigger "clipCode1 & (aMinFlag|aMaxFlag)" case in + // clippedlinerenderer.hxx that was not taken for the test + // above + pClippedDevice->drawLine( aPt3, aPt6, aCol, DrawMode_XOR ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 8", + countPixel( rDevice, aCol ) == 8); + + } + + void implTestPolyDrawClip(const BitmapDeviceSharedPtr& rDevice) + { + const Color aCol(0xFFFFFFFF); + const Color aBgCol(0); + rDevice->clear(aBgCol); + basegfx::B2DPolyPolygon aPoly; + + // test all corner-touching lines of our clip rect. note that + // *all* of the four two-pixel lines in that polygon do *not* + // generate a single pixel, due to the rasterization effect. + basegfx::tools::importFromSvgD( aPoly, + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( + "M2 3 l1 -1 M4 2 l1 1 M2 8 l1 1 M5 8 l-1 1 M2 5 h4 M3 0 v10" )) ); + BitmapDeviceSharedPtr pClippedDevice=( + subsetBitmapDevice( rDevice, + basegfx::B2IBox(3,3,5,9) )); + + for( unsigned int i=0; i<aPoly.count(); ++i ) + pClippedDevice->drawPolygon( + aPoly.getB2DPolygon(i), + aCol, + DrawMode_PAINT ); + + CPPUNIT_ASSERT_MESSAGE("number of rendered pixel is not 7", + countPixel( rDevice, aCol ) == 7); + } + void implTestPolyPolyCrissCross(const BitmapDeviceSharedPtr& rDevice) { const Color aCol(0xFFFFFFFF); const Color aBgCol(0); rDevice->clear(aBgCol); basegfx::B2DPolyPolygon aPoly; - ::rtl::OUString aSvg; basegfx::tools::importFromSvgD( aPoly, ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( @@ -264,6 +345,18 @@ public: implTestPolyPolyClip(mpDevice32bpp); } + void testLineDrawClip() + { + implTestLineDrawClip(mpDevice1bpp); + implTestLineDrawClip(mpDevice32bpp); + } + + void testPolyDrawClip() + { + implTestPolyDrawClip(mpDevice1bpp); + implTestPolyDrawClip(mpDevice32bpp); + } + void testPolyPolyCrissCross() { implTestPolyPolyCrissCross(mpDevice1bpp); @@ -279,6 +372,8 @@ public: CPPUNIT_TEST(testHairline); CPPUNIT_TEST(testPolyPoly); CPPUNIT_TEST(testPolyPolyClip); + CPPUNIT_TEST(testLineDrawClip); + CPPUNIT_TEST(testPolyDrawClip); CPPUNIT_TEST(testPolyPolyCrissCross); CPPUNIT_TEST_SUITE_END(); }; |