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/textaspolygonextractor2d.hxx>
21 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
23 #include <drawinglayer/primitive2d/PolyPolygonHairlinePrimitive2D.hxx>
24 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
25 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
26 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
29 namespace drawinglayer::processor2d
31 void TextAsPolygonExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D
& rCandidate
)
33 switch(rCandidate
.getPrimitive2DID())
35 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D
:
37 // TextDecoratedPortionPrimitive2D can produce the following primitives
38 // when being decomposed:
40 // - TextSimplePortionPrimitive2D
41 // - PolygonWavePrimitive2D
42 // - PolygonStrokePrimitive2D
43 // - PolygonStrokePrimitive2D
44 // - PolyPolygonColorPrimitive2D
45 // - PolyPolygonHairlinePrimitive2D
46 // - PolygonHairlinePrimitive2D
47 // - ShadowPrimitive2D
48 // - ModifiedColorPrimitive2D
49 // - TransformPrimitive2D
50 // - TextEffectPrimitive2D
51 // - ModifiedColorPrimitive2D
52 // - TransformPrimitive2D
55 // encapsulate with flag and use decomposition
62 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D
:
64 // TextSimplePortionPrimitive2D can produce the following primitives
65 // when being decomposed:
67 // - PolyPolygonColorPrimitive2D
68 // - TextEffectPrimitive2D
69 // - ModifiedColorPrimitive2D
70 // - TransformPrimitive2D
73 // encapsulate with flag and use decomposition
81 // as can be seen from the TextSimplePortionPrimitive2D and the
82 // TextDecoratedPortionPrimitive2D, inside of the mnInText marks
83 // the following primitives can occur containing geometry data
84 // from text decomposition:
86 // - PolyPolygonColorPrimitive2D
87 // - PolygonHairlinePrimitive2D
88 // - PolyPolygonHairlinePrimitive2D (for convenience)
90 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D
:
94 const primitive2d::PolyPolygonColorPrimitive2D
& rPoPoCoCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D
& >(rCandidate
));
95 basegfx::B2DPolyPolygon
aPolyPolygon(rPoPoCoCandidate
.getB2DPolyPolygon());
97 if(aPolyPolygon
.count())
99 // transform the PolyPolygon
100 aPolyPolygon
.transform(getViewInformation2D().getObjectToViewTransformation());
102 // get evtl. corrected color
103 const basegfx::BColor
aColor(maBColorModifierStack
.getModifiedColor(rPoPoCoCandidate
.getBColor()));
105 // add to result vector
106 maTarget
.emplace_back(aPolyPolygon
, aColor
, true);
112 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D
:
116 const primitive2d::PolygonHairlinePrimitive2D
& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D
& >(rCandidate
));
117 basegfx::B2DPolygon
aPolygon(rPoHaCandidate
.getB2DPolygon());
121 // transform the Polygon
122 aPolygon
.transform(getViewInformation2D().getObjectToViewTransformation());
124 // get evtl. corrected color
125 const basegfx::BColor
aColor(maBColorModifierStack
.getModifiedColor(rPoHaCandidate
.getBColor()));
127 // add to result vector
128 maTarget
.emplace_back(basegfx::B2DPolyPolygon(aPolygon
), aColor
, false);
134 case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D
:
138 const primitive2d::PolyPolygonHairlinePrimitive2D
& rPoPoHaCandidate(static_cast< const primitive2d::PolyPolygonHairlinePrimitive2D
& >(rCandidate
));
139 basegfx::B2DPolyPolygon
aPolyPolygon(rPoPoHaCandidate
.getB2DPolyPolygon());
141 if(aPolyPolygon
.count())
143 // transform the Polygon
144 aPolyPolygon
.transform(getViewInformation2D().getObjectToViewTransformation());
146 // get evtl. corrected color
147 const basegfx::BColor
aColor(maBColorModifierStack
.getModifiedColor(rPoPoHaCandidate
.getBColor()));
149 // add to result vector
150 maTarget
.emplace_back(aPolyPolygon
, aColor
, false);
157 // usage of color modification stack is needed
158 case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D
:
160 const primitive2d::ModifiedColorPrimitive2D
& rModifiedColorCandidate(static_cast< const primitive2d::ModifiedColorPrimitive2D
& >(rCandidate
));
162 if(!rModifiedColorCandidate
.getChildren().empty())
164 maBColorModifierStack
.push(rModifiedColorCandidate
.getColorModifier());
165 process(rModifiedColorCandidate
.getChildren());
166 maBColorModifierStack
.pop();
172 // usage of transformation stack is needed
173 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D
:
175 // remember current transformation and ViewInformation
176 const primitive2d::TransformPrimitive2D
& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D
& >(rCandidate
));
177 const geometry::ViewInformation2D
aLastViewInformation2D(getViewInformation2D());
179 // create new transformations for CurrentTransformation and for local ViewInformation2D
180 geometry::ViewInformation2D
aViewInformation2D(getViewInformation2D());
181 aViewInformation2D
.setObjectTransformation(getViewInformation2D().getObjectTransformation() * rTransformCandidate
.getTransformation());
182 updateViewInformation(aViewInformation2D
);
185 process(rTransformCandidate
.getChildren());
187 // restore transformations
188 updateViewInformation(aLastViewInformation2D
);
193 // ignorable primitives
194 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D
:
195 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D
:
196 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D
:
197 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D
:
198 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D
:
199 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D
:
200 case PRIMITIVE2D_ID_MASKPRIMITIVE2D
:
207 // process recursively
214 TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D
& rViewInformation
)
215 : BaseProcessor2D(rViewInformation
),
216 maBColorModifierStack(),
221 TextAsPolygonExtractor2D::~TextAsPolygonExtractor2D()
225 } // end of namespace
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */