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