1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
33 using namespace com::sun::star
;
36 namespace drawinglayer
40 ContourExtractor2D::ContourExtractor2D(
41 const geometry::ViewInformation2D
& rViewInformation
,
42 bool bExtractFillOnly
)
43 : BaseProcessor2D(rViewInformation
),
45 mbExtractFillOnly(bExtractFillOnly
)
49 ContourExtractor2D::~ContourExtractor2D()
53 void ContourExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D
& rCandidate
)
55 switch(rCandidate
.getPrimitive2DID())
57 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D
:
59 if(!mbExtractFillOnly
)
61 // extract hairline in world coordinates
62 const primitive2d::PolygonHairlinePrimitive2D
& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D
& >(rCandidate
));
63 basegfx::B2DPolygon
aLocalPolygon(rPolygonCandidate
.getB2DPolygon());
64 aLocalPolygon
.transform(getViewInformation2D().getObjectTransformation());
66 if(aLocalPolygon
.isClosed())
68 // line polygons need to be represented as open polygons to differentiate them
69 // from filled polygons
70 basegfx::utils::openWithGeometryChange(aLocalPolygon
);
73 maExtractedContour
.emplace_back(aLocalPolygon
);
77 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D
:
79 // extract fill in world coordinates
80 const primitive2d::PolyPolygonColorPrimitive2D
& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D
& >(rCandidate
));
81 basegfx::B2DPolyPolygon
aLocalPolyPolygon(rPolygonCandidate
.getB2DPolyPolygon());
82 aLocalPolyPolygon
.transform(getViewInformation2D().getObjectTransformation());
83 maExtractedContour
.push_back(aLocalPolyPolygon
);
86 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D
:
88 // extract BoundRect from bitmaps in world coordinates
89 const primitive2d::BitmapPrimitive2D
& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D
& >(rCandidate
));
90 basegfx::B2DHomMatrix
aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate
.getTransform());
91 basegfx::B2DPolygon
aPolygon(basegfx::utils::createUnitPolygon());
92 aPolygon
.transform(aLocalTransform
);
93 maExtractedContour
.emplace_back(aPolygon
);
96 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D
:
98 // extract BoundRect from MetaFiles in world coordinates
99 const primitive2d::MetafilePrimitive2D
& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D
& >(rCandidate
));
100 basegfx::B2DHomMatrix
aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate
.getTransform());
101 basegfx::B2DPolygon
aPolygon(basegfx::utils::createUnitPolygon());
102 aPolygon
.transform(aLocalTransform
);
103 maExtractedContour
.emplace_back(aPolygon
);
106 case PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D
:
108 // sub-transparence group. Look at children
109 const primitive2d::TransparencePrimitive2D
& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D
& >(rCandidate
));
110 process(rTransCandidate
.getChildren());
113 case PRIMITIVE2D_ID_MASKPRIMITIVE2D
:
115 // extract mask in world coordinates, ignore content
116 const primitive2d::MaskPrimitive2D
& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D
& >(rCandidate
));
117 basegfx::B2DPolyPolygon
aMask(rMaskCandidate
.getMask());
118 aMask
.transform(getViewInformation2D().getObjectTransformation());
119 maExtractedContour
.push_back(aMask
);
122 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D
:
124 // remember current ViewInformation2D
125 const primitive2d::TransformPrimitive2D
& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D
& >(rCandidate
));
126 const geometry::ViewInformation2D
aLastViewInformation2D(getViewInformation2D());
128 // create new local ViewInformation2D
129 const geometry::ViewInformation2D
aViewInformation2D(
130 getViewInformation2D().getObjectTransformation() * rTransformCandidate
.getTransformation(),
131 getViewInformation2D().getViewTransformation(),
132 getViewInformation2D().getViewport(),
133 getViewInformation2D().getVisualizedPage(),
134 getViewInformation2D().getViewTime(),
135 getViewInformation2D().getExtendedInformationSequence());
136 updateViewInformation(aViewInformation2D
);
139 process(rTransformCandidate
.getChildren());
141 // restore transformations
142 updateViewInformation(aLastViewInformation2D
);
146 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D
:
148 // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
149 const primitive2d::ScenePrimitive2D
& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D
& >(rCandidate
));
150 const primitive2d::Primitive2DContainer
xExtracted2DSceneGeometry(rScenePrimitive2DCandidate
.getGeometry2D());
151 const primitive2d::Primitive2DContainer
xExtracted2DSceneShadow(rScenePrimitive2DCandidate
.getShadow2D());
154 if(!xExtracted2DSceneGeometry
.empty())
156 process(xExtracted2DSceneGeometry
);
160 if(!xExtracted2DSceneShadow
.empty())
162 process(xExtracted2DSceneShadow
);
167 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D
:
168 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D
:
169 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D
:
171 // ignorable primitives
174 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D
:
175 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D
:
177 // primitives who's BoundRect will be added in world coordinates
178 basegfx::B2DRange
aRange(rCandidate
.getB2DRange(getViewInformation2D()));
179 if (!aRange
.isEmpty())
181 aRange
.transform(getViewInformation2D().getObjectTransformation());
182 maExtractedContour
.emplace_back(basegfx::utils::createPolygonFromRect(aRange
));
188 // process recursively
195 } // end of namespace processor2d
196 } // end of namespace drawinglayer
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */