nss: upgrade to release 3.73
[LibreOffice.git] / drawinglayer / source / processor2d / textaspolygonextractor2d.cxx
blobe3a584f86172cff0395e3c79f514e20e633c47f0
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/PolyPolygonHairlinePrimitive2D.hxx>
23 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
24 #include <drawinglayer/primitive2d/polygonprimitive2d.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
53 // - GroupPrimitive2D
55 // encapsulate with flag and use decomposition
56 mnInText++;
57 process(rCandidate);
58 mnInText--;
60 break;
62 case PRIMITIVE2D_ID_TEXTSIMPLEPORTIONPRIMITIVE2D :
64 // TextSimplePortionPrimitive2D can produce the following primitives
65 // when being decomposed:
67 // - PolyPolygonColorPrimitive2D
68 // - TextEffectPrimitive2D
69 // - ModifiedColorPrimitive2D
70 // - TransformPrimitive2D
71 // - GroupPrimitive2D
73 // encapsulate with flag and use decomposition
74 mnInText++;
75 process(rCandidate);
76 mnInText--;
78 break;
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 :
92 if(mnInText)
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);
110 break;
112 case PRIMITIVE2D_ID_POLYGONHAIRLINEPRIMITIVE2D :
114 if(mnInText)
116 const primitive2d::PolygonHairlinePrimitive2D& rPoHaCandidate(static_cast< const primitive2d::PolygonHairlinePrimitive2D& >(rCandidate));
117 basegfx::B2DPolygon aPolygon(rPoHaCandidate.getB2DPolygon());
119 if(aPolygon.count())
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);
132 break;
134 case PRIMITIVE2D_ID_POLYPOLYGONHAIRLINEPRIMITIVE2D :
136 if(mnInText)
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);
154 break;
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();
169 break;
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 const geometry::ViewInformation2D aViewInformation2D(
181 getViewInformation2D().getObjectTransformation() * rTransformCandidate.getTransformation(),
182 getViewInformation2D().getViewTransformation(),
183 getViewInformation2D().getViewport(),
184 getViewInformation2D().getVisualizedPage(),
185 getViewInformation2D().getViewTime(),
186 getViewInformation2D().getExtendedInformationSequence());
187 updateViewInformation(aViewInformation2D);
189 // process content
190 process(rTransformCandidate.getChildren());
192 // restore transformations
193 updateViewInformation(aLastViewInformation2D);
195 break;
198 // ignorable primitives
199 case PRIMITIVE2D_ID_SCENEPRIMITIVE2D :
200 case PRIMITIVE2D_ID_WRONGSPELLPRIMITIVE2D :
201 case PRIMITIVE2D_ID_MARKERARRAYPRIMITIVE2D :
202 case PRIMITIVE2D_ID_POINTARRAYPRIMITIVE2D :
203 case PRIMITIVE2D_ID_BITMAPPRIMITIVE2D :
204 case PRIMITIVE2D_ID_METAFILEPRIMITIVE2D :
205 case PRIMITIVE2D_ID_MASKPRIMITIVE2D :
207 break;
210 default :
212 // process recursively
213 process(rCandidate);
214 break;
219 TextAsPolygonExtractor2D::TextAsPolygonExtractor2D(const geometry::ViewInformation2D& rViewInformation)
220 : BaseProcessor2D(rViewInformation),
221 maTarget(),
222 maBColorModifierStack(),
223 mnInText(0)
227 TextAsPolygonExtractor2D::~TextAsPolygonExtractor2D()
231 } // end of namespace
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */