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