update emoji autocorrect entries from po-files
[LibreOffice.git] / drawinglayer / source / processor2d / contourextractor2d.cxx
blob62896bb133312bb0547074e5467bf5b7b326d2ea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <drawinglayer/processor2d/contourextractor2d.hxx>
21 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
23 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
24 #include <drawinglayer/primitive2d/bitmapprimitive2d.hxx>
25 #include <basegfx/polygon/b2dpolygontools.hxx>
26 #include <drawinglayer/primitive2d/metafileprimitive2d.hxx>
27 #include <drawinglayer/primitive2d/transparenceprimitive2d.hxx>
28 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
29 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
30 #include <drawinglayer/primitive2d/sceneprimitive2d.hxx>
34 using namespace com::sun::star;
38 namespace drawinglayer
40 namespace processor2d
42 ContourExtractor2D::ContourExtractor2D(
43 const geometry::ViewInformation2D& rViewInformation,
44 bool bExtractFillOnly)
45 : BaseProcessor2D(rViewInformation),
46 maExtractedContour(),
47 mbExtractFillOnly(bExtractFillOnly)
51 ContourExtractor2D::~ContourExtractor2D()
55 void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
57 switch(rCandidate.getPrimitive2DID())
59 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
61 if(!mbExtractFillOnly)
63 // extract hairline in world coordinates
64 const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
65 basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
66 aLocalPolygon.transform(getViewInformation2D().getObjectTransformation());
68 if(aLocalPolygon.isClosed())
70 // line polygons need to be represented as open polygons to differentiate them
71 // from filled polygons
72 basegfx::tools::openWithGeometryChange(aLocalPolygon);
75 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aLocalPolygon));
77 break;
79 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
81 // extract fill in world coordinates
82 const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
83 basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
84 aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation());
85 maExtractedContour.push_back(aLocalPolyPolygon);
86 break;
88 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
90 // extract BoundRect from bitmaps in world coordinates
91 const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
92 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform());
93 basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
94 aPolygon.transform(aLocalTransform);
95 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
96 break;
98 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
100 // extract BoundRect from MetaFiles in world coordinates
101 const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate));
102 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform());
103 basegfx::B2DPolygon aPolygon(basegfx::tools::createUnitPolygon());
104 aPolygon.transform(aLocalTransform);
105 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aPolygon));
106 break;
108 case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D :
110 // sub-transparence group. Look at children
111 const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate));
112 process(rTransCandidate.getChildren());
113 break;
115 case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
117 // extract mask in world coordinates, ignore content
118 const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
119 basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
120 aMask.transform(getViewInformation2D().getObjectTransformation());
121 maExtractedContour.push_back(basegfx::B2DPolyPolygon(aMask));
122 break;
124 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
126 // remember current ViewInformation2D
127 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
128 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
130 // create new local ViewInformation2D
131 const geometry::ViewInformation2D aViewInformation2D(
132 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
133 getViewInformation2D().getViewTransformation(),
134 getViewInformation2D().getViewport(),
135 getViewInformation2D().getVisualizedPage(),
136 getViewInformation2D().getViewTime(),
137 getViewInformation2D().getExtendedInformationSequence());
138 updateViewInformation(aViewInformation2D);
140 // process content
141 process(rTransformCandidate.getChildren());
143 // restore transformations
144 updateViewInformation(aLastViewInformation2D);
146 break;
148 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
150 // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
151 const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate));
152 const primitive2d::Primitive2DSequence xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D());
153 const primitive2d::Primitive2DSequence xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D(getViewInformation2D()));
155 // process content
156 if(xExtracted2DSceneGeometry.hasElements())
158 process(xExtracted2DSceneGeometry);
161 // process content
162 if(xExtracted2DSceneShadow.hasElements())
164 process(xExtracted2DSceneShadow);
167 break;
169 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
170 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
171 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
173 // ignorable primitives
174 break;
176 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
177 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
179 // primitives who's BoundRect will be added in world coordinates
180 basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D()));
181 aRange.transform(getViewInformation2D().getObjectTransformation());
182 maExtractedContour.push_back(basegfx::B2DPolyPolygon(basegfx::tools::createPolygonFromRect(aRange)));
183 break;
185 default :
187 // process recursively
188 process(rCandidate.get2DDecomposition(getViewInformation2D()));
189 break;
194 } // end of namespace processor2d
195 } // end of namespace drawinglayer
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */