1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "basebmp/polypolygonrenderer.hxx"
25 
26 #include <algorithm>
27 
28 
29 namespace basebmp
30 {
31 namespace detail
32 {
setupGlobalEdgeTable(VectorOfVectorOfVertices & rGET,basegfx::B2DPolyPolygon const & rPolyPoly,sal_Int32 nMinY)33     sal_uInt32 setupGlobalEdgeTable( VectorOfVectorOfVertices&      rGET,
34                                      basegfx::B2DPolyPolygon const& rPolyPoly,
35                                      sal_Int32                      nMinY )
36     {
37         sal_Int32 const nNumScanlines( (sal_Int32)rGET.size() );
38 
39         // add all polygons to GET
40         for( sal_uInt32 i(0), nCount(rPolyPoly.count());
41              i<nCount;
42              ++i )
43         {
44             // add all vertices to GET
45             const basegfx::B2DPolygon& rPoly( rPolyPoly.getB2DPolygon(i) );
46             for( sal_uInt32 k(0), nVertices(rPoly.count());
47                  k<nVertices;
48                  ++k )
49             {
50                 const basegfx::B2DPoint& rP1( rPoly.getB2DPoint(k) );
51                 const basegfx::B2DPoint& rP2( rPoly.getB2DPoint( (k + 1) % nVertices ) );
52 
53                 const sal_Int32 nVertexYP1( basegfx::fround(rP1.getY()) );
54                 const sal_Int32 nVertexYP2( basegfx::fround(rP2.getY()) );
55 
56                 // insert only vertices which are not strictly
57                 // horizontal. Strictly horizontal vertices don't add
58                 // any information that is not already present - due
59                 // to their adjacent vertices.
60                 if(nVertexYP1 != nVertexYP2)
61                 {
62                     if( nVertexYP2 < nVertexYP1 )
63                     {
64                         const sal_Int32 nStartScanline(nVertexYP2 - nMinY);
65 
66                         // edge direction is upwards - add with swapped vertices
67                         if( nStartScanline < nNumScanlines )
68                             rGET[ nStartScanline ].push_back( Vertex(rP2, rP1, false) );
69                     }
70                     else
71                     {
72                         const sal_Int32 nStartScanline(nVertexYP1 - nMinY);
73 
74                         if( nStartScanline < nNumScanlines )
75                             rGET[ nStartScanline ].push_back( Vertex(rP1, rP2, true) );
76                     }
77                 }
78             }
79         }
80 
81         // now sort all scanlines individually, with increasing x
82         // coordinates
83         VectorOfVectorOfVertices::iterator       aIter( rGET.begin() );
84         const VectorOfVectorOfVertices::iterator aEnd( rGET.end() );
85         sal_uInt32                               nVertexCount(0);
86         RasterConvertVertexComparator            aComp;
87         while( aIter != aEnd )
88         {
89             std::sort( aIter->begin(),
90                        aIter->end(),
91                        aComp );
92             nVertexCount += aIter->size();
93 
94             ++aIter;
95         }
96 
97         return nVertexCount;
98     }
99 
sortAET(VectorOfVertexPtr & rAETSrc,VectorOfVertexPtr & rAETDest)100     void sortAET( VectorOfVertexPtr& rAETSrc,
101                   VectorOfVertexPtr& rAETDest )
102     {
103         static RasterConvertVertexComparator aComp;
104 
105         rAETDest.clear();
106 
107         // prune AET from ended edges
108         VectorOfVertexPtr::iterator iter( rAETSrc.begin() );
109         VectorOfVertexPtr::iterator const end( rAETSrc.end() );
110         while( iter != end )
111         {
112             if( (*iter)->mnYCounter > 0 )
113                 rAETDest.push_back( *iter );
114             ++iter;
115         }
116 
117         // stable sort is necessary, to avoid segment crossing where
118         // none was intended.
119         std::stable_sort( rAETDest.begin(), rAETDest.end(), aComp );
120     }
121 
122 } // namespace detail
123 } // namespace basebmp
124