Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / drawinglayer / source / processor2d / textaspolygonextractor2d.cxx
blob830a189f3091f139a64f1cc0e5ba498602d0b83f
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/textaspolygonextractor2d.hxx>
21 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
22 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
23 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
24 #include <drawinglayer/primitive2d/modifiedcolorprimitive2d.hxx>
25 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
28 namespace drawinglayer
30 namespace processor2d
32 void TextAsPolygonExtractor2D::processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate)
34 switch(rCandidate.getPrimitive2DID())
36 case PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D :
38 // TextDecoratedPortionPrimitive2D can produce the following primitives
39 // when being decomposed:
41 // - TextSimplePortionPrimitive2D
42 // - PolygonWavePrimitive2D
43 // - PolygonStrokePrimitive2D
44 // - PolygonStrokePrimitive2D
45 // - PolyPolygonColorPrimitive2D
46 // - PolyPolygonHairlinePrimitive2D
47 // - PolygonHairlinePrimitive2D
48 // - ShadowPrimitive2D
49 // - ModifiedColorPrimitive2D
50 // - TransformPrimitive2D
51 // - TextEffectPrimitive2D
52 // - ModifiedColorPrimitive2D
53 // - TransformPrimitive2D
54 // - GroupPrimitive2D
56 // encapsulate with flag and use decomposition
57 mnInText++;
58 process(rCandidate.get2DDecomposition(getViewInformation2D()));
59 mnInText--;
61 break;
63 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
65 // TextSimplePortionPrimitive2D can produce the following primitives
66 // when being decomposed:
68 // - PolyPolygonColorPrimitive2D
69 // - TextEffectPrimitive2D
70 // - ModifiedColorPrimitive2D
71 // - TransformPrimitive2D
72 // - GroupPrimitive2D
74 // encapsulate with flag and use decomposition
75 mnInText++;
76 process(rCandidate.get2DDecomposition(getViewInformation2D()));
77 mnInText--;
79 break;
82 // as can be seen from the TextSimplePortionPrimitive2D and the
83 // TextDecoratedPortionPrimitive2D, inside of the mnInText marks
84 // the following primitives can occur containing geometry data
85 // from text decomposition:
87 // - PolyPolygonColorPrimitive2D
88 // - PolygonHairlinePrimitive2D
89 // - PolyPolygonHairlinePrimitive2D (for convenience)
91 case PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D :
93 if(mnInText)
95 const primitive2d::PolyPolygonColorPrimitive2D& rPoPoCoCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
96 basegfx::B2DPolyPolygon aPolyPolygon(rPoPoCoCandidate.getB2DPolyPolygon());
98 if(aPolyPolygon.count())
100 // transform the PolyPolygon
101 aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
103 // get evtl. corrected color
104 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoCoCandidate.getBColor()));
106 // add to result vector
107 maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, true));
111 break;
113 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
115 if(mnInText)
117 const primitive2d::PolygonHairlinePrimitive2D& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
118 basegfx::B2DPolygon aPolygon(rPoHaCandidate.getB2DPolygon());
120 if(aPolygon.count())
122 // transform the Polygon
123 aPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
125 // get evtl. corrected color
126 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoHaCandidate.getBColor()));
128 // add to result vector
129 maTarget.push_back(TextAsPolygonDataNode(basegfx::B2DPolyPolygon(aPolygon), aColor, false));
133 break;
135 case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D :
137 if(mnInText)
139 const primitive2d::PolyPolygonHairlinePrimitive2D& rPoPoHaCandidate(static_cast< const primitive2d::PolyPolygonHairlinePrimitive2D& >(rCandidate));
140 basegfx::B2DPolyPolygon aPolyPolygon(rPoPoHaCandidate.getB2DPolyPolygon());
142 if(aPolyPolygon.count())
144 // transform the Polygon
145 aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
147 // get evtl. corrected color
148 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoHaCandidate.getBColor()));
150 // add to result vector
151 maTarget.push_back(TextAsPolygonDataNode(aPolyPolygon, aColor, false));
155 break;
158 // usage of color modification stack is needed
159 case PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D :
161 const primitive2d::ModifiedColorPrimitive2D& rModifiedColorCandidate(static_cast< const primitive2d::ModifiedColorPrimitive2D& >(rCandidate));
163 if(!rModifiedColorCandidate.getChildren().empty())
165 maBColorModifierStack.push(rModifiedColorCandidate.getColorModifier());
166 process(rModifiedColorCandidate.getChildren());
167 maBColorModifierStack.pop();
170 break;
173 // usage of transformation stack is needed
174 case PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D :
176 // remember current transformation and ViewInformation
177 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
178 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
180 // create new transformations for CurrentTransformation and for local ViewInformation2D
181 const geometry::ViewInformation2D aViewInformation2D(
182 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
183 getViewInformation2D().getViewTransformation(),
184 getViewInformation2D().getViewport(),
185 getViewInformation2D().getVisualizedPage(),
186 getViewInformation2D().getViewTime(),
187 getViewInformation2D().getExtendedInformationSequence());
188 updateViewInformation(aViewInformation2D);
190 // process content
191 process(rTransformCandidate.getChildren());
193 // restore transformations
194 updateViewInformation(aLastViewInformation2D);
196 break;
199 // ignorable primitives
200 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
201 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
202 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
203 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
204 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
205 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
206 case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
208 break;
211 default :
213 // process recursively
214 process(rCandidate.get2DDecomposition(getViewInformation2D()));
215 break;
220 TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation)
221 : BaseProcessor2D(rViewInformation),
222 maTarget(),
223 maBColorModifierStack(),
224 mnInText(0)
228 TextAsPolygonExtractor2D::~TextAsPolygonExtractor2D()
231 } // end of namespace processor2d
232 } // end of namespace drawinglayer
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */