LibreOffice Module drawinglayer (master) 1
contourextractor2d.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
31
32
33using namespace com::sun::star;
34
35
37{
39 const geometry::ViewInformation2D& rViewInformation,
40 bool bExtractFillOnly)
41 : BaseProcessor2D(rViewInformation),
42 mbExtractFillOnly(bExtractFillOnly)
43 {
44 }
45
47 {
48 }
49
51 {
52 switch(rCandidate.getPrimitive2DID())
53 {
55 {
57 {
58 // extract hairline in world coordinates
59 const primitive2d::PolygonHairlinePrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
60 basegfx::B2DPolygon aLocalPolygon(rPolygonCandidate.getB2DPolygon());
61 aLocalPolygon.transform(getViewInformation2D().getObjectTransformation());
62
63 if(aLocalPolygon.isClosed())
64 {
65 // line polygons need to be represented as open polygons to differentiate them
66 // from filled polygons
68 }
69
70 maExtractedContour.emplace_back(aLocalPolygon);
71 }
72 break;
73 }
75 {
76 // extract fill in world coordinates
77 const primitive2d::PolyPolygonColorPrimitive2D& rPolygonCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
78 basegfx::B2DPolyPolygon aLocalPolyPolygon(rPolygonCandidate.getB2DPolyPolygon());
79 aLocalPolyPolygon.transform(getViewInformation2D().getObjectTransformation());
80 maExtractedContour.push_back(aLocalPolyPolygon);
81 break;
82 }
84 {
85 // extract BoundRect from bitmaps in world coordinates
86 const primitive2d::BitmapPrimitive2D& rBitmapCandidate(static_cast< const primitive2d::BitmapPrimitive2D& >(rCandidate));
87 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rBitmapCandidate.getTransform());
89 aPolygon.transform(aLocalTransform);
90 maExtractedContour.emplace_back(aPolygon);
91 break;
92 }
94 {
95 // extract BoundRect from MetaFiles in world coordinates
96 const primitive2d::MetafilePrimitive2D& rMetaCandidate(static_cast< const primitive2d::MetafilePrimitive2D& >(rCandidate));
97 basegfx::B2DHomMatrix aLocalTransform(getViewInformation2D().getObjectTransformation() * rMetaCandidate.getTransform());
99 aPolygon.transform(aLocalTransform);
100 maExtractedContour.emplace_back(aPolygon);
101 break;
102 }
104 {
105 // sub-transparence group. Look at children
106 const primitive2d::TransparencePrimitive2D& rTransCandidate(static_cast< const primitive2d::TransparencePrimitive2D& >(rCandidate));
107 process(rTransCandidate.getChildren());
108 break;
109 }
111 {
112 // extract mask in world coordinates, ignore content
113 const primitive2d::MaskPrimitive2D& rMaskCandidate(static_cast< const primitive2d::MaskPrimitive2D& >(rCandidate));
114 basegfx::B2DPolyPolygon aMask(rMaskCandidate.getMask());
115 aMask.transform(getViewInformation2D().getObjectTransformation());
116 maExtractedContour.push_back(aMask);
117 break;
118 }
120 {
121 // remember current ViewInformation2D
122 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
123 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
124
125 // create new local ViewInformation2D
127 aViewInformation2D.setObjectTransformation(getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation());
128 updateViewInformation(aViewInformation2D);
129
130 // process content
131 process(rTransformCandidate.getChildren());
132
133 // restore transformations
134 updateViewInformation(aLastViewInformation2D);
135
136 break;
137 }
139 {
140 // 2D Scene primitive containing 3D stuff; extract 2D contour in world coordinates
141 const primitive2d::ScenePrimitive2D& rScenePrimitive2DCandidate(static_cast< const primitive2d::ScenePrimitive2D& >(rCandidate));
142 const primitive2d::Primitive2DContainer xExtracted2DSceneGeometry(rScenePrimitive2DCandidate.getGeometry2D());
143 const primitive2d::Primitive2DContainer xExtracted2DSceneShadow(rScenePrimitive2DCandidate.getShadow2D());
144
145 // process content
146 if(!xExtracted2DSceneGeometry.empty())
147 {
148 process(xExtracted2DSceneGeometry);
149 }
150
151 // process content
152 if(!xExtracted2DSceneShadow.empty())
153 {
154 process(xExtracted2DSceneShadow);
155 }
156
157 break;
158 }
162 {
163 // ignorable primitives
164 break;
165 }
168 {
169 // primitives who's BoundRect will be added in world coordinates
171 if (!aRange.isEmpty())
172 {
173 aRange.transform(getViewInformation2D().getObjectTransformation());
175 }
176 break;
177 }
178 default :
179 {
180 // process recursively
181 process(rCandidate);
182 break;
183 }
184 }
185 }
186
187} // end of namespace
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void transform(const basegfx::B2DHomMatrix &rMatrix)
bool isClosed() const
void transform(const basegfx::B2DHomMatrix &rMatrix)
BASEGFX_DLLPUBLIC void transform(const B2DHomMatrix &rMatrix)
bool isEmpty() const
void setObjectTransformation(const basegfx::B2DHomMatrix &rNew)
virtual sal_uInt32 getPrimitive2DID() const =0
provide unique ID for fast identifying of known primitive implementations in renderers.
virtual basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &rViewInformation) const
The default implementation will use getDecomposition results to create the range.
const basegfx::B2DHomMatrix & getTransform() const
const Primitive2DContainer & getChildren() const
data read access
const basegfx::B2DPolyPolygon & getMask() const
data read access
const basegfx::B2DHomMatrix & getTransform() const
data read access
const basegfx::B2DPolyPolygon & getB2DPolyPolygon() const
data read access
const basegfx::B2DPolygon & getB2DPolygon() const
data read access
Primitive2DContainer getGeometry2D() const
public helpers
const basegfx::B2DHomMatrix & getTransformation() const
data read access
void process(const primitive2d::BasePrimitive2D &rCandidate)
void updateViewInformation(const geometry::ViewInformation2D &rViewInformation2D)
const geometry::ViewInformation2D & getViewInformation2D() const
data read access
ContourExtractor2D(const geometry::ViewInformation2D &rViewInformation, bool bExtractFillOnly)
basegfx::B2DPolyPolygonVector maExtractedContour
the extracted contour
void processBasePrimitive2D(const primitive2d::BasePrimitive2D &rCandidate) override
tooling methods
#define PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D
#define PRIMITIVE2D_ID_SCENEPRIMITIVE2D
#define PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D
#define PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D
#define PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D
#define PRIMITIVE2D_ID_TRANSPARENCEPRIMITIVE2D
#define PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D
#define PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D
#define PRIMITIVE2D_ID_MASKPRIMITIVE2D
#define PRIMITIVE2D_ID_METAFILEPRIMITIVE2D
#define PRIMITIVE2D_ID_BITMAPPRIMITIVE2D
#define PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D
#define PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
void openWithGeometryChange(B2DPolygon &rCandidate)
B2DPolygon const & createUnitPolygon()