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 #include "basebmp/polypolygonrenderer.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <algorithm> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir namespace basebmp 34*cdf0e10cSrcweir { 35*cdf0e10cSrcweir namespace detail 36*cdf0e10cSrcweir { 37*cdf0e10cSrcweir sal_uInt32 setupGlobalEdgeTable( VectorOfVectorOfVertices& rGET, 38*cdf0e10cSrcweir basegfx::B2DPolyPolygon const& rPolyPoly, 39*cdf0e10cSrcweir sal_Int32 nMinY ) 40*cdf0e10cSrcweir { 41*cdf0e10cSrcweir sal_Int32 const nNumScanlines( (sal_Int32)rGET.size() ); 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // add all polygons to GET 44*cdf0e10cSrcweir for( sal_uInt32 i(0), nCount(rPolyPoly.count()); 45*cdf0e10cSrcweir i<nCount; 46*cdf0e10cSrcweir ++i ) 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir // add all vertices to GET 49*cdf0e10cSrcweir const basegfx::B2DPolygon& rPoly( rPolyPoly.getB2DPolygon(i) ); 50*cdf0e10cSrcweir for( sal_uInt32 k(0), nVertices(rPoly.count()); 51*cdf0e10cSrcweir k<nVertices; 52*cdf0e10cSrcweir ++k ) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir const basegfx::B2DPoint& rP1( rPoly.getB2DPoint(k) ); 55*cdf0e10cSrcweir const basegfx::B2DPoint& rP2( rPoly.getB2DPoint( (k + 1) % nVertices ) ); 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir const sal_Int32 nVertexYP1( basegfx::fround(rP1.getY()) ); 58*cdf0e10cSrcweir const sal_Int32 nVertexYP2( basegfx::fround(rP2.getY()) ); 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // insert only vertices which are not strictly 61*cdf0e10cSrcweir // horizontal. Strictly horizontal vertices don't add 62*cdf0e10cSrcweir // any information that is not already present - due 63*cdf0e10cSrcweir // to their adjacent vertices. 64*cdf0e10cSrcweir if(nVertexYP1 != nVertexYP2) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir if( nVertexYP2 < nVertexYP1 ) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir const sal_Int32 nStartScanline(nVertexYP2 - nMinY); 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // edge direction is upwards - add with swapped vertices 71*cdf0e10cSrcweir if( nStartScanline < nNumScanlines ) 72*cdf0e10cSrcweir rGET[ nStartScanline ].push_back( Vertex(rP2, rP1, false) ); 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir else 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir const sal_Int32 nStartScanline(nVertexYP1 - nMinY); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir if( nStartScanline < nNumScanlines ) 79*cdf0e10cSrcweir rGET[ nStartScanline ].push_back( Vertex(rP1, rP2, true) ); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir } 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir } 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir // now sort all scanlines individually, with increasing x 86*cdf0e10cSrcweir // coordinates 87*cdf0e10cSrcweir VectorOfVectorOfVertices::iterator aIter( rGET.begin() ); 88*cdf0e10cSrcweir const VectorOfVectorOfVertices::iterator aEnd( rGET.end() ); 89*cdf0e10cSrcweir sal_uInt32 nVertexCount(0); 90*cdf0e10cSrcweir RasterConvertVertexComparator aComp; 91*cdf0e10cSrcweir while( aIter != aEnd ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir std::sort( aIter->begin(), 94*cdf0e10cSrcweir aIter->end(), 95*cdf0e10cSrcweir aComp ); 96*cdf0e10cSrcweir nVertexCount += aIter->size(); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir ++aIter; 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir return nVertexCount; 102*cdf0e10cSrcweir } 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void sortAET( VectorOfVertexPtr& rAETSrc, 105*cdf0e10cSrcweir VectorOfVertexPtr& rAETDest ) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir static RasterConvertVertexComparator aComp; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir rAETDest.clear(); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // prune AET from ended edges 112*cdf0e10cSrcweir VectorOfVertexPtr::iterator iter( rAETSrc.begin() ); 113*cdf0e10cSrcweir VectorOfVertexPtr::iterator const end( rAETSrc.end() ); 114*cdf0e10cSrcweir while( iter != end ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir if( (*iter)->mnYCounter > 0 ) 117*cdf0e10cSrcweir rAETDest.push_back( *iter ); 118*cdf0e10cSrcweir ++iter; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // stable sort is necessary, to avoid segment crossing where 122*cdf0e10cSrcweir // none was intended. 123*cdf0e10cSrcweir std::stable_sort( rAETDest.begin(), rAETDest.end(), aComp ); 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir } // namespace detail 127*cdf0e10cSrcweir } // namespace basebmp 128