update dev300-m58
[ooovba.git] / basebmp / source / polypolygonrenderer.cxx
bloba70fa3535ce5530bc5128ca28f8c8ef5003d618b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: polypolygonrenderer.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "basebmp/polypolygonrenderer.hxx"
33 #include <algorithm>
36 namespace basebmp
38 namespace detail
40 sal_uInt32 setupGlobalEdgeTable( VectorOfVectorOfVertices& rGET,
41 basegfx::B2DPolyPolygon const& rPolyPoly,
42 sal_Int32 nMinY )
44 sal_Int32 const nNumScanlines( (sal_Int32)rGET.size() );
46 // add all polygons to GET
47 for( sal_uInt32 i(0), nCount(rPolyPoly.count());
48 i<nCount;
49 ++i )
51 // add all vertices to GET
52 const basegfx::B2DPolygon& rPoly( rPolyPoly.getB2DPolygon(i) );
53 for( sal_uInt32 k(0), nVertices(rPoly.count());
54 k<nVertices;
55 ++k )
57 const basegfx::B2DPoint& rP1( rPoly.getB2DPoint(k) );
58 const basegfx::B2DPoint& rP2( rPoly.getB2DPoint( (k + 1) % nVertices ) );
60 const sal_Int32 nVertexYP1( basegfx::fround(rP1.getY()) );
61 const sal_Int32 nVertexYP2( basegfx::fround(rP2.getY()) );
63 // insert only vertices which are not strictly
64 // horizontal. Strictly horizontal vertices don't add
65 // any information that is not already present - due
66 // to their adjacent vertices.
67 if(nVertexYP1 != nVertexYP2)
69 if( nVertexYP2 < nVertexYP1 )
71 const sal_Int32 nStartScanline(nVertexYP2 - nMinY);
73 // edge direction is upwards - add with swapped vertices
74 if( nStartScanline < nNumScanlines )
75 rGET[ nStartScanline ].push_back( Vertex(rP2, rP1, false) );
77 else
79 const sal_Int32 nStartScanline(nVertexYP1 - nMinY);
81 if( nStartScanline < nNumScanlines )
82 rGET[ nStartScanline ].push_back( Vertex(rP1, rP2, true) );
88 // now sort all scanlines individually, with increasing x
89 // coordinates
90 VectorOfVectorOfVertices::iterator aIter( rGET.begin() );
91 const VectorOfVectorOfVertices::iterator aEnd( rGET.end() );
92 sal_uInt32 nVertexCount(0);
93 RasterConvertVertexComparator aComp;
94 while( aIter != aEnd )
96 std::sort( aIter->begin(),
97 aIter->end(),
98 aComp );
99 nVertexCount += aIter->size();
101 ++aIter;
104 return nVertexCount;
107 void sortAET( VectorOfVertexPtr& rAETSrc,
108 VectorOfVertexPtr& rAETDest )
110 static RasterConvertVertexComparator aComp;
112 rAETDest.clear();
114 // prune AET from ended edges
115 VectorOfVertexPtr::iterator iter( rAETSrc.begin() );
116 VectorOfVertexPtr::iterator const end( rAETSrc.end() );
117 while( iter != end )
119 if( (*iter)->mnYCounter > 0 )
120 rAETDest.push_back( *iter );
121 ++iter;
124 // stable sort is necessary, to avoid segment crossing where
125 // none was intended.
126 std::stable_sort( rAETDest.begin(), rAETDest.end(), aComp );
129 } // namespace detail
130 } // namespace basebmp