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 #ifndef _BGFX_POLYGON_B2DPOLYPOLYGONRASTERCONVERTER_HXX
25 #define _BGFX_POLYGON_B2DPOLYPOLYGONRASTERCONVERTER_HXX
26 
27 #include <basegfx/point/b2dpoint.hxx>
28 #include <basegfx/range/b2drectangle.hxx>
29 #include <basegfx/polygon/b2dpolypolygon.hxx>
30 #include <basegfx/polygon/b2dpolypolygonfillrule.hxx>
31 #include <vector>
32 #include <utility>
33 #include <basegfx/basegfxdllapi.h>
34 
35 //////////////////////////////////////////////////////////////////////////////
36 
37 namespace basegfx
38 {
39 	/** Raster-convert a poly-polygon.
40 
41 		This class can raster-convert a given poly-polygon. Simply
42 		derive from this, and override the span() method, which will
43 		get called for every scanline span of the poly-polygon.
44 
45         @derive
46         Overwrite span() with the render output method of your choice.
47      */
48     class BASEGFX_DLLPUBLIC B2DPolyPolygonRasterConverter
49     {
50     public:
51         /** Create raster-converter for given poly-polygon
52          */
53         B2DPolyPolygonRasterConverter(const B2DPolyPolygon& rPolyPolyRaster);
54 
55         /** Create raster-converter for given poly-polygon and raster
56             area.
57 
58             @param rPolyPolyRaster
59             Poly-Polygon to raster convert
60 
61             @param rMinUpdateArea
62             Minimal area to touch when raster-converting. The
63             rectangle given here is guaranteed to be iterated through
64             scanline by scanline (but the raster converter might
65             actually use more scanlines, e.g. if the poly-polygon's
66             bound rect is larger). One of the cases where this
67             parameter comes in handy is when rendering in the 'off'
68             spans, and a certain area must be filled. <em>Do not</em>
69             use this for clipping, as described above, the touched
70             area might also be larger.
71          */
72         B2DPolyPolygonRasterConverter(const B2DPolyPolygon& rPolyPolyRaster,
73                                       const B2DRectangle&	rRasterArea );
74 
75         virtual ~B2DPolyPolygonRasterConverter();
76 
77         /** Raster-convert the contained poly-polygon
78 
79         	@param eFillRule
80             Fill rule to use for span filling
81          */
82         void rasterConvert( FillRule eFillRule);
83 
84         /** Override this method, to be called for every scanline span
85             of the poly-polygon
86 
87             @param rfXLeft
88             The left end of the current horizontal span
89 
90             @param rfXRight
91             The right end of the current horizontal span
92 
93             @param nY
94             The y position of the current horizontal span
95 
96             @param bOn
97             Denotes whether this span is on or off, according to the
98             active fill rule.
99         */
100         virtual void span(const double& rfXLeft,
101                           const double& rfXRight,
102                           sal_Int32 	nY,
103                           bool 			bOn ) = 0;
104 
105         /// @internal
106         struct Vertex
107         {
108             inline Vertex();
109             inline Vertex( const B2DPoint&, const B2DPoint&, bool );
110 
111             B2DPoint	aP1;
112             B2DPoint	aP2;
113             bool 		bDownwards;
114         };
115 
116     private:
117         // default: disabled copy/assignment
118         B2DPolyPolygonRasterConverter(const B2DPolyPolygonRasterConverter&);
119         B2DPolyPolygonRasterConverter& operator=( const B2DPolyPolygonRasterConverter& );
120 
121         void init();
122 
123         typedef ::std::vector<Vertex>				VectorOfVertices;
124         typedef ::std::vector<VectorOfVertices>		VectorOfVertexVectors;
125 
126         /// The poly-polygon to raster-convert
127         B2DPolyPolygon								maPolyPolygon;
128         /// Total bound rect of the poly-polygon
129         const B2DRectangle							maPolyPolyRectangle;
130 
131         /** Vector containing for each scanline a vector which in turn
132             contains all vertices that start on the specific scanline
133          */
134         VectorOfVertexVectors						maScanlines;
135     };
136 }
137 
138 #endif /* _BGFX_POLYGON_B2DPOLYPOLYGONRASTERCONVERTER_HXX */
139