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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/processor2d/contourextractor2d.hxx>
28 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
30 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
31 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
32 #include <basegfx/polygon/b2dpolygontools.hxx>
33 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
34 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
35 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
36 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
37 #include <drawinglayer/primitive2d/sceneprimitive2d.hxx>
38 
39 //////////////////////////////////////////////////////////////////////////////
40 
41 using namespace com::sun::star;
42 
43 //////////////////////////////////////////////////////////////////////////////
44 
45 namespace drawinglayer
46 {
47 	namespace processor2d
48 	{
ContourExtractor2D(const geometry::ViewInformation2D & rViewInformation,bool bExtractFillOnly)49 		ContourExtractor2D::ContourExtractor2D(
50             const geometry::ViewInformation2D& rViewInformation,
51             bool bExtractFillOnly)
52 		:	BaseProcessor2D(rViewInformation),
53 			maExtractedContour(),
54             mbExtractFillOnly(bExtractFillOnly)
55 		{
56 		}
57 
~ContourExtractor2D()58 		ContourExtractor2D::~ContourExtractor2D()
59 		{
60 		}
61 
processBasePrimitive2D(const primitive2d::BasePrimitive2D & rCandidate)62 		void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
63 		{
64 			switch(rCandidate.getPrimitive2DID())
65 			{
66 				case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
67 				{
68                     if(!mbExtractFillOnly)
69                     {
70                         // extract hairline in world coordinates
71                         const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
72                         basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
73                         aLocalPolygon.transform(getViewInformation2D().getObjectTransformation());
74 
75                         if(aLocalPolygon.isClosed())
76                         {
77                             // line polygons need to be represented as open polygons to differentiate them
78                             // from filled polygons
79                             basegfx::tools::openWithGeometryChange(aLocalPolygon);
80                         }
81 
82                         maExtractedContour.push_back(basegfx::B2DPolyPolygon(aLocalPolygon));
83                     }
84 					break;
85 				}
86 				case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
87 				{
88 					// extract fill in world coordinates
89 					const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
90 					basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
91 					aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation());
92 					maExtractedContour.push_back(aLocalPolyPolygon);
93 					break;
94 				}
95 				case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
96 				{
97 					// extract BoundRect from bitmaps in world coordinates
98 					const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
99 					basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform());
100 					basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
101 					aPolygon.transform(aLocalTransform);
102                     maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
103 					break;
104 				}
105 				case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
106 				{
107 					// extract BoundRect from MetaFiles in world coordinates
108 					const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate));
109 					basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform());
110 					basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
111 					aPolygon.transform(aLocalTransform);
112 					maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
113 					break;
114 				}
115 				case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D :
116 				{
117 					// sub-transparence group. Look at children
118 					const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate));
119 					process(rTransCandidate.getChildren());
120 					break;
121 				}
122 				case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
123 				{
124 					// extract mask in world coordinates, ignore content
125 					const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
126 					basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
127 					aMask.transform(getViewInformation2D().getObjectTransformation());
128 					maExtractedContour.push_back(basegfx::B2DPolyPolygon(aMask));
129 					break;
130 				}
131 				case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
132 				{
133 					// remember current ViewInformation2D
134 					const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
135 					const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
136 
137 					// create new local ViewInformation2D
138 					const geometry::ViewInformation2D aViewInformation2D(
139 						getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
140 						getViewInformation2D().getViewTransformation(),
141 						getViewInformation2D().getViewport(),
142 						getViewInformation2D().getVisualizedPage(),
143 						getViewInformation2D().getViewTime(),
144 						getViewInformation2D().getExtendedInformationSequence());
145 					updateViewInformation(aViewInformation2D);
146 
147 					// proccess content
148 					process(rTransformCandidate.getChildren());
149 
150 					// restore transformations
151 					updateViewInformation(aLastViewInformation2D);
152 
153 					break;
154 				}
155 				case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
156 				{
157 					// 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
158 					const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate));
159 					const primitive2d::Primitive2DSequence xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D());
160 					const primitive2d::Primitive2DSequence xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D(getViewInformation2D()));
161 
162 					// proccess content
163 					if(xExtracted2DSceneGeometry.hasElements())
164 					{
165 						process(xExtracted2DSceneGeometry);
166 					}
167 
168 					// proccess content
169 					if(xExtracted2DSceneShadow.hasElements())
170 					{
171 						process(xExtracted2DSceneShadow);
172 					}
173 
174 					break;
175 				}
176                 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
177 				case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
178 				case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
179                 {
180 					// ignorable primitives
181 					break;
182 				}
183 				case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
184 				case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
185                 {
186 					// primitives who's BoundRect will be added in world coordinates
187 					basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D()));
188 					aRange.transform(getViewInformation2D().getObjectTransformation());
189 					maExtractedContour.push_back(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aRange)));
190 					break;
191 				}
192 				default :
193 				{
194 					// process recursively
195 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
196 					break;
197 				}
198 			}
199 		}
200 
201 	} // end of namespace processor2d
202 } // end of namespace drawinglayer
203 
204 //////////////////////////////////////////////////////////////////////////////
205 // eof
206