LibreOffice Module drawinglayer (master) 1
textaspolygonextractor2d.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
27
28
30{
32 {
33 switch(rCandidate.getPrimitive2DID())
34 {
36 {
37 // TextDecoratedPortionPrimitive2D can produce the following primitives
38 // when being decomposed:
39 //
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
53 // - GroupPrimitive2D
54
55 // encapsulate with flag and use decomposition
56 mnInText++;
57 process(rCandidate);
58 mnInText--;
59
60 break;
61 }
63 {
64 // TextSimplePortionPrimitive2D can produce the following primitives
65 // when being decomposed:
66 //
67 // - PolyPolygonColorPrimitive2D
68 // - TextEffectPrimitive2D
69 // - ModifiedColorPrimitive2D
70 // - TransformPrimitive2D
71 // - GroupPrimitive2D
72
73 // encapsulate with flag and use decomposition
74 mnInText++;
75 process(rCandidate);
76 mnInText--;
77
78 break;
79 }
80
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:
85 //
86 // - PolyPolygonColorPrimitive2D
87 // - PolygonHairlinePrimitive2D
88 // - PolyPolygonHairlinePrimitive2D (for convenience)
89 //
91 {
92 if(mnInText)
93 {
94 const primitive2d::PolyPolygonColorPrimitive2D& rPoPoCoCandidate(static_cast< const primitive2d::PolyPolygonColorPrimitive2D& >(rCandidate));
95 basegfx::B2DPolyPolygon aPolyPolygon(rPoPoCoCandidate.getB2DPolyPolygon());
96
97 if(aPolyPolygon.count())
98 {
99 // transform the PolyPolygon
100 aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
101
102 // get evtl. corrected color
103 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoCoCandidate.getBColor()));
104
105 // add to result vector
106 maTarget.emplace_back(aPolyPolygon, aColor, true);
107 }
108 }
109
110 break;
111 }
113 {
114 if(mnInText)
115 {
116 const primitive2d::PolygonHairlinePrimitive2D& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
117 basegfx::B2DPolygon aPolygon(rPoHaCandidate.getB2DPolygon());
118
119 if(aPolygon.count())
120 {
121 // transform the Polygon
122 aPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
123
124 // get evtl. corrected color
125 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoHaCandidate.getBColor()));
126
127 // add to result vector
128 maTarget.emplace_back(basegfx::B2DPolyPolygon(aPolygon), aColor, false);
129 }
130 }
131
132 break;
133 }
135 {
136 if(mnInText)
137 {
138 const primitive2d::PolyPolygonHairlinePrimitive2D& rPoPoHaCandidate(static_cast< const primitive2d::PolyPolygonHairlinePrimitive2D& >(rCandidate));
139 basegfx::B2DPolyPolygon aPolyPolygon(rPoPoHaCandidate.getB2DPolyPolygon());
140
141 if(aPolyPolygon.count())
142 {
143 // transform the Polygon
144 aPolyPolygon.transform(getViewInformation2D().getObjectToViewTransformation());
145
146 // get evtl. corrected color
147 const basegfx::BColor aColor(maBColorModifierStack.getModifiedColor(rPoPoHaCandidate.getBColor()));
148
149 // add to result vector
150 maTarget.emplace_back(aPolyPolygon, aColor, false);
151 }
152 }
153
154 break;
155 }
156
157 // usage of color modification stack is needed
159 {
160 const primitive2d::ModifiedColorPrimitive2D& rModifiedColorCandidate(static_cast< const primitive2d::ModifiedColorPrimitive2D& >(rCandidate));
161
162 if(!rModifiedColorCandidate.getChildren().empty())
163 {
164 maBColorModifierStack.push(rModifiedColorCandidate.getColorModifier());
165 process(rModifiedColorCandidate.getChildren());
167 }
168
169 break;
170 }
171
172 // usage of transformation stack is needed
174 {
175 // remember current transformation and ViewInformation
176 const primitive2d::TransformPrimitive2D& rTransformCandidate(static_cast< const primitive2d::TransformPrimitive2D& >(rCandidate));
177 const geometry::ViewInformation2D aLastViewInformation2D(getViewInformation2D());
178
179 // create new transformations for CurrentTransformation and for local ViewInformation2D
181 aViewInformation2D.setObjectTransformation(getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation());
182 updateViewInformation(aViewInformation2D);
183
184 // process content
185 process(rTransformCandidate.getChildren());
186
187 // restore transformations
188 updateViewInformation(aLastViewInformation2D);
189
190 break;
191 }
192
193 // ignorable primitives
201 {
202 break;
203 }
204
205 default :
206 {
207 // process recursively
208 process(rCandidate);
209 break;
210 }
211 }
212 }
213
215 : BaseProcessor2D(rViewInformation),
216 maBColorModifierStack(),
217 mnInText(0)
218 {
219 }
220
222 {
223 }
224
225} // end of namespace
226
227/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void transform(const basegfx::B2DHomMatrix &rMatrix)
sal_uInt32 count() const
void transform(const basegfx::B2DHomMatrix &rMatrix)
sal_uInt32 count() const
void push(const BColorModifierSharedPtr &rNew)
::basegfx::BColor getModifiedColor(const ::basegfx::BColor &rSource) 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.
const Primitive2DContainer & getChildren() const
data read access
const basegfx::BColorModifierSharedPtr & getColorModifier() const
data read access
const basegfx::B2DPolyPolygon & getB2DPolyPolygon() const
data read access
const basegfx::B2DPolyPolygon & getB2DPolyPolygon() const
data read access
const basegfx::B2DPolygon & getB2DPolygon() const
data read access
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
TextAsPolygonExtractor2D(const geometry::ViewInformation2D &rViewInformation)
void processBasePrimitive2D(const primitive2d::BasePrimitive2D &rCandidate) override
#define PRIMITIVE2D_ID_TEXTDECORATEDPORTIONPRIMITIVE2D
#define PRIMITIVE2D_ID_SCENEPRIMITIVE2D
#define PRIMITIVE2D_ID_TRANSFORMPRIMITIVE2D
#define PRIMITIVE2D_ID_POLYPOLYGONCOLORPRIMITIVE2D
#define PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D
#define PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D
#define PRIMITIVE2D_ID_MODIFIEDCOLORPRIMITIVE2D
#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