1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 30*cdf0e10cSrcweir #include "precompiled_basegfx.hxx" 31*cdf0e10cSrcweir // autogenerated file with codegen.pl 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "preextstl.h" 34*cdf0e10cSrcweir #include "cppunit/TestAssert.h" 35*cdf0e10cSrcweir #include "cppunit/TestFixture.h" 36*cdf0e10cSrcweir #include "cppunit/extensions/HelperMacros.h" 37*cdf0e10cSrcweir #include "postextstl.h" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <basegfx/tools/b2dclipstate.hxx> 40*cdf0e10cSrcweir #include <basegfx/range/b2dpolyrange.hxx> 41*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 42*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 43*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx> 44*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx> 45*cdf0e10cSrcweir #include <basegfx/numeric/ftools.hxx> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir #include <boost/bind.hpp> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir using namespace ::basegfx; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir namespace basegfx2d 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir class clipstate : public CppUnit::TestFixture 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir private: 58*cdf0e10cSrcweir tools::B2DClipState aUnion1; 59*cdf0e10cSrcweir tools::B2DClipState aUnion2; 60*cdf0e10cSrcweir tools::B2DClipState aIntersect; 61*cdf0e10cSrcweir tools::B2DClipState aXor; 62*cdf0e10cSrcweir tools::B2DClipState aSubtract; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir public: 65*cdf0e10cSrcweir void setUp() 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir B2DRange aCenter(100, 100, -100, -100); 68*cdf0e10cSrcweir B2DRange aNorth(-10, -110, 10, -90); 69*cdf0e10cSrcweir B2DRange aWest(-110, -10, -90, 10); 70*cdf0e10cSrcweir B2DRange aSouth(-10, 110, 10, 90); 71*cdf0e10cSrcweir B2DRange aEast(110, -10, 90, 10); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir aUnion1.unionRange(aCenter); 74*cdf0e10cSrcweir aUnion1.unionRange(aNorth); 75*cdf0e10cSrcweir aUnion1.unionRange(aWest); 76*cdf0e10cSrcweir aUnion1.unionRange(aSouth); 77*cdf0e10cSrcweir aUnion1.unionRange(aEast); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir aUnion2.makeNull(); 80*cdf0e10cSrcweir aUnion2.unionRange(aCenter); 81*cdf0e10cSrcweir aUnion2.unionRange(aNorth); 82*cdf0e10cSrcweir aUnion2.unionRange(aWest); 83*cdf0e10cSrcweir aUnion2.unionRange(aSouth); 84*cdf0e10cSrcweir aUnion2.unionRange(aEast); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir aIntersect.intersectRange(aCenter); 87*cdf0e10cSrcweir aIntersect.intersectRange(aNorth); 88*cdf0e10cSrcweir aIntersect.intersectRange(aWest); 89*cdf0e10cSrcweir aIntersect.intersectRange(aSouth); 90*cdf0e10cSrcweir aIntersect.intersectRange(aEast); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir aXor.makeNull(); 93*cdf0e10cSrcweir aXor.xorRange(aCenter); 94*cdf0e10cSrcweir aXor.xorRange(aNorth); 95*cdf0e10cSrcweir aXor.xorRange(aWest); 96*cdf0e10cSrcweir aXor.xorRange(aSouth); 97*cdf0e10cSrcweir aXor.xorRange(aEast); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir aSubtract.intersectRange(aCenter); 100*cdf0e10cSrcweir aSubtract.subtractRange(aNorth); 101*cdf0e10cSrcweir aSubtract.subtractRange(aWest); 102*cdf0e10cSrcweir aSubtract.subtractRange(aSouth); 103*cdf0e10cSrcweir aSubtract.subtractRange(aEast); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir void tearDown() 107*cdf0e10cSrcweir {} 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir void verifyPoly(const char* sName, const char* sSvg, const tools::B2DClipState& toTest) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir #if defined(VERBOSE) 112*cdf0e10cSrcweir fprintf(stderr, "%s - svg:d=\"%s\"\n", 113*cdf0e10cSrcweir sName, rtl::OUStringToOString( 114*cdf0e10cSrcweir basegfx::tools::exportToSvgD(toTest.getClipPoly()), 115*cdf0e10cSrcweir RTL_TEXTENCODING_UTF8).getStr() ); 116*cdf0e10cSrcweir #endif 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir B2DPolyPolygon aTmp1; 119*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE(sName, 120*cdf0e10cSrcweir tools::importFromSvgD( 121*cdf0e10cSrcweir aTmp1, 122*cdf0e10cSrcweir rtl::OUString::createFromAscii(sSvg))); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir const rtl::OUString aSvg= 125*cdf0e10cSrcweir tools::exportToSvgD(toTest.getClipPoly()); 126*cdf0e10cSrcweir B2DPolyPolygon aTmp2; 127*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE(sName, 128*cdf0e10cSrcweir tools::importFromSvgD( 129*cdf0e10cSrcweir aTmp2, 130*cdf0e10cSrcweir aSvg)); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE( 133*cdf0e10cSrcweir sName, 134*cdf0e10cSrcweir aTmp2 == aTmp1); 135*cdf0e10cSrcweir } 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir void verifySimpleRange() 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 140*cdf0e10cSrcweir const char* intersectSvg="m-100 10v-20h10v20zm80 90v-10h20v10zm-20-190v-10h20v10zm80 100v-20h10v20z"; 141*cdf0e10cSrcweir const char* xorSvg="m-100 10h10v-20h-10zm90 110h20v-10h-20zm0-180h20v-10h-20zm100 110h10v-20h-10zm10 20v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 142*cdf0e10cSrcweir const char* subtractSvg="m-90 10v-20h-10v-90h90v10h20v-10h90v90h-10v20h10v90h-90v-10h-20v10h-90v-90z"; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir CPPUNIT_ASSERT_MESSAGE("cleared clip stays empty under union operation", 145*cdf0e10cSrcweir aUnion1.isCleared()); 146*cdf0e10cSrcweir verifyPoly("union", unionSvg, aUnion2); 147*cdf0e10cSrcweir verifyPoly("intersect", intersectSvg, aIntersect); 148*cdf0e10cSrcweir verifyPoly("xor", xorSvg, aXor); 149*cdf0e10cSrcweir verifyPoly("subtract", subtractSvg, aSubtract); 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir void verifyMixedClips() 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir tools::B2DClipState aMixedClip; 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir const char* unionSvg="m100 10v90h-90v10h-20v-10h-90v-90h-10v-20h10v-90h90v-10h20v10h90v90h10v20z"; 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir B2DPolyPolygon aTmp1; 159*cdf0e10cSrcweir tools::importFromSvgD( 160*cdf0e10cSrcweir aTmp1, 161*cdf0e10cSrcweir rtl::OUString::createFromAscii(unionSvg)); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir aMixedClip.intersectPolyPolygon(aTmp1); 164*cdf0e10cSrcweir aMixedClip.subtractRange(B2DRange(-20,-150,20,0)); 165*cdf0e10cSrcweir aMixedClip.subtractRange(B2DRange(-150,-20,0,20)); 166*cdf0e10cSrcweir aMixedClip.xorRange(B2DRange(-150,-150,150,150)); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir const char* mixedClipSvg="m0 0v20h-100v80h90v10h20v-10h90v-90h10v-20h-10v-90h-80v100zm-40-20v-80h-80v80zm-50 170v-300h300v300z"; 169*cdf0e10cSrcweir verifyPoly("mixed clip", mixedClipSvg, aMixedClip); 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir CPPUNIT_TEST_SUITE(clipstate); 173*cdf0e10cSrcweir CPPUNIT_TEST(verifySimpleRange); 174*cdf0e10cSrcweir CPPUNIT_TEST(verifyMixedClips); 175*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_END(); 176*cdf0e10cSrcweir }; 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 179*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_REGISTRATION(basegfx2d::clipstate); 180*cdf0e10cSrcweir } // namespace basegfx2d 181