1*464702f4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*464702f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*464702f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*464702f4SAndrew Rist  * distributed with this work for additional information
6*464702f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*464702f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*464702f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*464702f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*464702f4SAndrew Rist  *
11*464702f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*464702f4SAndrew Rist  *
13*464702f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*464702f4SAndrew Rist  * software distributed under the License is distributed on an
15*464702f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*464702f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*464702f4SAndrew Rist  * specific language governing permissions and limitations
18*464702f4SAndrew Rist  * under the License.
19*464702f4SAndrew Rist  *
20*464702f4SAndrew Rist  *************************************************************/
21*464702f4SAndrew Rist 
22*464702f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <drawinglayer/processor2d/contourextractor2d.hxx>
28cdf0e10cSrcweir #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
29cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
30cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
31cdf0e10cSrcweir #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
33cdf0e10cSrcweir #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
34cdf0e10cSrcweir #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
35cdf0e10cSrcweir #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
36cdf0e10cSrcweir #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
37cdf0e10cSrcweir #include <drawinglayer/primitive2d/sceneprimitive2d.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using namespace com::sun::star;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
44cdf0e10cSrcweir 
45cdf0e10cSrcweir namespace drawinglayer
46cdf0e10cSrcweir {
47cdf0e10cSrcweir 	namespace processor2d
48cdf0e10cSrcweir 	{
49cdf0e10cSrcweir 		ContourExtractor2D::ContourExtractor2D(const geometry::ViewInformation2D& rViewInformation)
50cdf0e10cSrcweir 		:	BaseProcessor2D(rViewInformation),
51cdf0e10cSrcweir 			maExtractedContour()
52cdf0e10cSrcweir 		{
53cdf0e10cSrcweir 		}
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 		ContourExtractor2D::~ContourExtractor2D()
56cdf0e10cSrcweir 		{
57cdf0e10cSrcweir 		}
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 		void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 			switch(rCandidate.getPrimitive2DID())
62cdf0e10cSrcweir 			{
63cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
64cdf0e10cSrcweir 				{
65cdf0e10cSrcweir 					// extract hairline in world coordinates
66cdf0e10cSrcweir 					const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
67cdf0e10cSrcweir 					basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
68cdf0e10cSrcweir 					aLocalPolygon.transform(getViewInformation2D().getObjectTransformation());
69cdf0e10cSrcweir 
70cdf0e10cSrcweir                     if(aLocalPolygon.isClosed())
71cdf0e10cSrcweir                     {
72cdf0e10cSrcweir                         // line polygons need to be represented as open polygons to differentiate them
73cdf0e10cSrcweir                         // from filled polygons
74cdf0e10cSrcweir                         basegfx::tools::openWithGeometryChange(aLocalPolygon);
75cdf0e10cSrcweir                     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir                     maExtractedContour.push_back(basegfx::B2DPolyPolygon(aLocalPolygon));
78cdf0e10cSrcweir 					break;
79cdf0e10cSrcweir 				}
80cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
81cdf0e10cSrcweir 				{
82cdf0e10cSrcweir 					// extract fill in world coordinates
83cdf0e10cSrcweir 					const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
84cdf0e10cSrcweir 					basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
85cdf0e10cSrcweir 					aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation());
86cdf0e10cSrcweir 					maExtractedContour.push_back(aLocalPolyPolygon);
87cdf0e10cSrcweir 					break;
88cdf0e10cSrcweir 				}
89cdf0e10cSrcweir 				case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
90cdf0e10cSrcweir 				{
91cdf0e10cSrcweir 					// extract BoundRect from bitmaps in world coordinates
92cdf0e10cSrcweir 					const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
93cdf0e10cSrcweir 					basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform());
94cdf0e10cSrcweir 					basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
95cdf0e10cSrcweir 					aPolygon.transform(aLocalTransform);
96cdf0e10cSrcweir                     maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
97cdf0e10cSrcweir 					break;
98cdf0e10cSrcweir 				}
99cdf0e10cSrcweir 				case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
100cdf0e10cSrcweir 				{
101cdf0e10cSrcweir 					// extract BoundRect from MetaFiles in world coordinates
102cdf0e10cSrcweir 					const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate));
103cdf0e10cSrcweir 					basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform());
104cdf0e10cSrcweir 					basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
105cdf0e10cSrcweir 					aPolygon.transform(aLocalTransform);
106cdf0e10cSrcweir 					maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
107cdf0e10cSrcweir 					break;
108cdf0e10cSrcweir 				}
109cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D :
110cdf0e10cSrcweir 				{
111cdf0e10cSrcweir 					// sub-transparence group. Look at children
112cdf0e10cSrcweir 					const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate));
113cdf0e10cSrcweir 					process(rTransCandidate.getChildren());
114cdf0e10cSrcweir 					break;
115cdf0e10cSrcweir 				}
116cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
117cdf0e10cSrcweir 				{
118cdf0e10cSrcweir 					// extract mask in world coordinates, ignore content
119cdf0e10cSrcweir 					const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
120cdf0e10cSrcweir 					basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
121cdf0e10cSrcweir 					aMask.transform(getViewInformation2D().getObjectTransformation());
122cdf0e10cSrcweir 					maExtractedContour.push_back(basegfx::B2DPolyPolygon(aMask));
123cdf0e10cSrcweir 					break;
124cdf0e10cSrcweir 				}
125cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
126cdf0e10cSrcweir 				{
127cdf0e10cSrcweir 					// remember current ViewInformation2D
128cdf0e10cSrcweir 					const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
129cdf0e10cSrcweir 					const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 					// create new local ViewInformation2D
132cdf0e10cSrcweir 					const geometry::ViewInformation2D aViewInformation2D(
133cdf0e10cSrcweir 						getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
134cdf0e10cSrcweir 						getViewInformation2D().getViewTransformation(),
135cdf0e10cSrcweir 						getViewInformation2D().getViewport(),
136cdf0e10cSrcweir 						getViewInformation2D().getVisualizedPage(),
137cdf0e10cSrcweir 						getViewInformation2D().getViewTime(),
138cdf0e10cSrcweir 						getViewInformation2D().getExtendedInformationSequence());
139cdf0e10cSrcweir 					updateViewInformation(aViewInformation2D);
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 					// proccess content
142cdf0e10cSrcweir 					process(rTransformCandidate.getChildren());
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 					// restore transformations
145cdf0e10cSrcweir 					updateViewInformation(aLastViewInformation2D);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 					break;
148cdf0e10cSrcweir 				}
149cdf0e10cSrcweir 				case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
150cdf0e10cSrcweir 				{
151cdf0e10cSrcweir 					// 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
152cdf0e10cSrcweir 					const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate));
153cdf0e10cSrcweir 					const primitive2d::Primitive2DSequence xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D());
154cdf0e10cSrcweir 					const primitive2d::Primitive2DSequence xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D(getViewInformation2D()));
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 					// proccess content
157cdf0e10cSrcweir 					if(xExtracted2DSceneGeometry.hasElements())
158cdf0e10cSrcweir 					{
159cdf0e10cSrcweir 						process(xExtracted2DSceneGeometry);
160cdf0e10cSrcweir 					}
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 					// proccess content
163cdf0e10cSrcweir 					if(xExtracted2DSceneShadow.hasElements())
164cdf0e10cSrcweir 					{
165cdf0e10cSrcweir 						process(xExtracted2DSceneShadow);
166cdf0e10cSrcweir 					}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 					break;
169cdf0e10cSrcweir 				}
170cdf0e10cSrcweir                 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
171cdf0e10cSrcweir 				case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
172cdf0e10cSrcweir 				case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
173cdf0e10cSrcweir                 {
174cdf0e10cSrcweir 					// ignorable primitives
175cdf0e10cSrcweir 					break;
176cdf0e10cSrcweir 				}
177cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
178cdf0e10cSrcweir 				case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
179cdf0e10cSrcweir                 {
180cdf0e10cSrcweir 					// primitives who's BoundRect will be added in world coordinates
181cdf0e10cSrcweir 					basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D()));
182cdf0e10cSrcweir 					aRange.transform(getViewInformation2D().getObjectTransformation());
183cdf0e10cSrcweir 					maExtractedContour.push_back(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aRange)));
184cdf0e10cSrcweir 					break;
185cdf0e10cSrcweir 				}
186cdf0e10cSrcweir 				default :
187cdf0e10cSrcweir 				{
188cdf0e10cSrcweir 					// process recursively
189cdf0e10cSrcweir 					process(rCandidate.get2DDecomposition(getViewInformation2D()));
190cdf0e10cSrcweir 					break;
191cdf0e10cSrcweir 				}
192cdf0e10cSrcweir 			}
193cdf0e10cSrcweir 		}
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	} // end of namespace processor2d
196cdf0e10cSrcweir } // end of namespace drawinglayer
197cdf0e10cSrcweir 
198cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
199cdf0e10cSrcweir // eof
200