Update ooo320-m1
[ooovba.git] / drawinglayer / source / processor2d / contourextractor2d.cxx
blob096585d0a49a459b4115978d469116f6955c3563
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: contourextractor2d.cxx,v $
7 * $Revision: 1.6 $
9 * last change: $Author: aw $ $Date: 2008-06-24 15:31:08 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/processor2d/contourextractor2d.hxx>
40 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
41 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
42 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
43 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
44 #include <basegfx/polygon/b2dpolygontools.hxx>
45 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
46 #include <drawinglayer/primitive2d/alphaprimitive2d.hxx>
47 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
48 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
49 #include <drawinglayer/primitive2d/sceneprimitive2d.hxx>
51 //////////////////////////////////////////////////////////////////////////////
53 using namespace com::sun::star;
55 //////////////////////////////////////////////////////////////////////////////
57 namespace drawinglayer
59 namespace processor2d
61 ContourExtractor2D::ContourExtractor2D(const geometry::ViewInformation2D& rViewInformation)
62 : BaseProcessor2D(rViewInformation),
63 maExtractedContour()
67 ContourExtractor2D::~ContourExtractor2D()
71 void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
73 switch(rCandidate.getPrimitiveID())
75 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
77 // extract hairline in world coordinates
78 const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
79 basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
80 aLocalPolygon.transform(getViewInformation2D().getObjectTransformation());
82 if(aLocalPolygon.isClosed())
84 // line polygons need to be represented as open polygons to differentiate them
85 // from filled polygons
86 basegfx::tools::openWithGeometryChange(aLocalPolygon);
89 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aLocalPolygon));
90 break;
92 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
94 // extract fill in world coordinates
95 const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
96 basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
97 aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation());
98 maExtractedContour.push_back(aLocalPolyPolygon);
99 break;
101 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
103 // extract BoundRect from bitmaps in world coordinates
104 const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
105 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform());
106 basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
107 aPolygon.transform(aLocalTransform);
108 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
109 break;
111 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
113 // extract BoundRect from MetaFiles in world coordinates
114 const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate));
115 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform());
116 basegfx::B2DPolygon aPolygon(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
117 aPolygon.transform(aLocalTransform);
118 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
119 break;
121 case PRIMITIVE2D_ID_ALPHAPRIMITIVE2D :
123 // sub-transparence group. Look at children
124 const primitive2d::AlphaPrimitive2D& rTransCandidate(static_cast< const primitive2d::AlphaPrimitive2D& >(rCandidate));
125 process(rTransCandidate.getChildren());
126 break;
128 case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
130 // extract mask in world coordinates, ignore content
131 const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
132 basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
133 aMask.transform(getViewInformation2D().getObjectTransformation());
134 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aMask));
135 break;
137 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
139 // remember current ViewInformation2D
140 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
141 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
143 // create new local ViewInformation2D
144 const geometry::ViewInformation2D aViewInformation2D(
145 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
146 getViewInformation2D().getViewTransformation(),
147 getViewInformation2D().getViewport(),
148 getViewInformation2D().getVisualizedPage(),
149 getViewInformation2D().getViewTime(),
150 getViewInformation2D().getExtendedInformationSequence());
151 updateViewInformation(aViewInformation2D);
153 // proccess content
154 process(rTransformCandidate.getChildren());
156 // restore transformations
157 updateViewInformation(aLastViewInformation2D);
159 break;
161 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
163 // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
164 const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate));
165 const primitive2d::Primitive2DSequence xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D(getViewInformation2D()));
167 // proccess content
168 if(xExtracted2DSceneGeometry.hasElements())
170 process(xExtracted2DSceneGeometry);
173 break;
175 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
176 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
177 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
179 // ignorable primitives
180 break;
182 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
183 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
185 // primitives who's BoundRect will be added in world coordinates
186 basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D()));
187 aRange.transform(getViewInformation2D().getObjectTransformation());
188 maExtractedContour.push_back(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aRange)));
189 break;
191 default :
193 // process recursively
194 process(rCandidate.get2DDecomposition(getViewInformation2D()));
195 break;
200 } // end of namespace processor2d
201 } // end of namespace drawinglayer
203 //////////////////////////////////////////////////////////////////////////////
204 // eof