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